merlin.timeseries

merlin.timeseries.add_dates(dates, dods, key='dates')[source]

Inserts dates into each subdictionary of the parent dictionary.

Parameters:
  • dod – A dictionary of dictionaries
  • dates – A sequence of dates
  • key – Subdict key where dates values is inserted
Returns:

An updated dictionary of dictionaries with

merlin.timeseries.create(point, chips_url, acquired, queries, chips_fn=<function get>, dates_fn=<function symmetric_dates>, format_fn=<function pyccd_format>, specs_fn=<function get>)[source]

Queries data, performs date filtering/checking and formats the results.

Parameters:
  • point – Tuple of (x, y) which is within the extents of a chip
  • chips_url – URL to the chips host:port/context
  • acquired – Date range string as start/end, ISO 8601 date format
  • queries – dict of URL queries to retrieve chip specs keyed by spectra
  • chips_fn – Function that accepts x, y, acquired, url, ubids and returns chips.
  • dates_fn – Function that accepts dict of {spectra: [specs],[chips]} and returns a sequence of dates that should be included in the time series. May raise an Exception to halt time series construction.
  • format_fn – Function that accepts chip_x, chip_y, chip_locations, chips_and_specs, dates and returns it’s representation of a time series.
  • specs_fn – Function that accepts a url query and returns chip specs
Returns:

Return value from format_fn

merlin.timeseries.errorhandler(msg='', raises=False)[source]

Constructs, logs and raises error messages

Parameters:
  • msg – Custom message string
  • raises – Whether to raise an exception or not
Returns:

exception handler function

merlin.timeseries.identify(chip_x, chip_y, rod)[source]

Adds chip ids (chip_x, chip_y) to the key for each dict entry

Parameters:
  • chip_x – x coordinate that identifies the source chip
  • chip_y – y coordinate that identifies the source chip
  • rod – dict of (x, y): [values]
Returns:

{(chip_x, chip_y, x, y): [values]}

Return type:

dict

merlin.timeseries.pyccd_format(chip_x, chip_y, chip_locations, chips_and_specs, dates)[source]

Builds inputs for the pyccd algorithm.

Parameters:
  • chip_x – x coordinate for chip identifier
  • chip_y – y coordinate for chip identifier
  • chip_locations – chip shaped 2d array of projection coordinates
  • chips_and_specs – {k: [chips],[specs]}
  • dates – sequence of chip dates to be included in output
Returns:

A tuple of tuples.

Description:

The pyccd format requires a key of (chip_x, chip_y, x, y) with a dictionary of sorted numpy arrays representing each spectra plus an additional sorted dates array.

>>> pyccd_format(*args)
(((chip_x, chip_y, x1, y1), {"dates": [],  "reds": [],
                             "greens": [], "blues": [],
                             "nirs1": [],  "swir1s": [],
                             "swir2s": [], "thermals": [],
                             "quality": []}),
 ((chip_x, chip_y, x1, y2), {"dates": [],  "reds": [],
                             "greens": [], "blues": [],
                             "nirs1": [],  "swir1s": [],
                             "swir2s": [], "thermals": [],
                             "quality": []}))
...
merlin.timeseries.refspec(cas)[source]

Returns the first chip spec from the first key to use as a reference.

Parameters:cas – chips and specs {key: [chips],[specs]}
Returns:chip spec
Return type:dict
merlin.timeseries.sort(chips, key=<function <lambda>>)[source]

Sorts all the returned chips by date.

Parameters:chips – sequence of chips
Returns:sorted sequence of chips
merlin.timeseries.symmetric_dates(dates)[source]

Returns a sequence of dates for chips that should be included in downstream functions. May raise Exception.

Parameters:dates – {key: [datestrings,]}
Returns:Sequence of date strings or Exception

Example

>>> symmetrical_dates({"red":  [ds3, ds1, ds2],
                       "blue": [ds2, ds3, ds1]})
[2, 3, 1]
>>>
>>> symmetrical_dates({"red":  [ds3, ds1],
                       "blue": [ds2, ds3, ds1]})
Exception: red:[3, 1] does not match blue:[2, 3, 1]