1

I came across an example shared on YouTube by Madhu Mysore. Here is the link: https://www.youtube.com/watch?v=IGUYSeoeHhg&t=2105s.

I changed the code as I am not interested in regions at the moment, but rather in daily/weekly observations. What I am struggling to do is to add a timestamp to the following code. I checked multiple forums and EE developers page but cannot figure it out.

import ee
import pandas as pd
ee.Initialize()
districts = ee.FeatureCollection('users/mdm/za/za_districts')

chirps = ee.ImageCollection("UCSB-CHG/CHIRPS/DAILY").select('precipitation').filterDate('2018-01-01', '2018-12-31').mean()
evi = ee.ImageCollection('MODIS/006/MOD13A2').select('EVI').filterDate('2018-01-01', '2018-12-31').mean()

composite = ee.Image.cat([chirps, evi])

dist_stats = composite.reduceRegions(districts, 'mean', 5000)

dist_stats = dist_stats.select(['precipitation', 'EVI'], ['tot_rainfall', 'med_evi'], retainGeometry=False).getInfo()

dtstats_df = pd.DataFrame()
for dist in dist_stats['features']:
    df = pd.DataFrame([dist['properties']],columns=dist['properties'].keys())
    dtstats_df = pd.concat([dtstats_df, df], axis=0)

dtstats_df = dtstats_df[['tot_rainfall', 'med_evi']]

dtstats_df

1 Answer 1

1

You can add a timestamp to your dataframe like this:

dtstats_df['date'] = '2018-07-01'
dtstats_df

Since you are taking the mean of a collection of images, the time element has sort of been lost. Here I have simply added the middle of your date range as a YYYY-MM-dd formatted date to the dataframe.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.