0

I'm trying to convert from netCDF4 to scipy.io netcdf as the web page the program is going onto doesn't have the module netCDF4.

The program works perfectly well in netCDF4 retrieving values from a file for temperatures in degK giving me values such as:

[[ 258.77999878  258.77999878  258.77999878 ...,  258.77999878
258.77999878  258.77999878]
 [ 259.29998779  259.54998779  259.82000732 ...,  258.3500061
258.70001221  258.97000122]
 [ 264.1000061   264.47000122  264.82000732 ...,  262.40002441
263.04998779  263.6000061 ]].

However when using scipy.io netcdf and the same file used in the netCDF4. The program runs it should again give values of temperature in degK but the values come out as:

[[-25403 -25403 -25403 ..., -25403 -25403 -25403]
 [-25351 -25326 -25299 ..., -25446 -25411 -25384]
 [-24871 -24834 -24799 ..., -25041 -24976 -24921]].

I was just wondering if anyone has come across this problem before and how you solve it so that the scipy.io netcdf program will give the same values.

1 Answer 1

3

First off, you need to distinguish wether you are reading a netCDF-3 or netCDF-4 file. The scipy.io.netcdf module can only read netCDF-3, so if it's a netCDF-4 file, then you are out of luck. Not that the difference is that netCDF-4 files use HDF-5 as the file storage. That said, it looks like it read in something from your file, so it's likely that you have a netCDF-3 file.

If this is the case, you will need to look for "scale" and "offset" attributes on your temperature variable and apply those directly when using scipy.io.netcdf. The netCDF-4-python module automagically looks for these attributes and applies them 'behind the scenes' for you, which is why your data look ok when going through that module.

Cheers,

Sean

Sign up to request clarification or add additional context in comments.

1 Comment

OP can probably also use netCDF.Dataset('file.nc', 'w', format='NETCDF3_CLASSIC') when working locally, and then the file will b correctly readable by scipy.io.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.