1 | #def prepare_data(file_in): |
---|
2 | """This script reads .grd files containing Lidar data and |
---|
3 | converts to csv/txt format as required for ANUGA. |
---|
4 | This script also creates file_list.csv, a list of the |
---|
5 | files that have been created (all txt files in the working directory). |
---|
6 | """ |
---|
7 | from Numeric import array, zeros, Float, allclose |
---|
8 | from Scientific.IO.NetCDF import NetCDFFile |
---|
9 | from Numeric import array |
---|
10 | #import project |
---|
11 | import os |
---|
12 | from os import sep |
---|
13 | import csv |
---|
14 | import glob, fnmatch |
---|
15 | |
---|
16 | #folder = '//nas/gemd/georisk_models/inundation/data/new_south_wales/gosford_tsunami_scenario_2009/original_reference_data/GosfordLidar/Ground/' |
---|
17 | folder = '//nas/gemd/georisk_models/inundation/data/new_south_wales/gosford_tsunami_scenario_2009/original_reference_data/bathymetry/Offshore/' |
---|
18 | |
---|
19 | |
---|
20 | #input_grd = glob.glob(folder + '*.grd') |
---|
21 | input_grd = [folder+ 'AUS197_MGA_LAT_1972.txt'] |
---|
22 | |
---|
23 | for file_in in input_grd: |
---|
24 | #boundary_csv = file_in |
---|
25 | out_file = file_in[:-12] + 'AHD_1972.txt' |
---|
26 | print 'Creating', out_file |
---|
27 | |
---|
28 | |
---|
29 | # Read the grd file |
---|
30 | fid = open(file_in) |
---|
31 | |
---|
32 | # Skip first line |
---|
33 | line = fid.readline() |
---|
34 | |
---|
35 | # Read remaining lines |
---|
36 | lines = fid.readlines() |
---|
37 | fid.close() |
---|
38 | |
---|
39 | |
---|
40 | N = len(lines) |
---|
41 | X = zeros(N, Float) #eastin |
---|
42 | Y = zeros(N, Float) #northing |
---|
43 | Z = zeros(N, Float) #elevation |
---|
44 | |
---|
45 | |
---|
46 | for i, line in enumerate(lines): |
---|
47 | fields = line.split(',') |
---|
48 | |
---|
49 | X[i] = float(fields[1]) #easting |
---|
50 | Y[i] = float(fields[2]) #northing |
---|
51 | Z[i] = float(fields[3])+1.0 #elevation |
---|
52 | |
---|
53 | |
---|
54 | |
---|
55 | # Create new csv file |
---|
56 | outwriter = csv.writer(open(out_file,'w')) |
---|
57 | outwriter.writerow(['x','y','elevation']) |
---|
58 | for i, line in enumerate(lines): |
---|
59 | outwriter.writerow([X[i], Y[i], Z[i]]) |
---|
60 | |
---|
61 | ##filelist = [] |
---|
62 | ##filelist_file = folder+'file_list2.csv' |
---|
63 | ## |
---|
64 | ### Create csv file of filenames |
---|
65 | ##outwriter2 = csv.writer(open(filelist_file,'w')) |
---|
66 | ## |
---|
67 | ##for file in os.listdir(folder): |
---|
68 | ## if fnmatch.fnmatch(file, '*.txt'): |
---|
69 | ## outwriter2.writerow([file]) |
---|
70 | ## |
---|
71 | |
---|
72 | |
---|