-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME
189 lines (139 loc) · 7.34 KB
/
README
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
This project is intended to illustrate the hacking of "I/O API metadata" (aka IOAPI metadata) in netCDF files. (For more info on those standards, see
http://www.baronams.com/products/ioapi/
http://www.unidata.ucar.edu/software/netcdf/
) The top-level drivers are two bash scripts:
1 computeCropSum.sh: this takes an input of valid IOAPI (but which is semantically crippled), and
* removes all but the data variable of interest
* fixes the problem with its data
* assimilates some BELD data to a separate layer
* integrates the data over each gridcell
* "windows" the data to a subdomain
* plots the data, for each layer, recording metadata
2 mergeWithCmaqEmissions.sh: this takes as input
* the output of computeCropSum.sh (aka "EPIC emissions")
* emissions files from specified CMAQ-5 evaluation dates (aka "CMAQ emissions")
* MCIP output, containing map scale factors (MSFs), from one of those dates (since the MSFs are presumed time-invariant)
and
* windows each of the CMAQ emissions to match the EPIC emissions' domain
* adds to each CMAQ emissions file a specie=N2O for contain the integration of the EPIC emissions
* converts the EPIC emissions' units to match those of the CMAQ emissions
while ensuring IOAPI-validity is conserved (e.g., the output can be
* loaded by VERDI, which is notoriously "hard to please"
* consumed by CCTM (aka CMAQ)
). The top-level drivers mostly drive two sets of netCDF-aware tools:
1 NCO
http://nco.sourceforge.net/
2 R, specifically packages=ncdf4, M3
http://cirrus.ucsd.edu/~pierce/ncdf/
http://cran.r-project.org/web/packages/M3/
Note that package=M3 requires (among others) package=ncdf4, which requires netCDF 4.
For IOAPI testing, this project also uses
3 m3tools, specifically m3stat and m3wndw
www.baronams.com/products/ioapi/M3STAT.html
www.baronams.com/products/ioapi/M3WNDW.html
For display, this project also uses
4 R package=fields
http://www.image.ucar.edu/Software/Fields/
5 a commandline PDF viewer of your choice (edit the script, or comment out)
Since the code requires bash and netCDF 4, you may have difficulty running on windows: cygwin may be helpful. (If you're only interested in reading the most-IOAPI-aware code, see ioapi.r.) To run the example,
0 Ensure you have proper dependencies. Check your
* NCO: should be uplevel (I have version=4.0.5, latest=4.1.0) and in the path
* R: it should be uplevel (I have version=2.14.0, latest=2.15.0), in the path, and include the above packages
* bash: should be uplevel (I have version=3.2.25, latest=4.2) and your shell (always :-)
* m3tools: should be uplevel and in path
* PDF viewer: edit the driver script to call yours (or comment it out)
1 Fork the git repository, which will create a folder for following activity.
E.g. (in bash),
$ rm -fr /tmp/ioapi-hack-R/
$ pushd /tmp
/tmp $ env GIT_SSL_NO_VERIFY=true git clone https://[email protected]/TomRoche/ioapi-hack-R.git
> Cloning into 'ioapi-hack-R'...
> remote: Counting objects: 29, done.
> remote: Compressing objects: 100% (22/22), done.
> remote: Total 29 (delta 9), reused 27 (delta 7)
> Unpacking objects: 100% (29/29), done.
/tmp $ popd ; pushd /tmp/ioapi-hack-R/
The folder contents should resemble
> drwxr-xr-x you yours 4.0K date time .
> -rwxr-xr-x you yours 6.6K date time beldRead.r
> -rwxr-xr-x you yours 963 date time beldToRDS.r
> -rw-r--r-- you yours 15K date time computeCropSum.r
> -rwxr-xr-x you yours 13K date time computeCropSum.sh
> -rw-r--r-- you yours 6.2K date time demonotonicizeVar.r
> drwxr-xr-x you yours 4.0K date time .git
> -rw-r--r-- you yours 120 date time .gitignore
> -rw-r--r-- you yours 16K date time ioapi.r
> -rwxr-xr-x you yours 3.8K date time plotLayersForTimestep.r
> -rw-r--r-- you yours 6.5K date time processLayers.r
> -rw-r--r-- you yours 6.1K date time processVars.r
> -rw-r--r-- you yours 1.7K date time README
> -rw-r--r-- you yours 1.8K date time tlrRutilities.r
> -rw-r--r-- you yours 8.4K date time windowEmissions.r
> -rw-r--r-- you yours 8.1K date time writeBELDlayer.r
2 Download the input data from
https://github.com/TomRoche/ioapi-hack-R/downloads
E.g. (in bash),
URI_ROOT="https://github.com/downloads/TomRoche/ioapi-hack-R"
DIR="/tmp/ioapi-hack-R"
for FN in \
"map.CMAQkm.world.dat" \
"epic_site_crops_0529_USA_2Ellen.csv" \
"epic_site_crops_0529_USA_2Ellen.rds" \
"5yravg.test.nc" \
; do
URI="${URI_ROOT}/${FN}"
FP="${DIR}/${FN}" # file path
# curl can't handle the redirects, so use wget
# ARGS="-c -O ${FP}"
# for broken-cert environments (like EPA terrae) use '--no-check-certificate'
ARGS="--no-check-certificate -c -O ${FP}"
for CMD in \
"wget ${ARGS} ${URI}" \
; do
echo -e "$ ${CMD}"
eval "${CMD}"
done
done
The folder contents should resemble
-rwxr-xr-x you yours 6.6K date time beldRead.r
-rwxr-xr-x you yours 963 date time beldToRDS.r
-rw-r--r-- you yours 15K date time computeCropSum.r
-rwxr-xr-x you yours 13K date time computeCropSum.sh
-rw-r--r-- you yours 6.2K date time demonotonicizeVar.r
drwxr-xr-x you yours 4.0K date time .git
-rw-r--r-- you yours 120 date time .gitignore
-rw-r--r-- you yours 16K date time ioapi.r
-rwxr-xr-x you yours 3.8K date time plotLayersForTimestep.r
-rw-r--r-- you yours 6.5K date time processLayers.r
-rw-r--r-- you yours 6.1K date time processVars.r
-rw-r--r-- you yours 1.7K date time README
-rw-r--r-- you yours 1.8K date time tlrRutilities.r
-rw-r--r-- you yours 8.4K date time windowEmissions.r
-rw-r--r-- you yours 8.1K date time writeBELDlayer.r
-rw-r--r-- you yours 1.1M date time map.CMAQkm.world.dat
-rw-r--r-- you yours 1.5M date time epic_site_crops_0529_USA_2Ellen.rds
-rw-r--r-- you yours 5.5M date time epic_site_crops_0529_USA_2Ellen.csv
-rw-r--r-- you yours 638M date time 5yravg.test.nc
3 Run it: e.g.,
/tmp/ioapi-hack-R $ ./computeCropSum.sh
It should produce
3.1 a ginormous console trace, at times paused
3.2 several new netCDF files, e.g.,
-rw-r--r-- you yours 400K date time 5yravg.DN2windowed.nc
-rw-r--r-- you yours 24M date time 5yravg.DN2summed.nc
-rw-r--r-- you yours 24M date time 5yravg.DN2belded.nc
-rw-r--r-- you yours 24M date time 5yravg.DN2layers_fixed.nc
-rw-r--r-- you yours 24M date time 5yravg.DN2layered.nc
-rw-r--r-- you yours 1.1M date time temp.extend.nc
-rw-r--r-- you yours 24M date time temp.full.nc
-rw-r--r-- you yours 22M date time 5yravg.DN2demonotonicized.nc
-rw-r--r-- you yours 22M date time 5yravg.DN2vars_fixed.nc
-rw-r--r-- you yours 22M date time 5yravg.DN2stripped.nc
The main output is '5yravg.DN2windowed.nc', which you should be able to open with VERDI (the point of the IOAPI part of this exercise :-) Compared to the source NetCDF (5yravg.test.nc), that output
* covers a smaller horizontal extent
* has many fewer datavars: in fact, only one (DN2) other than the IOAPI "metadatavar" TFLAG.
3.3 a plot file containing plots of each data layer in the window, plus
* a plot of the sum of the BELD proportions in each gridcell (penultimate layer)
* a plot of the integrated DN2 emissions over each gridcell (final layer)
After you run it, improve it! The code is currently quite crude, so feel free to fix/extend--and then send me pull request!
HTH, Tom Roche <[email protected]>