From c45a861332899a69151ed34befad05d4063d15ce Mon Sep 17 00:00:00 2001 From: Norman Fomferra Date: Wed, 20 Sep 2017 14:36:36 +0200 Subject: [PATCH] fixes #372 --- cate/conf/conf.py | 15 +++++++++++++-- cate/conf/defaults.py | 4 ++++ cate/conf/template.py | 14 ++++++++++++++ cate/core/workspace.py | 18 ++++++++++++++---- test/conf/__init__.py | 0 test/conf/test_conf.py | 13 +++++++++++++ test/ds/test_esa_cci_ftp.py | 6 +++--- 7 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 test/conf/__init__.py create mode 100644 test/conf/test_conf.py diff --git a/cate/conf/conf.py b/cate/conf/conf.py index 1db29a4d3..091cc1cba 100644 --- a/cate/conf/conf.py +++ b/cate/conf/conf.py @@ -22,9 +22,9 @@ __author__ = "Norman Fomferra (Brockmann Consult GmbH)" import os.path -from typing import Any +from typing import Any, Dict, Optional -from .defaults import GLOBAL_CONF_FILE, LOCAL_CONF_FILE, LOCATION_FILE, VERSION_CONF_FILE +from .defaults import GLOBAL_CONF_FILE, LOCAL_CONF_FILE, LOCATION_FILE, VERSION_CONF_FILE, VARIABLE_DISPLAY_SETTINGS _CONFIG = None @@ -55,6 +55,17 @@ def get_config_value(name: str, default=None) -> Any: return get_config().get(name, default) +def get_variable_display_settings(var_name: str) -> Optional[Dict[str, Any]]: + """ + Get the global variable display settings which is a combination of defaults. + :return: + """ + d = get_config().get('variable_display_settings', None) + if d and var_name in d: + return d[var_name] + return VARIABLE_DISPLAY_SETTINGS.get(var_name) + + def get_config() -> dict: """ Get the global Cate configuration dictionary. diff --git a/cate/conf/defaults.py b/cate/conf/defaults.py index a0c1ec3a4..f458ca43b 100644 --- a/cate/conf/defaults.py +++ b/cate/conf/defaults.py @@ -77,3 +77,7 @@ #: 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 + +VARIABLE_DISPLAY_SETTINGS = { + "lccs_class": dict(color_map='land_cover_cci'), +} diff --git a/cate/conf/template.py b/cate/conf/template.py index 440204981..a350e55e2 100644 --- a/cate/conf/template.py +++ b/cate/conf/template.py @@ -5,6 +5,7 @@ # the settings provided here. ############################################################################### + # 'data_stores_path' is denotes a directory where Cate stores information about data stores and also saves # local data files synchronized with their remote versions. # Use the tilde '~' (also on Windows) within the path to point to your home directory. @@ -18,6 +19,7 @@ # # use_workspace_imagery_cache = False + # Include/exclude data sources (currently effective in Cate Desktop GUI only, not used by API, CLI). # # If 'included_data_sources' is a list, its entries are expected to be wildcard patterns for the identifiers of data @@ -38,3 +40,15 @@ # Exclude Land Cover CCI, see issues #361, #364, #371 'esacci.LC.*', ] + + +# 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: +# color_map - name of a color map taken from from https://matplotlib.org/examples/color/colormaps_reference.html +# display_min - minimum variable value that corresponds to the lower end of the color map +# display_max - maximum variable value that corresponds to the upper end of the color map +# +# variable_display_settings = { +# 'my_var': dict(color_map='inferno', display_min=0.1, display_max=0.8), +# } diff --git a/cate/core/workspace.py b/cate/core/workspace.py index 95fe56b12..894670191 100644 --- a/cate/core/workspace.py +++ b/cate/core/workspace.py @@ -33,6 +33,7 @@ import pandas as pd import xarray as xr +from ..conf import conf from ..conf.defaults import WORKSPACE_DATA_DIR_NAME, WORKSPACE_WORKFLOW_FILE_NAME, SCRATCH_WORKSPACES_PATH from ..core.cdm import get_lon_dim_name, get_lat_dim_name from ..core.op import OP_REGISTRY @@ -369,9 +370,9 @@ def _get_xarray_variable_descriptor(self, variable: xr.DataArray, is_coord=False } if not is_coord: - image_config = self._get_variable_image_config(variable) - if image_config: - variable_info['imageLayout'] = image_config + image_layout = self._get_variable_image_layout(variable) + if image_layout: + variable_info['imageLayout'] = image_layout variable_info['isYFlipped'] = Workspace._is_y_flipped(variable) elif variable.ndim == 1: # Serialize data of coordinate variables. @@ -379,10 +380,19 @@ def _get_xarray_variable_descriptor(self, variable: xr.DataArray, is_coord=False # Note that the 'data' field is used to display coordinate labels in the GUI only. variable_info['data'] = to_json(variable.data) + display_settings = conf.get_variable_display_settings(variable.name) + if display_settings: + mapping = dict(colorMapName='color_map', + displayMin='display_min', + displayMax='display_max') + for var_prop_name, display_settings_name in mapping.items(): + if display_settings_name in display_settings: + variable_info[var_prop_name] = display_settings[display_settings_name] + return variable_info # noinspection PyMethodMayBeStatic - def _get_variable_image_config(self, variable): + def _get_variable_image_layout(self, variable): lat_dim_name = get_lat_dim_name(variable) lon_dim_name = get_lon_dim_name(variable) if not lat_dim_name or not lon_dim_name: diff --git a/test/conf/__init__.py b/test/conf/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/test/conf/test_conf.py b/test/conf/test_conf.py new file mode 100644 index 000000000..65d44a060 --- /dev/null +++ b/test/conf/test_conf.py @@ -0,0 +1,13 @@ +from unittest import TestCase + +from cate.conf import conf + + +class ConfTest(TestCase): + def test_get_variable_display_settings(self): + settings = conf.get_variable_display_settings('__bibo__') + self.assertIsNone(settings) + + settings = conf.get_variable_display_settings('lccs_class') + self.assertIsNotNone(settings) + self.assertIn('color_map', settings) diff --git a/test/ds/test_esa_cci_ftp.py b/test/ds/test_esa_cci_ftp.py index 888bc194c..9a7164ced 100644 --- a/test/ds/test_esa_cci_ftp.py +++ b/test/ds/test_esa_cci_ftp.py @@ -4,17 +4,17 @@ from unittest import TestCase import cate.core.ds as io -from cate.core.ds import DATA_STORE_REGISTRY +from cate.core.ds import DATA_STORE_REGISTRY, get_data_stores_path from cate.ds.esa_cci_ftp import FileSetDataStore, set_default_data_store class EsaCciFtpTest(TestCase): def test_set_default_data_store(self): set_default_data_store() + data_stores_path = get_data_stores_path() data_store = DATA_STORE_REGISTRY.get_data_store('esa_cci_ftp') self.assertIsInstance(data_store, FileSetDataStore) - self.assertEqual(data_store.root_dir, - os.path.expanduser(os.path.join('~', '.cate', 'data_stores', 'esa_cci_ftp'))) + self.assertEqual(data_store.root_dir, os.path.join(data_stores_path, 'esa_cci_ftp')) class FileSetDataSourceTest(TestCase):