Closed
Description
openedon Aug 21, 2023
hi! the following gives a confusing result:
import netCDF4 as nc
import numpy as np
import numpy.ma as ma
ds = nc.Dataset('lal.nc', "w")
dim = ds.createDimension('time', 48)
var = ds.createVariable('blaat', np.uint8, ('time',),
zlib=True, complevel=4, shuffle=True, fletcher32=True,
fill_value=240)
mask = np.full((48,), False)
for x in range(30):
mask[x] = True
mama = ma.array(np.full((48,), True), mask=mask)
#mama = ma.array(np.zeros((48,)), mask=mask)
print('masked elems', np.count_nonzero(mama.mask))
var[:] = mama
print('created var', var)
print('masked output', np.count_nonzero(var[:].mask))
leading to the following output:
masked elems 30
created var <class 'netCDF4._netCDF4.Variable'>
uint8 blaat(time)
_FillValue: 240
unlimited dimensions:
current shape = (48,)
filling on
masked output 0
so in the end, nothing is masked, even though a mask is passed with 30 masked elements..
interestingly, when swapping the commented line with the above (so passing ints instead of bools as data), it does work fine.
so it appears that when converting from bool to uint8, the mask gets lost..?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Metadata
Assignees
Labels
No labels