diff --git a/bdsf/rmsimage.py b/bdsf/rmsimage.py index 3e8a49e..cdb6fa6 100644 --- a/bdsf/rmsimage.py +++ b/bdsf/rmsimage.py @@ -371,9 +371,8 @@ def CheckShape(A): if pol == 'I': # Apply mask to mean_map and rms_map by setting masked values to NaN if isinstance(mask, np.ndarray): - pix_masked = np.where(mask == True) - mean[pix_masked] = np.nan - rms[pix_masked] = np.nan + mean[mask] = np.nan + rms[mask] = np.nan img.mean_arr = mean img.rms_arr = rms @@ -400,9 +399,8 @@ def CheckShape(A): else: resdir = img.basedir + '/background/' if not os.path.exists(resdir): os.makedirs(resdir) - zero_pixels = np.where(rms <= 0.0) rms_nonzero = rms.copy() - rms_nonzero[zero_pixels] = np.nan + rms_nonzero[rms <= 0.0] = np.nan func.write_image_to_file(img.use_io, img.imagename + '.norm_I.fits', (image-mean)/rms_nonzero, img, resdir) mylog.info('%s %s' % ('Writing ', resdir+img.imagename+'.norm_I.fits')) else: @@ -423,8 +421,7 @@ def check_rmsmap(self, img, rms): bm = (img.beam[0], img.beam[1]) fw_pix = sqrt(np.prod(bm)/abs(np.prod(cdelt))) if img.masked: - unmasked = np.where(~img.mask_arr) - stdsub = np.std(rms[unmasked]) + stdsub = np.std(rms[~img.mask_arr]) else: stdsub = np.std(rms) @@ -451,8 +448,7 @@ def check_meanmap(self, img, mean): bm = (img.beam[0], img.beam[1]) fw_pix = sqrt(np.prod(bm)/abs(np.prod(cdelt))) if img.masked: - unmasked = np.where(~img.mask_arr) - stdsub = np.std(mean[unmasked]) + stdsub = np.std(mean[~img.mask_arr]) else: stdsub = np.std(mean) rms_expect = img.clipped_rms/img.rms_box[0]*fw_pix @@ -763,7 +759,7 @@ def rms_mean_map(self, arr, mask=False, kappa=3, box=None, ncores=None): rms_map[co] = cr # Check if all regions have too few unmasked pixels - if mask is not None and np.size(np.where(mean_map != np.inf)) == 0: + if mask is not None and not np.any(mean_map != np.inf): raise RuntimeError("No unmasked regions from which to determine "\ "mean and rms maps") @@ -862,8 +858,7 @@ def correct_borders(map): # Step 5: fill in boxes with < 5 unmasked pixels (set to values of # np.inf) - unmasked_boxes = np.where(mean_map != np.inf) - if np.size(unmasked_boxes,1) < mapshape[0]*mapshape[1]: + if np.count_nonzero(mean_map != np.inf) < mapshape[0]*mapshape[1]: mean_map = self.fill_masked_regions(mean_map) rms_map = self.fill_masked_regions(rms_map) @@ -902,7 +897,7 @@ def fill_masked_regions(self, themap, magic=np.inf): themap[x, y] = np.nanmean(goodcutout) delx += 1 dely += 1 - themap[np.where(np.isnan(themap))] = 0.0 + themap[np.isnan(themap)] = 0.0 return themap def pad_array(self, arr, new_shape):