Skip to content

Commit 0e9196f

Browse files
authored
DAS-2331: refactors test_is_projection_x_or_y (#54)
1 parent 8743ed5 commit 0e9196f

File tree

5 files changed

+75
-5
lines changed

5 files changed

+75
-5
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## v3.1.0
2+
### 2025-03-25
3+
4+
### Added:
5+
6+
* `VariableBase::is_projection_x` and `VariableBase::is_projection_y` added to
7+
determine a variable's exact projected coordinate.
8+
9+
### Changed:
10+
11+
* earthdata-varinfo's numpy requirements relaxed to allow numpy v2.
12+
113
## v3.0.3
214
### 2025-03-21
315

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.3
1+
3.1.0

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
netCDF4 ~= 1.7.2
2-
numpy >= 1.24.2,< 2.0
1+
netCDF4 >= 1.7.2
2+
numpy >= 1.24.2,<2.3
33
python-cmr ~= 0.12.0
44
requests ~= 2.31.0

tests/unit/test_variable.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ def test_is_geographic(self):
562562
self.assertFalse(variable.is_geographic())
563563

564564
def test_is_latitude(self):
565-
"""Ensure that a varaible is correctly identified a latitudinal based
565+
"""Ensure that a variable is correctly identified a latitudinal based
566566
on its `units` metadata attribute.
567567
568568
"""
@@ -678,6 +678,41 @@ def test_is_projection_x_or_y(self):
678678

679679
self.assertFalse(variable.is_projection_x_or_y())
680680

681+
def test_is_projection_x(self):
682+
"""Ensure that a variable is correctly identified as a projected
683+
spatial dimension based on its `standard_name` metadata
684+
attribute.
685+
686+
"""
687+
test_args = [
688+
[
689+
'Projected x variable',
690+
self.projection_x_variable_string,
691+
self.assertTrue,
692+
self.assertFalse,
693+
],
694+
[
695+
'Projected y variable',
696+
self.projection_y_variable_string,
697+
self.assertFalse,
698+
self.assertTrue,
699+
],
700+
]
701+
702+
for description, variable_string, x_assertion, y_assertion in test_args:
703+
with self.subTest(description):
704+
variable_tree = ET.fromstring(variable_string)
705+
variable = VariableFromDmr(
706+
variable_tree,
707+
self.fakesat_config,
708+
self.namespace,
709+
'/variable',
710+
self.fake_all_dimensions_sizes,
711+
)
712+
713+
x_assertion(variable.is_projection_x())
714+
y_assertion(variable.is_projection_y())
715+
681716
def test_get_range(self):
682717
"""Ensure the correct valid range is returned based either on the
683718
`valid_range` metadata attribute or both the `valid_min` and

varinfo/variable.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,33 @@ def is_projection_x_or_y(self) -> bool:
189189
`projection_x_angular_coordinate` and
190190
`projection_y_angular_coordinate`.
191191
192+
"""
193+
return self.is_projection_x() or self.is_projection_y()
194+
195+
def is_projection_x(self) -> bool:
196+
"""Determine if the variable is a projected x spatial coordinate based
197+
on the `standard_name` metadata attribute being
198+
`projection_x_coordinate`, as defined by the CF Conventions
199+
(v1.9). Note, geostationary projections have coordinate with
200+
`standard_name` metadata attribute value of
201+
`projection_x_angular_coordinate`.
202+
192203
"""
193204
return self.attributes.get('standard_name') in [
194205
'projection_x_coordinate',
195206
'projection_x_angular_coordinate',
207+
]
208+
209+
def is_projection_y(self) -> bool:
210+
"""Determine if the variable is a projected y spatial coordinate based
211+
on the `standard_name` metadata attribute being
212+
`projection_y_coordinate`, as defined by the CF Conventions
213+
(v1.9). Note, geostationary projections have coordinate with
214+
`standard_name` metadata attribute value of
215+
`projection_y_angular_coordinate`.
216+
217+
"""
218+
return self.attributes.get('standard_name') in [
196219
'projection_y_coordinate',
197220
'projection_y_angular_coordinate',
198221
]
@@ -218,7 +241,7 @@ def _get_all_cf_references(self) -> dict[str, set[str]]:
218241
}
219242

220243
def _get_cf_references(self, attribute_name: str) -> set[str]:
221-
"""Retrieve an attribute from the parsed varaible metadata, correcting
244+
"""Retrieve an attribute from the parsed variable metadata, correcting
222245
for any known artefacts (missing or incorrect references). Then
223246
split this string and qualify the individual references.
224247

0 commit comments

Comments
 (0)