From 05382e8d302edd7768cb55d52f5b71aaad20b689 Mon Sep 17 00:00:00 2001 From: Duncan Watson-Parris Date: Sun, 7 Jan 2018 20:13:33 +0000 Subject: [PATCH 01/13] Try the STASH attribute when checking for possible names (as is already done in the summary method) --- lib/iris/_cube_coord_common.py | 11 ++++++----- lib/iris/cube.py | 5 +---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/iris/_cube_coord_common.py b/lib/iris/_cube_coord_common.py index dd49355bf4..70e0f4ae3b 100644 --- a/lib/iris/_cube_coord_common.py +++ b/lib/iris/_cube_coord_common.py @@ -1,4 +1,4 @@ -# (C) British Crown Copyright 2010 - 2016, Met Office +# (C) British Crown Copyright 2010 - 2018, Met Office # # This file is part of Iris. # @@ -88,12 +88,13 @@ def name(self, default='unknown'): """ Returns a human-readable name. - First it tries :attr:`standard_name`, then 'long_name', then 'var_name' - before falling back to the value of `default` (which itself defaults to - 'unknown'). + First it tries :attr:`standard_name`, then 'long_name', then + 'var_name', then the STASH attribute before falling back to + the value of `default` (which itself defaults to 'unknown'). """ - return self.standard_name or self.long_name or self.var_name or default + return self.standard_name or self.long_name or self.var_name or \ + str(self.attributes.get('STASH', default)) def rename(self, name): """ diff --git a/lib/iris/cube.py b/lib/iris/cube.py index 57dd4078f8..f80d569134 100644 --- a/lib/iris/cube.py +++ b/lib/iris/cube.py @@ -1,4 +1,4 @@ -# (C) British Crown Copyright 2010 - 2017, Met Office +# (C) British Crown Copyright 2010 - 2018, Met Office # # This file is part of Iris. # @@ -1770,9 +1770,6 @@ def summary(self, shorten=False, name_padding=35): nameunit = '{name} / ({units})'.format(name=self.name(), units=self.units) - # If all unknown and a STASH attribute exists, use it. - if nameunit == 'unknown / (unknown)' and 'STASH' in self.attributes: - nameunit = '{}'.format(self.attributes['STASH']) cube_header = '{nameunit!s:{length}} ({dimension})'.format( length=name_padding, nameunit=nameunit, From fa2eaa7aa90b5cb62f895c9e0d90120e42016ed6 Mon Sep 17 00:00:00 2001 From: Duncan Watson-Parris Date: Fri, 12 Jan 2018 08:28:05 +0000 Subject: [PATCH 02/13] Refactor slightly to make it easier to extend --- lib/iris/_cube_coord_common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/iris/_cube_coord_common.py b/lib/iris/_cube_coord_common.py index 70e0f4ae3b..43eef03abd 100644 --- a/lib/iris/_cube_coord_common.py +++ b/lib/iris/_cube_coord_common.py @@ -94,7 +94,7 @@ def name(self, default='unknown'): """ return self.standard_name or self.long_name or self.var_name or \ - str(self.attributes.get('STASH', default)) + str(self.attributes.get('STASH', '')) or default def rename(self, name): """ From 73679da38051c42c33e9df16ad5a8b0d73d11210 Mon Sep 17 00:00:00 2001 From: Duncan Watson-Parris Date: Fri, 12 Jan 2018 08:46:26 +0000 Subject: [PATCH 03/13] Adding a couple of tests --- lib/iris/tests/test_cdm.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/iris/tests/test_cdm.py b/lib/iris/tests/test_cdm.py index e225ef4714..4c06d29c47 100644 --- a/lib/iris/tests/test_cdm.py +++ b/lib/iris/tests/test_cdm.py @@ -730,6 +730,16 @@ def test_var_name(self): self.t.var_name = 'bar' self.assertEqual(self.t.var_name, 'bar') + def test_default_name(self): + self.t.long_name = '' + self.assertEqual(self.t.name(), 'unknown') + self.assertEqual(self.t.name('a_different_default'), 'a_different_default') + + def test_stash_name(self): + self.t.long_name = '' + self.t.attributes['STASH'] = iris.fileformats.pp.STASH(1, 2, 3) + self.assertEqual(self.t.name(), 'm01s02i003') + def test_name_and_var_name(self): # Assign only var_name. self.t.standard_name = None From 6eb131321ce00c1753bef5a74acb4bc5681ddc39 Mon Sep 17 00:00:00 2001 From: Duncan Watson-Parris Date: Fri, 12 Jan 2018 08:48:21 +0000 Subject: [PATCH 04/13] Shorten line... --- lib/iris/tests/test_cdm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/iris/tests/test_cdm.py b/lib/iris/tests/test_cdm.py index 4c06d29c47..6ddcd63282 100644 --- a/lib/iris/tests/test_cdm.py +++ b/lib/iris/tests/test_cdm.py @@ -733,7 +733,7 @@ def test_var_name(self): def test_default_name(self): self.t.long_name = '' self.assertEqual(self.t.name(), 'unknown') - self.assertEqual(self.t.name('a_different_default'), 'a_different_default') + self.assertEqual(self.t.name('a_default'), 'a_default') def test_stash_name(self): self.t.long_name = '' From e5641f609d0812ee890af0eda8c60d8eaa55ea03 Mon Sep 17 00:00:00 2001 From: Duncan Watson-Parris Date: Wed, 17 Jan 2018 13:06:04 +0000 Subject: [PATCH 05/13] Minor test fix --- lib/iris/tests/unit/cube/test_CubeList.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/iris/tests/unit/cube/test_CubeList.py b/lib/iris/tests/unit/cube/test_CubeList.py index f7adb35571..1e79d5ae69 100644 --- a/lib/iris/tests/unit/cube/test_CubeList.py +++ b/lib/iris/tests/unit/cube/test_CubeList.py @@ -296,7 +296,7 @@ def test_summary_name_unit(self): def test_summary_stash(self): self.cubes[0].attributes['STASH'] = STASH.from_msi('m01s00i004') - expected = ('0: m01s00i004 ' + expected = ('0: m01s00i004 / (unknown) ' ' (latitude: 3; longitude: 4)') self.assertEqual(str(self.cubes), expected) From deb11b3b9a56db226d533f44c274a8988791d2c9 Mon Sep 17 00:00:00 2001 From: Duncan Watson-Parris Date: Wed, 17 Jan 2018 14:43:09 +0000 Subject: [PATCH 06/13] Update header --- lib/iris/tests/unit/cube/test_CubeList.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/iris/tests/unit/cube/test_CubeList.py b/lib/iris/tests/unit/cube/test_CubeList.py index 1e79d5ae69..15e6bd16ce 100644 --- a/lib/iris/tests/unit/cube/test_CubeList.py +++ b/lib/iris/tests/unit/cube/test_CubeList.py @@ -1,4 +1,4 @@ -# (C) British Crown Copyright 2014 - 2017, Met Office +# (C) British Crown Copyright 2014 - 2018, Met Office # # This file is part of Iris. # From 500a80f5ffb5d2984c89639811ac2c6ab7bae7b4 Mon Sep 17 00:00:00 2001 From: Duncan Watson-Parris Date: Tue, 1 May 2018 16:26:53 +0100 Subject: [PATCH 07/13] Fix whitespace in test --- lib/iris/tests/unit/cube/test_CubeList.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/iris/tests/unit/cube/test_CubeList.py b/lib/iris/tests/unit/cube/test_CubeList.py index 15e6bd16ce..394d28e6de 100644 --- a/lib/iris/tests/unit/cube/test_CubeList.py +++ b/lib/iris/tests/unit/cube/test_CubeList.py @@ -297,7 +297,7 @@ def test_summary_name_unit(self): def test_summary_stash(self): self.cubes[0].attributes['STASH'] = STASH.from_msi('m01s00i004') expected = ('0: m01s00i004 / (unknown) ' - ' (latitude: 3; longitude: 4)') + ' (latitude: 3; longitude: 4)') self.assertEqual(str(self.cubes), expected) From 982f6f0fce0c6b7376a9461d02f9f901cbe8fd15 Mon Sep 17 00:00:00 2001 From: Duncan Watson-Parris Date: Wed, 2 May 2018 10:29:20 +0100 Subject: [PATCH 08/13] Update header --- lib/iris/tests/test_cdm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/iris/tests/test_cdm.py b/lib/iris/tests/test_cdm.py index 6ddcd63282..be08a9c5c6 100644 --- a/lib/iris/tests/test_cdm.py +++ b/lib/iris/tests/test_cdm.py @@ -1,4 +1,4 @@ -# (C) British Crown Copyright 2010 - 2017, Met Office +# (C) British Crown Copyright 2010 - 2018, Met Office # # This file is part of Iris. # From 95aa0ecbfaa6fd7c26e305b07ab00b3e63397496 Mon Sep 17 00:00:00 2001 From: Duncan Watson-Parris Date: Thu, 3 May 2018 08:36:13 +0100 Subject: [PATCH 09/13] Ensure cube is nameless by removing stash code too --- lib/iris/tests/test_quickplot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/iris/tests/test_quickplot.py b/lib/iris/tests/test_quickplot.py index f71e7fefce..87f671ef1e 100644 --- a/lib/iris/tests/test_quickplot.py +++ b/lib/iris/tests/test_quickplot.py @@ -149,6 +149,7 @@ def test_contourf(self): def test_contourf_nameless(self): cube = self._small() cube.standard_name = None + cube.attributes['STASH'] = '' qplt.contourf(cube, coords=['grid_longitude', 'model_level_number']) self.check_graphic() From 4438d484e4e7500e0e4c6005146d28585fa5c708 Mon Sep 17 00:00:00 2001 From: Duncan Watson-Parris Date: Thu, 3 May 2018 19:55:51 +0100 Subject: [PATCH 10/13] Another header fix... --- lib/iris/tests/test_quickplot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/iris/tests/test_quickplot.py b/lib/iris/tests/test_quickplot.py index 87f671ef1e..eab0caf44c 100644 --- a/lib/iris/tests/test_quickplot.py +++ b/lib/iris/tests/test_quickplot.py @@ -1,4 +1,4 @@ -# (C) British Crown Copyright 2010 - 2016, Met Office +# (C) British Crown Copyright 2010 - 2018, Met Office # # This file is part of Iris. # From ea79aa424d62d818d96875b5fb4c6cd0f81012cc Mon Sep 17 00:00:00 2001 From: Duncan Watson-Parris Date: Thu, 3 May 2018 20:01:35 +0100 Subject: [PATCH 11/13] Added whatsnew --- .../contributions_2.1/newfeature_2018-May-03_stash_names.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 docs/iris/src/whatsnew/contributions_2.1/newfeature_2018-May-03_stash_names.txt diff --git a/docs/iris/src/whatsnew/contributions_2.1/newfeature_2018-May-03_stash_names.txt b/docs/iris/src/whatsnew/contributions_2.1/newfeature_2018-May-03_stash_names.txt new file mode 100644 index 0000000000..7c3eacbb1c --- /dev/null +++ b/docs/iris/src/whatsnew/contributions_2.1/newfeature_2018-May-03_stash_names.txt @@ -0,0 +1,3 @@ +* Updated :func:`iris.cube.Cube.name` to return a STASH code if the cube has + one and no other valid names are present. This is now consistent with the + summary information. \ No newline at end of file From 511dc0bdccfa4a528e4b3cb5de9e8ddb071ead20 Mon Sep 17 00:00:00 2001 From: Duncan Watson-Parris Date: Thu, 3 May 2018 20:46:34 +0100 Subject: [PATCH 12/13] Update test data --- .../pp_to_cf_conversion/to_netcdf/st0fc942.b_0.cdl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/iris/tests/results/usecases/pp_to_cf_conversion/to_netcdf/st0fc942.b_0.cdl b/lib/iris/tests/results/usecases/pp_to_cf_conversion/to_netcdf/st0fc942.b_0.cdl index 1f14983bd7..bb1c0d212e 100644 --- a/lib/iris/tests/results/usecases/pp_to_cf_conversion/to_netcdf/st0fc942.b_0.cdl +++ b/lib/iris/tests/results/usecases/pp_to_cf_conversion/to_netcdf/st0fc942.b_0.cdl @@ -5,12 +5,12 @@ dimensions: pseudo_level = 4 ; time = 4 ; variables: - float unknown(pseudo_level, time, depth, grid_latitude) ; - unknown:_FillValue = 9.96921e+36f ; - unknown:um_stash_source = "m02s00i???" ; - unknown:cell_methods = "time: mean" ; - unknown:grid_mapping = "rotated_latitude_longitude" ; - unknown:coordinates = "forecast_period forecast_reference_time" ; + float m02s00i___(pseudo_level, time, depth, grid_latitude) ; + m02s00i___:_FillValue = 9.96921e+36f ; + m02s00i___:um_stash_source = "m02s00i???" ; + m02s00i___:cell_methods = "time: mean" ; + m02s00i___:grid_mapping = "rotated_latitude_longitude" ; + m02s00i___:coordinates = "forecast_period forecast_reference_time" ; int rotated_latitude_longitude ; rotated_latitude_longitude:grid_mapping_name = "rotated_latitude_longitude" ; rotated_latitude_longitude:longitude_of_prime_meridian = 0. ; From 76f352041517410cafa5b4016e6805dc529ce98e Mon Sep 17 00:00:00 2001 From: Duncan Watson-Parris Date: Thu, 3 May 2018 21:43:44 +0100 Subject: [PATCH 13/13] More test data fixes --- ...2000000000.44.101.131200.1920.09.01.00.00.b_0.cml | 2 +- ...8000000000.44.101.000128.1890.09.01.00.00.b_0.cml | 2 +- .../pp_to_cf_conversion/from_netcdf/st0fc699.b_0.cml | 2 +- .../pp_to_cf_conversion/from_netcdf/st0fc942.b_0.cml | 2 +- ...2000000000.44.101.131200.1920.09.01.00.00.b_0.cdl | 12 ++++++------ ...8000000000.44.101.000128.1890.09.01.00.00.b_0.cdl | 8 ++++---- .../pp_to_cf_conversion/to_netcdf/st0fc699.b_0.cdl | 12 ++++++------ 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/iris/tests/results/usecases/pp_to_cf_conversion/from_netcdf/002000000000.44.101.131200.1920.09.01.00.00.b_0.cml b/lib/iris/tests/results/usecases/pp_to_cf_conversion/from_netcdf/002000000000.44.101.131200.1920.09.01.00.00.b_0.cml index caea2f2556..390d94cbc8 100644 --- a/lib/iris/tests/results/usecases/pp_to_cf_conversion/from_netcdf/002000000000.44.101.131200.1920.09.01.00.00.b_0.cml +++ b/lib/iris/tests/results/usecases/pp_to_cf_conversion/from_netcdf/002000000000.44.101.131200.1920.09.01.00.00.b_0.cml @@ -1,6 +1,6 @@ - + diff --git a/lib/iris/tests/results/usecases/pp_to_cf_conversion/from_netcdf/008000000000.44.101.000128.1890.09.01.00.00.b_0.cml b/lib/iris/tests/results/usecases/pp_to_cf_conversion/from_netcdf/008000000000.44.101.000128.1890.09.01.00.00.b_0.cml index f524a54542..b9ac1df666 100644 --- a/lib/iris/tests/results/usecases/pp_to_cf_conversion/from_netcdf/008000000000.44.101.000128.1890.09.01.00.00.b_0.cml +++ b/lib/iris/tests/results/usecases/pp_to_cf_conversion/from_netcdf/008000000000.44.101.000128.1890.09.01.00.00.b_0.cml @@ -1,6 +1,6 @@ - + diff --git a/lib/iris/tests/results/usecases/pp_to_cf_conversion/from_netcdf/st0fc699.b_0.cml b/lib/iris/tests/results/usecases/pp_to_cf_conversion/from_netcdf/st0fc699.b_0.cml index f60710ceaf..c67d6f4ce3 100644 --- a/lib/iris/tests/results/usecases/pp_to_cf_conversion/from_netcdf/st0fc699.b_0.cml +++ b/lib/iris/tests/results/usecases/pp_to_cf_conversion/from_netcdf/st0fc699.b_0.cml @@ -1,6 +1,6 @@ - + diff --git a/lib/iris/tests/results/usecases/pp_to_cf_conversion/from_netcdf/st0fc942.b_0.cml b/lib/iris/tests/results/usecases/pp_to_cf_conversion/from_netcdf/st0fc942.b_0.cml index 602de7b2eb..5dc6fb5c9c 100644 --- a/lib/iris/tests/results/usecases/pp_to_cf_conversion/from_netcdf/st0fc942.b_0.cml +++ b/lib/iris/tests/results/usecases/pp_to_cf_conversion/from_netcdf/st0fc942.b_0.cml @@ -1,6 +1,6 @@ - + diff --git a/lib/iris/tests/results/usecases/pp_to_cf_conversion/to_netcdf/002000000000.44.101.131200.1920.09.01.00.00.b_0.cdl b/lib/iris/tests/results/usecases/pp_to_cf_conversion/to_netcdf/002000000000.44.101.131200.1920.09.01.00.00.b_0.cdl index e78f2799e9..9a1d5b8d8a 100644 --- a/lib/iris/tests/results/usecases/pp_to_cf_conversion/to_netcdf/002000000000.44.101.131200.1920.09.01.00.00.b_0.cdl +++ b/lib/iris/tests/results/usecases/pp_to_cf_conversion/to_netcdf/002000000000.44.101.131200.1920.09.01.00.00.b_0.cdl @@ -3,12 +3,12 @@ dimensions: depth = 20 ; latitude = 73 ; variables: - float unknown(depth, latitude) ; - unknown:_FillValue = 9.96921e+36f ; - unknown:um_stash_source = "m??s44i101" ; - unknown:ukmo__process_flags = "Mean_over_an_ensemble_of_parallel_runs Time_mean_field" ; - unknown:grid_mapping = "latitude_longitude" ; - unknown:coordinates = "forecast_period forecast_reference_time time" ; + float m__s44i101(depth, latitude) ; + m__s44i101:_FillValue = 9.96921e+36f ; + m__s44i101:um_stash_source = "m??s44i101" ; + m__s44i101:ukmo__process_flags = "Mean_over_an_ensemble_of_parallel_runs Time_mean_field" ; + m__s44i101:grid_mapping = "latitude_longitude" ; + m__s44i101:coordinates = "forecast_period forecast_reference_time time" ; int latitude_longitude ; latitude_longitude:grid_mapping_name = "latitude_longitude" ; latitude_longitude:longitude_of_prime_meridian = 0. ; diff --git a/lib/iris/tests/results/usecases/pp_to_cf_conversion/to_netcdf/008000000000.44.101.000128.1890.09.01.00.00.b_0.cdl b/lib/iris/tests/results/usecases/pp_to_cf_conversion/to_netcdf/008000000000.44.101.000128.1890.09.01.00.00.b_0.cdl index b0ba064b97..299adc662e 100644 --- a/lib/iris/tests/results/usecases/pp_to_cf_conversion/to_netcdf/008000000000.44.101.000128.1890.09.01.00.00.b_0.cdl +++ b/lib/iris/tests/results/usecases/pp_to_cf_conversion/to_netcdf/008000000000.44.101.000128.1890.09.01.00.00.b_0.cdl @@ -2,10 +2,10 @@ dimensions: depth = 20 ; time = 16 ; variables: - float unknown(depth, time) ; - unknown:_FillValue = 9.96921e+36f ; - unknown:um_stash_source = "m??s44i101" ; - unknown:cell_methods = "time: mean (interval: 24 hour)" ; + float m__s44i101(depth, time) ; + m__s44i101:_FillValue = 9.96921e+36f ; + m__s44i101:um_stash_source = "m??s44i101" ; + m__s44i101:cell_methods = "time: mean (interval: 24 hour)" ; float depth(depth) ; depth:axis = "Z" ; depth:units = "m" ; diff --git a/lib/iris/tests/results/usecases/pp_to_cf_conversion/to_netcdf/st0fc699.b_0.cdl b/lib/iris/tests/results/usecases/pp_to_cf_conversion/to_netcdf/st0fc699.b_0.cdl index 3b90568f00..2667dc8766 100644 --- a/lib/iris/tests/results/usecases/pp_to_cf_conversion/to_netcdf/st0fc699.b_0.cdl +++ b/lib/iris/tests/results/usecases/pp_to_cf_conversion/to_netcdf/st0fc699.b_0.cdl @@ -3,12 +3,12 @@ dimensions: latitude = 144 ; longitude = 288 ; variables: - float unknown(latitude, longitude) ; - unknown:_FillValue = 9.96921e+36f ; - unknown:um_stash_source = "m02s00i???" ; - unknown:cell_methods = "time: mean (interval: 2 hour)" ; - unknown:grid_mapping = "latitude_longitude" ; - unknown:coordinates = "forecast_period forecast_reference_time time" ; + float m02s00i___(latitude, longitude) ; + m02s00i___:_FillValue = 9.96921e+36f ; + m02s00i___:um_stash_source = "m02s00i???" ; + m02s00i___:cell_methods = "time: mean (interval: 2 hour)" ; + m02s00i___:grid_mapping = "latitude_longitude" ; + m02s00i___:coordinates = "forecast_period forecast_reference_time time" ; int latitude_longitude ; latitude_longitude:grid_mapping_name = "latitude_longitude" ; latitude_longitude:longitude_of_prime_meridian = 0. ;