-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharchive.py
308 lines (210 loc) · 11.7 KB
/
archive.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
'''
Urban-PLUMBER processing code
Associated with the manuscript: Harmonized, gap-filled dataset from 20 urban flux tower sites
Copyright (c) 2021 Mathew Lipson
Licensed under the Apache License, Version 2.0 (the "License").
You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
'''
__title__ = "Ancillary functions for archiving and copying processed files"
__version__ = "2022-09-22"
__author__ = "Mathew Lipson"
__email__ = "[email protected]"
import glob
import os
import sys
import importlib
import pandas as pd
# data path (local or server)
oshome=os.getenv('HOME')
projpath = f'{oshome}/git/urban-plumber_pipeline' # root of repository
sitelist = ['AU-Preston','AU-SurreyHills','CA-Sunset','FI-Kumpula','FI-Torni','FR-Capitole',
'GR-HECKOR','JP-Yoyogi','KR-Jungnang','KR-Ochang','MX-Escandon','NL-Amsterdam',
'PL-Lipowa','PL-Narutowicza','SG-TelokKurau06','UK-KingsCollege','UK-Swindon',
'US-Baltimore','US-Minneapolis1','US-Minneapolis2','US-WestPhoenix']
restricted = ['SG-TelokKurau'] # as used in model evaluation
open_sites = sorted(list(set(sitelist) - set(restricted)))
fluxdata_version = 'v1'
archive_version = 'v1'
sitedata_version = 'v1'
###################
# v0.9 original submission
# v0.92 update with SG-TelokKurau06
# v1 for publication in ESSD after peer review
###################
def main():
archive()
# web_archive()
# archive_light()
# copy_to_website()
return
def archive():
archpath = f'{oshome}/up_archive_{archive_version}'
if not os.path.exists(archpath):
print(f'making {archpath} dir')
os.mkdir(archpath)
os.chdir(archpath)
for sitename in sitelist:
sitepath = f'{projpath}/sites/{sitename}'
# make directories if necessary
for dirname in ['timeseries','index_files']:
if not os.path.exists(f'{archpath}/{sitename}/{dirname}'):
print(f'making {sitename}/{dirname} dir')
os.makedirs(f'{archpath}/{sitename}/{dirname}')
print(f'copying {sitename} files archive {fluxdata_version}')
# os.system(f'cp {sitepath}/log_processing_{sitename}_{fluxdata_version}.txt {archpath}/{sitename}/log_processing_{sitename}_{fluxdata_version}.txt')
os.system(f'cp {sitepath}/{sitename}_sitedata_{sitedata_version}.csv {archpath}/{sitename}/{sitename}_sitedata_{sitedata_version}.csv')
os.system(f'cp {sitepath}/index.html {archpath}/{sitename}/index.html')
os.system(f'cp {sitepath}/index_files/* {archpath}/{sitename}/index_files/')
for timeseries in ['clean_observations','metforcing','raw_observations']:
os.system(f'cp {sitepath}/timeseries/{sitename}_{timeseries}_{fluxdata_version}.nc {archpath}/{sitename}/timeseries/')
os.system(f'cp {sitepath}/timeseries/{sitename}_{timeseries}_{fluxdata_version}.txt {archpath}/{sitename}/timeseries/')
for timeseries in ['era5_corrected']:
os.system(f'cp {sitepath}/timeseries/{sitename}_{timeseries}_{fluxdata_version}.nc {archpath}/{sitename}/timeseries/')
os.system(f'cp {projpath}/README.html {archpath}/README.html')
########################################################################
# RESTRICTED NO LONGER REQUIRED, ALL ARE OPEN
# licence = 'These files are restricted. You must have written authorisation from data providers to access. Do not distribute.'
# create_readme(archpath,licence)
# print('creating zip archives')
# for sitename in restricted:
# os.system(f'zip -r -X Urban-PLUMBER_Sites_{sitename}.zip {sitename} README.md')
# os.system(f'zip -r -X Urban-PLUMBER_Sites_FullCollection.zip { f" ".join(sitelist)} README.md')
########################################################################
licence = 'Data are licenced under CC-BY-4.0. https://creativecommons.org/licenses/by/4.0/'
create_readme(archpath,licence)
os.system(f'zip -r -X -8 Urban-PLUMBER_FullCollection_{archive_version}.zip { f" ".join(open_sites)} README.html')
print('deleting unzipped folders')
for sitename in sitelist:
os.system(f'rm -r {archpath}/{sitename}')
# os.system(f'rm {archpath}/README.md')
########################################################################
print('collecting additional files')
os.makedirs(f'{archpath}/obs_in_one')
os.system(f'cp {projpath}/obs_in_one/* {archpath}/obs_in_one/')
os.system(f'zip -r -X -8 Urban-PLUMBER_obs_only_{archive_version}.zip obs_in_one')
os.system(f'rm -r {archpath}/obs_in_one')
return
def create_readme(archpath,licence):
with open(f'{archpath}/README.md', 'w') as f:
f.write(f'''
{licence}
---
# Urban-PLUMBER site data collection
Files in this folder are associated with the manuscript:
> "Harmonized, gap-filled dataset from 20 urban flux tower sites"
Published in Earth System Science Data (2022).
Use of any data must give credit through citation of the above manuscript, the data repository, and other site references as appropriate.
We recommend data users consult with site contributing authors and/or the coordination team in the project planning stage.
Relevant contacts are included in timeseries metadata.
This data was downloaded from: https://doi.org/10.5281/zenodo.5517550
For site information and timeseries plots see https://urban-plumber.github.io/sites.
For processing code see https://github.com/matlipson/urban-plumber_pipeline.
### Included files
Within each site folder:
- `index.html`: A summary page with site characteristics and timeseries plots.
- `SITENAME_sitedata_vX.csv`: comma seperated file for numerical site characteristics e.g. location, surface cover fraction etc.
- `timeseries/` (following files available as netCDF and txt)
- `SITENAME_raw_observations_vX`: site observed timeseries before project-wide quality control.
- `SITENAME_clean_observations_vX`: site observed timeseries after project-wide quality control.
- `SITENAME_metforcing_vX`: site observed timeseries after project-wide quality control and gap filling.
- `SITENAME_era5_corrected_vX`: site ERA5 surface data (1990-2020) with bias corrections as applied in the final dataset.
- `log_processing_SITENAME_vX.txt`: a log of the print statements through running the create_dataset_SITENAME scripts.
Timeseries in netcdf (nc) and space-seperated text (txt) formats contain identical data.
### All-in-one observations
Additionally, clean observational timeseries data (as in `SITENAME_clean_observations_vX.nc`) have been combined into single files for convenience:
- `UP_all_clean_observations_UTC_v1.nc`: in coordinated universal time (UTC)
- `UP_all_clean_observations_localstandardtime_v1.nc`: in local standard time
These data are available in a seperate archive at: https://doi.org/10.5281/zenodo.5517550
Additional information is availale in that archive's README.md.
### Authors
Mathew Lipson, Sue Grimmond, Martin Best, Andreas Christen, Andrew Coutts, Ben Crawford, Bert Heusinkveld,
Erik Velasco, Helen Claire Ward, Hirofumi Sugawara, Je-Woo Hong, Jinkyu Hong, Jonathan Evans, Joseph McFadden,
Keunmin Lee, Krzysztof Fortuniak, Leena Järvi, Matthias Roth, Nektarios Chrysoulakis, Nigel Tapper, Oliver Michels,
Simone Kotthaus, Stevan Earl, Sungsoo Jo, Valéry Masson, Winston Chow, Wlodzimierz Pawlak, Yeon-Hee Kim.
Corresponding author: Mathew Lipson ([email protected])
Alternative contact: Sue Grimmond ([email protected])
### Versions
- v0.9 original submission
- v0.92 update with SG-TelokKurau06
- v1 for publication in ESSD after peer review
''')
return
def copy_index_only():
webpath = f'{oshome}/git/urban-plumber.github.io'
for sitename in sitelist:
sitepath = f'{projpath}/sites/{sitename}'
os.system(f'cp {sitepath}/index.md {webpath}/{sitename}/index.md')
return
def copy_from_website_light():
''' copies files not automatically produced by the pipeline from the website folder the pipeline folder'''
for sitename in sitelist:
sitepath = f'{projpath}/sites/{sitename}'
print(f'copying image files from website')
for image in ['site_photo.jpg']:
os.system(f'cp {webpath}/{sitename}/images/{sitename}_{image} {sitepath}/images/{sitename}_{image}')
subsitelist = ['FI-Kumpula','FI-Torni','JP-Yoyogi','US-Minneapolis1','US-Minneapolis2']
for sitename in subsitelist:
sitepath = f'{projpath}/sites/{sitename}'
print(f'copying image files from website')
for image in ['site_sat.jpg']:
os.system(f'cp {webpath}/{sitename}/images/{sitename}_{image} {sitepath}/images/{sitename}_{image}')
return
def web_archive():
'''for archiving index.html site pages (created from index.md)'''
archpath = f'{oshome}/up_web_archive_{fluxdata_version}'
if not os.path.exists(archpath):
print(f'making {archpath} dir')
os.mkdir(archpath)
for sitename in sitelist:
sitepath = f'{projpath}/sites/{sitename}'
# make directories if necessary
for dirname in ['index_files']:
if not os.path.exists(f'{archpath}/{sitename}/{dirname}'):
print(f'making {sitename}/{dirname} dir')
os.makedirs(f'{archpath}/{sitename}/{dirname}')
print(f'copying {sitename} files archive {fluxdata_version}')
os.system(f'cp {sitepath}/index.html {archpath}/{sitename}/index.html')
os.system(f'cp {sitepath}/index_files/* {archpath}/{sitename}/index_files/')
return
def copy_to_website():
webpath = f'{oshome}/git/urban-plumber.github.io'
for sitename in sitelist:
sitepath = f'{projpath}/sites/{sitename}'
for dirname in ['obs_plots','era_correction','images']:
# make directories if necessary
if not os.path.exists(f'{webpath}/{sitename}/{dirname}'):
print(f'making {dirname} dir')
os.makedirs(f'{webpath}/{sitename}/{dirname}')
print(f'copying {sitename} files to git for website')
os.system(f'cp {sitepath}/index.md {webpath}/{sitename}/index.md')
os.system(f'cp {sitepath}/obs_plots/* {webpath}/{sitename}/obs_plots/')
for flux in ['Tair','Qair','PSurf','LWdown','SWdown','Wind','Rainf']:
os.system(f'cp {sitepath}/era_correction/{sitename}_{flux}_all_diurnal.png {webpath}/{sitename}/era_correction/')
print(f'copying image files to website')
for image in ['region_map.jpg','site_map.jpg','site_photo.jpg','site_sat.jpg']:
os.system(f'cp {sitepath}/images/{sitename}_{image} {webpath}/{sitename}/images/{sitename}_{image} ')
return
def clean_out():
for sitename in sitelist:
sitepath = f'{projpath}/sites/{sitename}'
os.system(f'rm -r {sitepath}/{sitename}_siteattrs*')
os.system(f'rm -r {sitepath}/log_processing*')
os.system(f'rm -r {sitepath}/index.md')
os.system(f'rm -r {sitepath}/index.html')
print(f'removing {sitename} files')
if os.path.exists(f'{sitepath}/obs_plots'):
os.system(f'rm -r {sitepath}/obs_plots')
if os.path.exists(f'{sitepath}/era_correction'):
os.system(f'rm -r {sitepath}/era_correction')
if os.path.exists(f'{sitepath}/precip_plots'):
os.system(f'rm -r {sitepath}/precip_plots')
if os.path.exists(f'{sitepath}/processing'):
os.system(f'rm -r {sitepath}/processing')
if os.path.exists(f'{sitepath}/timeseries'):
os.system(f'rm -r {sitepath}/timeseries')
if os.path.exists(f'{sitepath}/index_files'):
os.system(f'rm -r {sitepath}/index_files')
if os.path.exists(f'{sitepath}/images'):
os.system(f'rm -r {sitepath}/images')
if __name__ == "__main__":
main()