本文整理汇总了Python中numpy.ma.make_mask函数的典型用法代码示例。如果您正苦于以下问题:Python make_mask函数的具体用法?Python make_mask怎么用?Python make_mask使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_mask函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: regions
def regions(cube,clim=False,maxf=True):
mons = 4
lag = 1
max_i = 35 + lag
max_f = max_i + mons
min_i = 11 + lag
min_f = min_i + mons
if maxf:
forc_i = max_i
forc_f = max_f
else:
forc_i = min_i
forc_f = min_f
if clim:
cube_max = cube.collapsed('time',iris.analysis.MEAN)
else:
cube_max = cube[forc_i:forc_f,:,::].collapsed('time',iris.analysis.MEAN)
# cube_anom = cube-cube_mean
cube_max.coord('latitude').guess_bounds()
cube_max.coord('longitude').guess_bounds()
print cube_max.shape
# ---------- define sst/tland----------
lsmask = iris.load_cube(ncfile_path + 'lsmask.nc')[0,0,::]
landmask = ~(ma.make_mask(lsmask.data.copy()) + np.zeros(cube_max.shape)).astype(bool) # mask sea, show land
# mask out the enso region: masked = 1, not masked = 0
# mask from x = 43:73, y = 32:40
enso_mask = np.zeros(cube_max.shape)
enso_mask[0,30:42,43:75] = 1
seamask = (ma.make_mask(lsmask.data.copy()) + np.zeros(cube_max.shape) + enso_mask).astype(bool) # mask land, show sea
Cocean = cube_max.copy()
Cland = cube_max.copy()
Cocean.data = ma.array(Cocean.data, mask=seamask)
Cland.data = ma.array(Cland.data, mask=landmask)
# --------------
land_cube = Cland
ocean_cube = Cocean
oclat10, oclat10_mean = regmean(ocean_cube,loni=0,lonf=360,lati=-10,latf=10)
oclatp20, oclatp20_mean = regmean(ocean_cube,loni=0,lonf=360,lati=10,latf=20)
oclatm20, oclatm20_mean = regmean(ocean_cube,loni=0,lonf=360,lati=-20,latf=-10)
oclatp30, oclatp30_mean = regmean(ocean_cube,loni=0,lonf=360,lati=20,latf=30)
oclatm30, oclatm30_mean = regmean(ocean_cube,loni=0,lonf=360,lati=-30,latf=-20)
lat10, lat10_mean = regmean(land_cube,loni=0,lonf=360,lati=-10,latf=10)
latp20, latp20_mean = regmean(land_cube,loni=0,lonf=360,lati=10,latf=20)
latm20, latm20_mean = regmean(land_cube,loni=0,lonf=360,lati=-20,latf=-10)
latp30, latp30_mean = regmean(land_cube,loni=0,lonf=360,lati=20,latf=30)
latm30, latm30_mean = regmean(land_cube,loni=0,lonf=360,lati=-30,latf=-20)
# lat20mean = latp20
return [oclat10_mean, lat10_mean, oclatp20_mean, latp20_mean, oclatm20_mean, latm20_mean, oclatp30_mean, latp30_mean, oclatm30_mean, latm30_mean]
开发者ID:nltyrrell,项目名称:pacemaker,代码行数:56,代码来源:oc_ln_varresponse.py
示例2: regions
def regions(cube,clim=False,maxf=True):
mons = 4
lag = 1
max_i = 35 + lag
max_f = max_i + mons
min_i = 11 + lag
min_f = min_i + mons
if maxf:
forc_i = max_i
forc_f = max_f
else:
forc_i = min_i
forc_f = min_f
if clim:
cube_max = cube.collapsed('time',iris.analysis.MEAN)
else:
cube_max = cube[forc_i:forc_f,:,::].collapsed('time',iris.analysis.MEAN)
# cube_anom = cube-cube_mean
cube_max.coord('latitude').guess_bounds()
cube_max.coord('longitude').guess_bounds()
print cube_max.shape
# ---------- define sst/tland----------
lsmask = iris.load_cube(ncfile_path + 'lsmask.nc')[0,0,::]
landmask = ~(ma.make_mask(lsmask.data.copy()) + np.zeros(cube_max.shape)).astype(bool) # mask sea, show land
seamask = (ma.make_mask(lsmask.data.copy()) + np.zeros(cube_max.shape)).astype(bool) # mask land, show sea
Cocean = cube_max.copy()
Cland = cube_max.copy()
Cocean.data = ma.array(Cocean.data, mask=seamask)
Cland.data = ma.array(Cland.data, mask=landmask)
# --------------
land_cube = Cland
India, India_mean = regmean(land_cube,loni=60,lonf=75,lati=0,latf=30)
MC, MC_mean = regmean(land_cube,loni=90,lonf=140,lati=-10,latf=10)
TropSthAm, TropSthAm_mean = regmean(land_cube,loni=290,lonf=315,lati=-23,latf=0)
SthSthAm, SthSthAm_mean = regmean(land_cube,loni=270,lonf=315,lati=-60,latf=-24)
NthWestAfr, NthWestAfr_mean = regmean(land_cube,loni=-15,lonf=15,lati=10,latf=30)
NthEastAfr, NthEastAfr_mean = regmean(land_cube,loni=15,lonf=50,lati=10,latf=30)
TropAfr, TropAfr_mean = regmean(land_cube,loni=12,lonf=40,lati=-15,latf=5)
SthAfr, SthAfr_mean = regmean(land_cube,loni=12,lonf=40,lati=-35,latf=-15)
Aus, Aus_mean = regmean(land_cube,loni=120,lonf=140,lati=-30,latf=-17)
lat10, lat10_mean = regmean(land_cube,loni=0,lonf=360,lati=-10,latf=10)
latp20, latp20_mean = regmean(land_cube,loni=0,lonf=360,lati=10,latf=20)
latm20, latm20_mean = regmean(land_cube,loni=0,lonf=360,lati=-20,latf=-10)
latp30, latp30_mean = regmean(land_cube,loni=0,lonf=360,lati=20,latf=30)
latm30, latm30_mean = regmean(land_cube,loni=0,lonf=360,lati=-30,latf=-20)
# lat20mean = latp20
return [India_mean , MC_mean , TropSthAm_mean , SthSthAm_mean , NthWestAfr_mean , NthEastAfr_mean, TropAfr_mean, SthAfr_mean, Aus_mean, lat10_mean, latp20_mean, latm20_mean, latp30_mean, latm30_mean]
开发者ID:nltyrrell,项目名称:pacemaker,代码行数:55,代码来源:regional_response.py
示例3: test_testCopySize
def test_testCopySize(self):
# Tests of some subtle points of copying and sizing.
n = [0, 0, 1, 0, 0]
m = make_mask(n)
m2 = make_mask(m)
assert_(m is m2)
m3 = make_mask(m, copy=1)
assert_(m is not m3)
x1 = np.arange(5)
y1 = array(x1, mask=m)
assert_(y1._data is not x1)
assert_(allequal(x1, y1._data))
assert_(y1._mask is m)
y1a = array(y1, copy=0)
# For copy=False, one might expect that the array would just
# passed on, i.e., that it would be "is" instead of "==".
# See gh-4043 for discussion.
assert_(y1a._mask.__array_interface__ ==
y1._mask.__array_interface__)
y2 = array(x1, mask=m3, copy=0)
assert_(y2._mask is m3)
assert_(y2[2] is masked)
y2[2] = 9
assert_(y2[2] is not masked)
assert_(y2._mask is m3)
assert_(allequal(y2.mask, 0))
y2a = array(x1, mask=m, copy=1)
assert_(y2a._mask is not m)
assert_(y2a[2] is masked)
y2a[2] = 9
assert_(y2a[2] is not masked)
assert_(y2a._mask is not m)
assert_(allequal(y2a.mask, 0))
y3 = array(x1 * 1.0, mask=m)
assert_(filled(y3).dtype is (x1 * 1.0).dtype)
x4 = arange(4)
x4[2] = masked
y4 = resize(x4, (8,))
assert_(eq(concatenate([x4, x4]), y4))
assert_(eq(getmask(y4), [0, 0, 1, 0, 0, 0, 1, 0]))
y5 = repeat(x4, (2, 2, 2, 2), axis=0)
assert_(eq(y5, [0, 0, 1, 1, 2, 2, 3, 3]))
y6 = repeat(x4, 2, axis=0)
assert_(eq(y5, y6))
开发者ID:numpy,项目名称:numpy,代码行数:50,代码来源:test_old_ma.py
示例4: MakeFrameMask
def MakeFrameMask(data,frame):
pixelSize = data['pixelSize']
scalex = pixelSize[0]/1000.
scaley = pixelSize[1]/1000.
blkSize = 512
Nx,Ny = data['size']
nXBlks = (Nx-1)/blkSize+1
nYBlks = (Ny-1)/blkSize+1
tam = ma.make_mask_none(data['size'])
for iBlk in range(nXBlks):
iBeg = iBlk*blkSize
iFin = min(iBeg+blkSize,Nx)
for jBlk in range(nYBlks):
jBeg = jBlk*blkSize
jFin = min(jBeg+blkSize,Ny)
nI = iFin-iBeg
nJ = jFin-jBeg
tax,tay = np.mgrid[iBeg+0.5:iFin+.5,jBeg+.5:jFin+.5] #bin centers not corners
tax = np.asfarray(tax*scalex,dtype=np.float32)
tay = np.asfarray(tay*scaley,dtype=np.float32)
tamp = ma.make_mask_none((1024*1024))
tamp = ma.make_mask(pm.polymask(nI*nJ,tax.flatten(),
tay.flatten(),len(frame),frame,tamp)[:nI*nJ])-True #switch to exclude around frame
if tamp.shape:
tamp = np.reshape(tamp[:nI*nJ],(nI,nJ))
tam[iBeg:iFin,jBeg:jFin] = ma.mask_or(tamp[0:nI,0:nJ],tam[iBeg:iFin,jBeg:jFin])
else:
tam[iBeg:iFin,jBeg:jFin] = True
return tam.T
开发者ID:svaksha,项目名称:pyGSAS,代码行数:29,代码来源:GSASIIimage.py
示例5: bit_pixels
def bit_pixels(bit_shape="cylinder", diameter=3):
radius = diameter / 2.0
if diameter % 2:
size = diameter
x, y = mgrid[:size, :size]
x = x + 0.5
y = y + 0.5
else:
size = diameter + 1
x, y = mgrid[:size, :size]
sphere = (x - radius) ** 2 + (y - radius) ** 2
circle_mask = ma.make_mask(sphere > radius ** 2) # true when outside the circle
high = ones(circle_mask.shape) * 10000
if bit_shape in ["cylinder", "ball", "sphere"]:
if bit_shape == "cylinder":
output = circle_mask * high
else:
# print "test"
output = (circle_mask == False) * sphere + circle_mask * high
elif bit_shape.startswith("v"):
angle = float(bit_shape[1:]) / 2.0
angle = radians(90 - angle)
step = tan(angle)
cone = sqrt(sphere) * step
output = (circle_mask == False) * cone + circle_mask * high
return output
开发者ID:nathanielstenzel,项目名称:bucket_mill,代码行数:26,代码来源:bucket_mill.py
示例6: regions
def regions(cube,clim=False,maxf=True, maskprint=False):
mons = 4
lag = 1
max_i = 35 + lag
max_f = max_i + mons
min_i = 11 + lag
min_f = min_i + mons
if maxf:
forc_i = max_i
forc_f = max_f
else:
forc_i = min_i
forc_f = min_f
if clim:
cube_max = cube.collapsed('time',iris.analysis.MEAN)
else:
cube_max = cube[forc_i:forc_f,:,::].collapsed('time',iris.analysis.MEAN)
# cube_anom = cube-cube_mean
cube_max.coord('latitude').guess_bounds()
cube_max.coord('longitude').guess_bounds()
print cube_max.shape
# ---------- define sst/tland----------
lsmask = iris.load_cube(ncfile_path + 'lsmask.nc')[0,0,::]
landmask = ~(ma.make_mask(lsmask.data.copy()) + np.zeros(cube_max.shape)).astype(bool) # mask sea, show land
# mask out the enso region: masked = 1, not masked = 0
# mask from x = 43:73, y = 32:40
enso_mask = np.zeros(cube_max.shape)
enso_mask[:,20:56,43:75] = 1
seamask = (ma.make_mask(lsmask.data.copy()) + np.zeros(cube_max.shape) + enso_mask).astype(bool) # mask land, show sea
# if maskprint:
ocean_cube = cube_max.copy()
land_cube = cube_max.copy()
ocean_cube.data = ma.array(ocean_cube.data, mask=seamask)
land_cube.data = ma.array(land_cube.data, mask=landmask)
# --------------
oc_zonmean = ocean_cube.collapsed(['longitude'],
iris.analysis.MEAN)
ln_zonmean = land_cube.collapsed(['longitude'],
iris.analysis.MEAN)
return [oc_zonmean, ln_zonmean]
开发者ID:nltyrrell,项目名称:pacemaker,代码行数:47,代码来源:zon_response.py
示例7: downsample_to_bit_diameter
def downsample_to_bit_diameter(image, scale, bit_diameter, bit="square"):
# print image.shape
bit_diameter = int(bit_diameter)
height, width = image.shape
scaled_width = width * scale
scaled_height = height * scale
output = zeros((scaled_height, scaled_width), dtype=integer)
# coordinates are height,width
print "output is %s" % str(output.shape)
print "target width, target height, scale = ", scaled_width, scaled_height, scale
# print "downsample_to_bit_diamter width=%i height=%i" % (width,height)
# print "downsample_to_bit_diameter shape:", output.shape
# print len(image[::bit_diameter,::bit-_diameter].tolist()[0])
# print "bit_diameter:",bit_diameter
for y in range(int(scaled_height)):
for x in range(int(scaled_width)):
# print "%s:%s,%s:%s = %s" % ( (y)/scale,(y+bit_diameter)/scale,x/scale,(x+bit_diameter)/scale,amax(image[(y)/scale:(y+bit_diameter)/scale,x/scale:(x+bit_diameter)/scale]))
left = (x - bit_diameter / 2) / scale
right = (x + bit_diameter / 2 + 1) / scale
top = (y - bit_diameter / 2) / scale
bottom = (y + bit_diameter / 2 + 1) / scale
if bit == "square":
left = max(left, 0)
right = min(right, width)
top = max(top, 0)
bottom = min(bottom, height)
# this line will have to be a bit more precise for final cuts
output[y, x] = amax(image[top:bottom, left:right])
else:
# print "-"*80
# print left,right,top,bottom, "at %s,%s" % (y,x)
my, mx = mgrid[top:bottom, left:right]
mask_for_bit_check = ma.make_mask((mx >= 0) * (mx < width) * (my >= 0) * (my < height))
left = max(left, 0)
right = min(right, width)
top = max(top, 0)
bottom = min(bottom, height)
surface_subset = image[top:bottom, left:right]
# print "surface:",surface_subset
surface_subset = surface_subset.flatten()
bit_subset = extract(mask_for_bit_check, bit)
# print "surface:",surface_subset.tolist()
# print "bit:",bit_subset.tolist()
# print dir(bit_subset)
# print "image:",surface_subset.shape,"vs","bit:",bit_subset.shape
try:
output[y, x] = amax(surface_subset - bit_subset)
except:
print mask_for_bit_check.sum()
raise
# print "result:",output[y,x]
# if I save that range instead of doing amax on it, I could:
# 1. do amax on it for zigzag or trace cuts
# or
# 2. subtract a grid of values from it where 0 is the tip of the bit and then amax the result
# how do I get a grid that represents the shape of the bit?
# will that affect the speed too much?
# print "downsample_to_bit_diameter shape:", output.shape
return output
开发者ID:nathanielstenzel,项目名称:bucket_mill,代码行数:59,代码来源:bucket_mill.py
示例8: test_testCopySize
def test_testCopySize(self):
# Tests of some subtle points of copying and sizing.
n = [0, 0, 1, 0, 0]
m = make_mask(n)
m2 = make_mask(m)
assert_(m is m2)
m3 = make_mask(m, copy=1)
assert_(m is not m3)
x1 = np.arange(5)
y1 = array(x1, mask=m)
assert_(y1._data is not x1)
assert_(allequal(x1, y1._data))
assert_(y1.mask is m)
y1a = array(y1, copy=0)
assert_(y1a.mask is y1.mask)
y2 = array(x1, mask=m3, copy=0)
assert_(y2.mask is m3)
assert_(y2[2] is masked)
y2[2] = 9
assert_(y2[2] is not masked)
assert_(y2.mask is m3)
assert_(allequal(y2.mask, 0))
y2a = array(x1, mask=m, copy=1)
assert_(y2a.mask is not m)
assert_(y2a[2] is masked)
y2a[2] = 9
assert_(y2a[2] is not masked)
assert_(y2a.mask is not m)
assert_(allequal(y2a.mask, 0))
y3 = array(x1 * 1.0, mask=m)
assert_(filled(y3).dtype is (x1 * 1.0).dtype)
x4 = arange(4)
x4[2] = masked
y4 = resize(x4, (8,))
assert_(eq(concatenate([x4, x4]), y4))
assert_(eq(getmask(y4), [0, 0, 1, 0, 0, 0, 1, 0]))
y5 = repeat(x4, (2, 2, 2, 2), axis=0)
assert_(eq(y5, [0, 0, 1, 1, 2, 2, 3, 3]))
y6 = repeat(x4, 2, axis=0)
assert_(eq(y5, y6))
开发者ID:dreamsxin,项目名称:numpy,代码行数:46,代码来源:test_old_ma.py
示例9: test_hdmedian
def test_hdmedian():
# 1-D array
x = ma.arange(11)
assert_allclose(ms.hdmedian(x), 5, rtol=1e-14)
x.mask = ma.make_mask(x)
x.mask[:7] = False
assert_allclose(ms.hdmedian(x), 3, rtol=1e-14)
# Check that `var` keyword returns a value. TODO: check whether returned
# value is actually correct.
assert_(ms.hdmedian(x, var=True).size == 2)
# 2-D array
x2 = ma.arange(22).reshape((11, 2))
assert_allclose(ms.hdmedian(x2, axis=0), [10, 11])
x2.mask = ma.make_mask(x2)
x2.mask[:7, :] = False
assert_allclose(ms.hdmedian(x2, axis=0), [6, 7])
开发者ID:BranYang,项目名称:scipy,代码行数:18,代码来源:test_mstats_extras.py
示例10: test_testCopySize
def test_testCopySize(self):
# Tests of some subtle points of copying and sizing.
with suppress_warnings() as sup:
sup.filter(
np.ma.core.MaskedArrayFutureWarning,
"setting an item on a masked array which has a "
"shared mask will not copy")
n = [0, 0, 1, 0, 0]
m = make_mask(n)
m2 = make_mask(m)
self.assertTrue(m is m2)
m3 = make_mask(m, copy=1)
self.assertTrue(m is not m3)
x1 = np.arange(5)
y1 = array(x1, mask=m)
self.assertTrue(y1._data is not x1)
self.assertTrue(allequal(x1, y1._data))
self.assertTrue(y1.mask is m)
y1a = array(y1, copy=0)
self.assertTrue(y1a.mask is y1.mask)
y2 = array(x1, mask=m, copy=0)
self.assertTrue(y2.mask is m)
self.assertTrue(y2[2] is masked)
y2[2] = 9
self.assertTrue(y2[2] is not masked)
self.assertTrue(y2.mask is not m)
self.assertTrue(allequal(y2.mask, 0))
y3 = array(x1 * 1.0, mask=m)
self.assertTrue(filled(y3).dtype is (x1 * 1.0).dtype)
x4 = arange(4)
x4[2] = masked
y4 = resize(x4, (8,))
self.assertTrue(eq(concatenate([x4, x4]), y4))
self.assertTrue(eq(getmask(y4), [0, 0, 1, 0, 0, 0, 1, 0]))
y5 = repeat(x4, (2, 2, 2, 2), axis=0)
self.assertTrue(eq(y5, [0, 0, 1, 1, 2, 2, 3, 3]))
y6 = repeat(x4, 2, axis=0)
self.assertTrue(eq(y5, y6))
开发者ID:ContinuumIO,项目名称:numpy,代码行数:44,代码来源:test_old_ma.py
示例11: setup
def setup(self):
"Generic setup"
d = np.arange(5)
m = ma.make_mask([1, 0, 0, 1, 1])
base_d = np.r_[d, d[::-1]].reshape(2, -1).T
base_m = np.r_[[m, m[::-1]]].T
base = ma.array(base_d, mask=base_m)
mrec = mr.fromarrays(base.T,)
dlist = ['2007-%02i' % (i + 1) for i in d]
dates = date_array(dlist)
mts = time_series(mrec, dates)
rts = time_records(mrec, dates)
self.data = [d, m, mrec, dlist, dates, mts, rts]
开发者ID:B-Rich,项目名称:scikits.timeseries-sandbox,代码行数:13,代码来源:test_trecords.py
示例12: Make2ThetaAzimuthMap
def Make2ThetaAzimuthMap(data,masks,iLim,jLim,times): #most expensive part of integration!
'Needs a doc string'
#transforms 2D image from x,y space to 2-theta,azimuth space based on detector orientation
pixelSize = data['pixelSize']
scalex = pixelSize[0]/1000.
scaley = pixelSize[1]/1000.
tay,tax = np.mgrid[iLim[0]+0.5:iLim[1]+.5,jLim[0]+.5:jLim[1]+.5] #bin centers not corners
tax = np.asfarray(tax*scalex,dtype=np.float32)
tay = np.asfarray(tay*scaley,dtype=np.float32)
nI = iLim[1]-iLim[0]
nJ = jLim[1]-jLim[0]
t0 = time.time()
#make position masks here
frame = masks['Frames']
tam = ma.make_mask_none((nI,nJ))
if frame:
tamp = ma.make_mask_none((1024*1024))
tamp = ma.make_mask(pm.polymask(nI*nJ,tax.flatten(),
tay.flatten(),len(frame),frame,tamp)[:nI*nJ])-True #switch to exclude around frame
tam = ma.mask_or(tam.flatten(),tamp)
polygons = masks['Polygons']
for polygon in polygons:
if polygon:
tamp = ma.make_mask_none((1024*1024))
tamp = ma.make_mask(pm.polymask(nI*nJ,tax.flatten(),
tay.flatten(),len(polygon),polygon,tamp)[:nI*nJ])
tam = ma.mask_or(tam.flatten(),tamp)
if tam.shape: tam = np.reshape(tam,(nI,nJ))
spots = masks['Points']
for X,Y,diam in spots:
tamp = ma.getmask(ma.masked_less((tax-X)**2+(tay-Y)**2,(diam/2.)**2))
tam = ma.mask_or(tam,tamp)
times[0] += time.time()-t0
t0 = time.time()
TA = np.array(GetTthAzmG(tax,tay,data)) #includes geom. corr. as dist**2/d0**2 - most expensive step
times[1] += time.time()-t0
TA[1] = np.where(TA[1]<0,TA[1]+360,TA[1])
return np.array(TA),tam #2-theta, azimuth & geom. corr. arrays & position mask
开发者ID:svaksha,项目名称:pyGSAS,代码行数:39,代码来源:GSASIIimage.py
示例13: test_hardmask
def test_hardmask(self):
# Test hardmask
base = self.base.copy()
mbase = base.view(mrecarray)
mbase.harden_mask()
self.assertTrue(mbase._hardmask)
mbase.mask = nomask
assert_equal_records(mbase._mask, base._mask)
mbase.soften_mask()
self.assertTrue(not mbase._hardmask)
mbase.mask = nomask
# So, the mask of a field is no longer set to nomask...
assert_equal_records(mbase._mask, ma.make_mask_none(base.shape, base.dtype))
self.assertTrue(ma.make_mask(mbase["b"]._mask) is nomask)
assert_equal(mbase["a"]._mask, mbase["b"]._mask)
开发者ID:hitej,项目名称:meta-core,代码行数:15,代码来源:test_mrecords.py
示例14: __getitem__
def __getitem__(self, indx):
"""Returns all the fields sharing the same fieldname base.
The fieldname base is either `_data` or `_mask`."""
_localdict = self.__dict__
# We want a field ........
if indx in ndarray.__getattribute__(self, "dtype").names:
obj = self._data[indx].view(TimeSeries)
obj._dates = _localdict["_dates"]
obj._mask = make_mask(_localdict["_mask"][indx])
return obj
# We want some elements ..
obj = TimeSeries.__getitem__(self, indx)
if isinstance(obj, MaskedArray) and not isinstance(obj, TimeSeries):
obj = ndarray.view(obj, MaskedRecords)
return obj
开发者ID:pierregm,项目名称:scikits.timeseries,代码行数:15,代码来源:trecords.py
示例15: test_testPut
def test_testPut(self):
# Test of put
d = arange(5)
n = [0, 0, 0, 1, 1]
m = make_mask(n)
x = array(d, mask=m)
self.assertTrue(x[3] is masked)
self.assertTrue(x[4] is masked)
x[[1, 4]] = [10, 40]
self.assertTrue(x.mask is not m)
self.assertTrue(x[3] is masked)
self.assertTrue(x[4] is not masked)
self.assertTrue(eq(x, [0, 10, 2, -1, 40]))
x = array(d, mask=m)
x.put([0, 1, 2], [-1, 100, 200])
self.assertTrue(eq(x, [-1, 100, 200, 0, 0]))
self.assertTrue(x[3] is masked)
self.assertTrue(x[4] is masked)
开发者ID:8ballbb,项目名称:ProjectRothar,代码行数:19,代码来源:test_old_ma.py
示例16: __setmask__
def __setmask__(self, mask):
"Sets the mask and update the fieldmask."
names = self.dtype.names
fmask = self.__dict__['_fieldmask']
#
if isinstance(mask,ndarray) and mask.dtype.names == names:
for n in names:
fmask[n] = mask[n].astype(bool)
# self.__dict__['_fieldmask'] = fmask.view(recarray)
return
newmask = make_mask(mask, copy=False)
if names is not None:
if self._hardmask:
for n in names:
fmask[n].__ior__(newmask)
else:
for n in names:
fmask[n].flat = newmask
return
开发者ID:8848,项目名称:Pymol-script-repo,代码行数:19,代码来源:mrecords.py
示例17: maskedarray
def maskedarray(self, center, left, right):
# check whether we have enough data left and right:
if len(self.data.shape) > 1:
mask = \
np.zeros((self.data.shape[0], int((right+left)/self.dt)))
maskedarray = \
ma.zeros((self.data.shape[0], int((right+left)/self.dt)))
else:
mask = np.zeros((int((right+left)/self.dt)))
maskedarray = ma.zeros((int((right+left)/self.dt)))
offset = 0
if center - left < 0:
if len(self.data.shape) > 1:
mask[:, :int((left-center)/self.dt)] = 1
else:
mask[:int((left-center)/self.dt)] = 1
leftindex = 0
offset = int((left-center)/self.dt)
else:
leftindex = int((center-left)/self.dt)
if center + right >= len(self.data) * self.dt:
endtime = len(self.data) * self.dt
if len(self.data.shape) > 1:
mask[:, -int((center+right-endtime)/self.dt):] = 1
else:
mask[-int((center+right-endtime)/self.dt):] = 1
rightindex = int(endtime/self.dt)
else:
rightindex = int((center+right)/self.dt)
for timest in range(leftindex, rightindex):
if len(self.data.shape) > 1:
if timest-leftindex+offset < maskedarray.shape[1] and \
timest < self.data.shape[1]:
maskedarray[:, timest-leftindex+offset] = \
self.data[:, timest]
else:
if timest-leftindex+offset < len(maskedarray):
maskedarray[timest-leftindex+offset] = \
self.data[timest]
maskedarray.mask = ma.make_mask(mask)
return Timeseries(maskedarray, self.dt)
开发者ID:410pfeliciano,项目名称:stimfit,代码行数:41,代码来源:stfio_plot.py
示例18: test_testPut
def test_testPut(self):
# Test of put
d = arange(5)
n = [0, 0, 0, 1, 1]
m = make_mask(n)
m2 = m.copy()
x = array(d, mask=m)
assert_(x[3] is masked)
assert_(x[4] is masked)
x[[1, 4]] = [10, 40]
assert_(x._mask is m)
assert_(x[3] is masked)
assert_(x[4] is not masked)
assert_(eq(x, [0, 10, 2, -1, 40]))
x = array(d, mask=m2, copy=True)
x.put([0, 1, 2], [-1, 100, 200])
assert_(x._mask is not m2)
assert_(x[3] is masked)
assert_(x[4] is masked)
assert_(eq(x, [-1, 100, 200, 0, 0]))
开发者ID:numpy,项目名称:numpy,代码行数:21,代码来源:test_old_ma.py
示例19: combine_masks
def combine_masks(imarray, mask_paths, verbose = False, transpose = False):
"""
Takes a list of paths to .npy mask files and returns a numpy array
consisting of those masks ANDed together.
"""
# Initialize the mask based on zero values in imarray.
import numpy.ma as ma
base_mask = ma.make_mask(np.ones(np.shape(imarray)))
base_mask[imarray == 0.] = False
if not mask_paths:
log( "No additional masks provided")
return base_mask
else:
# Data arrays must be transposed here for the same reason that they
# are in data_extractor.
if transpose:
masks = [np.load(path).T for path in mask_paths]
else:
masks = [np.load(path) for path in mask_paths]
log( "Applying mask(s): ", mask_paths)
return base_mask & reduce(lambda x, y: x & y, masks)
开发者ID:hoidn,项目名称:utils,代码行数:21,代码来源:utils.py
示例20: __setmask__
def __setmask__(self, mask):
"Sets the mask and update the fieldmask."
fmask = self.__dict__['_fieldmask']
names = fmask.dtype.names
#
if isinstance(mask,ndarray) and mask.dtype.names == names:
for n in names:
fmask[n] = mask[n].astype(bool)
# self.__dict__['_fieldmask'] = fmask.view(recarray)
return
newmask = make_mask(mask, copy=False)
if names is not None:
if self._hardmask:
for n in names:
fmask[n].__ior__(newmask)
else:
for n in names:
current = fmask[n]
if current.shape == newmask.shape or newmask.size == 1:
current.flat = newmask
else:
for (i,n) in enumerate(newmask):
current[i] = n
return
开发者ID:mbentz80,项目名称:jzigbeercp,代码行数:24,代码来源:mrecords.py
注:本文中的numpy.ma.make_mask函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论