Skip to content

Commit

Permalink
Miscellaneous cleanup (#1042)
Browse files Browse the repository at this point in the history
* Always use "ns" precision in numpy.datetime64's.

* Remove unused utility function.

* Remove whitespace in template - I think this a regression in pyows.

* And I think this is a numpy2 thing?

* Fix documentation typos.
  • Loading branch information
SpacemanPaul authored Aug 1, 2024
1 parent e6c7b6e commit b510f5e
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 35 deletions.
4 changes: 2 additions & 2 deletions datacube_ows/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,8 +901,8 @@ def feature_info(args):
elif pt_native.crs != ds.crs:
pt_native = geo_point.to_crs(ds.crs)
if ds.extent and ds.extent.contains(pt_native):
# tolist() converts a numpy datetime64 to a python datatime
dt = stacker.group_by.group_by_func(ds).tolist()
# convert numpy datetime64 to a python datatime
dt = Timestamp(stacker.group_by.group_by_func(ds)).to_pydatetime()
if params.product.time_resolution.is_subday():
feature_json["data_available_for_dates"].append(dt.isoformat())
else:
Expand Down
14 changes: 0 additions & 14 deletions datacube_ows/ogc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,6 @@ def solar_date(dt: datetime.datetime, tz: datetime.tzinfo) -> datetime.date:
return dt.astimezone(tz).date()


def local_date(ds: "datacube.model.Dataset", tz: Optional[datetime.tzinfo] = None) -> datetime.date:
"""
Calculate the local (solar) date for a dataset.
:param ds: An ODC dataset object
:param tz: (optional) A timezone object. If not provided, determine the timezone from extent of the dataset.
:return: A date object.
"""
dt_utc: datetime.datetime = dataset_center_time(ds)
if not tz:
tz = tz_for_geometry(ds.extent)
return solar_date(dt_utc, tz)


def tz_for_dataset(ds: "datacube.model.Dataset") -> datetime.tzinfo:
"""
Determine the timezone for a dataset (using it's extent)
Expand Down
4 changes: 1 addition & 3 deletions datacube_ows/templates/wms_capabilities.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@
{% elif lyr.regular_time_axis %}
<Dimension name="time" units="ISO8601" default="{{ lyr.default_time.isoformat() }}">{{ lyr.time_axis_representation() }}</Dimension>
{% elif lyr_ranges.times|length > 1 %}
<Dimension name="time" units="ISO8601" default="{{ lyr.default_time.isoformat() }}">
{% for t in lyr_ranges.times %}{{ t.isoformat() }}{% if not loop.last %},{% endif %}{% endfor %}
</Dimension>
<Dimension name="time" units="ISO8601" default="{{ lyr.default_time.isoformat() }}">{% for t in lyr_ranges.times %}{{ t.isoformat() }}{% if not loop.last %},{% endif %}{% endfor %}</Dimension>
{% endif %}

{% if lyr.attribution %}
Expand Down
8 changes: 5 additions & 3 deletions datacube_ows/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def group_by_begin_datetime(pnames: Optional[List[str]] = None,
ds.time.begin.year,
ds.time.begin.month,
ds.time.begin.day,
tzinfo=pytz.utc))
tzinfo=pytz.utc), "ns")
else:
grp_by = lambda ds: npdt64(datetime.datetime(
ds.time.begin.year,
Expand All @@ -79,7 +79,7 @@ def group_by_begin_datetime(pnames: Optional[List[str]] = None,
ds.time.begin.hour,
ds.time.begin.minute,
ds.time.begin.second,
tzinfo=ds.time.begin.tzinfo))
tzinfo=ds.time.begin.tzinfo), "ns")
return GroupBy(
dimension='time',
group_by_func=grp_by,
Expand Down Expand Up @@ -120,7 +120,9 @@ def group_by_mosaic(pnames: Optional[List[str]] = None) -> "datacube.api.query.G
sort_key = lambda ds: (solar_day(ds), base_sort_key(ds))
return GroupBy(
dimension='time',
group_by_func=lambda n: npdt64(datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc)),
group_by_func=lambda n: npdt64(
datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc),
"ns"),
units='seconds since 1970-01-01 00:00:00',
sort_key=sort_key
)
Expand Down
2 changes: 1 addition & 1 deletion datacube_ows/wcs1_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def get_coverage_data(req, qprof):
)
if req.product.time_resolution.is_subday():
timevals = [
numpy.datetime64(dt.astimezone(pytz.utc).isoformat())
numpy.datetime64(dt.astimezone(pytz.utc).isoformat(), "ns")
for dt in req.times
]
else:
Expand Down
4 changes: 2 additions & 2 deletions docs/cfg_styling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,9 @@ In addition to the custom includes defined `at the layer level
If the GetFeatureInfo requests a style AND multiple dates, then the multi-date handler
can define additional custom feature info.

An additional dictionary is appended to the `propoerties::data` list, that already contains a dictionary
An additional dictionary is appended to the `properties::data` list, that already contains a dictionary
for each date returned by the query. The additional dictionary has ``"time": "all"`` and the fields
defined by the multi-date handler custom_includes entry.

Unlike other ``custom_include`` entries, the functions specified by the mult-date version is passed
Unlike other ``custom_include`` entries, the functions specified by the multi-date version is passed
a MULTI_DATE, single-pixel, multi-band ``xarray.Dataset``. (Note that no ODC metadata is passed.)
10 changes: 0 additions & 10 deletions tests/test_ogc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,6 @@ def test_tz_bad_coords():
tzinf = datacube_ows.ogc_utils.tz_for_coord(-88.8, 155.2)


def test_local_date(dummy_ds):
ld = datacube_ows.ogc_utils.local_date(dummy_ds)
assert ld.year == 2020
assert ld.day == 26
tz = datacube_ows.ogc_utils.tz_for_dataset(dummy_ds)
ld = datacube_ows.ogc_utils.local_date(dummy_ds, tz)
assert ld.year == 2020
assert ld.day == 26


def test_month_date_range_wrap():
d = datetime.date(2019, 12, 1)
a, b = datacube_ows.ogc_utils.month_date_range(d)
Expand Down

0 comments on commit b510f5e

Please sign in to comment.