Skip to content

Commit 55035bc

Browse files
committed
Extract with a bounding box
1 parent da5037f commit 55035bc

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

src/py_eddy_tracker/observations/observation.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ def __init__(
174174
self.active = True
175175
self.sign_type = None
176176

177+
@property
178+
def longitude(self):
179+
return self.observations["lon"]
180+
181+
@property
182+
def latitude(self):
183+
return self.observations["lat"]
184+
177185
@property
178186
def time(self):
179187
return self.observations["time"]
@@ -211,7 +219,7 @@ def dtype(self):
211219
data_type = VAR_DESCR[elt][
212220
"compute_type"
213221
if "compute_type" in VAR_DESCR[elt] and not self.raw_data
214-
else "nc_type"
222+
else "output_type"
215223
]
216224
if elt in self.array_variables:
217225
dtype.append((elt, data_type, (self.track_array_variables,)))

src/py_eddy_tracker/observations/tracking.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,22 @@ def set_global_attr_netcdf(self, h_nc):
122122
h_nc.time_coverage_start = d_start.strftime('%Y-%m-%dT00:00:00Z')
123123
h_nc.time_coverage_end = d_end.strftime('%Y-%m-%dT00:00:00Z')
124124

125+
def extract_with_area(self, area, **kwargs):
126+
"""
127+
Extract with a bounding box
128+
Args:
129+
area: 4 coordinates in a dictionary to specify bounding box (lower left corner and upper right corner)
130+
**kwargs:
131+
132+
Returns:
133+
134+
"""
135+
mask = (self.latitude > area['llcrnrlat']) * (self.latitude < area['urcrnrlat'])
136+
lon0 = area['llcrnrlon']
137+
lon = (self.longitude - lon0) % 360 + lon0
138+
mask *= (lon > lon0) * (lon < area['urcrnrlon'])
139+
return self.__extract_with_mask(mask, **kwargs)
140+
125141
def extract_with_period(self, period, **kwargs):
126142
"""
127143
Extract with a period

src/scripts/EddySubSetter

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ def id_parser():
1818
help='Extract path, if one obs or more are selected')
1919
parser.add_argument('-d', '--remove_incomplete', action='store_true',
2020
help='Extract path only if all obs are selected')
21+
parser.add_argument('-a', '--area', nargs=4, type=float,
22+
metavar=('llcrnrlon', 'llcrnrlat', 'urcrnrlon', 'urcrnrlat'),
23+
help='Coordinates of bounding to extract'
24+
)
2125
return parser
2226

2327

@@ -29,5 +33,14 @@ if __name__ == '__main__':
2933
dataset = dataset.extract_with_period(args.period, full_path=args.full_path,
3034
remove_incomplete=args.remove_incomplete)
3135

36+
if args.area is not None:
37+
area = dict(llcrnrlon=args.area[0],
38+
llcrnrlat=args.area[1],
39+
urcrnrlon=args.area[2],
40+
urcrnrlat=args.area[3],
41+
)
42+
dataset = dataset.extract_with_area(area, full_path=args.full_path,
43+
remove_incomplete=args.remove_incomplete)
44+
3245
if len(dataset) != 0:
3346
dataset.write_netcdf(filename=args.filename_out)

0 commit comments

Comments
 (0)