-
Notifications
You must be signed in to change notification settings - Fork 22
/
run.sh
210 lines (150 loc) · 6.46 KB
/
run.sh
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
#!/usr/bin/env bash
set -e
#######
# setup
#######
# set wd to root of repo
cd "$(dirname "$0")/.."
# make sure conda is initialized
CONDA_PREFIX_1=${CONDA_PREFIX_1:-/opt/conda}
source $CONDA_PREFIX_1/etc/profile.d/conda.sh
# take in passed conda environment name as argument
# if none passed, use current conda env
ENVNAME=${1:-$CONDA_DEFAULT_ENV}
conda activate $ENVNAME
# install kernel if needed, otherwise simply correct the kernel name
if [[ -z $ENVNAME || "$ENVNAME" = "base" ]]
then
ENVNAME="python3"
else
python -m ipykernel install --user --name $ENVNAME
fi
export MOSAIKS_OVERWRITE=True
# ensure trailing slash for consistency in filepaths
MOSAIKS_HOME=${MOSAIKS_HOME:-$(pwd)}
export MOSAIKS_HOME=${MOSAIKS_HOME%/}/
export MOSAIKS_RESULTS=${MOSAIKS_RESULTS:-${MOSAIKS_HOME}results}/
export MOSAIKS_DATA=${MOSAIKS_DATA:-${MOSAIKS_HOME}data}/
export MOSAIKS_CODE=${MOSAIKS_CODE:-${MOSAIKS_HOME}code}/
# define env vars
GRID_DIR=${MOSAIKS_CODE}analysis/0_grid_creation
FEAT_DIR=${MOSAIKS_CODE}analysis/1_feature_extraction
LAB_DIR=${MOSAIKS_CODE}analysis/2_label_creation
FIG_DIR=${MOSAIKS_CODE}analysis/3_figures_and_tables
# install our utilities
pip install -e $MOSAIKS_CODE
# define alias to run nb's from command line
run_nb() {
NBPATH=$1
OUTPATH=${NBPATH/"code/analysis"/"${MOSAIKS_RESULTS}/nb_logs"}
mkdir -p $(dirname "$OUTPATH")
shift
papermill $NBPATH $OUTPATH \
-k $ENVNAME \
-p overwrite True \
-p fixed_lambda True \
--cwd $(dirname "$NBPATH") \
"$@"
}
#########################################
# Grid, feature, and label pre-processing
#########################################
echo "The pre-processing steps of grid cell sampling, feature extraction, and ground \
truth label extraction are not included in this replication script due to \
computational time. However, they may be run individually via the associated \
scripts..."
# create grids
#time Rscript ${GRID_DIR}/create_grid_CONTUS_and_WORLD.R
#time Rscript ${GRID_DIR}/create_grid_dense_sample_regions.R
# extract features
#time python ${FEAT_DIR}/1_create_rcf_feature_matrices.py
#time python ${FEAT_DIR}/2_featurize_models_deep_pretrained
# extract labels: See various scripts in code/analysis/2_label_creation
########################################
# replicate all figures and tables
########################################
echo "Replicating the creation of all figures... (NOTE: Some time-intensive steps such \
as CNN training are not included in this replication but may be run individually via \
the associated scripts.)"
# Fig 2
echo "Running Fig 2: Regressions..."
time run_nb ${FIG_DIR}/Fig2_randomCV/1_run_regressions.ipynb
echo "Running Fig 2: Plots..."
time run_nb ${FIG_DIR}/Fig2_randomCV/2_make_fig.ipynb
# Fig 3
echo "Running Fig3: Training CNN (skipped for time)..."
# for LABEL in treecover elevation population nightlights income roads housing; do
# time python ${FIG_DIR}/Fig3_diagnostics/train_CNN.py \
# ${MOSAIKS_DATA}/output/cnn_comaprison/resnet18_${LABEL} --outcome $LABEL
# done
echo "Running Fig 3: Sensitivity to N and K..."
time run_nb ${FIG_DIR}/Fig3_diagnostics/model_sensitivity.ipynb
echo "Running Fig 3: Spatial cross-validation..."
time run_nb ${FIG_DIR}/Fig3_diagnostics/spatial_analyses_jitter_gammaLoop_interpolation.ipynb
echo "Running Fig 3: Transfer Learning comparison..."
time run_nb ${FIG_DIR}/Fig3_diagnostics/run_pretrained_resnet_regressions.ipynb
echo "Running Fig 3: Plotting..."
time run_nb ${FIG_DIR}/Fig3_diagnostics/fig_3.ipynb
# Fig 4
echo "Running Fig 4: Global regressions..."
time run_nb ${FIG_DIR}/Fig4_global_ACS_and_SR/world_model.ipynb
echo "Running Fig 4: Super-resolution (model training skipped due to need for raw imagery...)"
# time run_nb ${FIG_DIR}/Fig4_global_ACS_and_SR/superres/1_choose_sr_lambda.ipynb
# time python ${FIG_DIR}/Fig4_global_ACS_and_SR/superres/2_compute_superres.py 16000
time run_nb ${FIG_DIR}/Fig4_global_ACS_and_SR/superres/3_sr_figs.ipynb
echo "Running Fig 4: Zoomed-in dense predictions..."
time Rscript ${FIG_DIR}/Fig4_global_ACS_and_SR/plot_labels_preds_dense_zoom_regions.R
echo "Running Fig 4: ACS regressions..."
time run_nb ${FIG_DIR}/Fig4_global_ACS_and_SR/ACS/1_run_regressions.ipynb
echo "Running Fig 4: ACS plot..."
time run_nb ${FIG_DIR}/Fig4_global_ACS_and_SR/ACS/2_make_fig.ipynb
# Fig S1
echo "Running Fig S1: Panel A..."
time Rscript ${FIG_DIR}/supplementary_figs/FigS1/FigS1_A.R
echo "Running Fig S1: Panel B..."
time python ${FIG_DIR}/supplementary_figs/FigS1/FigS1_B_1.py
time Rscript ${FIG_DIR}/supplementary_figs/FigS1/FigS1_B_2.R
# Fig S2
echo "Running Fig S2..."
time Rscript ${FIG_DIR}/supplementary_figs/FigS2/correlation_across_tasks.R
# Fig S3 cannot be generated with publicly available data
# Fig S4 generated manually
# Fig S5 generated manually
# Fig S6
echo "Running Fig S6 (feature extraction skipped for time)..."
# See notebook for instructions on how to extract and save features using each patch size
time run_nb ${FIG_DIR}/supplementary_figs/FigS6/patch_size_regressions.ipynb
# Fig S7
echo "Running Fig S7..."
time Rscript ${FIG_DIR}/supplementary_figs/FigS7/logs_vs_levels_hists.R
# Fig S8
echo "Running Fig S8..."
time run_nb ${FIG_DIR}/supplementary_figs/FigS8/beta_correlations.ipynb
# Fig S9
echo "Running Fig S9..."
time run_nb ${FIG_DIR}/supplementary_figs/FigS9/plot_FigS9.ipynb
# Fig S10 generated manually
# Fig S11 generated manually
# Fig S12 generated by Fig4_global_ACS_and_SR/superres/3_sr_figs.ipynb
# Fig S13 generated by Fig4_global_ACS_and_SR/superres/3_sr_figs.ipynb
# Fig S14 generated by Fig4_global_ACS_and_SR/world_model.ipynb
# Fig S15 from previous work
# Fig S16 (skipped due to need for DHS data)
# time Rscript ${FIG_DIR}/supplementary_figs/FigS16/make_nl_features.R
# time run_nb ${FIG_DIR}/supplementary_figs/FigS16/head_replication.ipynb
# Fig S17
echo "Running Fig S17..."
time run_nb ${FIG_DIR}/supplementary_figs/FigS17/cnn_vs_MOSAIKS_scatter.ipynb
# Table S1 generated manually
# Table S2 generated by Fig2_randomCV/1_run_regressions.ipynb
# Table S3
echo "Running Table S3..."
time run_nb ${FIG_DIR}/supplementary_tables/TableS3/logs_vs_levels_model_selection.ipynb
# Table S4 generated manually
# Table S5
echo "Running Table S5/7..."
time run_nb ${FIG_DIR}/supplementary_tables/TableS5/mosaiks_comparisons.ipynb
# Table S6
echo "Running Table S6..."
Rscript ${FIG_DIR}/supplementary_tables/TableS6/head_etal_comparison_table.R
#Table S7 generated by supplementary_tables/TableS5/cnn_mosaiks_combo.ipynb