Re: Passing field to a function

From: David Ian Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Mon, 4 Dec 2006 18:22:01 -0700

Hi Jesper,
I am not totally sure I understand your questions completely, but here
is my attempt at an answer.
Assuming you have done something such as the folllowing:

f = Nio.open_file("testfile.grb")
v = f.variables['TMP']
f = []

I can say that setting the variable 'f' to an empty list does not close
the file,
and therefore 'v' is still a viable NioVariable object that can be used
access all that is known about the variable 'TMP' inside the file. Even
you can no longer access the NioFile object variable, Python does not
get rid
of it, because 'v' (I believe) contains a reference to it.
When you print v, you get metadata associated with v. The dimensions
coordinate variables that are printed along with v are not Python
that would need to be garbage-collected. They are simply part of the
that is obtained from the file and for the most part cached by the now
file object. I believe the file object reference will be
garbage-collected when the
variable object is deleted either through reassignment of variable 'v'
or by some
other means.

Note however, that removing a file reference by reassignment does not
that the file is closed by the operating system. In cases where a
great many
files are accessed this could eventually lead to the file system giving
an 'out of
file descriptors' error message. The proper way to close a file after
you are
done with it is to call
Only after this call should you normally reassign the NioFile object

However, for NetCDF files you can ensure the file gets closed after
every operation
by setting the "SafeMode" option to True. For other file types, the
file is always closed
by the Nio library after each operation.

On Nov 29, 2006, at 4:03 AM, Jesper Larsen wrote:

> Hi PyNIO and PyNGL users,
> I have an application in which I would like to pass a single
> NioVariable to a
> function. In the function I also have to use some dimension
> NioVariable and
> therefore pass them in as well. However, if I only keep my NioVariable
> (nv)
> and set the parent NioFile object to [] and subsequently
> print nv
> it prints the dimensions as well - even though they are deleted. It
> therefore
> seems like nv has kept a reference to the parent NioFile object and
> children
> dimension NioVariables (and thus prevented them from being garbage
> collected).
> My question is: Is it possible and advisable to only pass my
> NioVariable (nv)
> into my function and use the reference to the parent NioFile object
> (which I
> can't find - but maybe you can tell me how to find it) to retrieve the
> dimension NioVariables that I need as well? And how do I do that?
> Regards,
> Jesper
> _______________________________________________
> pyngl-talk mailing list

pyngl-talk mailing list
Received on Mon Dec 04 2006 - 18:22:01 MST

This archive was generated by hypermail 2.2.0 : Tue Dec 05 2006 - 13:30:16 MST