Skip to content

Commit

Permalink
minor aesthetic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
uchchwhash committed Feb 6, 2019
1 parent 1bb8818 commit b7c52a6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 47 deletions.
26 changes: 13 additions & 13 deletions datacube/virtual/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .impl import VirtualProduct, Transformation, VirtualProductException
from .transformations import MakeMask, ApplyMask, ToFloat, Rename, Select
from .statistics import Mean, year, month, week, day
from .transformations import Mean, year, month, week, day
from .utils import reject_keys

from datacube.model import Measurement
Expand All @@ -15,7 +15,7 @@
class NameResolver:
""" Apply a mapping from name to callable objects in a recipe. """

def __init__(self, **lookup_table):
def __init__(self, lookup_table):
self.lookup_table = lookup_table

def construct(self, **recipe) -> VirtualProduct:
Expand Down Expand Up @@ -88,23 +88,23 @@ def lookup(name, namespace=None, kind='transformation'):
raise VirtualProductException("no group_by for aggregate in {}".format(recipe))

return VirtualProduct(dict(aggregate=lookup(cls_name, 'aggregate'),
group_by=lookup(group_by, 'aggregate_group_by', kind='group_by'),
group_by=lookup(group_by, 'aggregate/group_by', kind='group_by'),
input=self.construct(**input_product),
**reject_keys(recipe, ['aggregate', 'input', 'group_by'])))

raise VirtualProductException("could not understand virtual product recipe: {}".format(recipe))


DEFAULT_RESOLVER = NameResolver(transform=dict(make_mask=MakeMask,
apply_mask=ApplyMask,
to_float=ToFloat,
rename=Rename,
select=Select),
aggregate=dict(mean=Mean),
aggregate_group_by=dict(year=year,
month=month,
week=week,
day=day))
DEFAULT_RESOLVER = NameResolver({'transform': dict(make_mask=MakeMask,
apply_mask=ApplyMask,
to_float=ToFloat,
rename=Rename,
select=Select),
'aggregate': dict(mean=Mean),
'aggregate/group_by': dict(year=year,
month=month,
week=week,
day=day)})


def construct(**recipe: Mapping[str, Any]) -> VirtualProduct:
Expand Down
34 changes: 0 additions & 34 deletions datacube/virtual/statistics.py

This file was deleted.

33 changes: 33 additions & 0 deletions datacube/virtual/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,36 @@ def compute(self, data):
return data.drop([measurement
for measurement in data.data_vars
if measurement not in self.measurement_names])


def year(time):
return time.astype('datetime64[Y]')


def month(time):
return time.astype('datetime64[M]')


def week(time):
return time.astype('datetime64[W]')


def day(time):
return time.astype('datetime64[D]')


# TODO: all time stats

class Mean(Transformation):
"""
Take the mean of the measurements.
"""

def __init__(self, dim='time'):
self.dim = dim

def measurements(self, input_measurements):
return input_measurements

def compute(self, data):
return data.mean(dim=self.dim)

0 comments on commit b7c52a6

Please sign in to comment.