Changeset 6058
- Timestamp:
- Dec 11, 2008, 1:14:46 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/most2nc.py
r3564 r6058 1 1 """This has to do with creating elevation data files for use with ferret2sww. 2 It reads a bathymetry ascii file and creates a NetCDF (nc) file similar to MOSTs output. 2 It reads a bathymetry ascii file and creates a NetCDF (nc) file similar to 3 MOSTs output. 3 4 4 5 $Author: Peter Row … … 6 7 """ 7 8 9 import sys 10 from Scientific.IO.NetCDF import NetCDFFile 8 11 9 def most2nc(input_file=None,output_file=None,inverted_bathymetry = False,\10 verbose = True):11 #input_file = 'small.txt'12 #output_file = 'small_e.nc'13 12 13 ## 14 # @brief Convert a MOST file to NetCDF format. 15 # @param input_file The input file to convert. 16 # @param output_file The name of the oputput NetCDF file to create, 17 # @param inverted_bathymetry ?? 18 # @param verbose True if the function is to be verbose. 19 def most2nc(input_file, output_file, inverted_bathymetry=False, verbose=True): 20 # variable names 14 21 long_name = 'LON' 15 22 lat_name = 'LAT' 23 elev_name = 'ELEVATION' 24 25 # set up bathymetry 16 26 if inverted_bathymetry: 17 27 up = -1. … … 19 29 up = +1. 20 30 21 from Scientific.IO.NetCDF import NetCDFFile22 i mport sys31 # read data from the MOST file 32 in_file = open(input_file,'r') 23 33 24 try: 25 if input_file is None: 26 input_file = sys.argv[1] 27 if output_file is None: 28 output_file = sys.argv[2] 29 except: 30 raise 'usage is: most2nc input output' 34 if verbose: print 'reading header' 31 35 32 in_file = open(input_file,'r')33 if verbose: print 'reading header'34 36 nx_ny_str = in_file.readline() 35 37 nx_str,ny_str = nx_ny_str.split() … … 60 62 #j = k/nx 61 63 out_depth_list[(k-1)/nx].append(float(string)*up) 62 #print k,len(out_depth_list),(k-1)/nx,out_depth_list[(k-1)/nx][-1],len(out_depth_list[(k-1)/nx])63 64 if k==nx*ny: 64 65 break … … 71 72 depth_list = out_depth_list 72 73 74 # write the NetCDF file 73 75 if verbose: print 'writing results' 74 76 … … 76 78 77 79 out_file.createDimension(long_name,nx) 80 78 81 out_file.createVariable(long_name,'d',(long_name,)) 79 82 out_file.variables[long_name].point_spacing='uneven' … … 87 90 out_file.variables[lat_name].assignValue(h2_list) 88 91 89 out_file.createVariable( 'ELEVATION','d',(lat_name,long_name))90 out_file.variables[ 'ELEVATION'].point_spacing='uneven'91 out_file.variables[ 'ELEVATION'].units='meters'92 out_file.variables[ 'ELEVATION'].assignValue(depth_list)92 out_file.createVariable(elev_name,'d',(lat_name,long_name)) 93 out_file.variables[elev_name].point_spacing='uneven' 94 out_file.variables[elev_name].units='meters' 95 out_file.variables[elev_name].assignValue(depth_list) 93 96 94 97 out_file.close()
Note: See TracChangeset
for help on using the changeset viewer.