forked from AmirhosseinAhrari/GoogleEarthEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path00090_python_series_plot
More file actions
66 lines (40 loc) · 1.63 KB
/
Copy path00090_python_series_plot
File metadata and controls
66 lines (40 loc) · 1.63 KB
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
61
62
63
64
65
66
"""GEE_0005_temperature_plot3.ipynb
Tutorial Code by Amirhossein Ahrari
YouTube: https://www.youtube.com/@amirhosseinahrarigee
Tutorial Video: Google Earth Engine Tutorial-95: Time Series Plot using Google Colab
This code is part of a tutorial series on Earth Engine programming techniques
presented on the Amirhossein Ahrari YouTube channel. You are free to use and modify
this code for academic and non-academic purposes. Don't forget to subscribe to
the Amirhossein Ahrari channel and follow the videos to support the instructor!
"""
import ee
import geemap as gee
ee.Authenticate()
ee.Initialize(project = 'ee-amirhosseinahrari')
temp = ee.ImageCollection("ECMWF/ERA5_LAND/MONTHLY_AGGR").filterDate('2022','2024').select('temperature_2m')
temp
map = gee.Map(basemap = 'SATELLITE')
map
roi = map.draw_last_feature.geometry()
roi
def temp_val(img):
date = img.date().format('YYYY-MM-dd')
temp_mean = img.reduceRegion(reducer = ee.Reducer.mean(), geometry = roi, scale = 10000).values().get(0)
return ee.Feature(None, {'date': date, 'temp': temp_mean})
features = temp.map(temp_val)
features
data_list = features.toList(features.size()).getInfo()
data_list
date = [item['properties']['date'] for item in data_list]
temp_list = [item['properties']['temp'] for item in data_list]
temp_list
import pandas as pd
df = pd.DataFrame({'date': date, 'temp': temp_list}).round(2)
df
df.to_csv('temp_2022-2023.csv')
df['date'] = pd.to_datetime(df['date'])
import matplotlib.pyplot as plt
plt.plot(df['date'], df['temp'], lw = 2, ls = '--', color = 'red', marker = 'o')
plt.title('temperature')
plt.ylabel('K$^o$')
plt.savefig('temp_fig.png',dpi = 360)