source: anuga_core/source/anuga/extras/thinbathy.py @ 3930

Last change on this file since 3930 was 3677, checked in by sexton, 19 years ago

(i) make thinbathy into a function (ii) make work for Hobart test (iii) needs a unit test (esp if other uses end up using MOST?)

File size: 1.2 KB
Line 
1"""Thin out MOST NetCDF bathymetry and store as nc file
2
3"""
4
5#input_file = 'e5_bathy_corr5.cdf'
6#output_file = 'SU-AU_e.nc'
7
8#This should have a test
9
10def thinbathy(input_file, output_file):
11
12    lat_thin = lon_thin = 4 
13
14    from Scientific.IO.NetCDF import NetCDFFile
15
16    fid = NetCDFFile(input_file, 'r')
17
18    latitudes = fid.variables['LAT'][::lat_thin]
19    longitudes = fid.variables['LON'][::lon_thin]
20    elevations = fid.variables['ELEVATION'][::lat_thin,::lon_thin]
21
22    outfile = NetCDFFile(output_file, 'w')
23    outfile.createDimension('LON', fid.dimensions['LON']/lon_thin) # + 1)
24    outfile.createDimension('LAT', fid.dimensions['LAT']/lat_thin) # + 1)
25
26    import Numeric
27    outfile.createVariable('LON', Numeric.Float64, ('LON',))
28    outfile.createVariable('LAT', Numeric.Float64, ('LAT',))
29    outfile.createVariable('ELEVATION', Numeric.Float32, ('LAT', 'LON'))
30
31    #Assign to NC file
32    #Precision used by MOST for lat/lon is 4 or 5 decimals
33    outfile.variables['LAT'][:] = Numeric.around(latitudes, 5)
34    outfile.variables['LON'][:] = Numeric.around(longitudes, 5)
35    outfile.variables['ELEVATION'][:] = elevations
36
37    fid.close()
38    outfile.close()
Note: See TracBrowser for help on using the repository browser.