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 | lat_thin = lon_thin = 4 |
---|
9 | |
---|
10 | from Scientific.IO.NetCDF import NetCDFFile |
---|
11 | |
---|
12 | fid = NetCDFFile(input_file, 'r') |
---|
13 | |
---|
14 | latitudes = fid.variables['LAT'][::lat_thin] |
---|
15 | longitudes = fid.variables['LON'][::lon_thin] |
---|
16 | elevations = fid.variables['ELEVATION'][::lat_thin,::lon_thin] |
---|
17 | |
---|
18 | |
---|
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) |
---|
22 | |
---|
23 | |
---|
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')) |
---|
28 | |
---|
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 |
---|
34 | |
---|
35 | fid.close() |
---|
36 | outfile.close() |
---|