Last active
August 5, 2020 06:00
-
-
Save cbur24/7c8bb64b622505f11acf91cf1b85edd7 to your computer and use it in GitHub Desktop.
custom reduce function for `collect_training_data`
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
from datacube.utils.geometry import assign_crs | |
import datacube | |
import numpy as np | |
import sys | |
import xarray as xr | |
sys.path.append('../Scripts') | |
from deafrica_bandindices import calculate_indices | |
from deafrica_temporal_statistics import temporal_statistics | |
from deafrica_classificationtools import HiddenPrints | |
from deafrica_datahandling import load_ard | |
def phenology_features(ds): | |
dc = datacube.Datacube(app='training') | |
data = calculate_indices(ds, | |
index=['NDVI'], | |
drop=True, | |
collection='s2') | |
#temporal stats | |
ts = temporal_statistics(data.NDVI, | |
stats=['f_mean', 'abs_change','discordance' | |
'complexity','central_diff']) | |
#Surface reflectance results | |
print("SR..") | |
sr = ds.median('time') | |
print('Merging...') | |
result = xr.merge([ts, sr], compat='override') | |
result = assign_crs(result, crs=ds.geobox.crs) | |
return result.squeeze() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment