aodn / python-aodntools

Repository for templates and code relating to generating standard NetCDF files for the Australia Ocean Data Network
GNU Lesser General Public License v3.0
10 stars 3 forks source link

_FillValues attribute doesn't seem to be handled properly #5

Closed lbesnard closed 6 years ago

lbesnard commented 6 years ago
from ncwriter import DatasetTemplate
import numpy as np

template = DatasetTemplate.from_json('test_ncwriter/template1.json')
template.variables[u"TEST"] = {
    "dimensions": ["TIME"],
    "type": "float32",
    "attributes": {
        "standard_name": "sea_water_temperature",
        "units": "degC",
        "valid_min": 0.0,
        "valid_max": 42.00,
        "_FillValue":-999.9
    }
}
template.variables['TIME']['values'] = np.arange(10)
template.variables['DEPTH']['values'] = np.arange(10)
del(template.variables['TEMP'])

template.variables['TEST']['values'] = np.array([-999.9, -999.9, -999.9, -999.9, -999.9, 12.6, 12.7, 12.8, 12.9, 13.0])

template.to_netcdf('example2.nc')

This generates a example2.nc file. with a TEST variable containing a np.array(unmasked) with a _FillVlaue attribute. Checking the file afterwards, the _FillValue attribute disappears. And the values aren't being masked as they should.

ocehugo commented 6 years ago

Test required!

mhidas commented 6 years ago

@lbesnard I have fixed this in #7 if you'd care to review?

lbesnard commented 6 years ago

thx. will check this today