Last change
on this file since 9737 was
9405,
checked in by steve, 10 years ago
|
Adding in some upper directories to allow anuga_core to be smaller size
|
File size:
1.0 KB
|
Line | |
---|
1 | |
---|
2 | |
---|
3 | def xya2pts(name_in, name_out=None, verbose=False): |
---|
4 | """Convert a file with xy and elevation data to NetCDF pts file. |
---|
5 | """ |
---|
6 | |
---|
7 | from anuga.geospatial_data import Geospatial_data |
---|
8 | |
---|
9 | root = name_in[:-4] |
---|
10 | |
---|
11 | if name_out is None: name_out = root + '.pts' |
---|
12 | |
---|
13 | if verbose: print 'Creating', name_out |
---|
14 | |
---|
15 | # Read the ascii (.xya) version of this file, |
---|
16 | # make it comma separated and invert the bathymetry |
---|
17 | # (Below mean sea level should be negative) |
---|
18 | infile = open(name_in) |
---|
19 | |
---|
20 | points = [] |
---|
21 | attribute = [] |
---|
22 | |
---|
23 | for line in infile.readlines()[1:]: #Skip first line (the header) |
---|
24 | fields = line.strip().split(',') |
---|
25 | |
---|
26 | x = float(fields[0]) |
---|
27 | y = float(fields[1]) |
---|
28 | z = float(fields[2]) # Bathymetry is inverted in original file |
---|
29 | |
---|
30 | points.append([x,y]) |
---|
31 | attribute.append(z) |
---|
32 | infile.close() |
---|
33 | |
---|
34 | # Convert to geospatial data and store as NetCDF |
---|
35 | G = Geospatial_data(data_points=points, |
---|
36 | attributes=attribute) |
---|
37 | G.export_points_file(name_out) |
---|
38 | |
---|
39 | |
---|
Note: See
TracBrowser
for help on using the repository browser.