-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathexample_spatial_02.py
executable file
·107 lines (78 loc) · 9.35 KB
/
example_spatial_02.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 20 12:17:22 2018
@author: eemeg
An example of the ICASAR software with real data from LiCSBAS that contains a deformation signals that is not visible in a single 6/12 days Sentinel-1 interferogram.
"""
#%% Imports
import numpy as np
import matplotlib.pyplot as plt
from pathlib import Path
import sys
import icasar
from icasar.icasar_funcs import ICASAR, LiCSBAS_to_ICASAR
from icasar.aux import visualise_ICASAR_inversion
#%% Prep: load some LiCSBAS data
LiCSBAS_out_folder_campi_flegrei = Path('./campi_flegrei_LiCSBAS_example_data/') # the main results file from LICSBAS, which includes the incremental (between epoch or acquisition) deformation.
print(f"Opening the LiCSBAS .h5 file...", end = '')
displacement_r2, tbaseline_info, ref_xy = LiCSBAS_to_ICASAR(LiCSBAS_out_folder_campi_flegrei, figures=True) # open various LiCSBAS products, spatial ones in displacement_r2, temporal ones in tbaseline_info
print(f"Done. ")
spatial_data = {'ifgs_dc' : displacement_r2['incremental'],
'mask' : displacement_r2['mask'],
'ifg_dates_dc' : tbaseline_info['ifg_dates'], # this is optional. In the previous example, we didn't have it, in form YYYYMMDD_YYYYMMDD as a list of strings.
'dem' : displacement_r2['dem'], # this is optional. In the previous example, we didn't have it
'lons' : displacement_r2['lons'],
'lats' : displacement_r2['lats']}
#%% Example 1: sICA after creating all interferograms
print(f"\n\n###################\n Example 01 \n###################")
ICASAR_settings = {"n_comp" : 5, # number of components to recover with ICA (ie the number of PCA sources to keep)
"bootstrapping_param" : (200, 0), # (number of runs with bootstrapping, number of runs without bootstrapping) "hdbscan_param" : (35, 10), # (min_cluster_size, min_samples)
"tsne_param" : (30, 12), # (perplexity, early_exaggeration)
"ica_param" : (1e-2, 150), # (tolerance, max iterations)
"hdbscan_param" : (100,10), # (min_cluster_size, min_samples) Discussed in more detail in Mcinnes et al. (2017). min_cluster_size sets the smallest collection of points that can be considered a cluster. min_samples sets how conservative the clustering is. With larger values, more points will be considered noise.
"out_folder" : Path('example_spatial_02_outputs_sICA'), # outputs will be saved here
"load_fastICA_results" : True, # If all the FastICA runs already exisit, setting this to True speeds up ICASAR as they don't need to be recomputed.
"ifgs_format" : 'all', # small signals are hard for ICA to extact from time series, so make it easier by creating all possible long temporal baseline ifgs from the incremental data.
'sica_tica' : 'sica', # controls whether spatial sources or time courses are independent.
'max_n_all_ifgs' : 1000,
'label_sources' : True, # ICASAR will try to identify which sources are deformation / topo. correlated APS / turbulent Aps.
"figures" : "png+window"} # if png, saved in a folder as .png. If window, open as interactive matplotlib figures,
# if 'png+window', both.
# default is "window" as 03_clustering_and_manifold is interactive.
S_ica, A_ica, x_train_residual_ts, Iq, n_clusters, S_all_info, phUnw_mean, sources_labels = ICASAR(spatial_data = spatial_data, **ICASAR_settings)
# We an also visualise how interferograms are fit using the learned components (ICs, contained in S_best)
visualise_ICASAR_inversion(spatial_data['ifgs_dc'], S_ica, A_ica, displacement_r2['mask'], n_data = 10)
#%% Example 2: sICA with only incremental interferograms
print(f"\n\n###################\n Example 02 \n###################")
ICASAR_settings = {"n_comp" : 5, # number of components to recover with ICA (ie the number of PCA sources to keep)
"bootstrapping_param" : (200, 0), # (number of runs with bootstrapping, number of runs without bootstrapping) "hdbscan_param" : (35, 10), # (min_cluster_size, min_samples)
"tsne_param" : (30, 12), # (perplexity, early_exaggeration)
"ica_param" : (1e-2, 150), # (tolerance, max iterations)
"hdbscan_param" : (100,10), # (min_cluster_size, min_samples) Discussed in more detail in Mcinnes et al. (2017). min_cluster_size sets the smallest collection of points that can be considered a cluster. min_samples sets how conservative the clustering is. With larger values, more points will be considered noise.
"out_folder" : Path('example_spatial_02_outputs_sICA_incremental'), # outputs will be saved here
"load_fastICA_results" : True, # If all the FastICA runs already exisit, setting this to True speeds up ICASAR as they don't need to be recomputed.
"ifgs_format" : 'inc', # small signals are hard for ICA to extact from time series, so make it easier by creating all possible long temporal baseline ifgs from the incremental data.
'max_n_all_ifgs' : 1000,
'sica_tica' : 'sica', # controls whether spatial sources or time courses are independent.
'label_sources' : True, # ICASAR will try to identify which sources are deformation / topo. correlated APS / turbulent Aps.
"figures" : "png+window"} # if png, saved in a folder as .png. If window, open as interactive matplotlib figures,
# if 'png+window', both.
# default is "window" as 03_clustering_and_manifold is interactive.
S_ica, A_ica, x_train_residual_ts, Iq, n_clusters, S_all_info, phUnw_mean, sources_labels = ICASAR(spatial_data = spatial_data, **ICASAR_settings)
#%% Example 3: tICA given the incremental interferograms, but this will calculate the cumulative interferograms.
print(f"\n\n###################\n Example 03 \n###################")
ICASAR_settings = {"n_comp" : 5, # number of components to recover with ICA (ie the number of PCA sources to keep)
"bootstrapping_param" : (200, 0), # (number of runs with bootstrapping, number of runs without bootstrapping) "hdbscan_param" : (35, 10), # (min_cluster_size, min_samples)
"tsne_param" : (30, 12), # (perplexity, early_exaggeration)
"ica_param" : (1e-2, 150), # (tolerance, max iterations)
"hdbscan_param" : (100,10), # (min_cluster_size, min_samples) Discussed in more detail in Mcinnes et al. (2017). min_cluster_size sets the smallest collection of points that can be considered a cluster. min_samples sets how conservative the clustering is. With larger values, more points will be considered noise.
"out_folder" : Path('example_spatial_02_outputs_tICA_incremental'), # outputs will be saved here
"load_fastICA_results" : True, # If all the FastICA runs already exisit, setting this to True speeds up ICASAR as they don't need to be recomputed.
'max_n_all_ifgs' : 1000,
'sica_tica' : 'tica', # controls whether spatial sources or time courses are independent.
'label_sources' : True, # ICASAR will try to identify which sources are deformation / topo. correlated APS / turbulent Aps.
"figures" : "png+window"} # if png, saved in a folder as .png. If window, open as interactive matplotlib figures,
# if 'png+window', both.
# default is "window" as 03_clustering_and_manifold is interactive.
S_ica, A_ica, x_train_residual_ts, Iq, n_clusters, S_all_info, phUnw_mean, sources_labels = ICASAR(spatial_data = spatial_data, **ICASAR_settings)
#%%