From b85b1370d61dc9ed01261f07f5fb75822e0b93e4 Mon Sep 17 00:00:00 2001 From: Stephen Moseley Date: Tue, 18 Jan 2022 15:20:27 +0000 Subject: [PATCH] Adds handling of a model-id-attr to wxcode-modal (#1634) * Updates checksums following addition of mosg__model_configuration to wxcode-modal gridded test data * Adds model-id-attr to wxcode modal - Adds a test for this - Updates acceptance tests to use this - and updates checksums as acceptance test inputs modified so that - mosg__model_configuration is set - title is consistent with a blended data-set * Black and flake8 * Debugs new tests to that the new parametrized variable is available where it's needed * Updates checksums with gridded wxcode-modal attribute update * Updates checksums with spot wxcode-modal attribute update * Updates checksums after merging with master * Updates checksums following reapplication of meta-data using IMPROVER load/save wrappers. * Updates checksums following recreation of KGO. * Recreates checksums following rebase of acceptance test branch to hotfix 1.0.3 * Removes useless comment * Corrects checksums following rebase of acceptance test data branch --- improver/cli/wxcode_modal.py | 8 +- improver/wxcode/modal_code.py | 24 +++- improver_tests/acceptance/SHA256SUMS | 134 +++++++++--------- .../acceptance/test_wxcode_modal.py | 2 + .../wxcode/wxcode/test_ModalCode.py | 37 +++-- 5 files changed, 126 insertions(+), 79 deletions(-) diff --git a/improver/cli/wxcode_modal.py b/improver/cli/wxcode_modal.py index 206263495c..85e67cc1ba 100644 --- a/improver/cli/wxcode_modal.py +++ b/improver/cli/wxcode_modal.py @@ -36,7 +36,7 @@ @cli.clizefy @cli.with_output -def process(*cubes: cli.inputcube): +def process(*cubes: cli.inputcube, model_id_attr: str = None): """Generates a modal weather symbol for the period covered by the input weather symbol cubes. Where there are different weather codes available for night and day, the modal code returned is always a day code, regardless @@ -46,6 +46,10 @@ def process(*cubes: cli.inputcube): cubes (iris.cube.CubeList): A cubelist containing weather symbols cubes that cover the period over which a modal symbol is desired. + model_id_attr (str): + Name of attribute recording source models that should be + inherited by the output cube. The source models are expected as + a space-separated string. Returns: iris.cube.Cube: @@ -56,4 +60,4 @@ def process(*cubes: cli.inputcube): if not cubes: raise RuntimeError("Not enough input arguments. See help for more information.") - return ModalWeatherCode()(cubes) + return ModalWeatherCode(model_id_attr=model_id_attr)(cubes) diff --git a/improver/wxcode/modal_code.py b/improver/wxcode/modal_code.py index 25dc25d16f..024352cf20 100644 --- a/improver/wxcode/modal_code.py +++ b/improver/wxcode/modal_code.py @@ -73,10 +73,20 @@ class ModalWeatherCode(BasePlugin): covered by the input files. """ - def __init__(self): - """Create an aggregator instance for reuse""" + def __init__(self, model_id_attr: str = None): + """ + Set up plugin and create an aggregator instance for reuse + + Args: + model_id_attr: + Name of attribute recording source models that should be + inherited by the output cube. The source models are expected as + a space-separated string. + """ self.aggregator_instance = Aggregator("mode", self.mode_aggregator) + self.model_id_attr = model_id_attr + # Create the expected cell method for use with single cube inputs # that do not pass through the aggregator. self.mode_cell_method = iris.coords.CellMethod("mode", coords="time") @@ -205,6 +215,16 @@ def process(self, cubes: CubeList) -> Cube: result = cube.collapsed("time", self.aggregator_instance) self._set_blended_times(result) + if self.model_id_attr: + # Update contributing models + contributing_models = set() + for source_cube in cubes: + for model in source_cube.attributes[self.model_id_attr].split(" "): + contributing_models.update([model]) + result.attributes[self.model_id_attr] = " ".join( + sorted(list(contributing_models)) + ) + # Handle any unset points where it was hard to determine a suitable mode if (result.data == UNSET_CODE_INDICATOR).any(): self._group_codes(result, cube) diff --git a/improver_tests/acceptance/SHA256SUMS b/improver_tests/acceptance/SHA256SUMS index 55ee87589c..43276b7b94 100644 --- a/improver_tests/acceptance/SHA256SUMS +++ b/improver_tests/acceptance/SHA256SUMS @@ -631,73 +631,73 @@ e653ae271dd789dde8b03e6237cc7b48552dd9d5206d3430ee68d283683247a0 ./wind_downsca de5cee66ebf03a6dc6fe4350fb8fedd782adc0bb5da72726a4098c3b62422130 ./wind_downscaling/with_realization/kgo.nc e50cf0c7e23b12317412e34ea45f959532beb6ba4247e075be08c2a6732e8cd8 ./wind_downscaling/with_realization/sigma.nc 933e1b15c22d3bf302c57dff3fc92c33d45d056b9b6eaa6d677e870537a42e7c ./wind_downscaling/with_realization/standard_orog.nc -97de7945072ae9a2845424904e925aaa1e722fac0c959bb3e534392d4e4a7795 ./wxcode-modal/blend_mismatch_inputs/20201209T0700Z-weather_symbols-PT01H.nc -f76ea9210c563997354ee5e5d3d819192a9d7bb329374839cdebe02d464643d6 ./wxcode-modal/blend_mismatch_inputs/20201209T0800Z-weather_symbols-PT01H.nc -b5f4fc01b1f03811505d4a64cd4e3aa49d94f7a0cb6882b22a5cfd826f82be0d ./wxcode-modal/blend_mismatch_inputs/20201209T0900Z-weather_symbols-PT01H.nc -80bc644d22207485bad81b2ee6d3abab8327ccde982c0771d05e9887d6b9ff7d ./wxcode-modal/blend_mismatch_inputs/20201209T1000Z-weather_symbols-PT01H.nc -cc20c480460357559bbe9151ad069e97535df17a0687ae9e0fa1f5ef3cf9f9a6 ./wxcode-modal/blend_mismatch_inputs/20201209T1100Z-weather_symbols-PT01H.nc -a4576afe3c045c00718692164a89bc0acb70191f70f34bcd300dfa899b9c6f15 ./wxcode-modal/blend_mismatch_inputs/20201209T1200Z-weather_symbols-PT01H.nc -b479b8d6e9b002e716575a8a9051a70891f4cc8862af8ee80b53ecb05d37e8a3 ./wxcode-modal/blend_mismatch_inputs/20201209T1300Z-weather_symbols-PT01H.nc -2b1241b79c97e991ed06c34e6109e85dc1517726d2d375f104a7ac85d939d0a2 ./wxcode-modal/blend_mismatch_inputs/20201209T1400Z-weather_symbols-PT01H.nc -e42830916b5bf8b3f97ace0e54dec8e80be3cf93d9faf420274bab1cfb1772e4 ./wxcode-modal/blend_mismatch_inputs/20201209T1500Z-weather_symbols-PT01H.nc -b4bba902e61db128924d33f145e73aecb6cdf27dc71db6d66d17c9dcfcc498b5 ./wxcode-modal/blend_mismatch_inputs/20201209T1600Z-weather_symbols-PT01H.nc -09da6234ded5f1572183b8e297aa8f633fc20fe3571b5fc3d22b3a8c95c80a8a ./wxcode-modal/blend_mismatch_inputs/20201209T1700Z-weather_symbols-PT01H.nc -56a8d8f763072027c4a4819e0cab298ea0b820cf32903ae010132fa0a72a2eb9 ./wxcode-modal/blend_mismatch_inputs/20201209T1800Z-weather_symbols-PT01H.nc -d081b4d643e2e7734a6a2084efd69a2a0a01ce90f8c234190729a4ceeba53c2b ./wxcode-modal/blend_mismatch_inputs/kgo.nc -c2d9ae0d65cd3da79a7484e8db57b351159d68ab66c3024294b66a95f166f957 ./wxcode-modal/gridded_input/20201209T0700Z-weather_symbols-PT01H.nc -61a2e23ae036a1dc91ce3acc4a8eb105405507718e19a0c07696a47017cd7d75 ./wxcode-modal/gridded_input/20201209T0800Z-weather_symbols-PT01H.nc -181011db593ba39126b67a0166f28844658fc4f9ab9479dd7bdc507f8222f3a5 ./wxcode-modal/gridded_input/20201209T0900Z-weather_symbols-PT01H.nc -fd430134e0fefe8e20a23cee7e301ef99526336c4864ac89d26494400fbecfe8 ./wxcode-modal/gridded_input/20201209T1000Z-weather_symbols-PT01H.nc -7ab5b13f76af59c38b5b725b8f7eee3e3dcd66c07df03c7c9540f7ff8d8a1a1c ./wxcode-modal/gridded_input/20201209T1100Z-weather_symbols-PT01H.nc -f71ebe242cc3f677e2418f04b67c88ce6f152ad31315f066329735512b9fee3d ./wxcode-modal/gridded_input/20201209T1200Z-weather_symbols-PT01H.nc -3845f7fa94d0b595d03438a5f6e36a6f2bcd94b313a50135ae475924f6c2b5cd ./wxcode-modal/gridded_input/20201209T1300Z-weather_symbols-PT01H.nc -9370226d29ba38f069c9e6ac44a85fb6969db0e24b99e6a55675a509677d55e1 ./wxcode-modal/gridded_input/20201209T1400Z-weather_symbols-PT01H.nc -9e91a6231b1ded5bfd6781a4dae87927981657d65d103cff7406d43663928261 ./wxcode-modal/gridded_input/20201209T1500Z-weather_symbols-PT01H.nc -9e84306e6cb7f0bed95c7cc02a6905e8c3389d778acbd14c5d9a4f0ce28d0b44 ./wxcode-modal/gridded_input/20201209T1600Z-weather_symbols-PT01H.nc -11847c4063f937ddb9a6612521228ee14f2658c7ca38a56ce2f26c799caedf85 ./wxcode-modal/gridded_input/20201209T1700Z-weather_symbols-PT01H.nc -e053c2d1a27f708a0bc24c52d2a069e2cf57e499014a7a905e72652ccdebf26b ./wxcode-modal/gridded_input/20201209T1800Z-weather_symbols-PT01H.nc -af44bfd1d30dbe0cd673f15a4e0d0d51473ba320365d6cfe9502c23c9d81dfbb ./wxcode-modal/gridded_input/kgo.nc -6da2c57289d7a5577b4b68f5def5364b35f600f20e823d6bf8803c266e670914 ./wxcode-modal/gridded_ties/20201209T0700Z-weather_symbols-PT01H.nc -c42d8c691b3cf06f12a8bb007bb68a2bf4d2e2d0b195938e852a3e269a1298e1 ./wxcode-modal/gridded_ties/20201209T0800Z-weather_symbols-PT01H.nc -e471cd8a242598db8350e73dedd8f144966b38fd8eb2cd193048e26de5b9b973 ./wxcode-modal/gridded_ties/20201209T0900Z-weather_symbols-PT01H.nc -0dc5ebf2212b3ac28dddefcf5d95ab85a93cf91d93604ce40ed67156c03ebfda ./wxcode-modal/gridded_ties/20201209T1000Z-weather_symbols-PT01H.nc -f6a8a6897507309a1f350f73fb5ba72f2d926f477f7b31026db7e740f36ddbc1 ./wxcode-modal/gridded_ties/20201209T1100Z-weather_symbols-PT01H.nc -ec0f5e8f13facb0f107fa3112e14c46ff34d4ac7531b6c36f9b186fc1e38d3a7 ./wxcode-modal/gridded_ties/20201209T1200Z-weather_symbols-PT01H.nc -9f930cd3fcd02769bc686994e9728d2e47eb7229704377d924391ac45c2321d0 ./wxcode-modal/gridded_ties/20201209T1300Z-weather_symbols-PT01H.nc -8e0af1a80bd199c6c8bfdf011a435203474d7a3f7778b5373b02a6d73a8761ff ./wxcode-modal/gridded_ties/20201209T1400Z-weather_symbols-PT01H.nc -a47daaf93e3fb3ac81b196a1e549b5870c3f21f43ad42e077567aaf0031cde43 ./wxcode-modal/gridded_ties/20201209T1500Z-weather_symbols-PT01H.nc -fa3ec96946235d6655cd82c1f687013b1b02596bde0629aa5081223c26f3c324 ./wxcode-modal/gridded_ties/20201209T1600Z-weather_symbols-PT01H.nc -a316682d14c5d45344ad3863dbb29ca9f414aa009536c602759a2c45eb5576bf ./wxcode-modal/gridded_ties/20201209T1700Z-weather_symbols-PT01H.nc -f61521064c98081d182630bae2ecc36150f6c53bbb6279725b4ebade326c3af7 ./wxcode-modal/gridded_ties/20201209T1800Z-weather_symbols-PT01H.nc -c28ef3583fc70dc5fa7ccaa4edc832da8467ac8afe170d7340b50aab43087fc4 ./wxcode-modal/gridded_ties/kgo.nc -7ba7e060ed581804c956ac2e3e66a41c625ba100541dc63256208cc801f6ea63 ./wxcode-modal/single_input/20201210T0000Z-weather_symbols-PT01H.nc -bb4a38f1b0f93ae6920fd00c6683c8258fe5b2edebb23195771a4cb7358e742d ./wxcode-modal/single_input/kgo.nc -97de7945072ae9a2845424904e925aaa1e722fac0c959bb3e534392d4e4a7795 ./wxcode-modal/spot_input/20201209T0700Z-weather_symbols-PT01H.nc -f76ea9210c563997354ee5e5d3d819192a9d7bb329374839cdebe02d464643d6 ./wxcode-modal/spot_input/20201209T0800Z-weather_symbols-PT01H.nc -b5f4fc01b1f03811505d4a64cd4e3aa49d94f7a0cb6882b22a5cfd826f82be0d ./wxcode-modal/spot_input/20201209T0900Z-weather_symbols-PT01H.nc -80bc644d22207485bad81b2ee6d3abab8327ccde982c0771d05e9887d6b9ff7d ./wxcode-modal/spot_input/20201209T1000Z-weather_symbols-PT01H.nc -cc20c480460357559bbe9151ad069e97535df17a0687ae9e0fa1f5ef3cf9f9a6 ./wxcode-modal/spot_input/20201209T1100Z-weather_symbols-PT01H.nc -950bee63559cf13b6af9f4b56d8d7a628a6afc77353345d44ea6798015c2148f ./wxcode-modal/spot_input/20201209T1200Z-weather_symbols-PT01H.nc -b479b8d6e9b002e716575a8a9051a70891f4cc8862af8ee80b53ecb05d37e8a3 ./wxcode-modal/spot_input/20201209T1300Z-weather_symbols-PT01H.nc -2b1241b79c97e991ed06c34e6109e85dc1517726d2d375f104a7ac85d939d0a2 ./wxcode-modal/spot_input/20201209T1400Z-weather_symbols-PT01H.nc -e42830916b5bf8b3f97ace0e54dec8e80be3cf93d9faf420274bab1cfb1772e4 ./wxcode-modal/spot_input/20201209T1500Z-weather_symbols-PT01H.nc -b4bba902e61db128924d33f145e73aecb6cdf27dc71db6d66d17c9dcfcc498b5 ./wxcode-modal/spot_input/20201209T1600Z-weather_symbols-PT01H.nc -09da6234ded5f1572183b8e297aa8f633fc20fe3571b5fc3d22b3a8c95c80a8a ./wxcode-modal/spot_input/20201209T1700Z-weather_symbols-PT01H.nc -56a8d8f763072027c4a4819e0cab298ea0b820cf32903ae010132fa0a72a2eb9 ./wxcode-modal/spot_input/20201209T1800Z-weather_symbols-PT01H.nc -d081b4d643e2e7734a6a2084efd69a2a0a01ce90f8c234190729a4ceeba53c2b ./wxcode-modal/spot_input/kgo.nc -c68ee173a914f9dd5c47d7a528db0c6335aabe8b1506095f009f7f2b308f11b1 ./wxcode-modal/spot_ties/20201209T0700Z-weather_symbols-PT01H.nc -5443a2d3502838bb83cc030f0e55867465dc4587a8407c9279204d0fcde7a27b ./wxcode-modal/spot_ties/20201209T0800Z-weather_symbols-PT01H.nc -35ff246048347536289053839c02b64255415aabe6763ca2b2289777b083a6ee ./wxcode-modal/spot_ties/20201209T0900Z-weather_symbols-PT01H.nc -1025491e3a2f207a2c1fd68d8a494bf54b9d0a4838bf35d54039eaeb0ab11778 ./wxcode-modal/spot_ties/20201209T1000Z-weather_symbols-PT01H.nc -2e6d8a6ed2b7e4ae88c74b25ad04dc38d7cce58574a0c52339bf3076fe0b8929 ./wxcode-modal/spot_ties/20201209T1100Z-weather_symbols-PT01H.nc -5bfc0319d35a7b7a230fdd51f3e8b6bfddf5632b32dde8e0ff023a6b106268f7 ./wxcode-modal/spot_ties/20201209T1200Z-weather_symbols-PT01H.nc -8f94e92886c8df8070db44b273037b032615e4b8768a3e45c708686061f0c8bc ./wxcode-modal/spot_ties/20201209T1300Z-weather_symbols-PT01H.nc -4fb839e28d711fd0ebbf87090358644b62f7dfa0d8dcdcad9c5dc322ce28eaac ./wxcode-modal/spot_ties/20201209T1400Z-weather_symbols-PT01H.nc -c798e3530eac9a45305711d5e91daa56d5005b826ce85bb48e2889e328ea965c ./wxcode-modal/spot_ties/20201209T1500Z-weather_symbols-PT01H.nc -83ba8460875232fc555976872cdb5ac59d5092ccc0da88f88beb9168a3403ac3 ./wxcode-modal/spot_ties/20201209T1600Z-weather_symbols-PT01H.nc -a6698b2aae8bc223a2d362ccb3047dd9882e6c0df21962e55c577e1ad5850e29 ./wxcode-modal/spot_ties/20201209T1700Z-weather_symbols-PT01H.nc -9290b2899eedfca038226c6707e100025ce68b0798972a60360845ccf36858d2 ./wxcode-modal/spot_ties/20201209T1800Z-weather_symbols-PT01H.nc -ceb7106e5b8919590327a75d4a8b740fb1a2c7cb5a271a5bf980f0c1396c7d22 ./wxcode-modal/spot_ties/kgo.nc +6513b722e1fdca6ad68acd768f3506ec814f78e9ccd4799972ec00a2316ef7cf ./wxcode-modal/blend_mismatch_inputs/20201209T0700Z-weather_symbols-PT01H.nc +d4c5d626ad2e5a805f90f2902f6da5d33651eb6fdcb1e16116e2290d0c608bf6 ./wxcode-modal/blend_mismatch_inputs/20201209T0800Z-weather_symbols-PT01H.nc +4642fc43faf4bdde6a678578868fdebb22163064fe6ef0eef41f2f39a959ca89 ./wxcode-modal/blend_mismatch_inputs/20201209T0900Z-weather_symbols-PT01H.nc +ce6a854694aecd515063c91774eeb6160f39c9dbf5e970f72f960a3527e157e9 ./wxcode-modal/blend_mismatch_inputs/20201209T1000Z-weather_symbols-PT01H.nc +300c38e7f522ff1e9257708b183148f3441bb1a861c15eaff2a5f1713bbbc872 ./wxcode-modal/blend_mismatch_inputs/20201209T1100Z-weather_symbols-PT01H.nc +df077177d1ac4b4faccb945f5e64c0bcf2bf19356dee5acef8caffc5db602823 ./wxcode-modal/blend_mismatch_inputs/20201209T1200Z-weather_symbols-PT01H.nc +5ab6b249ec615ddab9995629aaddbd85bba352ad52b7bcb0be5b3037d75c22ca ./wxcode-modal/blend_mismatch_inputs/20201209T1300Z-weather_symbols-PT01H.nc +340205e12625ff9466c1afba8c007343aa40e21b837ab2f2143fa032e6c47bd3 ./wxcode-modal/blend_mismatch_inputs/20201209T1400Z-weather_symbols-PT01H.nc +776739d288b6e43b3d9341ba301feead160986d2540514f0663f243ca003e55a ./wxcode-modal/blend_mismatch_inputs/20201209T1500Z-weather_symbols-PT01H.nc +4655358c22abdd0acfd5f4e08f156a7f4f629a1764dd8314f28f121964725078 ./wxcode-modal/blend_mismatch_inputs/20201209T1600Z-weather_symbols-PT01H.nc +28ee3f9d419bb9766cc68e1c74fa9e8e5010dc63a600635a54356a33795f6644 ./wxcode-modal/blend_mismatch_inputs/20201209T1700Z-weather_symbols-PT01H.nc +073fd0175e35afcf7f9fe61fedfa63bbd9ea5299f68d8b0287bc30085339b942 ./wxcode-modal/blend_mismatch_inputs/20201209T1800Z-weather_symbols-PT01H.nc +a6b3f48f8c2003c2d84da0a4cb8634bed24f0d54594d6cc9235c470858f49c19 ./wxcode-modal/blend_mismatch_inputs/kgo.nc +70adb1084eb1999513abe77fe43e385c04a5dd967ee57516f5113b6f8aec5454 ./wxcode-modal/gridded_input/20201209T0700Z-weather_symbols-PT01H.nc +03ab503a17fe14c03e3bafc03b44bc994e5a77d7d7ee9649d36c01bba91be813 ./wxcode-modal/gridded_input/20201209T0800Z-weather_symbols-PT01H.nc +2f23984f9e31a79d98e80a3426c551e4ddf32f44ec03cf095d11bf5e2e281113 ./wxcode-modal/gridded_input/20201209T0900Z-weather_symbols-PT01H.nc +4c21a13a71682482c8b5aac5babbe442ade17f8485c3d5e8d573f510d4a94080 ./wxcode-modal/gridded_input/20201209T1000Z-weather_symbols-PT01H.nc +6361353d199cb0c3d7c5e1d601e1b82377bcd7deba37f8f00e5910cc87649ab1 ./wxcode-modal/gridded_input/20201209T1100Z-weather_symbols-PT01H.nc +c649787aef87184392252660d9efeb1fd3c9933c308d02041a03a882ce1fbb59 ./wxcode-modal/gridded_input/20201209T1200Z-weather_symbols-PT01H.nc +c7cf5b8141df473b9854008aa25a9bdbdb162f840d6a829a46fbfccafa57d749 ./wxcode-modal/gridded_input/20201209T1300Z-weather_symbols-PT01H.nc +bc1022649e1b0ace39d9da1f3fbca03be855a6ec785e4487b584139e92d7fb59 ./wxcode-modal/gridded_input/20201209T1400Z-weather_symbols-PT01H.nc +724a98e9d311546af88b68796b4ba40968183b06ffd4688a0a24e1b6299864b1 ./wxcode-modal/gridded_input/20201209T1500Z-weather_symbols-PT01H.nc +fd4ee760bee0077bc4abf0e4be0a8703c43e10097fa8de08b1abf9a3ea4a780b ./wxcode-modal/gridded_input/20201209T1600Z-weather_symbols-PT01H.nc +5d2fa6f476337c2c3783b77d52615652f269174d3b8e804e7c6f931c3e7df4dd ./wxcode-modal/gridded_input/20201209T1700Z-weather_symbols-PT01H.nc +8d150f86a12e4b914e7f2ee269e643022db664d26c2539927d83f4424706cb3e ./wxcode-modal/gridded_input/20201209T1800Z-weather_symbols-PT01H.nc +a37d508c6c356325b1c31c245726aa5459484c4fb34fb2fbf309b10265d24712 ./wxcode-modal/gridded_input/kgo.nc +94a8758ca265acf625a21f4f9c6a246181b7b51e35710f312675d22b394f4d54 ./wxcode-modal/gridded_ties/20201209T0700Z-weather_symbols-PT01H.nc +0dbf6702561e52bcd97a86ef3d954e353a5218b78a1376792144eeb0a673a0c8 ./wxcode-modal/gridded_ties/20201209T0800Z-weather_symbols-PT01H.nc +08881255e7b71679aa1eda6e7bec8b85ceba5adc3547ae169e192abfc3238c39 ./wxcode-modal/gridded_ties/20201209T0900Z-weather_symbols-PT01H.nc +fc4a6da438ac558080c11413de21cd9943f356795d6f145f8e43e9ca290d1412 ./wxcode-modal/gridded_ties/20201209T1000Z-weather_symbols-PT01H.nc +ed07ba61392f465d5890a06c6ad3cee9d9adf31ab03ed365e1d9771d005d646c ./wxcode-modal/gridded_ties/20201209T1100Z-weather_symbols-PT01H.nc +350f0754f7bb247a0a81bb81d05f3e69da4d8d768d8269c82f6fef73713b5b06 ./wxcode-modal/gridded_ties/20201209T1200Z-weather_symbols-PT01H.nc +e8dc643ec6446d495a96d4dda6104b958d08137c15c3e832bb397a50229062eb ./wxcode-modal/gridded_ties/20201209T1300Z-weather_symbols-PT01H.nc +77375be1e8258f0b641ea6475c7739beec64252dc66ae4216a5cc02a3f01cd6e ./wxcode-modal/gridded_ties/20201209T1400Z-weather_symbols-PT01H.nc +148cdbc9282a8fb44e4793144852757ee36c5cd63d6efebfcb63337186e96a2f ./wxcode-modal/gridded_ties/20201209T1500Z-weather_symbols-PT01H.nc +44c510792f566329597239006b43ea736b5faa1a884202fd523aba31ebc4f445 ./wxcode-modal/gridded_ties/20201209T1600Z-weather_symbols-PT01H.nc +182211dba9b8d18c2d48dce89f2871854ae9baa9457bc9cfad16c1cea80faf09 ./wxcode-modal/gridded_ties/20201209T1700Z-weather_symbols-PT01H.nc +2ed494728e73e8f740680ae090504770ee6b60131d543698c640db5ed4e08598 ./wxcode-modal/gridded_ties/20201209T1800Z-weather_symbols-PT01H.nc +fab89f125fe7b016a35fcbf52cd9b713cfa28c7009b90150f289f47d7bea6b12 ./wxcode-modal/gridded_ties/kgo.nc +9fbcfc0e0c3f6af0d07690c6be12e2f641123168af0c7e165b8e0ec6a2ca6f98 ./wxcode-modal/single_input/20201210T0000Z-weather_symbols-PT01H.nc +4e52a42de445064a987da6f93b7e888c0a8ca974063a4d9cf9818a57d9b60367 ./wxcode-modal/single_input/kgo.nc +6513b722e1fdca6ad68acd768f3506ec814f78e9ccd4799972ec00a2316ef7cf ./wxcode-modal/spot_input/20201209T0700Z-weather_symbols-PT01H.nc +d4c5d626ad2e5a805f90f2902f6da5d33651eb6fdcb1e16116e2290d0c608bf6 ./wxcode-modal/spot_input/20201209T0800Z-weather_symbols-PT01H.nc +4642fc43faf4bdde6a678578868fdebb22163064fe6ef0eef41f2f39a959ca89 ./wxcode-modal/spot_input/20201209T0900Z-weather_symbols-PT01H.nc +ce6a854694aecd515063c91774eeb6160f39c9dbf5e970f72f960a3527e157e9 ./wxcode-modal/spot_input/20201209T1000Z-weather_symbols-PT01H.nc +300c38e7f522ff1e9257708b183148f3441bb1a861c15eaff2a5f1713bbbc872 ./wxcode-modal/spot_input/20201209T1100Z-weather_symbols-PT01H.nc +48ef16ad1fd0b499f1d38f585ddb0a4299c39e7d7df625ad0fa6c3dc24e0f094 ./wxcode-modal/spot_input/20201209T1200Z-weather_symbols-PT01H.nc +5ab6b249ec615ddab9995629aaddbd85bba352ad52b7bcb0be5b3037d75c22ca ./wxcode-modal/spot_input/20201209T1300Z-weather_symbols-PT01H.nc +340205e12625ff9466c1afba8c007343aa40e21b837ab2f2143fa032e6c47bd3 ./wxcode-modal/spot_input/20201209T1400Z-weather_symbols-PT01H.nc +776739d288b6e43b3d9341ba301feead160986d2540514f0663f243ca003e55a ./wxcode-modal/spot_input/20201209T1500Z-weather_symbols-PT01H.nc +4655358c22abdd0acfd5f4e08f156a7f4f629a1764dd8314f28f121964725078 ./wxcode-modal/spot_input/20201209T1600Z-weather_symbols-PT01H.nc +28ee3f9d419bb9766cc68e1c74fa9e8e5010dc63a600635a54356a33795f6644 ./wxcode-modal/spot_input/20201209T1700Z-weather_symbols-PT01H.nc +073fd0175e35afcf7f9fe61fedfa63bbd9ea5299f68d8b0287bc30085339b942 ./wxcode-modal/spot_input/20201209T1800Z-weather_symbols-PT01H.nc +a6b3f48f8c2003c2d84da0a4cb8634bed24f0d54594d6cc9235c470858f49c19 ./wxcode-modal/spot_input/kgo.nc +db1612786b08a929ad096f13ca603f37cfd78de681e1306d909654f345f9f409 ./wxcode-modal/spot_ties/20201209T0700Z-weather_symbols-PT01H.nc +b5beedd2fa6c58ecaaa51358b8b7abadddc1ad072af2d5141bbf0019b458e84e ./wxcode-modal/spot_ties/20201209T0800Z-weather_symbols-PT01H.nc +c92e6cb002b8ff8f185c097a55ff214793c7595667c8a7ba4afc1ae0f456c13e ./wxcode-modal/spot_ties/20201209T0900Z-weather_symbols-PT01H.nc +fd216b5dc3837202f3293f22e664d4fa623f7a349abda9ee8aef3fb19df3f660 ./wxcode-modal/spot_ties/20201209T1000Z-weather_symbols-PT01H.nc +fbff18f7ef5c2e3d462cbc0d78de30aca7534a37f427472011f6fa1835ec8020 ./wxcode-modal/spot_ties/20201209T1100Z-weather_symbols-PT01H.nc +129beabb8e059e46d3f00be1c5a5b8c1cdd44c4f1f08fc86a4249d4a0f854272 ./wxcode-modal/spot_ties/20201209T1200Z-weather_symbols-PT01H.nc +063e6f151af8a05f4c2276995384fc4058571144a851953752653eff7886130c ./wxcode-modal/spot_ties/20201209T1300Z-weather_symbols-PT01H.nc +4d23d6d1f8861feeb288ec7b68e57e893fa2ffd633de1b25ab4d4bc4aa3316cc ./wxcode-modal/spot_ties/20201209T1400Z-weather_symbols-PT01H.nc +71aac305fce32fb389ea63822cd88511137cf1260c1c0a55e28c1a5fcbc91cab ./wxcode-modal/spot_ties/20201209T1500Z-weather_symbols-PT01H.nc +6fe4b1563f0fbb4579dba46b12654f983cd6486f39986d52231aad5d18acf508 ./wxcode-modal/spot_ties/20201209T1600Z-weather_symbols-PT01H.nc +d506afe1572ded010805662f057926ba19367a8bf0c9f700380b6b63ab440399 ./wxcode-modal/spot_ties/20201209T1700Z-weather_symbols-PT01H.nc +1c0c3b4fcc95ea2d5c9658ebd42cbee8a2043afa607843e0e9013d273f7fc460 ./wxcode-modal/spot_ties/20201209T1800Z-weather_symbols-PT01H.nc +cb558fc0cb3d1f0535e2402fc293982a122a08380df7d5594cacb9cf032acc5a ./wxcode-modal/spot_ties/kgo.nc a10668de8e2e0f506f4001eff6290adb3bc98eef49fd4a3eb304b166a60fe0ce ./wxcode/basic/kgo.nc a10668de8e2e0f506f4001eff6290adb3bc98eef49fd4a3eb304b166a60fe0ce ./wxcode/basic/kgo_no_lightning.nc 59f399b9944948af2f4da472756ec91ca281fa19f28ec616aa50e429cabd760b ./wxcode/basic/probability_of_lightning_flashes_per_unit_area_in_vicinity_above_threshold.nc diff --git a/improver_tests/acceptance/test_wxcode_modal.py b/improver_tests/acceptance/test_wxcode_modal.py index 4c49d7668d..21320df4ac 100644 --- a/improver_tests/acceptance/test_wxcode_modal.py +++ b/improver_tests/acceptance/test_wxcode_modal.py @@ -68,6 +68,8 @@ def test_expected(tmp_path, test_path): output_path = tmp_path / "output.nc" args = [ *input_paths, + "--model-id-attr", + "mosg__model_configuration", "--output", output_path, ] diff --git a/improver_tests/wxcode/wxcode/test_ModalCode.py b/improver_tests/wxcode/wxcode/test_ModalCode.py index 7001a1898c..17b5230c73 100644 --- a/improver_tests/wxcode/wxcode/test_ModalCode.py +++ b/improver_tests/wxcode/wxcode/test_ModalCode.py @@ -33,10 +33,11 @@ from calendar import timegm from datetime import datetime as dt from datetime import timedelta +from typing import Tuple import numpy as np import pytest -from iris.cube import Cube +from iris.cube import CubeList from improver.spotdata.build_spotdata_cube import build_spotdata_cube from improver.synthetic_data.set_up_test_cubes import construct_scalar_time_coords @@ -44,11 +45,14 @@ from . import set_up_wxcube +MODEL_ID_ATTR = "mosg__model_configuration" TARGET_TIME = dt(2020, 6, 15, 18) @pytest.fixture(name="wxcode_series") -def wxcode_series_fixture(data, cube_type, offset_reference_times: bool) -> Cube: +def wxcode_series_fixture( + data, cube_type, offset_reference_times: bool, model_id_attr: bool, +) -> Tuple[bool, CubeList]: """Generate a time series of weather code cubes for combination to create a period representative code. When offset_reference_times is set, each successive cube will have a reference time one hour older.""" @@ -56,7 +60,7 @@ def wxcode_series_fixture(data, cube_type, offset_reference_times: bool) -> Cube time = TARGET_TIME ntimes = len(data) - wxcubes = [] + wxcubes = CubeList() for i in range(ntimes): wxtime = time - timedelta(hours=i) @@ -93,9 +97,13 @@ def wxcode_series_fixture(data, cube_type, offset_reference_times: bool) -> Cube scalar_coords=time_coords, ) ) - return wxcubes + if model_id_attr: + [c.attributes.update({MODEL_ID_ATTR: "uk_ens"}) for c in wxcubes] + wxcubes[0].attributes.update({MODEL_ID_ATTR: "uk_det uk_ens"}) + return model_id_attr, wxcubes +@pytest.mark.parametrize("model_id_attr", [False, True]) @pytest.mark.parametrize("offset_reference_times", [False, True]) @pytest.mark.parametrize("cube_type", ["gridded", "spot"]) @pytest.mark.parametrize( @@ -133,13 +141,15 @@ def wxcode_series_fixture(data, cube_type, offset_reference_times: bool) -> Cube ) def test_expected_values(wxcode_series, expected): """Test that the expected period representative symbol is returned.""" - result = ModalWeatherCode()(wxcode_series) + _, wxcode_cubes = wxcode_series + result = ModalWeatherCode()(wxcode_cubes) assert result.data.flatten()[0] == expected +@pytest.mark.parametrize("model_id_attr", [False, True]) @pytest.mark.parametrize("offset_reference_times", [False, True]) @pytest.mark.parametrize("cube_type", ["gridded", "spot"]) -@pytest.mark.parametrize("data", [np.ones((12)), np.ones((1))]) +@pytest.mark.parametrize("data", [np.ones(12), np.ones(1)]) def test_metadata(wxcode_series): """Check that the returned metadata is correct. In this case we expect a time coordinate with bounds that describe the full period over which the @@ -154,9 +164,16 @@ def test_metadata(wxcode_series): def as_utc_timestamp(time): return timegm(time.utctimetuple()) - result = ModalWeatherCode()(wxcode_series) + model_id_attr, wxcode_cubes = wxcode_series - n_times = len(wxcode_series) + if model_id_attr: + kwargs = {"model_id_attr": MODEL_ID_ATTR} + else: + kwargs = {} + + result = ModalWeatherCode(**kwargs)(wxcode_cubes) + + n_times = len(wxcode_cubes) expected_time = TARGET_TIME expected_bounds = [TARGET_TIME - timedelta(hours=n_times), TARGET_TIME] expected_reference_time = TARGET_TIME - timedelta(hours=18) @@ -180,3 +197,7 @@ def as_utc_timestamp(time): ) assert result.cell_methods[0].method == expected_cell_method[0] assert result.cell_methods[0].coord_names[0] == expected_cell_method[1] + if model_id_attr: + assert result.attributes[MODEL_ID_ATTR] == "uk_det uk_ens" + else: + assert MODEL_ID_ATTR not in result.attributes.keys()