-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e7150f6
commit 2ba1e0c
Showing
23 changed files
with
605 additions
and
128 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
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
78 changes: 78 additions & 0 deletions
78
stac_generator/plugins/extraction_methods/datetime_bound_to_centroid.py
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,78 @@ | ||
__author__ = "Richard Smith" | ||
__date__ = "28 May 2021" | ||
__copyright__ = "Copyright 2018 United Kingdom Research and Innovation" | ||
__license__ = "BSD - see LICENSE file in top-level package directory" | ||
__contact__ = "richard.d.smith@stfc.ac.uk" | ||
|
||
|
||
import logging | ||
|
||
from datetime import datetime | ||
|
||
# Package imports | ||
from stac_generator.core.extraction_method import BaseExtractionMethod | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class DatetimeBoundToCentroidExtract(BaseExtractionMethod): | ||
""" | ||
Processor Name: ``datetime_bound_to_centroid`` | ||
Description: | ||
Accepts a dictionary of coordinate values and converts to `RFC 7946, section 5 <https://tools.ietf.org/html/rfc7946#section-5>`_ | ||
formatted bbox. | ||
Configuration Options: | ||
- ``coordinate_keys``: ``REQUIRED`` list of keys to convert to bbox array. Ordering is respected. | ||
Example Configuration: | ||
.. code-block:: yaml | ||
- method: stac_bbox | ||
inputs: | ||
output_term: polygon | ||
""" | ||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
|
||
if not hasattr(self, "start_term"): | ||
self.start_term = {"name": "start_datetime", "format": "%Y-%m-%dT%H:%M:%S"} | ||
|
||
if "name" not in self.start_term: | ||
self.start_term["name"] = "start_datetime" | ||
|
||
if "format" not in self.start_term: | ||
self.start_term["format"] = "%Y-%m-%dT%H:%M:%S" | ||
|
||
if not hasattr(self, "end_term"): | ||
self.end_term = {"name": "end_datetime", "format": "%Y-%m-%dT%H:%M:%S"} | ||
|
||
if "name" not in self.end_term: | ||
self.end_term["name"] = "start_datetime" | ||
|
||
if "format" not in self.end_term: | ||
self.end_term["format"] = "%Y-%m-%dT%H:%M:%S" | ||
|
||
if not hasattr(self, "output_term"): | ||
self.output_term = {"name": "datetime", "format": "%Y-%m-%dT%H:%M:%S"} | ||
|
||
if "name" not in self.output_term: | ||
self.output_term["name"] = "datetime" | ||
|
||
if "format" not in self.output_term: | ||
self.output_term["format"] = "%Y-%m-%dT%H:%M:%S" | ||
|
||
def run(self, body: dict, **kwargs): | ||
|
||
start_datetime = datetime.strptime(body[self.start_term["name"]], self.start_term["format"]) | ||
end_datetime = datetime.strptime(body[self.end_term["name"]], self.end_term["format"]) | ||
|
||
centroid_datetime = start_datetime + (end_datetime - start_datetime) / 2 | ||
|
||
body[self.output_term["name"]] = centroid_datetime.strftime(self.output_term["format"]) | ||
|
||
return body |
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
Oops, something went wrong.