-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_inversion.sh
executable file
·153 lines (119 loc) · 5.42 KB
/
run_inversion.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
#!/bin/bash
#SBATCH -n 1
#SBATCH -N 1
#SBATCH -p huce_intel
#SBATCH -t 0-03:00
#SBATCH --mem 4000
#SBATCH -o run_inversion_%j.out
#SBATCH -e run_inversion_%j.err
##=======================================================================
## Parse config.yml file
##=======================================================================
printf "\n=== PARSING CONFIG FILE ===\n"
# Get configuration
source ../../../setup_CH4/parse_yaml.sh
eval $(parse_yaml ../../../setup_CH4/config.yml)
# This defines $StartDate, $EndDate, $nBufferClusters, $RunName, $isAWS
# It also define $PriorError, $ObsError, $Gamma, $PrecomputedJacobian
# Parsing the config file here facilitates generation of inversion ensembles
# All that needs to be done is to edit the config file for $PriorError, $ObsError, and $Gamma,
# make sure $PrecomputedJacobian is true, and then re-run this script (or run_ch4_inversion.sh
# with only the $DoInversion module switched on in config.yml).
#=======================================================================
# Configuration (these settings generated on initial setup)
#=======================================================================
LonMinInvDomain={LON_MIN}
LonMaxInvDomain={LON_MAX}
LatMinInvDomain={LAT_MIN}
LatMaxInvDomain={LAT_MAX}
nElements={STATE_VECTOR_ELEMENTS}
MyPath={MY_PATH}
Res={RES}
SpinupDir="${MyPath}/${RunName}/spinup_run"
JacobianRunsDir="${MyPath}/${RunName}/jacobian_runs"
PosteriorRunDir="${MyPath}/${RunName}/posterior_run"
StateVectorFile={STATE_VECTOR_PATH}
SensiDir="./Sensi"
GCDir="./data_GC"
JacobianDir="./data_converted"
tropomiCache="${MyPath}/${RunName}/data_TROPOMI"
# Only matters for Kalman filter inversions, to be implemented in a future version of the IMI
FirstSimSwitch=true
printf "\n=== EXECUTING RUN_INVERSION.SH ===\n"
#=======================================================================
# Error checks
#=======================================================================
# Make sure specified paths exist
if [[ ! -d ${JacobianRunsDir} ]]; then
printf "${JacobianRunsDir} does not exist. Please fix JacobianRunsDir in run_inversion.sh.\n"
exit 1
fi
if [[ ! -f ${StateVectorFile} ]]; then
printf "${StateVectorFile} does not exist. Please fix StateVectorFile in run_inversion.sh.\n"
exit 1
fi
#=======================================================================
# Postprocess the SpeciesConc and LevelEdgeDiags files from GEOS-Chem
#=======================================================================
if ! "$PrecomputedJacobian"; then
printf "Calling postproc_diags.py, FSS=$FirstSimSwitch\n"
if "$FirstSimSwitch"; then
if [[ ! -d ${SpinupDir} ]]; then
printf "${SpinupDir} does not exist. Please fix SpinupDir or set FirstSimSwitch to False in run_inversion.sh.\n"
exit 1
fi
PrevDir=$SpinupDir
else
PrevDir=%$PosteriorRunDir
if [[ ! -d ${PosteriorRunDir} ]]; then
printf "${PosteriorRunDir} does not exist. Please fix PosteriorRunDir in run_inversion.sh.\n"
exit 1
fi
fi
printf " - Hour 0 for ${StartDate} will be obtained from ${PrevDir}\n"
python postproc_diags.py $RunName $JacobianRunsDir $PrevDir $StartDate; wait
printf "DONE -- postproc_diags.py\n\n"
fi
#=======================================================================
# Calculate GEOS-Chem sensitivities and save to Sensi directory
#=======================================================================
if ! "$PrecomputedJacobian"; then
# 50% perturbation
Perturbation=0.5
printf "Calling calc_sensi.py\n"
python calc_sensi.py $nElements $Perturbation $StartDate $EndDate $JacobianRunsDir $RunName $SensiDir; wait
printf "DONE -- calc_sensi.py\n\n"
fi
#=======================================================================
# Setup GC data directory in workdir
#=======================================================================
if ! "$PrecomputedJacobian"; then
GCsourcepth="${JacobianRunsDir}/${RunName}_0000/OutputDir"
printf "Calling setup_gc_cache.py\n"
python setup_gc_cache.py $StartDate $EndDate $GCsourcepth $GCDir; wait
printf "DONE -- setup_gc_cache.py\n\n"
fi
#=======================================================================
# Generate Jacobian matrix files
#=======================================================================
if ! "$PrecomputedJacobian"; then
printf "Calling jacobian.py\n"
isPost="False"
python jacobian.py $StartDate $EndDate $LonMinInvDomain $LonMaxInvDomain $LatMinInvDomain $LatMaxInvDomain $nElements $tropomiCache $isPost; wait
printf " DONE -- jacobian.py\n\n"
fi
#=======================================================================
# Do inversion
#=======================================================================
posteriorSF="./inversion_result.nc"
printf "Calling invert.py\n"
python invert.py $nElements $JacobianDir $posteriorSF $LonMinInvDomain $LonMaxInvDomain $LatMinInvDomain $LatMaxInvDomain $PriorError $ObsError $Gamma $Res; wait
printf "DONE -- invert.py\n\n"
#=======================================================================
# Create gridded posterior scaling factor netcdf file
#=======================================================================
GriddedPosterior="./gridded_posterior.nc"
printf "Calling make_gridded_posterior.py\n"
python make_gridded_posterior.py $posteriorSF $StateVectorFile $GriddedPosterior; wait
printf "DONE -- make_gridded_posterior.py\n\n"
exit 0