示例#1
0
def apply_datacube(cube: XarrayDataCube, context: dict) -> XarrayDataCube:
    array: xarray.DataArray = cube.get_array()
    array += 1000
    # Shape (#dates, #bands, #rows, #cols)
    array.loc[:, 'red'] += 10
    array.loc[:, 'nir'] += 100
    return XarrayDataCube(array)
示例#2
0
def apply_hypercube(cube: XarrayDataCube, context: dict) -> XarrayDataCube:
    from scipy.signal import savgol_filter

    array: xarray.DataArray = cube.get_array()
    filled = array.interpolate_na(dim='t')
    smoothed_array = savgol_filter(filled.values, 5, 2, axis=0)
    return XarrayDataCube(xarray.DataArray(smoothed_array, dims=array.dims, coords=array.coords))
示例#3
0
def apply_datacube(cube: XarrayDataCube, context: dict) -> XarrayDataCube:
    inarr = cube.get_array()
    B4 = inarr.loc[:, 'bandzero']
    B8 = inarr.loc[:, 'bandone']
    ndvi = (B8 - B4) / (B8 + B4)
    ndvi = ndvi.expand_dims(dim='bands', axis=-3).assign_coords(bands=['ndvi'])
    return XarrayDataCube(ndvi)
def apply_datacube(cube: XarrayDataCube, context: dict) -> XarrayDataCube:
    """
    Apply Savitzky-Golay smoothing to a timeseries datacube.
    This UDF preserves dimensionality, and assumes an input
    datacube with a temporal dimension 't' as input.
    """
    array: xarray.DataArray = cube.get_array()
    filled = array.interpolate_na(dim='t')
    smoothed_array = savgol_filter(filled.values, 5, 2, axis=0)
    return XarrayDataCube(array=xarray.DataArray(
        smoothed_array, dims=array.dims, coords=array.coords))
示例#5
0
def apply_datacube(cube: XarrayDataCube, context: dict) -> XarrayDataCube:
    """Compute the NDVI based on sentinel2 tiles"""
    array: xarray.DataArray = cube.get_array()
    red = array.sel(bands="TOC-B04_10M")
    nir = array.sel(bands="TOC-B08_10M")
    ndvi = (nir - red) / (nir + red)

    import os
    statinfo = os.stat("/data/users/Public")
    print(statinfo)
    return XarrayDataCube(ndvi)
示例#6
0
def apply_datacube(cube: XarrayDataCube, context: dict) -> XarrayDataCube:
    # access the underlying xarray
    inarr=cube.get_array()

    # ndvi
    B4=inarr.loc[:,'B04']
    B8=inarr.loc[:,'B08']
    ndvi=(B8-B4)/(B8+B4)
    
    # extend bands dim
    ndvi=ndvi.expand_dims(dim='bands', axis=-3).assign_coords(bands=['ndvi'])
    
    # wrap back to datacube and return
    return XarrayDataCube(ndvi)
示例#7
0
def apply_datacube(cube: XarrayDataCube, context: dict) -> XarrayDataCube:
    """
    Applies a rolling window median composite to a timeseries datacube.
    This UDF preserves dimensionality, and assumes a datacube with a temporal dimension 't' as input.
    """

    array: xarray.DataArray = cube.get_array()

    #this method computes dekad's, can be used to resample data to desired frequency

    time_dimension_index = array.get_index('t')

    d = time_dimension_index.day - np.clip((time_dimension_index.day - 1) // 10, 0, 2) * 10 - 1
    date = time_dimension_index.values - np.array(d, dtype="timedelta64[D]")

    #replace each value with 30-day window median
    #first median rolling window to fill gaps on all dates
    composited = array.rolling(t=30,min_periods=1, center=True).median().dropna("t")
    #resample rolling window medians to dekads
    ten_daily_composite = composited.groupby_bins("t",date).median()
    return XarrayDataCube(ten_daily_composite)
示例#8
0
def apply_datacube(cube: XarrayDataCube, context: dict) -> XarrayDataCube:
    array: xarray.DataArray = cube.get_array()
    array += 60
    return XarrayDataCube(array)