forked from whitelightning450/NWM_ML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EE_funcs.py
31 lines (21 loc) · 879 Bytes
/
EE_funcs.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
import pandas as pd
def ee_array_to_df(arr, list_of_bands):
"""Transforms client-side ee.Image.getRegion array to pandas.DataFrame."""
df = pd.DataFrame(arr)
# Rearrange the header.
headers = df.iloc[0]
df = pd.DataFrame(df.values[1:], columns=headers)
# Remove rows without data inside.
df = df[['longitude', 'latitude', 'time', *list_of_bands]].dropna()
# Convert the data to numeric values.
for band in list_of_bands:
df[band] = pd.to_numeric(df[band], errors='coerce')
# Convert the time field into a datetime.
df['datetime'] = pd.to_datetime(df['time'], unit='ms')
# Keep the columns of interest.
df = df[['time','datetime', *list_of_bands]]
return df
def t_modis_to_celsius(t_modis):
"""Converts MODIS LST units to degrees Celsius."""
t_celsius = 0.02*t_modis - 273.15
return t_celsius