mask one array using another array
I am trying to mask one array using another array. I have created a masked array using mask=MA.masked_equal(myarray, 0), that looks something like: [1 - - 1, 1 1 - 1, 1 1 1 1, - 1 - 1] I have an array of values that I want to mask whereever my mask has a a '-'. how do I do this? I have looked at http://www.cawcr.gov.au/bmrc/climdyn/staff/lih/pubs/docs/masks.pdf but the command: d = array(a, mask=c.mask() results in this error: TypeError: 'numpy.ndarray' object is not callable I basically want to do exactly what that article does in that equation. Any feedback will be greatly appreciated.
If your new array is x, you can use:
numpy.ma.masked_array(x, mask=mask.mask)
-=- Olivier
2011/11/21 questions anon
I am trying to mask one array using another array.
I have created a masked array using mask=MA.masked_equal(myarray, 0), that looks something like: [1 - - 1, 1 1 - 1, 1 1 1 1, - 1 - 1]
I have an array of values that I want to mask whereever my mask has a a '-'. how do I do this? I have looked at http://www.cawcr.gov.au/bmrc/climdyn/staff/lih/pubs/docs/masks.pdf but the command:
d = array(a, mask=c.mask()
results in this error: TypeError: 'numpy.ndarray' object is not callable
I basically want to do exactly what that article does in that equation.
Any feedback will be greatly appreciated.
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Excellent, thank you.
I just realised this does not work with my data because of the extra
dimension.
I have a mask that matches my 2-dimensional array but my data is for every
hour over a month so the arrays do not match. Is there a way to make them
match or mask each time?
thanks again
This is some of my code:
for ncfile in files:
if ncfile[-3:]=='.nc':
print "dealing with ncfiles:",
path+ncfile
ncfile=os.path.join(path,ncfile)
ncfile=Dataset(ncfile, 'r+', 'NETCDF4')
TSFC=ncfile.variables['T_SFC'][:]
TIME=ncfile.variables['time'][:]
fillvalue=ncfile.variables['T_SFC']._FillValue
TSFC=MA.masked_values(TSFC, fillvalue)
ncfile.close()
TSFC=MA.masked_array(TSFC,
mask=newmask.mask)
On Tue, Nov 22, 2011 at 11:21 AM, Olivier Delalleau
If your new array is x, you can use:
numpy.ma.masked_array(x, mask=mask.mask)
-=- Olivier
2011/11/21 questions anon
I am trying to mask one array using another array.
I have created a masked array using mask=MA.masked_equal(myarray, 0), that looks something like: [1 - - 1, 1 1 - 1, 1 1 1 1, - 1 - 1]
I have an array of values that I want to mask whereever my mask has a a '-'. how do I do this? I have looked at http://www.cawcr.gov.au/bmrc/climdyn/staff/lih/pubs/docs/masks.pdf but the command:
d = array(a, mask=c.mask()
results in this error: TypeError: 'numpy.ndarray' object is not callable
I basically want to do exactly what that article does in that equation.
Any feedback will be greatly appreciated.
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
I can't really figure out if that's the case in your code, but if you need
to repeat the mask along a new dimension (for instance, the first one), you
can do:
numpy.tile(mask.mask, [number_of_repeats] + [1] * len(mask.mask.shape))
(not sure that's the most elegant way to do it, but it should work)
-=- Olivier
2011/11/21 questions anon
Excellent, thank you. I just realised this does not work with my data because of the extra dimension. I have a mask that matches my 2-dimensional array but my data is for every hour over a month so the arrays do not match. Is there a way to make them match or mask each time? thanks again
This is some of my code:
for ncfile in files: if ncfile[-3:]=='.nc': print "dealing with ncfiles:", path+ncfile ncfile=os.path.join(path,ncfile) ncfile=Dataset(ncfile, 'r+', 'NETCDF4') TSFC=ncfile.variables['T_SFC'][:] TIME=ncfile.variables['time'][:]
fillvalue=ncfile.variables['T_SFC']._FillValue TSFC=MA.masked_values(TSFC, fillvalue) ncfile.close()
TSFC=MA.masked_array(TSFC, mask=newmask.mask)
On Tue, Nov 22, 2011 at 11:21 AM, Olivier Delalleau
wrote: If your new array is x, you can use:
numpy.ma.masked_array(x, mask=mask.mask)
-=- Olivier
2011/11/21 questions anon
I am trying to mask one array using another array.
I have created a masked array using mask=MA.masked_equal(myarray, 0), that looks something like: [1 - - 1, 1 1 - 1, 1 1 1 1, - 1 - 1]
I have an array of values that I want to mask whereever my mask has a a '-'. how do I do this? I have looked at http://www.cawcr.gov.au/bmrc/climdyn/staff/lih/pubs/docs/masks.pdf but the command:
d = array(a, mask=c.mask()
results in this error: TypeError: 'numpy.ndarray' object is not callable
I basically want to do exactly what that article does in that equation.
Any feedback will be greatly appreciated.
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
numpy.tile is what I was after.
Thank you!
On Tue, Nov 22, 2011 at 1:13 PM, Olivier Delalleau
I can't really figure out if that's the case in your code, but if you need to repeat the mask along a new dimension (for instance, the first one), you can do:
numpy.tile(mask.mask, [number_of_repeats] + [1] * len(mask.mask.shape))
(not sure that's the most elegant way to do it, but it should work)
-=- Olivier
2011/11/21 questions anon
Excellent, thank you. I just realised this does not work with my data because of the extra dimension. I have a mask that matches my 2-dimensional array but my data is for every hour over a month so the arrays do not match. Is there a way to make them match or mask each time? thanks again
This is some of my code:
for ncfile in files: if ncfile[-3:]=='.nc': print "dealing with ncfiles:", path+ncfile ncfile=os.path.join(path,ncfile) ncfile=Dataset(ncfile, 'r+', 'NETCDF4') TSFC=ncfile.variables['T_SFC'][:] TIME=ncfile.variables['time'][:]
fillvalue=ncfile.variables['T_SFC']._FillValue TSFC=MA.masked_values(TSFC, fillvalue) ncfile.close()
TSFC=MA.masked_array(TSFC, mask=newmask.mask)
On Tue, Nov 22, 2011 at 11:21 AM, Olivier Delalleau
wrote: If your new array is x, you can use:
numpy.ma.masked_array(x, mask=mask.mask)
-=- Olivier
2011/11/21 questions anon
I am trying to mask one array using another array.
I have created a masked array using mask=MA.masked_equal(myarray, 0), that looks something like: [1 - - 1, 1 1 - 1, 1 1 1 1, - 1 - 1]
I have an array of values that I want to mask whereever my mask has a a '-'. how do I do this? I have looked at http://www.cawcr.gov.au/bmrc/climdyn/staff/lih/pubs/docs/masks.pdf but the command:
d = array(a, mask=c.mask()
results in this error: TypeError: 'numpy.ndarray' object is not callable
I basically want to do exactly what that article does in that equation.
Any feedback will be greatly appreciated.
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
participants (2)
-
Olivier Delalleau
-
questions anon