Skip to content

Commit

Permalink
WIP: Renames raw datasource nodes. Adds TileCompositor tests. Removes…
Browse files Browse the repository at this point in the history
… interpolatoin classes from public data API.
  • Loading branch information
jmilloy committed Dec 16, 2020
1 parent 9e55e61 commit 571cf2e
Show file tree
Hide file tree
Showing 26 changed files with 226 additions and 177 deletions.
2 changes: 1 addition & 1 deletion podpac/core/compositor/compositor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from podpac.core.utils import common_doc, NodeTrait
from podpac.core.node import COMMON_NODE_DOC, Node
from podpac.core.data.datasource import COMMON_DATA_DOC
from podpac.core.interpolation.interpolation import InterpolationTrait
from podpac.core.interpolation import InterpolationTrait
from podpac.core.managers.multi_threading import thread_manager

COMMON_COMPOSITOR_DOC = COMMON_DATA_DOC.copy() # superset of COMMON_NODE_DOC
Expand Down
2 changes: 1 addition & 1 deletion podpac/core/compositor/ordered_compositor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class OrderedCompositor(BaseCompositor):
"""Compositor that combines sources based on their order in self.sources.
The requested data is interpolated by the sources before being composited.
The sources should generally be interpolated before being composited (i.e. not raw datasources).
Attributes
----------
Expand Down
47 changes: 40 additions & 7 deletions podpac/core/compositor/test/test_tiled_compositor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,48 @@
import numpy as np

import podpac
from podpac.core.data.datasource import DataSource
from podpac.core.data.array_source import Array, ArrayBase
from podpac.core.data.array_source import ArrayRaw
from podpac.core.compositor.tile_compositor import TileCompositorRaw, TileCompositor


class TestTileCompositor(object):
def test_basic_composition(self):
# TODO
pass
def test_composition(self):
a = ArrayRaw(source=np.arange(5) + 100, coordinates=podpac.Coordinates([[0, 1, 2, 3, 4]], dims=["lat"]))
b = ArrayRaw(source=np.arange(5) + 200, coordinates=podpac.Coordinates([[5, 6, 7, 8, 9]], dims=["lat"]))
c = ArrayRaw(source=np.arange(5) + 300, coordinates=podpac.Coordinates([[10, 11, 12, 13, 14]], dims=["lat"]))

def test_interpolated(self):
pass
node = TileCompositorRaw(sources=[a, b, c])

output = node.eval(podpac.Coordinates([[3.5, 4.5, 5.5]], dims=["lat"]))
np.testing.assert_array_equal(output["lat"], [3, 4, 5, 6])
np.testing.assert_array_equal(output, [103, 104, 200, 201])

def test_interpolation(self):
a = ArrayRaw(source=np.arange(5) + 100, coordinates=podpac.Coordinates([[0, 1, 2, 3, 4]], dims=["lat"]))
b = ArrayRaw(source=np.arange(5) + 200, coordinates=podpac.Coordinates([[5, 6, 7, 8, 9]], dims=["lat"]))
c = ArrayRaw(source=np.arange(5) + 300, coordinates=podpac.Coordinates([[10, 11, 12, 13, 14]], dims=["lat"]))

node = TileCompositor(sources=[a, b, c], interpolation="bilinear")

output = node.eval(podpac.Coordinates([[3.5, 4.5, 5.5]], dims=["lat"]))
np.testing.assert_array_equal(output["lat"], [3.5, 4.5, 5.5])
np.testing.assert_array_equal(output, [103.5, 152.0, 200.5])

def test_composition_stacked_multiindex_names(self):
a = ArrayRaw(
source=np.arange(5) + 100,
coordinates=podpac.Coordinates([[[0, 1, 2, 3, 4], [0, 1, 2, 3, 4]]], dims=["lat_lon"]),
)
b = ArrayRaw(
source=np.arange(5) + 200,
coordinates=podpac.Coordinates([[[5, 6, 7, 8, 9], [5, 6, 7, 8, 9]]], dims=["lat_lon"]),
)

node = TileCompositorRaw(sources=[a, b])

output = node.eval(podpac.Coordinates([[[3, 4, 5, 6], [3, 4, 5, 6]]], dims=["lat_lon"]))

# this is checking that the 'lat' and 'lon' multiindex names are still there
np.testing.assert_array_equal(output["lat"], [3, 4, 5, 6])
np.testing.assert_array_equal(output["lon"], [3, 4, 5, 6])
np.testing.assert_array_equal(output, [103, 104, 200, 201])
10 changes: 8 additions & 2 deletions podpac/core/data/array_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from podpac.core.interpolation.interpolation import InterpolationMixin


class ArrayBase(NoCacheMixin, DataSource):
class ArrayRaw(NoCacheMixin, DataSource):
"""Create a DataSource from an array -- this node is mostly meant for small experiments
Attributes
Expand All @@ -34,6 +34,10 @@ class ArrayBase(NoCacheMixin, DataSource):
------
`coordinates` need to supplied by the user when instantiating this node.
See Also
--------
Array : Interpolated array datasource.
This Node is not meant for large arrays, and cause issues with caching. As such, this Node override the default
cache behavior as having no cache -- its data is in RAM already and caching is not helpful.
Expand Down Expand Up @@ -94,5 +98,7 @@ def set_coordinates(self, value):
pass


