source: anuga_work/production/new_south_wales/batemans_bay/prepare_data_AUS197.py @ 7019

Last change on this file since 7019 was 7019, checked in by jgriffin, 15 years ago
File size: 2.0 KB
RevLine 
[7019]1#def prepare_data(file_in):
2"""This script reads .grd files containing Lidar data and
3converts to csv/txt format as required for ANUGA.
4This script also creates file_list.csv, a list of the
5files that have been created (all txt files in the working directory).
6"""
7from Numeric import array, zeros, Float, allclose
8from Scientific.IO.NetCDF import NetCDFFile
9from Numeric import array
10#import project
11import os
12from os import sep
13import csv
14import glob, fnmatch
15
16#folder = '//nas/gemd/georisk_models/inundation/data/new_south_wales/gosford_tsunami_scenario_2009/original_reference_data/GosfordLidar/Ground/'
17folder = '//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')
21input_grd = [folder+ 'AUS197_MGA_LAT_1972.txt']
22
23for 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
Note: See TracBrowser for help on using the repository browser.