Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
446 views
in Technique[技术] by (71.8m points)

sampling - How to extract the value of multiple pixels from an image collection in Google Colab?

Hi, I have an collection of Sentinel-2 images and would like to extract the NDVI values for pixels at different locations. However, I do not know how to do this step. I have provided my code below.

#This is how I created the collection over my area of interest called 'roi':

def maskS2clouds(image):   
 qa = image.select('QA60');    
 cloudBitMask = 1 << 10;   
 cirrusBitMask = 1 << 11;   
 mask = qa.bitwiseAnd(cloudBitMask).eq(0).And(qa.bitwiseAnd(cirrusBitMask).eq(0)); 
 return image.updateMask(mask).divide(10000); 

#calculate the NDVI

def addNDVI(image):   
 ndvi = image.normalizedDifference(['B8', 'B4']).rename('ndvi') 
 return image.addBands([ndvi]) 

dataset = ee.ImageCollection('COPERNICUS/S2').filterDate(first_date, end_date).filterBounds(roi).filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', cloud_percentage))
 .map(addNDVI) 
 .map(maskS2clouds)
 .sort('system:time_start')
 print("number of images:", dataset.size().getInfo())

#Now I have a list of points from a .csv file (called 'points_Ferndale.csv') that I have imported:

points=pd.read_csv('/content/gdrive/My Drive/colab_input/points_Ferndale.csv') 

#from 'points', I have now extracted the lat and lon information in this way:

points2=points_coordinates.iloc[1:,:]; points3 = points2.to_numpy();

#if I print points3, I got: [[-3.36411764 51.67790352] [-3.3395374 51.63922807] [-3.38080455 51.62893532] [-3.46511922 51.62077685] [-3.47932216 51.64617346]]

#the problem is that I do not know now how to map the value of ndvi from my image collection #over each #point in points3?

# I think I need to do something like:

points4 = [ee.Feature(ee.Geometry.Point(points3))]
question from:https://stackoverflow.com/questions/65883971/how-to-extract-the-value-of-multiple-pixels-from-an-image-collection-in-google-c

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...