From e53c1a760076b5abfc369712d6d07e23415afc18 Mon Sep 17 00:00:00 2001 From: andrewgryan Date: Fri, 20 Mar 2020 16:03:42 +0000 Subject: [PATCH] migrate intake_loader.py into drivers/ --- forest/__init__.py | 1 - forest/{ => drivers}/intake_loader.py | 21 +++++++++++++++++++-- forest/load.py | 3 --- forest/main.py | 5 ----- forest/navigate.py | 3 --- test/test_drivers_intake_loader.py | 21 +++++++++++++++++++++ 6 files changed, 40 insertions(+), 14 deletions(-) rename forest/{ => drivers}/intake_loader.py (95%) create mode 100644 test/test_drivers_intake_loader.py diff --git a/forest/__init__.py b/forest/__init__.py index df749198e..166c80b9a 100644 --- a/forest/__init__.py +++ b/forest/__init__.py @@ -29,7 +29,6 @@ from .config import * from . import ( - navigate, redux, tutorial) from .db import Database diff --git a/forest/intake_loader.py b/forest/drivers/intake_loader.py similarity index 95% rename from forest/intake_loader.py rename to forest/drivers/intake_loader.py index e68d00a3d..a757cac45 100644 --- a/forest/intake_loader.py +++ b/forest/drivers/intake_loader.py @@ -18,12 +18,29 @@ except ModuleNotFoundError: intake = None +import forest.view from forest import geo -from forest.drivers import gridded_forecast +from forest.drivers.gridded_forecast import _to_datetime # Location of the Pangeo-CMIP6 intake catalogue file. URL = 'https://raw.githubusercontent.com/NCAR/intake-esm-datastore/master/catalogs/pangeo-cmip6.json' + +class Dataset: + def __init__(self, pattern=None, color_mapper=None, **kwargs): + self.pattern = pattern + self.color_mapper = color_mapper + + def navigator(self): + return Navigator() + + def map_view(self): + loader = IntakeLoader(self.pattern) + view = forest.view.UMView(loader, self.color_mapper) + view.set_hover_properties(INTAKE_TOOLTIPS, INTAKE_FORMATTERS) + return view + + @functools.lru_cache(maxsize=64) def _get_intake_vars( experiment_id, @@ -115,7 +132,7 @@ def _get_bokeh_image(cube, """ def time_comp(select_time, time_cell): # - data_time = gridded_forecast._to_datetime(time_cell.point) + data_time = _to_datetime(time_cell.point) if abs((select_time - data_time).days) < 2: return True return False diff --git a/forest/load.py b/forest/load.py index 87f619e89..f4873e15d 100644 --- a/forest/load.py +++ b/forest/load.py @@ -25,7 +25,6 @@ exceptions, data, rdt, - intake_loader, nearcast) from forest.drivers import gridded_forecast @@ -88,8 +87,6 @@ def file_loader(file_type, pattern, label=None): return data.GPM(pattern) elif file_type == 'griddedforecast': return gridded_forecast.ImageLoader(label, pattern) - elif file_type == 'intake': - return intake_loader.IntakeLoader(pattern) elif file_type == 'nearcast': return nearcast.NearCast(pattern) else: diff --git a/forest/main.py b/forest/main.py index 29a266abf..33a0072c2 100644 --- a/forest/main.py +++ b/forest/main.py @@ -25,7 +25,6 @@ presets, redux, rx, - intake_loader, navigate, parse_args) import forest.components @@ -111,10 +110,6 @@ def main(argv=None): elif isinstance(loader, nearcast.NearCast): viewer = view.NearCast(loader, color_mapper) viewer.set_hover_properties(nearcast.NEARCAST_TOOLTIPS) - elif isinstance(loader, intake_loader.IntakeLoader): - viewer = view.UMView(loader, color_mapper) - viewer.set_hover_properties(intake_loader.INTAKE_TOOLTIPS, - intake_loader.INTAKE_FORMATTERS) else: viewer = view.UMView(loader, color_mapper) else: diff --git a/forest/navigate.py b/forest/navigate.py index 401a1c938..91657f775 100644 --- a/forest/navigate.py +++ b/forest/navigate.py @@ -11,7 +11,6 @@ drivers, db, rdt, - intake_loader, nearcast) from forest.drivers import gridded_forecast @@ -91,8 +90,6 @@ def from_file_type(cls, paths, file_type, pattern=None): elif file_type.lower() == 'griddedforecast': # XXX This needs a "Group" object ... not "paths" return gridded_forecast.Navigator(paths) - elif file_type.lower() == 'intake': - return intake_loader.Navigator() elif file_type.lower() == "nearcast": return nearcast.Navigator(pattern) else: diff --git a/test/test_drivers_intake_loader.py b/test/test_drivers_intake_loader.py new file mode 100644 index 000000000..b1dfd0193 --- /dev/null +++ b/test/test_drivers_intake_loader.py @@ -0,0 +1,21 @@ +import bokeh.models +import forest.drivers +import forest.view + + +def test_dataset_navigator(): + dataset = forest.drivers.get_dataset("intake_loader", {}) + navigator = dataset.navigator() + assert isinstance(navigator, forest.drivers.intake_loader.Navigator) + + +def test_dataset_map_view(): + pattern = "a_b_c_d_e_f" + dataset = forest.drivers.get_dataset("intake_loader", { + "pattern": pattern, + "color_mapper": bokeh.models.ColorMapper() + }) + map_view = dataset.map_view() + assert isinstance(map_view, forest.view.UMView) + assert map_view.tooltips == forest.drivers.intake_loader.INTAKE_TOOLTIPS + assert map_view.formatters == forest.drivers.intake_loader.INTAKE_FORMATTERS