Unidata / netcdf4-python

netcdf4-python: python/numpy interface to the netCDF C library
http://unidata.github.io/netcdf4-python
MIT License
754 stars 262 forks source link

python library incorrectly masking values? #932

Closed zaidrenteria closed 5 years ago

zaidrenteria commented 5 years ago

https://www.ncei.noaa.gov/data/avhrr-land-normalized-difference-vegetation-index/access/2015/AVHRR-Land_v004_AVH13C1_NOAA-19_20150102_c20150730112535.nc

In the above file many subsets of data appear to be masked but when I convert files using ArcGIS software there are no mask values.

For example doing the following:

f = Dataset(r"E:\AVHRR_New\2015\AVHRR-Land_v004_AVH13C1_NOAA-19_20150102_c20150730112535.nc")

ndvi = f["NDVI"]

values = ndvi[0,820:823,1150:1153]

values
Out[5]: 
masked_array(
  data=[[--, --, --],
        [--, --, --],
        [--, --, --]],
  mask=[[ True,  True,  True],
        [ True,  True,  True],
        [ True,  True,  True]],
  fill_value=-9999,
  dtype=float64)

However, the same array area in ArcGIS does show values as well as accessing the same in Matlab.

Any help would be appreciated

jswhit commented 5 years ago

netcdf4-python returns a masked array by default with invalid or missing values masked. In this example, the values are outside the valid_range (-1000 to 10000). You can turn this off using the set_auto_maskandscale Dataset method. For example,

f.set_auto_maskandscale(False)
ndvi = f["NDVI"]
ndvi[0,820:823,1150:1153]

[[-1896 -2002 -2002]
 [-2058 -2061 -1846]
 [-1841 -1774 -2086]]

Note that those values are less than -1000, so are considered invalid and are masked.

zaidrenteria commented 5 years ago

Thanks a lot! I appreciate the quit feedback