From e8d54c7d5d1d243018abb51fe5d756ba523c2f69 Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Fri, 20 Dec 2024 11:09:51 +0100 Subject: [PATCH 1/2] Fix features and tags --- geometric_features/features_and_tags.json | 133 ++++++++++------------ 1 file changed, 63 insertions(+), 70 deletions(-) diff --git a/geometric_features/features_and_tags.json b/geometric_features/features_and_tags.json index 30847e7a..a61ac70e 100644 --- a/geometric_features/features_and_tags.json +++ b/geometric_features/features_and_tags.json @@ -812,114 +812,111 @@ "eastCentralGreenland1": [ "eastCentralGreenland" ], + "eastCentralGreenland1_oceanExtended": [ + "eastCentralGreenland" + ], "eastCentralGreenland2": [ "eastCentralGreenland" ], + "eastCentralGreenland2_oceanExtended": [ + "eastCentralGreenland" + ], "eastCentralGreenland3": [ "eastCentralGreenland" ], + "eastCentralGreenland3_oceanExtended": [ + "eastCentralGreenland" + ], "northEastGreenland1": [ "northEastGreenland" ], + "northEastGreenland1_oceanExtended": [ + "northEastGreenland" + ], "northEastGreenland2": [ "northEastGreenland" ], + "northEastGreenland2_oceanExtended": [ + "northEastGreenland" + ], "northGreenland1": [ "northGreenland" ], + "northGreenland1_oceanExtended": [ + "northGreenland" + ], "northGreenland2": [ "northGreenland" ], + "northGreenland2_oceanExtended": [ + "northGreenland" + ], "northGreenland3": [ "northGreenland" ], + "northGreenland3_oceanExtended": [ + "northGreenland" + ], "northGreenland4": [ "northGreenland" ], "northWestGreenland1": [ "northWestGreenland" ], + "northWestGreenland1_oceanExtended": [ + "northWestGreenland" + ], "northWestGreenland2": [ "northWestGreenland" ], + "northWestGreenland2_oceanExtended": [ + "northWestGreenland" + ], "southEastGreenland1": [ "southEastGreenland" ], - "southEastGreenland2": [ + "southEastGreenland1_oceanExtended": [ "southEastGreenland" ], - "southEastGreenland3": [ + "southEastGreenland2": [ "southEastGreenland" ], - "southGreenland1": [ - "southGreenland" - ], - "southWestGreenland1": [ - "southWestGreenland" - ], - "southWestGreenland2": [ - "southWestGreenland" - ], - "westCentralGreenland1": [ - "westCentralGreenland" - ], - "westCentralGreenland2": [ - "westCentralGreenland" - ], - "eastCentralGreenland1_oceanExtended": [ - "eastCentralGreenland" - ], - "eastCentralGreenland2_oceanExtended": [ - "eastCentralGreenland" - ], - "eastCentralGreenland3_oceanExtended": [ - "eastCentralGreenland" - ], - "northEastGreenland1_oceanExtended": [ - "northEastGreenland" - ], - "northEastGreenland2_oceanExtended": [ - "northEastGreenland" - ], - "northGreenland1_oceanExtended": [ - "northGreenland" - ], - "northGreenland2_oceanExtended": [ - "northGreenland" - ], - "northGreenland3_oceanExtended": [ - "northGreenland" - ], - "northGreenland4_oceanExtended": [ - "northGreenland" - ], - "northWestGreenland1_oceanExtended": [ - "northWestGreenland" - ], - "northWestGreenland2_oceanExtended": [ - "northWestGreenland" - ], - "southEastGreenland1_oceanExtended": [ + "southEastGreenland2_oceanExtended": [ "southEastGreenland" ], - "southEastGreenland2_oceanExtended": [ + "southEastGreenland3": [ "southEastGreenland" ], "southEastGreenland3_oceanExtended": [ "southEastGreenland" ], + "southGreenland1": [ + "southGreenland" + ], "southGreenland1_oceanExtended": [ "southGreenland" ], + "southWestGreenland1": [ + "southWestGreenland" + ], "southWestGreenland1_oceanExtended": [ "southWestGreenland" ], + "southWestGreenland2": [ + "southWestGreenland" + ], "southWestGreenland2_oceanExtended": [ "southWestGreenland" ], + "westCentralGreenland1": [ + "westCentralGreenland" + ], "westCentralGreenland1_oceanExtended": [ "westCentralGreenland" ], + "westCentralGreenland2": [ + "westCentralGreenland" + ], "westCentralGreenland2_oceanExtended": [ "westCentralGreenland" ] @@ -1921,58 +1918,54 @@ }, "seaice": { "region": { - "April Historical Median Sea Ice Extent":[ + "April Historical Median Sea Ice Extent": [ "QGreenland", "Historical_Sea_Ice_Extent" ], - "August Historical Median Sea Ice Extent":[ + "August Historical Median Sea Ice Extent": [ "QGreenland", "Historical_Sea_Ice_Extent" - ], - "December Historical Median Sea Ice Extent":[ - "QGreenland", - "Historical_Sea_Ice_Extent" - ], - "February Historical Median Sea Ice Extent":[ + ], + "December Historical Median Sea Ice Extent": [ "QGreenland", "Historical_Sea_Ice_Extent" ], - "January Historical Median Sea Ice Extent":[ + "February Historical Median Sea Ice Extent": [ "QGreenland", "Historical_Sea_Ice_Extent" ], - "July Historical Median Sea Ice Extent":[ + "January Historical Median Sea Ice Extent": [ "QGreenland", "Historical_Sea_Ice_Extent" ], - "June Historical Median Sea Ice Extent":[ + "July Historical Median Sea Ice Extent": [ "QGreenland", "Historical_Sea_Ice_Extent" ], - "March Historical Median Sea Ice Extent":[ + "June Historical Median Sea Ice Extent": [ "QGreenland", "Historical_Sea_Ice_Extent" ], - "May Historical Median Sea Ice Extent":[ + "March Historical Median Sea Ice Extent": [ "QGreenland", "Historical_Sea_Ice_Extent" ], - "November Historical Median Sea Ice Extent":[ + "May Historical Median Sea Ice Extent": [ "QGreenland", "Historical_Sea_Ice_Extent" ], - "March Historical Median Sea Ice Extent":[ + "November Historical Median Sea Ice Extent": [ "QGreenland", "Historical_Sea_Ice_Extent" ], - "October Historical Median Sea Ice Extent":[ + "October Historical Median Sea Ice Extent": [ "QGreenland", "Historical_Sea_Ice_Extent" ], - "September Historical Median Sea Ice Extent":[ + "September Historical Median Sea Ice Extent": [ "QGreenland", "Historical_Sea_Ice_Extent" ] } } -} +} \ No newline at end of file From 137aa8ec881da9dbe7126768cd697d2379420c72 Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Fri, 20 Dec 2024 11:10:25 +0100 Subject: [PATCH 2/2] Add a test to check the features_and_tags.json file For convenience, don't print all the files in the test. --- .../test/test_features_and_tags.py | 40 +++++++++++++++++++ geometric_features/utils.py | 8 +++- 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 geometric_features/test/test_features_and_tags.py diff --git a/geometric_features/test/test_features_and_tags.py b/geometric_features/test/test_features_and_tags.py new file mode 100644 index 00000000..d5d1436c --- /dev/null +++ b/geometric_features/test/test_features_and_tags.py @@ -0,0 +1,40 @@ +import difflib +import os + +import pytest + +from geometric_features.test import TestCase, loaddatadir +from geometric_features.utils import write_feature_names_and_tags + + +@pytest.mark.usefixtures('loaddatadir') +class TestFeaturesAndTags(TestCase): + + def test_features_and_tags(self): + if 'GEOMETRIC_DATA_DIR' in os.environ: + cache_location = os.environ['GEOMETRIC_DATA_DIR'] + else: + cache_location = './geometric_data' + write_feature_names_and_tags(cacheLocation=cache_location, quiet=True) + assert os.path.exists('features_and_tags.json') + + filename1 = 'geometric_features/features_and_tags.json' + filename2 = 'features_and_tags.json' + with open(filename1, 'r') as f: + lines1 = f.readlines() + + with open(filename2, 'r') as f: + lines2 = f.readlines() + + diff = difflib.unified_diff(lines1, lines2, fromfile=filename1, + tofile=filename2) + + count = 0 + for line in diff: + print(line) + count + 1 + + if count != 0: + raise ValueError( + 'Unexpected differences in geometric_features/features_and_tags.json ' + 'compared with the results of geometric_features.utils.write_feature_names_and_tags()') diff --git a/geometric_features/utils.py b/geometric_features/utils.py index b475a9a3..08a84aa8 100644 --- a/geometric_features/utils.py +++ b/geometric_features/utils.py @@ -10,7 +10,7 @@ import datetime -def write_feature_names_and_tags(cacheLocation='./geometry_data'): +def write_feature_names_and_tags(cacheLocation='./geometry_data', quiet=False): """ Make a json file with all the available features and tags by component and object type, used to update the file when new geometric features are @@ -20,6 +20,9 @@ def write_feature_names_and_tags(cacheLocation='./geometry_data'): ---------- cacheLocation : str, optional The location of the geometric features cache + + quiet : bool, optional + Whether to suppress printing of feature filenames """ # Authors # ------- @@ -29,7 +32,8 @@ def write_feature_names_and_tags(cacheLocation='./geometry_data'): allFeaturesAndTags = OrderedDict() for fileName in fileNames: - print(fileName) + if not quiet: + print(fileName) with open(fileName) as f: features = json.load(f)['features'] feature = features[0]