How to extract Land Surface Temperature ( LST ) data from Google Earth Engine using Google Colab
This notebook will guide you to extracting land surface temperature data from the Google Earth Engine. Google Colab is used to deal with this process.
The goal is to be able to provide temperature data for the next process, such as forecasting temperatures in the future, or to combine it with other data for other studies.
We need to choose which remote sensing data we want to use. We could see all the details and descriptions of data from this Earth Engine data catalog.
Earth Engine Data Catalog | Google for Developers
Google Earth Engine combines a multi-petabyte catalog of satellite imagery and geospatial datasets with planetary-scale…
to make it easier, we can write which data we are looking for. In this notebook, we will focus on Land Surface Temperature.
We will use MOD11A1.061 Terra Land Surface Temperature and Emissivity Daily Global 1km. This Data was provided by NASA LP DAAC at the USGS EROS Center, data available from 2000–02–24 to 2023–06–15.
The resolution for this data is 1000 meters, and the unit temperature is in Kelvin. We will take this band to get temperature information during the day. we could also combine with other bands to get full-day temperature, but in this notebook, we are focusing on daytime temperature.
To work with the google earth engine, we need to initialize the API
# Trigger the authentication flow.
# Initialize the library.
The result of that will tell you how to use your account to give this notebook access to Earth Engine.
since we want to explore LST from Modis Terra Satelite, so we need to import the data.
you need the Earth engine snippet. it is like an id which data catalog from the Earth engine we want to work for.
you might see
ee.ImageCollection and ee.Image in this snippet. The differences is :
Images that are like features but may include several bands.
Collections are groups of features or images.
now we import the data :
# Import the MODIS LST collection.
lst = ee.ImageCollection('MODIS/061/MOD11A1')
now we put our focus : (duration and band of interest)
we are focused only for 1 year from 2022 -2023
# Initial date of interest (inclusive).
i_date = '2022-01-01'
# Final date of interest (exclusive).
f_date = '2023-01-01'
# Selection of appropriate bands and dates for LST.
band = lst.select('LST_Day_1km', 'QC_Day').filterDate(i_date, f_date)
now we put our focus : (location of interest)
we can take a look at the coordinates on Google or google maps
# Define the urban location of interest as a point.
# We gonna use hamburg location
Hamburg_lon = 9.993682
Hamburg_lat = 53.551086
Hamburg_point = ee.Geometry.Point(Hamburg_lon, Hamburg_lat)
now time to extract the data :
we will try to calculate and print the mean value of the LST collection at our interest point and convert from kelvin to celcius.
scale = 1000 # scale in meters
lst_hamburg = band.mean().sample(Hamburg_point, scale).first().get('LST_Day_1km').getInfo()
print('Hamburg average daytime LST:', round(lst_hamburg*0.02 -273.15, 2), '°C')
# output is : Hamburg average daytime LST: 16.83 °C
now get whole interest data
lst_Hamburg_full = band.getRegion(Hamburg_point, scale).getInfo()
lst_Hamburg_full[:3] # Preview the output.
we can already see the data. We will transform the data into a pandas data frame to make it easier.
import pandas as pd
df = pd.DataFrame(lst_Hamburg_full) #Convert list to dataframe
headers = df.iloc # Rearrange the header.
df = pd.DataFrame(df.values[1:], columns=headers) # Rearrange the header.
df = df[['longitude', 'latitude', 'time', "LST_Day_1km" ]].dropna() # Remove rows with null data.
df[ "LST_Day_1km"] = pd.to_numeric(df[ "LST_Day_1km"], errors='coerce') # Convert to numeric values.
df['datetime'] = pd.to_datetime(df['time'], unit='ms') # Convert datetime to datetime values.
df = df[['time','datetime', "LST_Day_1km" ]] # take interest part
I'm not familiar with kelvin, so I'm gonna convert the temperature to Celsius
t_celsius = t_kelvin*0.02 - 273.15
df['LST_Day_1km'] = df['LST_Day_1km'].apply(kelvin_to_celcius)
basically, we have done the process. We extracted temperature data between 2022 to 2023 in Hamburg.
With the help of Scipy library, we will fit the temperature curve in Hamburg.
import matplotlib.pyplot as plt
import numpy as np
from scipy import optimize
x_data_u = np.asanyarray(df['time'].apply(float))
y_data_u = np.asanyarray(df['LST_Day_1km'].apply(float))
fig, ax = plt.subplots(figsize=(14, 6))
c='black', alpha=0.2, label='Hamburg (data)')
def fit_func(t, lst0, delta_lst, tau, phi):
return lst0 + (delta_lst/2)*np.sin(2*np.pi*t/tau + phi)
lst0 = 20
delta_lst = 40
tau = 365*24*3600*1000
phi = 2*np.pi*4*30.5*3600*1000/tau
params_u, params_covariance_u = optimize.curve_fit(
fit_func, x_data_u, y_data_u, p0=[lst0, delta_lst, tau, phi])
fit_func(x_data_u, params_u, params_u, params_u, params_u),
label='Hamburg (fitted)', color='black', lw=2.5)
ax.set_title('Daytime Land Surface Temperature Hamburg', fontsize=16)
ax.set_ylabel('Temperature [C]', fontsize=14)
ax.legend(fontsize=14, loc='lower right')
- Gorelick, N., Hancher, M., Dixon, M., Ilyushchenko, S., Thau, D., & Moore, R. (2017). Google Earth Engine: Planetary-scale geospatial analysis for everyone. Remote Sensing of Environment.
- MODIS Mount TERRA image from 2022 to 2023 was retrieved on 2023_19_06 from https://lpdaac.usgs.gov, maintained by the NASA EOSDIS Land Processes Distributed Active Archive Center (LP DAAC) at the USGS Earth Resources Observation and Science (EROS) Center, Sioux Falls, South Dakota. 2018.
- Guiattard. (n.d.). An intro to the Earth Engine Python API | google earth engine | google for developers. Google. https://developers.google.com/earth-engine/tutorials/community/intro-to-python-api