Skip to content

Commit

Permalink
Remove long name if standard name present (#2059)
Browse files Browse the repository at this point in the history
* Remove long name if standard name present

* Remove long_name if standard_name present

* Remove long_name if standard_name is present

* Remove long_name if standard_name present

* Replace long_name if standard_name present

* Correct formatting and Contribution list

* Added Name to mail map and rerun ruff

* edit .mailmap

* assert message edited
  • Loading branch information
lambert-p authored Dec 10, 2024
1 parent b2d4fa1 commit 3353f33
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Meabh NicGuidhir <[email protected]> <meabh.nicguidhir@metoffice
Neil Crosswaite <[email protected]> <[email protected]>
Paul Abernethy <[email protected]> <[email protected]>
Peter Jordan <[email protected]> <[email protected]>
Phoebe Lambert <[email protected]> <[email protected]>
Sam Griffiths <[email protected]> <[email protected]>
Shafiat Dewan <[email protected]> <[email protected]>
Shubhendra Singh Chauhan <[email protected]> <[email protected]>
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ below:
- Caroline Jones (Met Office, UK)
- Peter Jordan (Met Office, UK)
- Bruno P. Kinoshita (NIWA, NZ)
- Phoebe Lambert (Met Office, UK)
- Lucy Liu (Bureau of Meteorology, Australia)
- Daniel Mentiplay (Bureau of Meteorology, Australia)
- Stephen Moseley (Met Office, UK)
Expand Down
10 changes: 10 additions & 0 deletions improver/standardise.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,15 @@ def _discard_redundant_cell_methods(cube: Cube) -> None:

cube.cell_methods = updated_cms

@staticmethod
def _remove_long_name_if_standard_name(cube: Cube) -> None:
"""
Remove the long_name attribute from cubes if the cube also has a standard_name defined
"""

if cube.standard_name and cube.long_name:
cube.long_name = None

def process(self, cube: Cube) -> Cube:
"""
Perform compulsory and user-configurable metadata adjustments. The
Expand Down Expand Up @@ -269,6 +278,7 @@ def process(self, cube: Cube) -> Cube:
if self._attributes_dict:
amend_attributes(cube, self._attributes_dict)
self._discard_redundant_cell_methods(cube)
self._remove_long_name_if_standard_name(cube)

# this must be done after unit conversion as if the input is an integer
# field, unit conversion outputs the new data as float64
Expand Down
8 changes: 8 additions & 0 deletions improver_tests/standardise/test_StandardiseMetadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,14 @@ def test_air_temperature_status_flag_coord_without_realization(self):
self.assertArrayEqual(result.data, target.data)
self.assertEqual(result.coords(), target.coords())

def test_long_name_removed(self):
cube = self.cube.copy()
cube.long_name = "kittens"
result = StandardiseMetadata().process(cube)
assert (
result.long_name is None
), "long_name removal expected, but long_name is not None"


if __name__ == "__main__":
unittest.main()

0 comments on commit 3353f33

Please sign in to comment.