0

I have been trying to make a raster of regression values between reflectance value vs input data at each pixel position in a collection (So, for example the R^2 relationship between daily average precipitation and reflectence value at every pixel position within a given extent). I have tried doing this by filtering MODIS by a list of dates and applying a constant band to each image with a respective input daily data value from CSV data, but I am having trouble extracting a specific CSV value for an individual date and applying it to an individual, respective image. The following code has returned the error "single positional indexer is out-of-bounds" when using the python Google Earth Engine API :

    import numpy as np
    import pandas as pd
    import ee
    ee.Initialize()
    df=pd.read_csv('.csv')
    ROI=ee.Geometry.Polygon([coords])
    
    dates=df['Date'].tolist()
    df['DateMillis'] = df['datetime'].astype(np.int64) / int(1e6)
    data=df['Data'].tolist()    
    date = ee.List(dates).map(lambda date: ee.Date(date).millis());
    d=ee.List(data)
    
    def maskModisClouds(image):
        return image.updateMask(image.select('state_1km').bitwiseAnd(1 << 10).eq(0))
    
    def timeband(image):
         return image.addBands(image.metadata('system:time_start'))
    
    def databand(image):
        return image.updateMask(ee.Image(((df.loc[df['DateMillis']==image.get('system:time_start'),'Data']).iloc[0])).addBands(image))
        
    col = ee.ImageCollection('MODIS/006/MOD09GQ').filter(ee.Filter.inList("system:time_start", date));
    Image = col.filterBounds(ROI);
    image=Image.map(maskModisClouds).map(timeband).map(Databand)
1

Your code is improperly mixing client-side and server-side objects. I can't tell what your databand function is trying to do, but it's not possible, for instance to map a function using "==".

For more information, see: https://developers.google.com/earth-engine/guides/client_server

1
  • Thanks for the response! I suspected that was the case. The databand function is basically (attempting) to call a data value from a csv from a date equaling the image capture date/time and adding that data value as a constant band to the respective image... Next step would be to do linear regression between reflectance band and datavalue constant band throughout a collection at every position... Feb 15 at 18:45

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.