1

I'm trying to export to a dataframe the time series of the CFS model for the maximum temperature since 2000 for any latitude/longitude, but I have a Time Out problem. So, I tried a for each year and after doing an append and then joining everything, but after the 2 year it just timeouts too.

import pandas as pd
import geemap, ee
import seaborn as sns
import matplotlib.pyplot as plt
import geemap, ee
import seaborn as sns
import matplotlib.pyplot as plt

try:
        ee.Initialize()
except Exception as e:
        ee.Authenticate()
        ee.Initialize()

poi = ee.Geometry.Point(127.072483, 37.515817).buffer(200)

viirs = ee.ImageCollection("NOAA/CFSV2/FOR6H").filterDate('2000-01-01','2022-01-01')

def poi_mean(img):
    mean = img.reduceRegion(reducer=ee.Reducer.mean(), geometry=poi, scale=30).get('Maximum_temperature_height_above_ground_6_Hour_Interval')
    return img.set('date', img.date().format()).set('mean',mean)

poi_reduced_imgs = viirs.map(poi_mean)

nested_list = poi_reduced_imgs.reduceColumns(ee.Reducer.toList(2), ['date','mean']).values().get(0)

df = pd.DataFrame(nested_list.getInfo(), columns=['date','mean'])

Second way:

years=[2000,2001,2002, 2003... to 2016,2017,2018,2019,2020,2021] # for example

df=pd.DataFrame()
temp = pd.DataFrame()
for year in years:
    print(year)
    viirs = ee.ImageCollection("NOAA/CFSV2/FOR6H").filterDate(str(year)+'-01-01',str(year+1)+'-01-01')
    
    poi_reduced_imgs = viirs.map(poi_mean)
    
    nested_list = poi_reduced_imgs.reduceColumns(ee.Reducer.toList(2), ['date','mean']).values().get(0)
    
    df = pd.DataFrame(nested_list.getInfo(), columns=['date','mean'])
    df['date'] = pd.to_datetime(df['date'])
    df = df.set_index('date')
    df = df.resample('D').max()
    
    temp=temp.append(df)
    df=pd.DataFrame()

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.