Problem with scale_factor and off_set with opening netCDF file
12 views (last 30 days)
Show older comments
I downloaded netcdf data and opened it in matlab, when I have done this in previous times the scale_factor =1 and add_offset=0 and the data is int32
In this new file I downloaded I get the following (the code is exactly the same):
scale_factor = 1.298e-05
add_offset = 0.50271
The values should be between 0 and 1 and instead I get really high and low numbers
I am not really sure what to do in order to get the scale factor and offset to the right values again, also the data is int16
0 Comments
Answers (1)
Shushant
on 16 Feb 2023
My understanding of your problem is that when you previously read a netcdf data file you got the “scale_factor” as 1 and “add_offset” as 0 and datatype was int32. But when you downloaded a new file having datatype as int16 and ran the same code again you got a different value for “scale_factor” and “add_offset”. And that you are getting a really high and low numbers which I assume is the value of your data inside the netcdf file and not the “scale_factor/add_offset” as they are already in the range of 0 and 1. The main aim of your problem is getting correct values of “scale_factor” and “add_offset” again.
When reading NetCDF data in MATLAB using the “ncread” the MATLAB automatically finds the best match for the data file and applies both the “scale_factor” and “add_offset”. So, the change in the datatype of the file is reflected on the values of “scale_factor” and “add_offset”. This is the reason you might be getting different values as the file format is different (int32 and int16). Check out this documentation (vardata – variable and More About section).
You can always normalize the data after reading it from the file by scaling and setting offset based on your requirements.
See Also
Categories
Find more on NetCDF in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!