ryanjdillon - 7 months ago 46

Python Question

**Question:**

Is there a way of forcing

`netCDF4`

I have a netCDF dataset of values on a grid, over time that I read using the

`netCDF4`

`nc_data = netCDF4.Dataset('file.nc', 'r')`

The initial timesteps yield masked arrays:

`var1_t0 = nc_data.variables['var1'][0][:]`

var1_t0

masked_array(...)

The later timesteps yield standard

`ndarrays`

`var1_t200 = nc_data.variables['var1'][200][:]`

var1_t200

ndarray(...)

I would like masked arrays for the latter with a mask of all

`False`

Answer

I don't think this is directly possible, but you can work it around by creating a `masked_array`

if necessary:

```
var1_t0 = nc_data.variables['var1'][0][:]
if type(v) !== numpy.ma.core.MaskedArray:
var1_t0 = numpy.ma.core.MaskedArray(m, numpy.zeros(m.shape, dtype = bool))
```