-
Notifications
You must be signed in to change notification settings - Fork 5
/
Earth_engine_temperature_2000_2010.py
60 lines (43 loc) · 1.75 KB
/
Earth_engine_temperature_2000_2010.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import ee, datetime
import pandas as pd
import geos
import gdal
import fiona
import geopandas as gpd
import matplotlib.dates as mdates
from IPython.display import Image
from matplotlib import dates
from shapely.geometry import shape
import skimage
def fc2df(fc):
# Convert a FeatureCollection into a pandas DataFrame
# Features is a list of dict with the output
features = fc.getInfo()['features']
dictarr = []
for f in features:
# Store all attributes in a dict
attr = f['properties']
# and treat geometry separately
attr['geometry'] = f['geometry'] # GeoJSON Feature!
# attr['geometrytype'] = f['geometry']['type']
dictarr.append(attr)
df = gpd.GeoDataFrame(dictarr)
# Convert GeoJSON features to shape
df['geometry'] = map(lambda s: shape(s), df.geometry)
return df
ee.Initialize()
collection = ee.ImageCollection('MODIS/006/MOD11A1').filterDate('2000-01-01', '2010-01-01').select('LST_Day_1km');
def function(im):
return im.rename([im.get("system:index")])
arr = collection.map(function)
collection = arr
def stackCollection(collection):
first = ee.Image(collection.first()).select([])
def appendBands(image, previous):
return ee.Image(previous).addBands(image)
return ee.Image(collection.iterate(appendBands, first))
stacked = stackCollection(collection)
Countries = ee.FeatureCollection('users/giacomofalchetta/shirebasin')
lightsum = stacked.reduceRegions(collection=Countries, reducer=ee.Reducer.mean())
lightsum = fc2df(lightsum)
lightsum.to_csv("C:\\Users\\Falchetta\\OneDrive - FONDAZIONE ENI ENRICO MATTEI\\Visiting IIASA\\hydropower_remotesensing/average_temperature_shirebasin_2000_2010.csv")