-
Notifications
You must be signed in to change notification settings - Fork 0
Home
The user defined function must be named udf_time_series_to_raster_map to be used in this module. The argument of this function is a dictionary that contains the name of the STRDS, the start- and end-time arrays of type pandas.DatetimeIndex and the three dimensional numpy.ndarray. The dictionary is created using the following function:
def create_udf_ts_tile_object(identifier, cell_array, start_time, end_time=None): """Create a time series object for a user defined function
:param identifier: The identifier of the time series, in GRASS GIS is would be the STRDS name :param cell_array: A three dimensional numpy ndarray. For each time stamp a two dimensional (x,y) slice of cell values is provided. - First (0) dimension is time, time stamps are located in separate arrays - Second (1) dimension is y - Third (2) dimension is x :param start_time: A pandas.DatetimeIndex object that includes the start-time-stamps of the first dimension of the cell array :param end_time: A pandas.DatetimeIndex object that includes the end-time-stamps of the first dimension of the cell array The provided data will be put into a dictionary that has the following layout: .. code: Python { "identifier":identifier, "cell_array":cell_array, "start_time":start_time, "end_time":end_time } :return: A dictionary that contains the time series tile """ data_object = {} data_object["identifier"] = identifier data_object["cell_array"] = cell_array data_object["start_time"] = start_time data_object["end_time"] = end_time return data_object
The user defined function must return a numpy.ndarray with the same size as a single (x,y) slice in the input numpy.ndarray. This array will be stored in the output raster map layer.
Compute the sum of all (x,y) slices in the time series cube along the time axis (0):
import numpy as np def udf_time_series_to_raster_map(t): return np.sum(t["cell_array"], axis=0)
Compute the sum of all slices in the time series cube along the time axis (0) and divide the sum by the number of days in which the time series is valid:
import numpy as np def udf_time_series_to_raster_map(t): if t["end_time"] is not None: td = t["end_time"][-1] - t["start_time"][0] else: td = t["start_time"][-1] - t["start_time"][0]return np.sum(t["cell_array"], axis=0)/td.days
Sören Gebbert