insar_eventnet package#
Subpackages#
Submodules#
insar_eventnet.aievents module#
insar_eventnet.config module#
Summary#
Holds global variables.
Notes
Created by Jason Herning.
insar_eventnet.etc module#
Summary#
Misc functions.
Notes
Created by Jason Herning.
insar_eventnet.gui module#
Summary#
GUI plotting of data and interactive visualizations.
Notes
Created by Jason Herning, Andrew Player, and Robert Lawton.
insar_eventnet.hyp3 module#
insar_eventnet.inference module#
Summary#
Functions for performing inference, such as masking events, and binary classification of events
Notes
Created by Andrew Player.
- insar_eventnet.inference.mask(mask_model_path: str, pres_model_path: str, image_path: str, output_image_path: str | None = None, tile_size: int = 0, crop_size: int = 0) ndarray [source]#
Generate a mask over potential events in a wrapped insar product.
Parameters:#
- mask_model_pathstr
The path to the model to use for generating the event-mask.
- pres_model_pathstr
The path to the model that predicts the presence of an event in a mask.
- image_pathstr
The path to the InSAR product from ASF that should be masked.
- output_image_pathstr
The output path for the inferred mask image
- tile_sizeint
The width and height of the tiles that the image will be broken into, this needs to match the input shape of the model.
- crop_sizeint, Optional
If the models output shape is different than the input shape, this value needs to be equal to the output shape of the masking model and input shape of the presence model.
Returns:#
- mask_prednp.ndarray(shape=(tile_size, tile_size) or (crop_size, crop_size))
The array containing the event-mask array as predicted by the model.
- presence_guessbool
True if there is an event else False.
- insar_eventnet.inference.mask_with_model(mask_model, pres_model, arr_w: ndarray, tile_size: int, crop_size: int = 0) ndarray [source]#
Use a keras model prediction to mask events in a wrapped interferogram.
- Parameters:
model_path (str) – The path to the model to use for masking.
pres_model_path (str) – The path to the model that predicts the presence of an event in a mask.
arr_w (np.ndarray) – The wrapped interferogram array.
tile_size (int) – The width and height of the tiles that the image will be broken into, this needs to match the input shape of the model.
crop_size (int, Optional) – If the models output shape is different than the input shape, this value needs to be equal to the output shape of the masking model and input shape of the presence model.
- Returns:
mask (np.ndarray(shape=(tile_size, tile_size) or (crop_size, crop_size))) – The array containing the event-mask array as predicted by the model.
pres_mask (np.ndarray(shape=(tile_size, tile_size) or (crop_size, crop_size))) – An array containing tiles where the tile is all 1s if there is an event else 0s. If even a single tile has 1s that means an event has been identified.
- insar_eventnet.inference.test_model(mask_model_path, pres_model_path, images_dir, tile_size, crop_size, save_images=False, output_dir=None)[source]#
Evaluate EventNet Models over a directory of real interferograms.
- Parameters:
model_path (str) – The path to the model to use for masking.
pres_model_path (str) – The path to the model that predicts the presence of an event in a mask.
images_dir (str) – A directory containing Positives and Negatives directories which have their respective tifs.
tile_size (int) – The width and height of the tiles that the image will be broken into, this needs to match the input shape of the model.
crop_size (int, Optional) – If the models output shape is different than the input shape, this value needs to be qual to the output shape of the masking model and input shape of the presence model.
insar_eventnet.io module#
Summary#
Functions to handle file read/write.
Notes
Created by Andrew Player.
- insar_eventnet.io.get_image_array(image_path: str) ndarray [source]#
Load a interferogram .tif from storage into an array.
- Parameters:
image_path (str) – The path to the interferogram .tif to be opened.
- Returns:
arr – The interferogram array.
- Return type:
np.ndarray
- insar_eventnet.io.get_product_arrays(product_path: str) Tuple[ndarray, ndarray, ndarray] [source]#
Load wrapped, unwrapped, and correlation .tifs from storage into arrays.
- Parameters:
product_path (str) – The path to the InSAR product folder containing the images.
- Returns:
wrapped (np.ndarray) – The array of the wrapped interferogram loaded from the .tif.
unwrapped (np.ndarray) – The array of the unwrapped interferogram loaded from the .tif.
correlation (np.ndarray) – The correlation map array loaded from the .tif,
- insar_eventnet.io.make_simulated_dataset(name: str, output_dir: str, amount: int, seed: int, tile_size: int, crop_size: int, model_path: str = '') Tuple[int, int, str] [source]#
Generate a dataset containing pairs of wrapped interferograms from simulated deformation along with their event-masks
- Parameters:
name (str) – The name of the dataset to be generate. The saved name will be formatted like <name>_amount<amount>_seed<seed>.
output_dir (str) – The directory to save the generated dataset to.
amount (int) – The amount of simulated interferogram pairs to be generated.
seed (int) – A seed for the random functions. For the same seed, with all other values the same as well, the interferogram generation will have the same results. If left at 0, a seed will be generated and the results will be different every time.
tile_size (int) – The size of the simulated interferograms, which should match the desired tile sizes of of the real interferograms. This also needs to match the input shape of the model.
crop_size (int) – If the model’s output shape does not match its input shape, this should be set to match the output shape. The unwrapped interferogram will be cropped to this.
- Returns:
seed (int) – The generated or inputed seed.
count (int) – The number of samples that were generated.
dir_name (str) – The generated name of the dataset directory.
- insar_eventnet.io.split_dataset(dataset_path: str, split: float) Tuple[int, int] [source]#
Split the dataset into train and test folders
- Parameters:
dataset_path (str) – The path to the dataset to be split
split (float) – The train/test split, 0 < Split < 1, size(validation) <= split
- Returns:
num_train (int) – The number of elements that went to the training set.
num_validation (int) – The number of elements that went to the validation set.
insar_eventnet.processing module#
Summary#
Functions for the pre and post-processing of interferogram arrays.
Notes
Created by Andrew Player.
- insar_eventnet.processing.simulate_unet_cropping(arr: ndarray, crop_shape: tuple) ndarray [source]#
Symmetrically crop the inputed array.
- Parameters:
arr (np.ndarray) – The 2-dimensional interferogram array to be cropped.
crop_shape (tuple) – The length of the rows and columns after being cropped, respectively. If the crop_shape in a direction does not divide 2, the extra value will be placed on the 0 side. This should match the models output shape.
- Returns:
cropped_arr – The cropped interferogram array.
- Return type:
np.ndarray
- insar_eventnet.processing.tile(arr: ndarray, tile_shape: Tuple[int, int], crop_size: int = 0, x_offset: int = 0, y_offset: int = 0, even_pad: bool = False, pad_value: float = 0.0) Tuple[ndarray, int, int] [source]#
Tile a 2-dimensional array into an array of tiles of shape tile_shape.
- Parameters:
arr (np.ndarray) – The 2-dimensional array that should be tiled.
tile_shape (tuple(int, int)) – The desired shape of the tiles: (row length, column length). This should match the input shape of the model.
crop_size (int, Optional) – An extra amount of padding to maintain full array coverage when the model will crop the tiles later. This amount should be equal to the shape of the output tiles from the model.
x_offset (int, Optional) – Offset the tiling process by this amount in the columns direction.
y_offset (int, Optional) – Offset the tiling process by this amount in the row direction.
even_pad (bool, Optional) – If True, the array will be padded symmetrically; else, it will be padded on the end of each dimension.
pad_value (float, Optional) – The value to fill the padded areas of the array with.
- Returns:
tiles (np.ndarray) – The array of tiles.
num_rows (int) – The number of rows of tiles.
num_cols (int) – The number of columns of tiles.
- insar_eventnet.processing.tiles_to_image(arr: ndarray, rows: int, cols: int, original_shape: Tuple[int, int]) ndarray [source]#
Stich an array of 2-dimensional tiles into a single 2-dimensional array.
- Parameters:
arr (np.ndarray(shape=(rows*cols, tile_size, tile_size))) – The array of tiles to be stiched together.
rows (int) – The number of tiles that should go in the row direction.
cols (int) – The number of tiles that should go in the column direction.
original_shape (Tuple[int, int]) – The shape of the interferogram before any processing.
cropped (bool) – Set to True if the model has cropping, else leave it as False.
tiling_size (int) – If the model was cropped, set this to the original tile size, else leave this false.
- Returns:
rebuilt_arr – The stiched 2-dimensional array.
- Return type:
np.ndarray(shape=(rows*tile_size, cols*tile_size))
insar_eventnet.sarsim module#
Summary#
Functions for simulated-deformation interferogram generation for training datasets.
References
Functions taken from https://github.com/matthew-gaddes/SyInterferoPy.
- class insar_eventnet.sarsim.Okada(source, source_xy_m, tile_size, **kwargs)[source]#
Bases:
object
Class that models surface deformation.
Based off of:
https://github.com/matthew-gaddes/SyInterferoPy
and
Okada, Surface deformation due to shear and tensile faults in a half-space, Bulletin of the Seismological Society of America (1985): 1135-1154
- compute_I_components()[source]#
Precompute all necessary I components to avoid doing it more than once.
- insar_eventnet.sarsim.aps_simulate(size: int = 512)[source]#
Generate simulated turbulent atmospheric error.
- Parameters:
size (int) – The size n for the (n, n) dimension array that is returned.
- Returns:
ph_turb – The array containing the turbulent atmospheric error.
- Return type:
np.ndarray
- insar_eventnet.sarsim.atm_topo_simulate(dem_m: ndarray, strength_mean: float = 56.0, strength_var: float = 2.0)[source]#
` Generate simulated topographic atmospheric error.
- Parameters:
dem_m (np.ndarray) – An array containing either real dem values (in meters) or simulated ones.
strength_mean (float) – The mean strength/magnitude of the error.
strength_var (float) – The maximum variation from strength_mean of the magnitude of the error.
difference (bool) – Whether the error should come from the difference of 2 aquisitions or just 1.
- Returns:
ph_turb – The array containing the turbulent atmospheric error.
- Return type:
np.ndarray
- insar_eventnet.sarsim.atmosphere_turb(n_atms, lons_mg, lats_mg, mean_m=0.02, difference=True)[source]#
A function to create synthetic turbulent atmospheres based on the methods in Lohman Simons 2005, or using Andy Hooper and Lin Shen’s fft method. Note that due to memory issues, when using the covariance (Lohman) method, largers ones are made by interpolateing smaller ones. Can return atmsopheres for an individual acquisition, or as the difference of two (as per an interferogram). Units are in metres.
- Parameters:
n_atms (int) – number of atmospheres to generate
lons_mg (rank 2 array) – longitudes of the bottom left corner of each pixel.
lats_mg (rank 2 array) – latitudes of the bottom left corner of each pixel.
method (string) – ‘fft’ or ‘cov’. Cov for the Lohmans Simons (sp?) method, fft for Andy Hooper/Lin Shen’s fft method (which is much faster). Currently no way to set length scale using fft method.
mean_m (float) – average max or min value of atmospheres that are created. e.g. if 3 atmospheres have max values of 0.02m, 0.03m, and 0.04m, their mean would be 0.03cm.
water_mask (rank 2 array) – If supplied, this is applied to the atmospheres generated, convering them to masked arrays.
difference (boolean) – If difference, two atmospheres are generated and subtracted from each other to make a single atmosphere.
verbose (boolean) – Controls info printed to screen when running.
cov_Lc (float) – length scale of correlation, in metres. If smaller, noise is patchier, and if larger, smoother.
cov_interpolate_threshold (int) – if n_pixs is greater than this, images will be generated at size so that the total number of pixels doesn’t exceed this. e.g. if set to 1e4 (10000, the default) and images are 120*120, they will be generated at 100*100 then upsampled to 120*120.
- Returns:
ph_turbs – n_atms x n_pixs x n_pixs, UNITS ARE M. Note that if a water_mask is provided, this is applied and a masked array is returned.
- Return type:
r3 array
- insar_eventnet.sarsim.coherence_mask_simulate(size: int = 512, threshold: float = 0.3)[source]#
Generate simulated incoherence to be masked out.
- Parameters:
size (int) – The size n for the (n, n) dimension array that is returned.
threshold (float) – The maximum value of coherence to be masked to zeros.
- Returns:
mask_coh – The masked coherence array.
- Return type:
np.ndarray
- insar_eventnet.sarsim.gen_fake_topo(size: int = 512, alt_scale_min: int = 0, alt_scale_max: int = 500)[source]#
Generate fake topography (a dem in meters) for generating simulated atmospheric topographic error.
- Parameters:
size (int) – The size n for the (n, n) dimension array that is returned.
alt_scale_min (int) – The minimum altitude scaling value for the generated perlin noise.
alt_scale_max (int) – The maximum altitude scaling value for the generated perlin noise.
- Returns:
dem – The array that is meant to be used as a simulated dem with values in meters.
- Return type:
np.ndarray
- insar_eventnet.sarsim.gen_gaussian_noise(seed: int = 0, tile_size: int = 512, noise_level: float = 282.7433388230814, threshold: float = 70.68583470577035)[source]#
- insar_eventnet.sarsim.gen_sim_noise(seed: int = 0, tile_size: int = 512, gaussian_only: bool = False, atmosphere_scalar: float = 282.7433388230814)[source]#
Generate a wrapped interferogram along with an event-mask simulating a noisy interferogram with no deformation.
- Parameters:
seed (int, Optional) – A seed for the random functions. For the same seed, with all other values the same as well, the interferogram generation will have the same results. If left at 0, the results will be different every time.
tile_size (int, Optional) – The desired dimensional size of the interferogram pairs. This should match the input shape of the model.
log (bool, Optional) – If true, the function will log various relevant values in the console.
atmosphere_scalar (float, Optional) – Scale factor for the intensity of atmospheric noise.
- Returns:
masked_grid (np.ndarray(shape=(tile_size, tile_size))) – An array representing a mask over the simulated deformation which simulates masking an event.
wrapped_grid (np.ndarray(shape=(tile_size, tile_size)) – The wrapped interferogram.
presence ([1] or [0]) – [1] if the image contains an event else [0]
- insar_eventnet.sarsim.gen_simulated_deformation(seed: int = 0, tile_size: int = 512, log: bool = False, atmosphere_scalar: float = 314.1592653589793, amplitude_scalar: float = 3141.592653589793, event_type: str = 'quake', **kwargs)[source]#
Generate a wrapped interferogram along with an event-mask from simulated deformation
- Parameters:
seed (int, Optional) – A seed for the random functions. For the same seed, with all other values the same as well, the interferogram generation will have the same results. If left at 0, the results will be different every time.
tile_size (int, Optional) – The desired dimensional size of the interferogram pairs. This should match the input shape of the model.
log (bool, Optional) – If true, the function will log various relevant values in the console.
atmosphere_scalar (float, Optional) – Scale factor for the intensity of atmospheric noise.
amplitude_scalar (float, Optional) – Scale factor for the deformation.
event_type (str, Optional) – The type of deformation event. Can be quake, sill, or dyke.
- Returns:
masked_grid (np.ndarray(shape=(tile_size, tile_size))) – An array representing a mask over the simulated deformation which simulates masking an event.
wrapped_grid (np.ndarray(shape=(tile_size, tile_size)) – The wrapped interferogram.
presence ([1] or [0]) – [1] if the image contains an event else [0]
- insar_eventnet.sarsim.gen_simulated_time_series(n_interferograms: int = 32, tile_size: int = 512, seed: int = 0, atmosphere_scalar: float = 282.7433388230814, noise_only: bool = False)[source]#
Generate a time-series of interferograms with simulated deformation. Correlated by a common dem.
- Parameters:
seed (int, Optional) – A seed for the random functions. For the same seed, with all other values the same as well, the interferogram generation will have the same results. If left at 0, the results will be different every time.
tile_size (int, Optional) – The desired dimensional size of the interferogram pairs. This should match the input shape of the model.
log (bool, Optional) – If true, the function will log various relevant values in the console.
atmosphere_scalar (float, Optional) – Scale factor for the intensity of atmospheric noise.
- Returns:
masked_grid (np.ndarray(shape=(tile_size, tile_size))) – An array representing a mask over the simulated deformation which simulates masking an event.
wrapped_grid (np.ndarray(shape=(tile_size, tile_size)) – The wrapped interferogram.
presence ([1] or [0]) – [1] if the image contains an event else [0]
insar_eventnet.synthetic_interferogram module#
Summary#
Functions for synthetic interferogram generation for training.
Notes
Created by Andrew Player.