Changeset 3677


Ignore:
Timestamp:
Sep 29, 2006, 1:43:41 PM (18 years ago)
Author:
sexton
Message:

(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?)

Location:
anuga_core/source/anuga/extras
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/extras/thinbathy.py

    r1798 r3677  
    33"""
    44
    5 input_file = 'e5_bathy_corr5.cdf'
    6 output_file = 'SU-AU_e.nc'
     5#input_file = 'e5_bathy_corr5.cdf'
     6#output_file = 'SU-AU_e.nc'
    77
    8 lat_thin = lon_thin = 4
     8#This should have a test
    99
    10 from Scientific.IO.NetCDF import NetCDFFile
     10def thinbathy(input_file, output_file):
    1111
    12 fid = NetCDFFile(input_file, 'r')
     12    lat_thin = lon_thin = 4
    1313
    14 latitudes = fid.variables['LAT'][::lat_thin]
    15 longitudes = fid.variables['LON'][::lon_thin]
    16 elevations = fid.variables['ELEVATION'][::lat_thin,::lon_thin]
     14    from Scientific.IO.NetCDF import NetCDFFile
    1715
     16    fid = NetCDFFile(input_file, 'r')
    1817
    19 outfile = NetCDFFile(output_file, 'w')
    20 outfile.createDimension('LON', fid.dimensions['LON']/lon_thin + 1)
    21 outfile.createDimension('LAT', fid.dimensions['LAT']/lat_thin + 1)
     18    latitudes = fid.variables['LAT'][::lat_thin]
     19    longitudes = fid.variables['LON'][::lon_thin]
     20    elevations = fid.variables['ELEVATION'][::lat_thin,::lon_thin]
    2221
     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)
    2325
    24 import Numeric
    25 outfile.createVariable('LON', Numeric.Float64, ('LON',))
    26 outfile.createVariable('LAT', Numeric.Float64, ('LAT',))
    27 outfile.createVariable('ELEVATION', Numeric.Float32, ('LAT', 'LON'))
     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'))
    2830
    29 #Assign to NC file
    30 #Precision used by MOST for lat/lon is 4 or 5 decimals
    31 outfile.variables['LAT'][:] = Numeric.around(latitudes, 5)
    32 outfile.variables['LON'][:] = Numeric.around(longitudes, 5)
    33 outfile.variables['ELEVATION'][:] = elevations
     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
    3436
    35 fid.close()
    36 outfile.close()
     37    fid.close()
     38    outfile.close()
Note: See TracChangeset for help on using the changeset viewer.