1 | """Convert from Arcview ASCII DEMs via native netcdf dem format |
---|
2 | to native pts netcdf format for use with least_squares fits |
---|
3 | """ |
---|
4 | |
---|
5 | import os |
---|
6 | import time |
---|
7 | |
---|
8 | |
---|
9 | from pyvolution.shallow_water import Domain, Reflective_boundary, File_boundary |
---|
10 | from pyvolution.data_manager import convert_dem_from_ascii2netcdf,\ |
---|
11 | dem2pts, ferret2sww |
---|
12 | from pyvolution.pmesh2domain import pmesh_to_domain_instance |
---|
13 | from caching import cache |
---|
14 | import project |
---|
15 | |
---|
16 | #Data preparation |
---|
17 | #Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
18 | demname = project.demname |
---|
19 | |
---|
20 | cache(convert_dem_from_ascii2netcdf, demname, {'verbose': True}, |
---|
21 | dependencies = [demname + '.asc'], |
---|
22 | verbose = True) |
---|
23 | #evaluate = True) |
---|
24 | |
---|
25 | cache(dem2pts, demname, {'verbose': True}, |
---|
26 | dependencies = [demname + '.dem'], |
---|
27 | verbose = True) |
---|
28 | |
---|
29 | |
---|
30 | #Convert MOST boundary |
---|
31 | source_dir = project.boundarydir |
---|
32 | |
---|
33 | |
---|
34 | #Data |
---|
35 | from pyvolution.data_manager import ferret2sww |
---|
36 | |
---|
37 | |
---|
38 | south = project.south |
---|
39 | north = project.north |
---|
40 | west = project.west |
---|
41 | east = project.east |
---|
42 | |
---|
43 | #Origin of existing dem (FIXME: Temporary measure) |
---|
44 | mesh_origin = (50, 421544.35127423, 7677669.5257159) |
---|
45 | |
---|
46 | ferret2sww(source_dir+project.boundary_basename, |
---|
47 | project.boundary_basename, |
---|
48 | verbose=True, |
---|
49 | minlat=south-1, maxlat=north+1, |
---|
50 | minlon=west-1, maxlon=east+1, |
---|
51 | origin = mesh_origin, |
---|
52 | zscale = 1, |
---|
53 | fail_on_NaN = False, |
---|
54 | inverted_bathymetry = True), |
---|
55 | |
---|
56 | |
---|
57 | |
---|
58 | #Setup domain |
---|
59 | mesh = project.meshname + '.msh' |
---|
60 | domain = cache(pmesh_to_domain_instance, (mesh, Domain), |
---|
61 | dependencies = [mesh], |
---|
62 | verbose = True) |
---|
63 | |
---|
64 | |
---|
65 | domain.set_name(project.basename) |
---|
66 | domain.set_datadir(project.outputdir) |
---|
67 | domain.store = True |
---|
68 | |
---|
69 | print "Number of triangles = ", len(domain) |
---|
70 | print 'The extent is ', domain.get_extent() |
---|
71 | |
---|
72 | |
---|
73 | #Setup IC |
---|
74 | domain.set_quantity('stage', 0) |
---|
75 | domain.set_quantity('elevation', |
---|
76 | filename = demname + '.pts', |
---|
77 | use_cache = True, |
---|
78 | verbose = True) |
---|
79 | |
---|
80 | #Setup BC |
---|
81 | Bf = File_boundary(project.boundary_basename + '.sww', domain, verbose = True) |
---|
82 | |
---|
83 | Br = Reflective_boundary(domain) |
---|
84 | domain.set_boundary( {'wall': Br} ) |
---|
85 | |
---|
86 | |
---|
87 | #Run |
---|
88 | for t in domain.evolve(yieldstep = 1, finaltime = 100): |
---|
89 | domain.write_time() |
---|