EnesYildirim / netcdf4-python

Automatically exported from code.google.com/p/netcdf4-python
Other
0 stars 0 forks source link

Saving netCDF from opendap connection #154

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi Jeff :)

I use latest version of netcdf4-python on Windows XP.

With it I connect to gfs dataset from grads data server. It reports netcdf3.
Now I want to store some of this data on my PC. Preferably in netCDF as most 
readers can handle it, but I can also use hdf5, as it's easier for me to make 
new dataset. For example, right now I do this after creating new nc dataset:

 - create dimensions (name and shape)
 - create variables for these dimensions (name, datatype, dimension)
 - set units
 - fill these variables with right data, and finally
 - store the variable data I'm interested in

This is the first time I tried to create nc dataset, and I wonder is there is 
easier way to slice data from opendap netcdf dataset to which I'm connected, 
without doing all above steps?

Thanks

Original issue reported on code.google.com by klo...@gmail.com on 23 Dec 2012 at 4:32

GoogleCodeExporter commented 8 years ago
You could use the nc3tonc4 utility to copy the entire dataset to a local file 
like this

nc3tonc4 <opendap URL> <local filename>

Original comment by josh.n.w...@gmail.com on 23 Dec 2012 at 7:45

GoogleCodeExporter commented 8 years ago
Dataset is huge as a whole, it's gfs product - it covers whole world and has 
many many variables

Thanks for the tip anyway, I just wanted to make sure there isn't easier way

Original comment by klo...@gmail.com on 23 Dec 2012 at 8:08

GoogleCodeExporter commented 8 years ago
I just updated nc3tonc4 in svn to take an extra command line arg 'vars', which 
is a comma separated list of variable names to copy.  If you use that, it will 
copy just those variables, plus all the dimension variables.  With a little 
more work, I could add subsetting by dimension variables (lat/lon) if it's 
needed.

Original comment by josh.n.w...@gmail.com on 24 Dec 2012 at 2:30

GoogleCodeExporter commented 8 years ago
Great, thanks for initiating this.
I tried to make slicing, and here is what I made: 
https://gist.github.com/b97e95f9529293dc8b35

Works for me :)

PS. I also took a liberty to do PEP8 corrections

Original comment by klo...@gmail.com on 24 Dec 2012 at 10:47

GoogleCodeExporter commented 8 years ago

Original comment by whitaker.jeffrey@gmail.com on 26 Feb 2014 at 2:04