From https://github.com/SciTools/iris/issues/83
It's time to nail this down into a concrete plan.
The purpose of this post is to present a solution for critical analysis and/or mockery.
I suggest:
So. Is this solution acceptable? Is it flawed? Are there any nicer alternatves?
Possibly ugly, but I think this works? Does floating point accuracy get in the way?
(61,)
[-30 -29 -28 -27 -26 -25 -24 -23 -22 -21 -20 -19 -18 -17 -16 -15 -14 -13
-12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 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]
(61,)
[330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
384 385 386 387 388 389 390]
======================================================================
FAIL: test_combined (iris.tests.test_cdm.TestCubeExtract)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/net/home/h05/itbb/git/iris/lib/iris/tests/test_cdm.py", line 576, in test_combined
self.assertCML(self.single_cube.extract(constraint), ('cdm', 'extract', 'lat_gt_10_and_lon_ge_10.cml'))
File "/net/home/h05/itbb/git/iris/lib/iris/tests/__init__.py", line 189, in assertCML
self._check_same(xml, reference_path, reference_filename)
File "/net/home/h05/itbb/git/iris/lib/iris/tests/__init__.py", line 245, in _check_same
self._assert_str_same(reference, item, reference_filename, type_comparison_name)
File "/net/home/h05/itbb/git/iris/lib/iris/tests/__init__.py", line 135, in _assert_str_same
self.fail("%s do not match: %s\n%s" % (type_comparison_name, reference_filename, diff))
AssertionError: CML do not match: ('cdm', 'extract', 'lat_gt_10_and_lon_ge_10.cml')
--- Reference
+++ Test result
@@ -80,2 +80,2 @@
- <dimCoord id="63128986" points="[11.25, 13.125, 15.0, ..., 354.375, 356.25,
- 358.125]" shape="(186,)" standard_name="longitude" units="Unit('degrees')" value_type="float32">
+ <dimCoord id="63128986" points="[11.25, 13.125, 15.0, ..., 365.625, 367.5,
+ 369.375]" shape="(192,)" standard_name="longitude" units="Unit('degrees')" value_type="float32">
@@ -150 +150 @@
- <data checksum="0x5552b088" dtype="float32" shape="(38, 64, 186)"/>
+ <data checksum="0x7684b27" dtype="float32" shape="(38, 64, 192)"/>
Here's a first working draft: https://github.com/bblay/iris/commit/c614f890afcb8962df4548e1f0247ddfbcea2fa7
new_coord.points = numpy.concatenate((
l_coord.points[-roll:],
c_coord.points[:-roll]))
if new_coord.has_bounds():
new_coord.bounds = numpy.concatenate((
l_coord.bounds[-roll:],
coord.bounds[:-roll]))
For a circular coordinate I'm not really sure what a one-sided constraint such as "lon >= 170" means. i.e. I don't know what result I'd expect.
Constraint(longitude=lambda l: l > 170)
Constraint(longitude=lambda l: 170 < l < end_point)
Constraint(longitude=WrapThingy(-30, 30, rh_inclusive=False))
WrapConstraint('longitude', -30, 30, rh_inclusive=False)
cube = wrapped_extract(cube, 'longitude', -30, 30, rh_inclusive=False
) # or just `extract(cube, ...)`
# Not strictly equivalent as it requires knowledge of the dimension order.
cube = cube.loc[:, -30:30]
def select_my_data(cubes, extent):
lon_min, lon_max, lat_min, lat_max = extent
cube = cube.extract(Constraint('latitude': lambda lat_min <= cell <= lat_max))
cube = wrapped_extract(cube, 'longitude', lon_min, lon_max)
# or (eventually?) just ...
def select_my_data(cubes, extent):
lon_min, lon_max, lat_min, lat_max = extent
cube = extract(cube, 'latitude', lat_min, lat_max))
cube = extract(cube, 'longitude', lon_min, lon_max)
In the context of various other discussions I'm wondering if we should be aiming to have a collection of utility functions/methods to help perform the various constraint/callback duties instead of ever more complex functional forms. In other words, an "extract" function would become "unspecial" because it'd be used everywhere.
cube = cube.extract(Constraint(longitude=lambda l: -30 < l < 30))
an "extract" function would become "unspecial" because it'd be used everywhere.
If we can develop something new that covers all cases I would be extremely pleased.
iris will need to know that the full range of longitudes covers 360 degrees
For example, consider a longitude dimension coordinate with just four cells: 0 to 90, 90 to 180, 180 to 270, and 270 to 360 (assume the point value is set to the mid-point). When requesting the range -60 to 100, what would one expect? What about the range -60 to 300?
Requesting -60 to 100 might produce:
* 0 to 90 only (i.e. only cells entirely within the requested range)
* -60 to 0, 0 to 90, and 90 to 100, where the first and last cells have had their extents modified.
* -60 to 0 and 0 to 90, where only the first cell has had its extents modified
* an exeception!
We have three valid flavours, perhaps called; "extract_cut", "extract_inner" and "extract_outer".
--
You received this message because you are subscribed to the Google Groups "Iris-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scitools-iris-...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
In the GIS world...
"extract_cut" is called "clip"
"extract_inner" is called "contains"
"extract_outer" is called "intersects"