I am trying to port some code from scipy.io.netcdf_file to netCDF4.Dataset. I have encountered an issue which is pretty significant for me. netCDF4.Dataset expects a string as its argument and is unable to accept an open file object. The issue can be seen in the following code
import netCDF4 from scipy.io import netcdf_file fobj = open('MODIS.nc', 'rb') nc3 = netcdf_file(fobj) fobj.close() fobj = open('MODIS.nc', 'rb') nc4 = netCDF4.Dataset(fobj) # this fails fobj.close()
The second-to-last line raises
TypeError: expected string or Unicode object, file found
This may seem like an unnecessary feature (why not just pass the filename directly), but the problem is that I have a large archive of bzipped netcdf files on disk. The way I usually read them is
import bz2 bz2_fobj = bz2.BZ2File('MODIS.nc.bz2') nc3 = netcdf_file(bz2_fobj)
If I can't do this with netCDF4, I will have do design a clumsy workaround involving system commands to manually unzip the files.
I considered tying to add this feature myself, but then I realized that the whole library was written in C. Hopefully you will consider adding support for reading file objects.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4