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

Last change on this file since 4154 was 4000, checked in by sexton, 18 years ago

update GIS documentation

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