Author Topic: NC file  (Read 4235 times)

0 Members and 1 Guest are viewing this topic.

Offline jdgayles16

  • QuantumATK Guru
  • ****
  • Posts: 108
  • Reputation: 0
    • View Profile
NC file
« on: July 12, 2010, 22:56 »
How does one get rid of information in a nc file?

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5575
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: NC file
« Reply #1 on: July 13, 2010, 00:03 »
There is no "delete" function (yet, maybe one will appear later), but you can just copy all the stuff you want to keep to a new file. The basic workflow is: get all the "object_ids" from the file, read all these quantities, figure out which to keep and not, and write those you want to keep to a new NC file. Simple code (hope you get the idea):
Code: python
old_filename = 'analysis.nc'
new_filename = 'analysis2.nc'
delete_these = ['gID001']
#-------------------------------------------------
from NL.IO.NLSaveUtilities import nlinspect
objs = nlinspect(old_filename)
all_ids = [i[1] for i in objs]
for id in all_ids:
    print id,
    if id in delete_these:
        print 'skippping'
    else:
        print 'including'
        obj = nlread(old_filename,object_id=id)[0]
        nlsave(new_filename,obj,object_id=id)
Inspecting the object_ids to find out which to keep or remove is most easily done in VNL. Note: the script above uses the undocumented function nlinspect; you can not trust its interface to remain constant in future editions of ATK, but for now it works this way. Play around with it!
« Last Edit: July 13, 2010, 00:05 by Anders Blom »

Offline jdgayles16

  • QuantumATK Guru
  • ****
  • Posts: 108
  • Reputation: 0
    • View Profile
Re: NC file
« Reply #2 on: July 13, 2010, 06:18 »
Cool thanks i was thinking of doing something similar, but i didnt want to have to move everything, thanks