class Array(InterpolationMixin, ArrayBase):
class Array(InterpolationMixin, ArrayRaw):
""" Array datasource with interpolation. """

pass
14 changes: 10 additions & 4 deletions podpac/core/data/csv_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


@common_doc(COMMON_DATA_DOC)
class CSVBase(FileKeysMixin, LoadFileMixin, BaseFileSource):
class CSVRaw(FileKeysMixin, LoadFileMixin, BaseFileSource):
"""Create a DataSource from a .csv file.
This class assumes that the data has a storage format such as:
Expand Down Expand Up @@ -39,6 +39,10 @@ class CSVBase(FileKeysMixin, LoadFileMixin, BaseFileSource):
altitude column number or column title, default 'alt'
crs : str
Coordinate reference system of the coordinates
See Also
--------
CSV : Interpolated CSV file datasource for general use.
"""

header = tl.Any(default_value=0).tag(attr=True)
Expand All @@ -50,7 +54,7 @@ class CSVBase(FileKeysMixin, LoadFileMixin, BaseFileSource):

@tl.default("data_key")
def _default_data_key(self):
return super(CSVBase, self)._default_data_key()
return super(CSVRaw, self)._default_data_key()

@tl.validate("data_key")
def _validate_data_key(self, d):
Expand Down Expand Up @@ -120,7 +124,7 @@ def get_coordinates(self):
Note: CSV files have StackedCoordinates.
"""

coords = super(CSVBase, self).get_coordinates()
coords = super(CSVRaw, self).get_coordinates()
if len(coords) == 1:
return coords
stacked = StackedCoordinates(list(coords.values()))
Expand Down Expand Up @@ -152,5 +156,7 @@ def _get_col(self, key):
return key if isinstance(key, int) else self.dataset.columns.get_loc(key)


class CSV(InterpolationMixin, CSVBase):
class CSV(InterpolationMixin, CSVRaw):
""" CSV datasource with interpolation. """

pass
12 changes: 9 additions & 3 deletions podpac/core/data/dataset_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


@common_doc(COMMON_DATA_DOC)
class DatasetBase(FileKeysMixin, LoadFileMixin, BaseFileSource):
class DatasetRaw(FileKeysMixin, LoadFileMixin, BaseFileSource):
"""Create a DataSource node using xarray.open_dataset.
Attributes
Expand All @@ -35,6 +35,10 @@ class DatasetBase(FileKeysMixin, LoadFileMixin, BaseFileSource):
extra_dim : dict
In cases where the data contain dimensions other than ['lat', 'lon', 'time', 'alt'], these dimensions need to be selected.
For example, if the data contains ['lat', 'lon', 'channel'], the second channel can be selected using `extra_dim=dict(channel=1)`
See Also
--------
Dataset : Interpolated xarray dataset source for general use.
"""

# dataset = tl.Instance(xr.Dataset).tag(readonly=True)
Expand All @@ -52,7 +56,7 @@ def open_dataset(self, fp):
return xr.open_dataset(fp)

def close_dataset(self):
super(DatasetBase, self).close_dataset()
super(DatasetRaw, self).close_dataset()
self.dataset.close()

@cached_property
Expand Down Expand Up @@ -80,5 +84,7 @@ def get_data(self, coordinates, coordinates_index):
return self.create_output_array(coordinates, data.data[coordinates_index])


class Dataset(InterpolationMixin, DatasetBase):
class Dataset(InterpolationMixin, DatasetRaw):
""" xarray dataset source with interpolation. """

pass
1 change: 0 additions & 1 deletion podpac/core/data/datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from podpac.core.node import Node, NodeException
from podpac.core.utils import common_doc
from podpac.core.node import COMMON_NODE_DOC
from podpac.core.interpolation.interpolation import Interpolate, InterpolationTrait

log = logging.getLogger(__name__)

Expand Down
12 changes: 9 additions & 3 deletions podpac/core/data/h5py_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


@common_doc(COMMON_DATA_DOC)
class H5PYBase(FileKeysMixin, BaseFileSource):
class H5PYRaw(FileKeysMixin, BaseFileSource):
"""Create a DataSource node using h5py.
Attributes
Expand Down Expand Up @@ -44,6 +44,10 @@ class H5PYBase(FileKeysMixin, BaseFileSource):
units, when decoding CF datetimes
cf_calendar : str
calendar, when decoding CF datetimes
See Also
--------
H5PY : Interpolated h5py datasource for general use.
"""

file_mode = tl.Unicode(default_value="r").tag(readonly=True)
Expand All @@ -55,7 +59,7 @@ def dataset(self):

def close_dataset(self):
"""Closes the file. """
super(H5PYBase, self).close_dataset()
super(H5PYRaw, self).close_dataset()
self.dataset.close()

# -------------------------------------------------------------------------
Expand Down Expand Up @@ -118,5 +122,7 @@ def _find_h5py_keys(obj, keys=[]):
return keys


class H5PY(InterpolationMixin, H5PYBase):
class H5PY(InterpolationMixin, H5PYRaw):
""" h5py datasource with interpolation. """

pass
10 changes: 8 additions & 2 deletions podpac/core/data/ogc.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class WCSError(NodeException):
pass


class WCSBase(DataSource):
class WCSRaw(DataSource):
"""
Access data from a WCS source.
Expand All @@ -54,6 +54,10 @@ class WCSBase(DataSource):
max_size : int
maximum request size, optional.
If provided, the coordinates will be tiled into multiple requests.
See Also
--------
WCS : WCS datasource with podpac interpolation.
"""

source = tl.Unicode().tag(attr=True)
Expand Down Expand Up @@ -282,5 +286,7 @@ def get_layers(cls, source=None):
return list(client.contents)


class WCS(InterpolationMixin, WCSBase):
class WCS(InterpolationMixin, WCSRaw):
""" WCS datasource with podpac interpolation. """

coordinate_index_type = tl.Unicode("slice", read_only=True)
10 changes: 8 additions & 2 deletions podpac/core/data/pydap_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@


@common_doc(COMMON_DATA_DOC)
class PyDAPBase(authentication.RequestsSessionMixin, DataSource):
class PyDAPRaw(authentication.RequestsSessionMixin, DataSource):
"""Create a DataSource from an OpenDAP server feed.
Attributes
Expand All @@ -46,6 +46,10 @@ class PyDAPBase(authentication.RequestsSessionMixin, DataSource):
{coordinates}
source : str
URL of the OpenDAP server.
See Also
--------
PyDAP : Interpolated OpenDAP datasource for general use.
"""

source = tl.Unicode().tag(attr=True)
Expand Down Expand Up @@ -132,5 +136,7 @@ def keys(self):
return self.dataset.keys()


class PyDAP(InterpolationMixin, PyDAPBase):
class PyDAP(InterpolationMixin, PyDAPRaw):
""" OpenDAP datasource with interpolation. """

pass
12 changes: 9 additions & 3 deletions podpac/core/data/rasterio_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


@common_doc(COMMON_DATA_DOC)
class RasterioBase(LoadFileMixin, BaseFileSource):
class RasterioRaw(LoadFileMixin, BaseFileSource):
"""Create a DataSource using rasterio.
Attributes
Expand All @@ -40,6 +40,10 @@ class RasterioBase(LoadFileMixin, BaseFileSource):
read_as_filename : bool, optional
Default is False. If True, the file will be read using rasterio.open(self.source) instead of being automatically
parsed to handle ftp, s3, in-memory files, etc.
See Also
--------
Rasterio : Interpolated rasterio datasource for general use.
"""

# dataset = tl.Instance(rasterio.DatasetReader).tag(readonly=True)
Expand All @@ -57,7 +61,7 @@ def dataset(self):
self.set_trait("read_from_source", True)
return rasterio.open(self.source)
else:
return super(RasterioBase, self).dataset
return super(RasterioRaw, self).dataset

@tl.default("band")
def _band_default(self):
Expand Down Expand Up @@ -207,5 +211,7 @@ def get_band_numbers(self, key, value):
return matches


class Rasterio(InterpolationMixin, RasterioBase):
class Rasterio(InterpolationMixin, RasterioRaw):
""" Rasterio datasource with interpolation. """

pass
9 changes: 8 additions & 1 deletion podpac/core/data/reprojection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

import logging
import copy
import warnings

from six import string_types
import traitlets as tl

from podpac.core.utils import common_doc, NodeTrait, cached_property
from podpac.core.coordinates import Coordinates
from podpac.core.node import Node
from podpac.core.interpolation.interpolation import InterpolationTrait
from podpac.core.data.datasource import COMMON_DATA_DOC, DataSource
from podpac.core.interpolation import InterpolationTrait

_logger = logging.getLogger(__name__)

Expand All @@ -37,6 +38,12 @@ class ReprojectedSource(DataSource):
_repr_keys = ["source", "interpolation"]

def _first_init(self, **kwargs):
warnings.warn(
"ReprojectedSource has been replaced by the Reproject algorithm node "
"and will be removed in a future version of podpac.",
DeprecationWarning,
)

if "reprojected_coordinates" in kwargs:
if isinstance(kwargs["reprojected_coordinates"], dict):
kwargs["reprojected_coordinates"] = Coordinates.from_definition(kwargs["reprojected_coordinates"])
Expand Down

0 comments on commit 571cf2e

Please sign in to comment.