[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] | 10 | def 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') |
---|
[1798] | 17 | |
---|
[3677] | 18 | latitudes = fid.variables['LAT'][::lat_thin] |
---|
| 19 | longitudes = fid.variables['LON'][::lon_thin] |
---|
| 20 | elevations = fid.variables['ELEVATION'][::lat_thin,::lon_thin] |
---|
[1798] | 21 | |
---|
[3677] | 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) |
---|
[1798] | 25 | |
---|
[3677] | 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')) |
---|
[1798] | 30 | |
---|
[3677] | 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 |
---|
[1798] | 36 | |
---|
[3677] | 37 | fid.close() |
---|
| 38 | outfile.close() |
---|