QuantumATK Forum

QuantumATK => General Questions and Answers => Topic started by: jdgayles16 on July 12, 2010, 22:56

Title: NC file
Post by: jdgayles16 on July 12, 2010, 22:56
How does one get rid of information in a nc file?
Title: Re: NC file
Post by: Anders Blom 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!
Title: Re: NC file
Post by: jdgayles16 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