-
Notifications
You must be signed in to change notification settings - Fork 6
/
LiCSAlert_examples.py
executable file
·215 lines (151 loc) · 16.6 KB
/
LiCSAlert_examples.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 8 10:55:48 2020
@author: matthew
To do:
- update colorbar ticks in results explorer
- check results explorere works with even number of sources.
- colour of labels (blakc, orange, purple).
"""
import sys
import pickle
from pathlib import Path
import copy
import numpy as np
import matplotlib.pyplot as plt
import pdb
import licsalert
from licsalert.monitoring_functions import LiCSAlert_monitoring_mode
from licsalert.plotting import licsalert_results_explorer
from licsalert.licsalert import reconstruct_ts_from_dir
#%% Example 01: Campi Flegrei, only the final figure.
licsalert_settings = {"baseline_end" : "20170101", # end baseline stage at YYYYMMDD, need to be before the last acquisition of LiCSAlert will never monitoring anyhting.
"figure_intermediate" : False, # if set to True, a figure is produced for all time steps in the monitoring data, which can be time consuming.
"figure_type" : 'both', # either 'window' or 'png' (to save as pngs), or 'both'
"downsample_run" : 0.5, # data can be downsampled to speed things up
"downsample_plot" : 0.5, # and a 2nd time for fast plotting. Note this is applied to the restuls of the first downsampling, so is compound
"residual_type" : 'cumulative', # controls the type of residual used in the lower plot. Either cumulative or window
"t_recalculate" : 40, # Number of acquisitions that the lines of best fit are calcualted over. Larger value makes the algorithm more sensitive
'inset_ifgs_scaling' : 15} # scales the size of the incremental and cumulative ifgs in the top row of the figure. Smaller values gives a bigger figures.
icasar_settings = {"n_pca_comp_start" : 6,
"n_pca_comp_stop" : 7,
"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.
"ifgs_format" : 'cum', # can be 'all', 'inc' (incremental - short temporal baselines), or 'cum' (cumulative - relative to first acquisition)
"sica_tica" : 'sica',
"load_fastICA_results" : True}
licsbas_settings = {"filtered" : False,
"date_start" : None,
"date_end" : None,
'mask_type' : 'licsbas', # "dem" or "licsbas"
'crop_pixels' : None}
outdir = Path("./")
volcano = '001_campi_flegrei_example' # outdir final
licsbas_dir = Path("./022D_04826_121209_campi_flegrei") # input data
LiCSAlert_monitoring_mode(outdir = outdir, region = None, volcano = volcano,
licsbas_dir = licsbas_dir,
licsalert_settings = licsalert_settings,
icasar_settings = icasar_settings,
licsbas_settings = licsbas_settings)
licsalert_out_dir = outdir / volcano
licsalert_results_explorer(outdir / volcano, fig_width = 18) # use this function to explore the results
#ics_one_hot = [1, 1, 1, 1] # One hot encoding of which sources to use in the reconstruction. 1 means used, 0 means not. list must be the same length as the number of ICs.
#X_inc_r3, X_cum_r3 = reconstruct_ts_from_dir(ics_one_hot, outdir / volcano) # return the cumualtive interferograms reconstrutced using the ICs selected above. All mean centering has been removed.
sys.exit()
#%% Example 2: make all intermediate figures
licsalert_settings = {"baseline_end" : "20170101", # end baseline stage at YYYYMMDD, need to be before the last acquisition of LiCSAlert will never monitoring anyhting.
### changed here
"figure_intermediate" : True, # if set to True, a figure is produced for all time steps in the monitoring data, which can be time consuming.
### end change
"figure_type" : 'png', # either 'window' or 'png' (to save as pngs), or 'both'
"downsample_run" : 0.5, # data can be downsampled to speed things up
"downsample_plot" : 0.5, # and a 2nd time for fast plotting. Note this is applied to the restuls of the first downsampling, so is compound
"residual_type" : 'cumulative', # controls the type of residual used in the lower plot. Either cumulative or window
"t_recalculate" : 40, # Number of acquisitions that the lines of best fit are calcualted over. Larger value makes the algorithm more sensitive
'inset_ifgs_scaling' : 15} # scales the size of the incremental and cumulative ifgs in the top row of the figure. Smaller values gives a bigger figures.
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.
"ifgs_format" : 'cum', # can be 'all', 'inc' (incremental - short temporal baselines), or 'cum' (cumulative - relative to first acquisition)
"sica_tica" : 'sica' }
licsbas_settings = {"filtered" : False,
"date_start" : None,
"date_end" : None,
'mask_type' : 'licsbas',
'crop_pixels' : None}
outdir = Path("./")
volcano = '002_campi_flegrei_example_all_figures' # outdir final
licsbas_dir = Path("./022D_04826_121209_campi_flegrei") # input data
LiCSAlert_monitoring_mode(outdir = outdir, region = None, volcano = volcano,
licsbas_dir = licsbas_dir,
licsalert_settings = licsalert_settings,
icasar_settings = icasar_settings,
licsbas_settings = licsbas_settings)
#%% Example 3: temporal ICA at Vesuvius
outdir = Path("./")
volcano = '003_vesuvius_example_tica' # outdir final
licsbas_dir = Path("./022D_04826_121209_vesuvius_crop_rationalized") # input data
licsalert_settings = {"baseline_end" : "20170101", # end baseline stage at YYYYMMDD, need to be before the last acquisition of LiCSAlert will never monitoring anyhting.
"figure_intermediate" : False, # if set to True, a figure is produced for all time steps in the monitoring data, which can be time consuming.
"figure_type" : 'png', # either 'window' or 'png' (to save as pngs), or 'both'
"downsample_run" : 0.5, # data can be downsampled to speed things up
"downsample_plot" : 0.5, # and a 2nd time for fast plotting. Note this is applied to the restuls of the first downsampling, so is compound
"t_recalculate" : 40, # Number of acquisitions that the lines of best fit are calcualted over. Larger value makes the algorithm more sensitive
"residual_type" : 'cumulative', # controls the type of residual used in the lower plot. Either cumulative or window
'inset_ifgs_scaling' : 15} # scales the size of the incremental and cumulative ifgs in the top row of the figure. Smaller values gives a bigger figures.
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.
#"ifgs_format" : 'cum', # ifg format is redundant when using tICA as cumulative signals must be considered when working temporally.
### Note set to tica here for temporal:
"sica_tica" : 'tica' }
licsbas_settings = {"filtered" : False,
"date_start" : '20141218',
"date_end" : '20211217',
'mask_type' : 'licsbas',
'crop_pixels' : None}
LiCSAlert_monitoring_mode(outdir = outdir, region = None, volcano = volcano,
licsbas_dir = licsbas_dir,
licsalert_settings = licsalert_settings,
icasar_settings = icasar_settings,
licsbas_settings = licsbas_settings)
licsalert_results_explorer(outdir / volcano, fig_width = 18) # use this function to explore the results
#%% Example 4: spatial ICA at Vesuvius
outdir = Path("./")
volcano = '004_vesuvius_example_sica'
licsbas_dir = Path("./022D_04826_121209_vesuvius_crop_rationalized") # input data
licsalert_settings = {"baseline_end" : "20170101", # end baseline stage at YYYYMMDD, need to be before the last acquisition of LiCSAlert will never monitoring anyhting.
"figure_intermediate" : False, # if set to True, a figure is produced for all time steps in the monitoring data, which can be time consuming.
"figure_type" : 'png', # either 'window' or 'png' (to save as pngs), or 'both'
"downsample_run" : 0.5, # data can be downsampled to speed things up
"downsample_plot" : 0.5, # and a 2nd time for fast plotting. Note this is applied to the restuls of the first downsampling, so is compound
"t_recalculate" : 40, # Number of acquisitions that the lines of best fit are calcualted over. Larger value makes the algorithm more sensitive
"residual_type" : 'cumulative', # controls the type of residual used in the lower plot. Either cumulative or window
'inset_ifgs_scaling' : 15} # scales the size of the incremental and cumulative ifgs in the top row of the figure. Smaller values gives a bigger figures.
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.
### begin change from example 3
"ifgs_format" : 'cum', # ifg format is redundant when using tICA as cumulative signals must be considered when working temporally.
"sica_tica" : 'sica' }
### end change from example 3
licsbas_settings = {"filtered" : False,
"date_start" : '20141218',
"date_end" : '20211217',
'mask_type' : 'licsbas',
'crop_pixels' : None}
LiCSAlert_monitoring_mode(outdir = outdir, region = None, volcano = volcano,
licsbas_dir = licsbas_dir,
licsalert_settings = licsalert_settings,
icasar_settings = icasar_settings,
licsbas_settings = licsbas_settings)
licsalert_results_explorer(outdir / volcano, fig_width = 18) # use this function to explore the results