Skip to content

Commit

Permalink
Fix bug in masking for one of figures.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-gaddes committed Mar 30, 2022
1 parent 3a2b1be commit f319896
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
29 changes: 29 additions & 0 deletions :
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
diff --git a/icasar/aux2.py b/icasar/aux2.py
index 9c084ea..b9c2687 100755
--- a/icasar/aux2.py
+++ b/icasar/aux2.py
@@ -243,13 +243,18 @@ def update_mask_sources_ifgs(mask_sources, sources, mask_ifgs, ifgs):
ifgs_new_mask | r2 array | as per ifgs, but with a new mask. 
History:
2020/06/26 | MEG | Written
+ 2022_03_30 | MEG | fix a bug in the number of pixels for the output array (ie. number of columns of ifgs_new_mask)
"""
- n_pixs_new = len(np.argwhere(mask_new == False)) 
- ifgs_new_mask = np.zeros((ifgs.shape[0], n_pixs_new)) # initiate an array to store the modified sources as row vectors 
- for ifg_n, ifg in enumerate(ifgs): # Loop through each source
- ifg_r2 = col_to_ma(ifg, mask_old) # turn it from a row vector into a rank 2 masked array 
- ifg_r2_new_mask = ma.array(ifg_r2, mask = mask_new) # apply the new mask 
- ifgs_new_mask[ifg_n, :] = ma.compressed(ifg_r2_new_mask) # convert to row vector and places in rank 2 array of modified sources
+
+ 
+ for ifg_n, ifg in enumerate(ifgs): # Loop through each source
+ ifg_r2 = col_to_ma(ifg, mask_old) # turn it from a row vector into a rank 2 masked array 
+ ifg_r2_new_mask = ma.array(ifg_r2, mask = mask_new) # apply the new mask 
+ ifg_r1_new_mask = ma.compressed(ifg_r2_new_mask) # convert to row vector 
+ if ifg_n == 0: # if it's the first ifg.. 
+ n_pixs_new = ifg_r1_new_mask.shape[0] # get the new number of pixels 
+ ifgs_new_mask = np.zeros((ifgs.shape[0], n_pixs_new)) # initiate an array of the correct size
+ ifgs_new_mask[ifg_n, :] = ifg_r1_new_mask # put the row vector into the array
return ifgs_new_mask


2 changes: 1 addition & 1 deletion icasar/aux.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def plot_spatial_signals(spatial_map, pixel_mask, tcs, shape, title, ifg_dates_d
temporal_baselines, figures = "window", png_path = './'):
"""
Input:
spatial map | pxc matrix of c component maps (p pixels)
spatial map | pxc matrix of c component maps (p pixels) (i.e. images are column vectors)
pixel_mask | mask to turn spaital maps back to regular grided masked arrays
tcs | cxt matrix of c time courses (t long)
shape | tuple | the shape of the grid that the spatial maps are reshaped to
Expand Down
17 changes: 11 additions & 6 deletions icasar/aux2.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,18 @@ def apply_new_mask(ifgs, mask_old, mask_new):
ifgs_new_mask | r2 array | as per ifgs, but with a new mask.
History:
2020/06/26 | MEG | Written
2022_03_30 | MEG | fix a bug in the number of pixels for the output array (ie. number of columns of ifgs_new_mask)
"""
n_pixs_new = len(np.argwhere(mask_new == False))
ifgs_new_mask = np.zeros((ifgs.shape[0], n_pixs_new)) # initiate an array to store the modified sources as row vectors
for ifg_n, ifg in enumerate(ifgs): # Loop through each source
ifg_r2 = col_to_ma(ifg, mask_old) # turn it from a row vector into a rank 2 masked array
ifg_r2_new_mask = ma.array(ifg_r2, mask = mask_new) # apply the new mask
ifgs_new_mask[ifg_n, :] = ma.compressed(ifg_r2_new_mask) # convert to row vector and places in rank 2 array of modified sources


for ifg_n, ifg in enumerate(ifgs): # Loop through each source
ifg_r2 = col_to_ma(ifg, mask_old) # turn it from a row vector into a rank 2 masked array
ifg_r2_new_mask = ma.array(ifg_r2, mask = mask_new) # apply the new mask
ifg_r1_new_mask = ma.compressed(ifg_r2_new_mask) # convert to row vector
if ifg_n == 0: # if it's the first ifg..
n_pixs_new = ifg_r1_new_mask.shape[0] # get the new number of pixels
ifgs_new_mask = np.zeros((ifgs.shape[0], n_pixs_new)) # initiate an array of the correct size
ifgs_new_mask[ifg_n, :] = ifg_r1_new_mask # put the row vector into the array
return ifgs_new_mask


Expand Down
5 changes: 2 additions & 3 deletions icasar/icasar_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ def baselines_from_names(self):
S_pca = S_pca[:n_comp,:] # truncate to desired number of components
A_pca = A_pca[:,:n_comp]


if fig_kwargs['figures'] != "none":
plot_pca_variance_line(PC_vals, title = '01_PCA_variance_line', **fig_kwargs)
if spatial:
Expand Down Expand Up @@ -578,7 +577,7 @@ def LiCSBAS_to_ICASAR(LiCSBAS_out_folder, filtered = False, figures = False, n_c
h5_file | string | path to h5 file. e.g. cum_filt.h5
figures | boolean | if True, make figures
n_cols | int | number of columns for figures. May want to lower if plotting a long time series
crop_pixels | tuple | coords to crop images to. x then y, 00 is top left. e.g. (10, 500, 600, 900).
crop_pixels | tuple | coords to crop images to. x start x stop y start y stop , 00 is top left. e.g. (10, 500, 600, 900).
x_start, x_stop, y_start, y_stop, No checking that inputted values make sense.
Note, generally better to have cropped (cliped in LiCSBAS language) to the correct area in LiCSBAS_for_LiCSAlert
return_r3 | boolean | if True, the rank 3 data is also returns (n_ifgs x height x width). Not used by ICASAR, so default is False
Expand Down Expand Up @@ -837,7 +836,7 @@ def read_img(file, length, width, dtype=np.float32, endian='little'):

if mask_type == 'dem':
mask = np.logical_or(mask_dem, mask_cum) # if dem, mask water (from DEM), and anything that's nan in cumulative (mask_cum)
elif mask_type == 'mask_licsbas':
elif mask_type == 'licsbas':
mask = np.logical_or(mask_licsbas, np.logical_or(mask_dem, mask_cum))

mask_r3 = np.repeat(mask[np.newaxis,], cumulative.shape[0], 0)
Expand Down

0 comments on commit f319896

Please sign in to comment.