source: inundation-numpy-branch/extras/thinbathy.py @ 2898

Last change on this file since 2898 was 1798, checked in by ole, 19 years ago

Added 'throw away code' for thinning out MOST bathymetries

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