source: DVD_images/update_DVD_images.py @ 7205

Last change on this file since 7205 was 7205, checked in by rwilson, 15 years ago

Commit the DVD image generation stuff. This will be archived later.

  • Property svn:executable set to *
File size: 20.4 KB
Line 
1#!/usr/bin/env python
2
3'''
4Program to update a DVD jurisdiction 'anuga' directory from the
5original source directory.
6
7usage: update.py <source>
8
9where <source> is one of:
10                  Hobart
11                  BatemansBay
12                  Gosford
13                  GoldCoast
14ie, the name of one of the DVD jurisdiction staging directories
15(case-insensitive).
16'''
17
18import os
19import sys
20import shutil
21import time
22
23
24# common base path to all data and project files
25main_path = '/nas/gemd/georisk_models/inundation'
26
27# structures holding data for each jurisdiction
28#   data_src_path  : sub-path to data directory
29#   proj_src_path  : sub-path to project files
30#   data_dst_path  : where to copy data files to
31#   proj_dst_path  : where to copy project files to
32#   copy_data_dirs : data directories to completely copy
33#   make_dst_dirs  : make these data directories (may be left empty)
34#   copy_data_files: individual data files to copy to <data_dst_path>
35#   copy_proj_files: individual project files to copy to <proj_dst_path>
36hobart_data = \
37{'jurisdiction':    'Hobart',           # jurisdiction name
38
39 # paths to various source directories
40 'data_src_path':   'data/tasmania/hobart_tsunami_scenario_2009/anuga',
41 'arcgis_src_path': 'data/tasmania/hobart_tsunami_scenario_2009/ArcGIS',
42 'proj_src_path':   'sandpits/kvanputten/ANUGA/anuga_work/production/hobart_2009',
43
44 # paths to destination directories (under 'jurisdiction' root)
45 'data_dst_path':   'data/tasmania/hobart_tsunami_scenario_2009/anuga',
46 'proj_dst_path':   'project',
47 'arcgis_dst_path': 'ArcGIS',
48
49 # copy or create whole directories
50 'make_dst_dirs':   ['gauges', 'outputs', 'topographies/elevation_fix', 'meshes'],
51 'copy_data_dirs':  ['boundaries', 'polygons'],
52
53 # copy 'data' files or directories
54 'copy_data_files': ['gauges/schema.ini', 'gauges/tsunamipointsMGA.csv',
55                     'topographies/hobart_combined_elevation.pts',
56                     'topographies/hobart_combined_elevation.txt',
57                     'topographies/elevation_fix/topo_grid_notsw.pts',
58                     'topographies/elevation_fix/topo_grid_notsw.dem',
59                     'topographies/elevation_fix/topo_grid_notsw.asc',
60                     'topographies/elevation_fix/topo_grid_notsw.prj'],
61
62 # copy 'project' files or directories
63 'copy_proj_files': ['build_elevation.py', 'build_urs_boundary.py', 'combine_gauges.py',
64                     'export_results_max.py', 'file_length.py', 'get_runup_v2.py',
65                     'get_timeseries.py', 'project.py', 'run_model.py', 'setup_model.py'],
66
67 # copy 'arcgis' files or directories
68 'copy_arc_files':  []
69}
70
71batemans_bay_data = \
72{'jurisdiction':    'BatemansBay',      # jurisdiction name
73
74 # paths to various source directories
75 'data_src_path':   'data/new_south_wales/batemans_bay_tsunami_scenario_2009/anuga',
76 'arcgis_src_path': 'data/new_south_wales/batemans_bay_tsunami_scenario_2009/ArcGIS',
77 'proj_src_path':   'sandpits/jgriffin/ANUGA/anuga_work/production/new_south_wales/batemans_bay',
78
79 # paths to destination directories (under 'jurisdiction' root)
80 'data_dst_path':   'data/new_south_wales/batemans_bay_tsunami_scenario_2009/anuga',
81 'proj_dst_path':   'project',
82 'arcgis_dst_path': 'ArcGIS',
83
84 # copy or create whole directories
85 'make_dst_dirs':   ['outputs', 'topographies', 'meshes'],
86 'copy_data_dirs':  ['boundaries', 'polygons', 'gauges'],
87
88 # copy 'data' files or directories
89 'copy_data_files': ['topographies/1a.asc', 'topographies/1b.asc', 'topographies/2b.asc',
90                     'topographies/2a_3.asc', 'topographies/3b.asc', 'topographies/3a.asc',
91                     'topographies/4a_2.asc', 'topographies/4b.asc', 'topographies/off1.asc',
92                     'topographies/off2.asc', 'topographies/off3.asc', 'topographies/bbhd.asc',
93                     'topographies/sd100031996_p.asc', 'topographies/sd100031996_p2.asc',
94                     'topographies/sd100031996_p3.asc', 'topographies/sd100031996_p4.asc',
95                     'topographies/1a.prj', 'topographies/1b.prj', 'topographies/2b.prj',
96                     'topographies/2a_3.prj', 'topographies/3b.prj', 'topographies/3a.prj',
97                     'topographies/4a_2.prj', 'topographies/4b.prj', 'topographies/off1.prj',
98                     'topographies/off2.prj', 'topographies/off3.prj', 'topographies/bbhd.prj',
99                     'topographies/sd100031996_p.prj', 'topographies/sd100031996_p2.prj',
100                     'topographies/sd100031996_p3.prj', 'topographies/sd100031996_p4.prj',
101                     'topographies/SD100031996_jgriffin_clip.csv', 'topographies/tomaga_offshore_AHD_MGA_1997.csv',
102                     'topographies/Batemans_BBHD_MGA_1995.csv', 'topographies/moruya_AHD_MGA_2000.csv',
103# these files are generated by build_elevation.py, but included as a courtesy (if space permits)
104                     'topographies/batemans_bay_combined_elevation.pts',
105                     'topographies/batemans_bay_combined_elevation.txt'],
106
107 # copy 'project' files or directories
108 #'copy_proj_files': ['project.py', 'run_model_250m.py', 'run_model.py', 'setup_model_250m.py',
109 #                    'setup_model.py', 'build_elevation_250m.py', 'build_elevation.py',
110 #                    'build_urs_boundary.py', 'export_results_max.py', 'extract_from_csv.py',
111 #                    'file_length.py', 'get_runup.py', ],
112 'copy_proj_files': ['project.py', 'run_model_250m.py', 'setup_model_250m.py',
113                     'setup_model.py', 'build_elevation_250m.py', 'build_elevation.py',
114                     'build_urs_boundary.py', 'export_results_max.py', 'extract_from_csv.py',
115                     'file_length.py', 'get_runup.py', ],
116
117 # copy 'arcgis' files or directories
118 'copy_arc_files':  []
119}
120
121gosford_data = \
122{'jurisdiction':    'Gosford',          # jurisdiction name
123
124 # paths to various source directories
125 'data_src_path':   'data/new_south_wales/gosford_tsunami_scenario_2009/anuga',
126 'arcgis_src_path': 'data/new_south_wales/gosford_tsunami_scenario_2009/ArcGIS',
127 'proj_src_path':   'sandpits/jgriffin/ANUGA/anuga_work/production/new_south_wales/gosford',
128
129 # paths to destination directories (under 'jurisdiction' root)
130 'data_dst_path':   'data/new_south_wales/gosford_tsunami_scenario_2009/anuga',
131 'proj_dst_path':   'project',
132 'arcgis_dst_path': 'ArcGIS',
133
134 # copy or create whole directories
135 'make_dst_dirs':   ['outputs', 'topographies/original', 'polygons', 'gauges',
136                     'meshes'],
137 'copy_data_dirs':  ['boundaries'],
138
139 # copy 'data' files or directories
140 'copy_data_files': ['topographies/original/e151_s34_clip2.asc',
141                     'topographies/original/e151_s34_clip2.prj',
142                     'topographies/original/aus197_topo2raster_clip2.asc',
143                     'topographies/original/aus197_topo2raster_clip2.prj',
144                     'topographies/original/hydro_topo2raster_clip2.asc',
145                     'topographies/original/hydro_topo2raster_clip2.prj',
146                     'topographies/original/file_list.csv',
147                     'topographies/original/G3346294.txt',
148                     'topographies/original/G3346296.txt',
149                     'topographies/original/G3366284.txt',
150                     'topographies/original/G3366286.txt',
151                     'topographies/original/G3366288.txt',
152                     'topographies/original/G3366290.txt',
153                     'topographies/original/G3366294.txt',
154                     'topographies/original/G3366296.txt',
155                     'topographies/original/G3366298.txt',
156                     'topographies/original/G3386284.txt',
157                     'topographies/original/G3386286.txt',
158                     'topographies/original/G3386288.txt',
159                     'topographies/original/G3386290.txt',
160                     'topographies/original/G3386292.txt',
161                     'topographies/original/G3386294.txt',
162                     'topographies/original/G3386296.txt',
163                     'topographies/original/G3386298.txt',
164                     'topographies/original/G3386300.txt',
165                     'topographies/original/G3406284.txt',
166                     'topographies/original/G3406286.txt',
167                     'topographies/original/G3406288.txt',
168                     'topographies/original/G3406290.txt',
169                     'topographies/original/G3406292.txt',
170                     'topographies/original/G3406294.txt',
171                     'topographies/original/G3406296.txt',
172                     'topographies/original/G3406298.txt',
173                     'topographies/original/G3406300.txt',
174                     'topographies/original/G3426284.txt',
175                     'topographies/original/G3426286.txt',
176                     'topographies/original/G3426288.txt',
177                     'topographies/original/G3426290.txt',
178                     'topographies/original/G3426292.txt',
179                     'topographies/original/G3426294.txt',
180                     'topographies/original/G3426296.txt',
181                     'topographies/original/G3426298.txt',
182                     'topographies/original/G3426300.txt',
183                     'topographies/original/G3426302.txt',
184                     'topographies/original/G3426304.txt',
185                     'topographies/original/G3446284.txt',
186                     'topographies/original/G3446286.txt',
187                     'topographies/original/G3446288.txt',
188                     'topographies/original/G3446290.txt',
189                     'topographies/original/G3446292.txt',
190                     'topographies/original/G3446294.txt',
191                     'topographies/original/G3446296.txt',
192                     'topographies/original/G3446298.txt',
193                     'topographies/original/G3446300.txt',
194                     'topographies/original/G3446302.txt',
195                     'topographies/original/G3446304.txt',
196                     'topographies/original/G3446306.txt',
197                     'topographies/original/G3466286.txt',
198                     'topographies/original/G3466288.txt',
199                     'topographies/original/G3466290.txt',
200                     'topographies/original/G3466292.txt',
201                     'topographies/original/G3466294.txt',
202                     'topographies/original/G3466296.txt',
203                     'topographies/original/G3466298.txt',
204                     'topographies/original/G3466300.txt',
205                     'topographies/original/G3466302.txt',
206                     'topographies/original/G3466304.txt',
207                     'topographies/original/G3466306.txt',
208                     'topographies/original/G3486288.txt',
209                     'topographies/original/G3486290.txt',
210                     'topographies/original/G3486292.txt',
211                     'topographies/original/G3486294.txt',
212                     'topographies/original/G3486296.txt',
213                     'topographies/original/G3486298.txt',
214                     'topographies/original/G3486300.txt',
215                     'topographies/original/G3486302.txt',
216                     'topographies/original/G3486304.txt',
217                     'topographies/original/G3486306.txt',
218                     'topographies/original/G3506288.txt',
219                     'topographies/original/G3506290.txt',
220                     'topographies/original/G3506292.txt',
221                     'topographies/original/G3506294.txt',
222                     'topographies/original/G3506296.txt',
223                     'topographies/original/G3506298.txt',
224                     'topographies/original/G3506300.txt',
225                     'topographies/original/G3506302.txt',
226                     'topographies/original/G3506304.txt',
227                     'topographies/original/G3506306.txt',
228                     'topographies/original/G3526288.txt',
229                     'topographies/original/G3526290.txt',
230                     'topographies/original/G3526292.txt',
231                     'topographies/original/G3526294.txt',
232                     'topographies/original/G3526296.txt',
233                     'topographies/original/G3526298.txt',
234                     'topographies/original/G3526300.txt',
235                     'topographies/original/G3526302.txt',
236                     'topographies/original/G3526304.txt',
237                     'topographies/original/G3546290.txt',
238                     'topographies/original/G3546292.txt',
239                     'topographies/original/G3546294.txt',
240                     'topographies/original/G3546296.txt',
241                     'topographies/original/G3546298.txt',
242                     'topographies/original/G3546300.txt',
243                     'topographies/original/G3546302.txt',
244                     'topographies/original/G3546304.txt',
245                     'topographies/original/G3566296.txt',
246                     'topographies/original/G3566298.txt',
247                     'topographies/original/G3566300.txt',
248                     'topographies/original/G3566302.txt',
249                     'topographies/original/G3566304.txt',
250                     'topographies/original/G3586302.txt',
251                     'topographies/original/estuaries.txt',
252                     'topographies/original/ENT5C1S08_03_AHD_prepared.txt',
253                     'topographies/original/ENT5C1S09_03_AHD_prepared.txt',
254                     'topographies/original/ENT5C1S10_03_AHD_prepared.txt',
255                     'topographies/original/hydro_clip_neg.txt',
256                     'polygons/bounding_polygon.csv',
257                     'polygons/aoi_umina_large.csv',
258                     'polygons/aoi_terrigal.csv',
259                     'polygons/aos_umina_large.csv',
260                     'polygons/aos_terrigal.csv',
261                     'polygons/initial_conditions.csv',
262                     'polygons/images.csv',
263                     'gauges/gauges.csv'],
264
265 # copy 'project' files or directories
266 'copy_proj_files': ['build_urs_boundary.py', 'export_results_max.py', 'file_length.py',
267                     'get_runup.py', 'prepare_data_AUS197.py', 'prepare_data_hydro.py',
268                     'project.py', 'run_model.py', 'build_elevation.py', 'extract_from_csv.py',
269                     'get_timeseries.py', 'prepare_data_ENT5CIS.py', 'prepare_data.py',
270                     'setup_model.py'],
271
272 # copy 'arcgis' files or directories
273 'copy_arc_files':  []
274}
275
276gold_coast_data = \
277{'jurisdiction':    'GoldCoast',        # jurisdiction name
278
279 # paths to various source directories
280 'data_src_path':   'data/queensland/gold_coast_tsunami_scenario_2009/anuga',
281 'arcgis_src_path': 'data/queensland/gold_coast_tsunami_scenario_2009/ArcGIS',
282 'proj_src_path':   'sandpits/lfountain/anuga_work/production/gold_coast_2009',
283
284 # paths to destination directories (under 'jurisdiction' root)
285 'data_dst_path':   'data/queensland/gold_coast_tsunami_scenario_2009/anuga',
286 'proj_dst_path':   'project',
287 'arcgis_dst_path': 'ArcGIS',
288
289 # copy or create whole directories
290 'make_dst_dirs':   ['outputs', 'meshes', 'polygons', 'topographies', 'gauges'],
291 'copy_data_dirs':  ['boundaries'],
292
293 # copy 'data' files or directories
294 'copy_data_files': ['outputs/Event1_HAT', 'outputs/Event1_MSL',
295                     'outputs/Event2_HAT', 'outputs/Event2_MSL',
296                     'outputs/Event3_HAT', 'outputs/Event3_MSL',
297                     'polygons/bounding_polygon_sml.csv',
298                     'polygons/initial_conditions_sml.csv',
299                     'polygons/images.csv',
300                     'topographies/gold_coast_combined_elevation_250m.pts',
301                     'topographies/grid250m_all_pro.asc',
302                     'topographies/grid250m_all_pro.prj'],
303
304 # copy 'project' files or directories
305 'copy_proj_files': ['build_elevation.py', 'export_results_max.py', 'file_length.py',
306                     'get_runup.py', 'project.py', 'run_model.py', 'setup_model.py',
307                     'build_urs_boundary.py', 'combine_gauges.py', 'get_timeseries.py',
308                     'run_multiple_events.py'
309                    ],
310
311 # copy 'arcgis' files or directories
312 'copy_arc_files':  ['gold_coast.mxd']
313}
314
315# dictionary mapping lower-case jurisdiction name to jurisdiction data dictionary
316source_jurisdiction_path = {'hobart': hobart_data,
317                            'batemansbay': batemans_bay_data,
318                            'gosford': gosford_data,
319                            'goldcoast': gold_coast_data
320                           }
321
322######
323# Routines to automate the script data above.
324######
325
326def log(msg=''):
327    print(msg)
328
329
330def dir_copy(src, dst):
331    cmd = 'cp -R %s %s' % (src, dst)
332    log('Doing: %s' % cmd)
333    fd = os.popen(cmd)
334    fd.close()
335
336def copy_file_or_dir(src, dst):
337    '''Copy a file or complete directory.'''
338
339    # could be a file or directory being copied
340    try:
341        shutil.copyfile(src, dst)
342    except IOError, e:
343        if 'Is a directory' in str(e):
344            shutil.copytree(src, dst)
345        else:
346            log('*' *72)
347            log('* %s' % str(e))
348            log('*' *72)
349
350def update_staging(jurisdiction):
351    # create a list of jurisdiction names
352    jurisdiction_names = []
353    for k in source_jurisdiction_path:
354        jurisdiction_names.append(source_jurisdiction_path[k]['jurisdiction'])
355
356    # get ready
357    j_dict = source_jurisdiction_path[jurisdiction]
358    j_name = j_dict['jurisdiction']
359    data_src_path = os.path.join(main_path, j_dict['data_src_path'])
360    data_dst_path = os.path.join(os.getcwd(), j_name, j_dict['data_dst_path'])
361    proj_src_path = os.path.join(main_path, j_dict['proj_src_path'])
362    proj_dst_path = os.path.join(os.getcwd(), j_name, j_dict['proj_dst_path'])
363    arcgis_src_path = os.path.join(main_path, j_dict['arcgis_src_path'])
364    arcgis_dst_path = os.path.join(os.getcwd(), j_name, j_dict['arcgis_dst_path'])
365
366    # create new output directory, delete old if there
367    if os.path.exists(j_name):
368        log('Deleting existing staging directory: %s' % j_name)
369        shutil.rmtree(j_name)
370    log('Creating staging directory: %s' % j_name)
371    os.makedirs(j_name)
372
373    # create required directories
374    for dir in j_dict['make_dst_dirs']:
375        new_dir = os.path.join(data_dst_path, dir)
376        log('Creating directory: %s' % dir)
377        os.makedirs(new_dir)
378
379    # copy required full directories
380    for copy_dir in j_dict['copy_data_dirs']:
381        src_dir = os.path.join(data_src_path, copy_dir)
382        dst_dir = os.path.join(data_dst_path, copy_dir)
383        log('Copying directory: %s' % copy_dir)
384        copy_file_or_dir(src_dir, dst_dir)
385
386    # copy required data files
387    for copy_file in j_dict['copy_data_files']:
388        src_file = os.path.join(data_src_path, copy_file)
389        new_file = os.path.join(data_dst_path, copy_file)
390        log('Copying: %s' % copy_file)
391        copy_file_or_dir(src_file, new_file)
392
393    # copy required project files
394    log('Creating directory: %s' % proj_dst_path)
395    os.makedirs(proj_dst_path)
396    for copy_file in j_dict['copy_proj_files']:
397        src_file = os.path.join(proj_src_path, copy_file)
398        new_file = os.path.join(proj_dst_path, copy_file)
399        log('Copying: %s' % copy_file)
400        copy_file_or_dir(src_file, new_file)
401
402    # copy required ArcGIS files
403    log('Creating directory: %s' % arcgis_dst_path)
404    os.makedirs(arcgis_dst_path)
405    for copy_file in j_dict['copy_arc_files']:
406        src_file = os.path.join(arcgis_src_path, copy_file)
407        new_file = os.path.join(arcgis_dst_path, copy_file)
408        log('Copying: %s' % copy_file)
409        copy_file_or_dir(src_file, new_file)
410
411    # now copy jurisdiction-specific DVD files
412    src_dir = 'extra_files/%s/*' % j_name
413    dst_dir = j_name
414    dir_copy(src_dir, dst_dir)
415
416    # copy the extra_files and special directories
417    src_dir = 'extra_files/browser_files'
418    dst_dir = j_name
419    dir_copy(src_dir, dst_dir)
420    src_dir = 'extra_files/documents'
421    dir_copy(src_dir, dst_dir)
422    src_file = 'extra_files/autorun.inf'
423    dir_copy(src_file, dst_dir)
424    src_dir = 'extra_files/.cache'
425    dir_copy(src_dir, dst_dir)
426
427    # get size of the staging directory
428    cmd = 'du -sh %s' % j_name
429    fd = os.popen(cmd, 'r')
430    res = fd.read()
431    fd.close()
432    (res, _) = res.split('\t', 1)
433    log('Staging directory %s has size %s' % (j_name, res))
434
435def usage():
436    print('usage: update.py <source>')
437    print('where <source> is one of the jurisdiction staging directories.')
438
439
440if len(sys.argv) != 2:
441    usage()
442    sys.exit(10)
443
444jurisdiction = sys.argv[1].lower()
445# remove any trailing '/' - from TAB completion
446if jurisdiction.endswith('/'):
447    jurisdiction = jurisdiction[:-1]
448
449start_time = time.time()
450update_staging(jurisdiction)
451stop_time = time.time()
452elapsed_time = stop_time - start_time
453log('Elapsed time is %.1fs' % elapsed_time)
Note: See TracBrowser for help on using the repository browser.