Skip to content

Commit

Permalink
Merge branch 'feature/split-datalib-to-separate-repo' into develop-3.X
Browse files Browse the repository at this point in the history
  • Loading branch information
mpu-creare committed Dec 27, 2023
2 parents 42b446f + cab69b8 commit 738d41f
Show file tree
Hide file tree
Showing 40 changed files with 44 additions and 5,609 deletions.
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'en'
language = "en"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down
24 changes: 12 additions & 12 deletions podpac/core/algorithm/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def chunk_size(self):

chunk_size = podpac.settings["CHUNK_SIZE"]
if chunk_size == "auto":
return 1024**2 # TODO
return 1024 ** 2 # TODO
else:
return chunk_size

Expand Down Expand Up @@ -611,7 +611,7 @@ def reduce_chunked(self, xs, output):
Nx = np.isfinite(x).sum(dim=self._dims)
M1x = x.mean(dim=self._dims)
Ex = x - M1x
Ex2 = Ex**2
Ex2 = Ex ** 2
Ex3 = Ex2 * Ex
M2x = (Ex2).sum(dim=self._dims)
M3x = (Ex3).sum(dim=self._dims)
Expand All @@ -632,13 +632,13 @@ def reduce_chunked(self, xs, output):
n = Nb + Nx
NNx = Nb * Nx

M3.data[b] += M3x + d**3 * NNx * (Nb - Nx) / n**2 + 3 * d * (Nb * M2x - Nx * M2b) / n
M2.data[b] += M2x + d**2 * NNx / n
M3.data[b] += M3x + d ** 3 * NNx * (Nb - Nx) / n ** 2 + 3 * d * (Nb * M2x - Nx * M2b) / n
M2.data[b] += M2x + d ** 2 * NNx / n
M1.data[b] += d * Nx / n
N.data[b] = n

# calculate skew
skew = np.sqrt(N) * M3 / np.sqrt(M2**3)
skew = np.sqrt(N) * M3 / np.sqrt(M2 ** 3)
return skew


Expand Down Expand Up @@ -697,9 +697,9 @@ def reduce_chunked(self, xs, output):
Nx = np.isfinite(x).sum(dim=self._dims)
M1x = x.mean(dim=self._dims)
Ex = x - M1x
Ex2 = Ex**2
Ex2 = Ex ** 2
Ex3 = Ex2 * Ex
Ex4 = Ex2**2
Ex4 = Ex2 ** 2
M2x = (Ex2).sum(dim=self._dims)
M3x = (Ex3).sum(dim=self._dims)
M4x = (Ex4).sum(dim=self._dims)
Expand All @@ -724,18 +724,18 @@ def reduce_chunked(self, xs, output):

M4.data[b] += (
M4x
+ d**4 * NNx * (Nb**2 - NNx + Nx**2) / n**3
+ 6 * d**2 * (Nb**2 * M2x + Nx**2 * M2b) / n**2
+ d ** 4 * NNx * (Nb ** 2 - NNx + Nx ** 2) / n ** 3
+ 6 * d ** 2 * (Nb ** 2 * M2x + Nx ** 2 * M2b) / n ** 2
+ 4 * d * (Nb * M3x - Nx * M3b) / n
)

M3.data[b] += M3x + d**3 * NNx * (Nb - Nx) / n**2 + 3 * d * (Nb * M2x - Nx * M2b) / n
M2.data[b] += M2x + d**2 * NNx / n
M3.data[b] += M3x + d ** 3 * NNx * (Nb - Nx) / n ** 2 + 3 * d * (Nb * M2x - Nx * M2b) / n
M2.data[b] += M2x + d ** 2 * NNx / n
M1.data[b] += d * Nx / n
N.data[b] = n

# calculate kurtosis
kurtosis = N * M4 / M2**2 - 3
kurtosis = N * M4 / M2 ** 2 - 3
return kurtosis


Expand Down
2 changes: 1 addition & 1 deletion podpac/core/coordinates/polar_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(self, center, radius, theta=None, theta_size=None, dims=None):
def _validate_dims(self, d):
val = d["value"]
for dim in val:
if dim not in ["lat", "lon"]: # Hardcoding example. What is actually trying to be accomplished?
if dim not in ["lat", "lon"]: # Hardcoding example. What is actually trying to be accomplished?
raise ValueError("PolarCoordinates dims must be 'lat' or 'lon', not '%s'" % dim)
if val[0] == val[1]:
raise ValueError("Duplicate dimension '%s'" % val[0])
Expand Down
1 change: 1 addition & 0 deletions podpac/core/data/csv_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class CSVRaw(FileKeysMixin, LoadFileMixin, BaseFileSource):
--------
CSV : Interpolated CSV file datasource for general use.
"""

# No support here for custom Dimension names? selection in dataset_source.py
header = tl.Any(default_value=0).tag(attr=True)
lat_key = tl.Union([tl.Unicode(), tl.Int()], default_value="lat").tag(attr=True)
Expand Down
1 change: 1 addition & 0 deletions podpac/core/data/dataset_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class DatasetRaw(FileKeysMixin, LoadFileMixin, BaseFileSource):
--------
Dataset : Interpolated xarray dataset source for general use.
"""

