From 5bd1fb7f136c9bd23c96c0b86db1b22746569749 Mon Sep 17 00:00:00 2001 From: Norman Fomferra Date: Tue, 17 Apr 2018 15:31:44 +0200 Subject: [PATCH] closes #590 --- CHANGES.md | 1 + cate/conf/conf.py | 7 ++++++- cate/conf/defaults.py | 16 ++++++++++++++-- cate/conf/template.py | 11 +++++++++++ cate/core/workspace.py | 3 ++- test/conf/test_conf.py | 6 ++++++ 6 files changed, 40 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 5bfb3b681..745447b8d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,6 @@ ## Version 2.0.0.dev9 (in dev) +* Representative default variables [#590](https://github.com/CCI-Tools/cate/issues/590). * Tasks are no longer executed in parallel [#606](https://github.com/CCI-Tools/cate/issues/606). * WebAPI service problem in CLI [#600](https://github.com/CCI-Tools/cate/issues/600) * Improve error messages and handling [#393](https://github.com/CCI-Tools/cate/issues/393), diff --git a/cate/conf/conf.py b/cate/conf/conf.py index 454e34e78..76ebb81d0 100644 --- a/cate/conf/conf.py +++ b/cate/conf/conf.py @@ -28,7 +28,7 @@ from .defaults import GLOBAL_CONF_FILE, LOCAL_CONF_FILE, LOCATION_FILE, VERSION_CONF_FILE, \ VARIABLE_DISPLAY_SETTINGS, DEFAULT_DATA_PATH, DEFAULT_VERSION_DATA_PATH, DEFAULT_COLOR_MAP, DEFAULT_RES_PATTERN, \ - WEBAPI_USE_WORKSPACE_IMAGERY_CACHE + WEBAPI_USE_WORKSPACE_IMAGERY_CACHE, DEFAULT_VARIABLES _CONFIG = None @@ -91,6 +91,11 @@ def get_default_res_pattern() -> str: return default_res_pattern +def is_default_variable(var_name: str) -> bool: + default_variables = get_config().get('default_variables', DEFAULT_VARIABLES) + return var_name in default_variables + + def get_variable_display_settings(var_name: str) -> Optional[Dict[str, Any]]: """ Get the global variable display settings which is a combination of defaults. diff --git a/cate/conf/defaults.py b/cate/conf/defaults.py index aaf6d0548..260782aa6 100644 --- a/cate/conf/defaults.py +++ b/cate/conf/defaults.py @@ -81,6 +81,18 @@ #: By default, WebAPI service will auto-exit after 5 seconds if all workspaces are closed, if WebAPI auto-exit enabled WEBAPI_ON_ALL_CLOSED_AUTO_STOP_AFTER = 5.0 + +DEFAULT_VARIABLES = { + 'absorbing_aerosol_index', # Aerosol CCI + 'cfc', # Cloud CCI + 'lccs_class', # LC CCI + 'kd_490', # OC CCI + 'O3_du', # Ozone CCI + 'sm', # Soil Moisture CCI + 'analysed_sst', # SST CCI +} + + VARIABLE_DISPLAY_SETTINGS = { # LC CCI 'lccs_class': dict(color_map='land_cover_cci'), @@ -94,7 +106,7 @@ 'MODISA_nobs_sum': dict(display_min=1, display_max=500), 'SeaWiFS_nobs_sum': dict(display_min=1, display_max=500), - # CLOUD CCI + # Cloud CCI 'cfc': dict(color_map="bone", display_min=0, display_max=1), # SST CCI @@ -104,7 +116,7 @@ 'sea_ice_fraction': dict(display_min=0., display_max=1.), 'sea_ice_fraction_error': dict(display_min=0., display_max=0.2), - # AEROSOL CCI + # Aerosol CCI 'absorbing_aerosol_index': dict(color_map="bwr", display_min=-2, display_max=2), 'solar_zenith_angle': dict(color_map="bwr", display_min=35, display_max=80), 'number_of_observations': dict(color_map="gray", display_min=0, display_max=150), diff --git a/cate/conf/template.py b/cate/conf/template.py index cd20c577b..5d8d068ef 100644 --- a/cate/conf/template.py +++ b/cate/conf/template.py @@ -108,6 +108,16 @@ ] +# Configure any default variables of a dataset that will be initially selected and displayed first. +# 'default_display_variables' is a list comprising variable name sets. Each set may represent +# multiple similar datasets. +# default_variables = { +# 'cfc', # Cloud CCI +# 'lccs_class', # Land Cover CCI +# 'analysed_sst', # Sea Surface Temperature CCI +# } + + # Configure / overwrite default variable display settings as used in various plot_() operations # and in the Cate Desktop GUI. # Each entry maps a variable name to a dictionary with the following entries: @@ -125,3 +135,4 @@ # https://matplotlib.org/examples/color/colormaps_reference.html # default_color_map = 'jet' default_color_map = 'inferno' + diff --git a/cate/core/workspace.py b/cate/core/workspace.py index ffe7455d4..e8726a728 100644 --- a/cate/core/workspace.py +++ b/cate/core/workspace.py @@ -383,7 +383,8 @@ def _get_xarray_variable_descriptor(cls, variable: xr.DataArray, is_coord=False) 'shape': variable.shape, 'chunkSizes': get_chunk_size(variable), 'attributes': Workspace._attrs_to_json_dict(attrs), - 'isCoord': is_coord + 'isCoord': is_coord, + 'isDefault': conf.is_default_variable(variable.name), } if not is_coord: diff --git a/test/conf/test_conf.py b/test/conf/test_conf.py index ead968ecd..49b171e3a 100644 --- a/test/conf/test_conf.py +++ b/test/conf/test_conf.py @@ -18,6 +18,12 @@ def test_get_variable_display_settings(self): self.assertIsNotNone(settings) self.assertIn('color_map', settings) + def test_is_default_variable(self): + self.assertTrue(conf.is_default_variable('lccs_class')) + self.assertTrue(conf.is_default_variable('analysed_sst')) + self.assertTrue(conf.is_default_variable('cfc')) + self.assertFalse(conf.is_default_variable('bibo')) + def test_get_default_res_prefix(self): default_res_prefix = conf.get_default_res_pattern() self.assertIsNotNone(default_res_prefix)