-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathextract_gebco_ll.py
More file actions
60 lines (48 loc) · 1.74 KB
/
extract_gebco_ll.py
File metadata and controls
60 lines (48 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
extract depths from gebco bathymetric data obtained from
British Oceanographic Data Centre http://www.bodc.ac.uk
from where the data from a selected lat/long bounding box can be downloaded with either 1 minute or 30 second resolution
needs netCDF4 http://code.google.com/p/netcdf4-python/
this script extracts a bounding box from a larger downloaded source file. For example the file may contain the whole of the Mediterranean
and the script extracts smaller areas from the whole
parameters
top left lat, long
botom right lat,lomg
source file except for .nc suffix)
target file (except for .dat suffix)
Chris Wallace
kitwallace.co.uk
"""
def latlong_to_array(lat,long) :
return [ int((long - xrangemin ) /scale) , int((yrangemax - lat) / scale)]
import netCDF4
from numpy import *
import sys
lat_max = float(sys.argv[1])
long_min = float(sys.argv[2])
lat_min = float(sys.argv[3])
long_max = float(sys.argv[4])
source= sys.argv[5]
target= sys.argv[6]
d= netCDF4.Dataset(source+'.nc', 'r')
print "dimensions" , d.variables['dimension'][:]
print "spacing ", d.variables['spacing'][:]
scale = d.variables['spacing'][0]
xrangemin = d.variables['x_range'][0]
yrangemax = d.variables['y_range'][1]
print 'data br', xrangemin, yrangemax
tl = latlong_to_array(lat_max,long_min)
br = latlong_to_array(lat_min,long_max)
print "tl ", tl
print "br ", br
print 'source', source
print 'target', target
print 'long samples', br[0] - tl[0]
print 'lat samples', br[1] - tl[1]
depths = d.variables['z'][:]
depths = depths.reshape(d.variables['dimension'][1], d.variables['dimension'][0])
depths = depths[ tl[1]: br[1],tl[0]: br[0]]
print depths.shape
depths = flipud(depths)
savetxt(target+'.dat',depths,"%d")
d.close()