# selection lets you use other dims
# dataset = tl.Instance(xr.Dataset).tag(readonly=True)
selection = tl.Dict(allow_none=True, default_value=None).tag(attr=True)
Expand Down
1 change: 1 addition & 0 deletions podpac/core/data/file_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class FileKeysMixin(tl.HasTraits):
cf_calendar : str
calendar, when decoding CF datetimes
"""

# Other dims?
data_key = tl.Union([tl.Unicode(), tl.List(trait=tl.Unicode())]).tag(attr=True)
lat_key = tl.Unicode(default_value="lat").tag(attr=True)
Expand Down
1 change: 1 addition & 0 deletions podpac/core/data/zarr_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ZarrRaw(S3Mixin, FileKeysMixin, BaseFileSource):
--------
Zarr : Interpolated Zarr Datasource for general use.
"""

# Doesnt support other dims
file_mode = tl.Unicode(default_value="r").tag(readonly=True)
coordinate_index_type = "slice"
Expand Down
2 changes: 1 addition & 1 deletion podpac/core/interpolation/nearest_neighbor_interpolator.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def _get_uniform_index(self, dim, source, request, bounds=None):
# Find all the 0.5 and 1.5's that were rounded to even numbers, and make sure they all round down
I = (index % 0.5) == 0
rindex[I] = np.ceil(index[I])
else: # "unbiased", that's the default np.around behavior, so do nothing
else: # "unbiased", that's the default np.around behavior, so do nothing
pass

stop_ind = int(source.size)
Expand Down
1 change: 1 addition & 0 deletions podpac/core/interpolation/none_interpolator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from podpac.core.coordinates.utils import get_timedelta
from podpac.core.interpolation.selector import Selector, _higher_precision_time_coords1d, _higher_precision_time_stack


@common_doc(COMMON_INTERPOLATOR_DOCS)
class NoneInterpolator(Interpolator):
"""None Interpolation"""
Expand Down
1 change: 1 addition & 0 deletions podpac/core/interpolation/test/test_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class InterpArray(InterpolationMixin, ArrayRaw):
np.testing.assert_array_equal(iaso.data, aso.data)
np.testing.assert_array_equal(abso.data, data)


from podpac.core.coordinates.utils import VALID_DIMENSION_NAMES


Expand Down
6 changes: 3 additions & 3 deletions podpac/core/test/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_pow(self):
dims=["lat", "lon", "alt"],
attrs={"units": ureg.meter},
)
assert (a**2).attrs["units"] == ureg.meter**2
assert (a ** 2).attrs["units"] == ureg.meter ** 2

def test_set_to_value_using_UnitsDataArray_as_mask_does_nothing_if_mask_has_dim_not_in_array(self):
a = UnitsDataArray(
Expand Down Expand Up @@ -273,7 +273,7 @@ def test_units_allpass(self):
assert a6[0, 0].data[()] == False

a7 = a1 * a2
assert a7[0, 0].to(ureg.m**2).data[()] == (1 * ureg.meter * ureg.inch).to(ureg.meter**2).magnitude
assert a7[0, 0].to(ureg.m ** 2).data[()] == (1 * ureg.meter * ureg.inch).to(ureg.meter ** 2).magnitude

a8 = a2 / a1
assert a8[0, 0].to_base_units().data[()] == (1 * ureg.inch / ureg.meter).to_base_units().magnitude
Expand Down Expand Up @@ -328,7 +328,7 @@ def test_ufuncs(self):
np.mean(a1)
np.min(a1)
np.max(a1)
a1**2
a1 ** 2

# These don't have units!
np.dot(a2.T, a1)
Expand Down
2 changes: 2 additions & 0 deletions podpac/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from . import settings
from podpac.core.coordinates.utils import VALID_DIMENSION_NAMES


def common_doc(doc_dict):
"""Decorator: replaces commond fields in a function docstring
Expand Down Expand Up @@ -144,6 +145,7 @@ def validate(self, obj, value):
super(OrderedDictTrait, self).validate(obj, value)
return value


else:
OrderedDictTrait = tl.Dict

Expand Down
26 changes: 9 additions & 17 deletions podpac/datalib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
"""
Datalib Public API
This module gets imported in the root __init__.py
This module import the podpacdatalib package
and exposed its contents to podpac.datalib
"""

import sys
try:
from podpacdatalib import *
except ModuleNotFoundError:
import logging

from podpac.datalib.cosmos_stations import COSMOSStations
from podpac.datalib.drought_monitor import DroughtCategory, DroughtMonitorCategory
from podpac.datalib.egi import EGI
from podpac.datalib.gfs import GFS, GFSLatest
from podpac.datalib.modis_pds import MODIS
from podpac.datalib.satutils import Landsat8, Sentinel2
from podpac.datalib.smap_egi import SMAP
from podpac.datalib.terraintiles import TerrainTiles
from podpac.datalib.weathercitizen import WeatherCitizen
from podpac.datalib.soilscape import SoilSCAPE20min
from podpac.datalib import soilgrids

# intake requires python >= 3.6
if sys.version >= "3.6":
from podpac.datalib.intake_catalog import IntakeCatalog
_logger = logging.getLogger(__name__)
_logger.warning(
"The podpacdatalib module is not installed but user tried to import podpac.datalib which depends on it."
)
Loading

0 comments on commit 738d41f

Please sign in to comment.