-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #299 from informatics-lab/earth-networks-datashader
Earth networks optimisation
- Loading branch information
Showing
14 changed files
with
165 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,34 @@ | ||
from importlib import import_module | ||
from forest.exceptions import DriverNotFound | ||
from functools import wraps | ||
|
||
|
||
_CACHE = {} | ||
|
||
|
||
def _cache(f): | ||
# Ensure per-server dataset instances | ||
def wrapped(driver_name, settings=None): | ||
uid = _uid(driver_name, settings) | ||
if uid not in _CACHE: | ||
_CACHE[uid] = f(driver_name, settings) | ||
return _CACHE[uid] | ||
return wrapped | ||
|
||
|
||
def _uid(driver_name, settings): | ||
if settings is None: | ||
return (driver_name,) | ||
return (driver_name,) + tuple(settings[k] for k in sorted(settings.keys())) | ||
|
||
|
||
@_cache | ||
def get_dataset(driver_name, settings=None): | ||
"""Find Dataset related to file type""" | ||
if settings is None: | ||
settings = {} | ||
try: | ||
module = import_module(f"forest.drivers.{driver_name}") | ||
except ModuleNotFoundError: | ||
raise DriverNotFound(driver_name) | ||
return module.Dataset(**settings) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
bokeh | ||
bokeh=1.4.0 # Port to 2.0.0 in future | ||
datashader | ||
iris | ||
intake | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from forest import drivers | ||
|
||
|
||
def test_singleton_dataset(): | ||
driver_name = "earth_networks" | ||
datasets = ( | ||
drivers.get_dataset(driver_name), | ||
drivers.get_dataset(driver_name)) | ||
assert id(datasets[0]) == id(datasets[1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters