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 | #This should have a test |
---|
9 | |
---|
10 | def thinbathy(input_file, output_file): |
---|
11 | |
---|
12 | lat_thin = lon_thin = 4 |
---|
13 | |
---|
14 | from Scientific.IO.NetCDF import NetCDFFile |
---|
15 | |
---|
16 | fid = NetCDFFile(input_file, 'r') |
---|
17 | print fid.variables |
---|
18 | |
---|
19 | # for first event |
---|
20 | latitudes = fid.variables['LAT'][::lat_thin] |
---|
21 | longitudes = fid.variables['LON'][::lon_thin] |
---|
22 | elevations = fid.variables['ELEVATION'][::lat_thin,::lon_thin] |
---|
23 | |
---|
24 | outfile = NetCDFFile(output_file, 'w') |
---|
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) |
---|
36 | |
---|
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')) |
---|
41 | |
---|
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 |
---|
47 | |
---|
48 | fid.close() |
---|
49 | outfile.close() |
---|