I am loading a few variables from a netcdf (.nc) file using python scipy.io.netcdf module. In the file that I am loading them from, missing data have a filler value of 99999, which I want to change to np.nan from numpy.
Once I have imported a variable and assigned it to a numpy array however, I can't clean up the 99999 filler values because I get:
RuntimeError: array is not writeable
I have attempted to change the attribute of the array writeable to True but that returns:
ValueError: cannot set WRITEABLE flag to True of this array
So I am at a loss. A simplified version of my code and a couple example outputs are below. Does anyone have any suggestions here? Originally I was using netCDF4 rather than scipy.io.netcdf and in that case I would set nc.set_auto_mask(False) however I haven't seen an analogous property in scipy.io so I have just left that out.
Sample code:
import scipy.io as sio
import numpy as np
nc = sio.netcdf.netcdf_file('filename.nc','r') # open file
arr = nc.variables['PARAMETER'][:] # load into np array
output_arr = cleanarr(arr) # replace filler 99999 vals with np.nan
nc.close()
Worth noting is it doesn't seem to matter if I do nc.close() before or after cleanarr(arr)
Sample outputs:
type(arr)
<type 'numpy.ndarray'>
arr.flags
C_CONTIGUOUS : True
F_CONTIGUOUS : False
OWNDATA : False
WRITEABLE : False
ALIGNED : True
UPDATEIFCOPY : False