diff --git a/ecoscope/analysis/seasons.py b/ecoscope/analysis/seasons.py index 2ef062ee..449eb319 100644 --- a/ecoscope/analysis/seasons.py +++ b/ecoscope/analysis/seasons.py @@ -20,20 +20,34 @@ def _min_max_scaler(x): return x_std -def std_ndvi_vals(aoi=None, start=None, end=None): - coll = ee.ImageCollection("MODIS/MCD43A4_006_NDVI").select("NDVI").filterDate(start, end) +def std_ndvi_vals( + aoi=None, + img_coll=None, + band=None, + img_scale=1, + start=None, + end=None +): + + coll = ee.ImageCollection(img_coll).select(band).filterDate(start, end).map(lambda x: x.multiply( + ee.Image(img_scale)).set("system:time_start", x.get("system:time_start"))) + if aoi: + geo = ee.Feature(shapely.geometry.mapping(aoi)).geometry() + else: + geo = None + ndvi_vals = ( coll.toBands() - .reduceRegion("mean", ee.Feature(shapely.geometry.mapping(aoi)).geometry(), bestEffort=True) + .reduceRegion("mean", geo, bestEffort=True) .values() .getInfo() ) - ndvi_vals_std = _min_max_scaler(ndvi_vals) + return pd.DataFrame( { "img_date": pd.to_datetime(coll.aggregate_array("system:time_start").getInfo(), unit="ms", utc=True), - "NDVI": ndvi_vals_std, + "NDVI": ndvi_vals, } ).dropna(axis=0)