Join at slido.com�#3153196
ⓘ Start presenting to display the joining instructions on this slide.
3153196
3153196
3153196
3153196
Climate Data Science and XArray
Data 100/Data 200, Spring 2023 @ UC Berkeley
Guest Lecture: Fernando Pérez
Lecture materials by: Dr. Chelle Gentemann, NASA
3
Lecture 19
3153196
3153196
The foundation of climate change: the Greenhouse Effect
3153196
Climate Change
A simplified animation of the greenhouse effect. Credit: NASA/JPL-Caltech
3153196
3153196
Video credit: NASA SVS
3153196
3153196
Video credit: NASA SVS
3153196
3153196
What does the data say about our climate?
3153196
Keeling Curve
https://pubs.acs.org/doi/10.1021/ac1001492
3153196
Video credit: NASA SVS
3153196
3153196
Calculating the Greenhouse Effect
Goal 1: Calculate how the temperature is changing with increasing CO2.
The Planetary energy balance:
Energy (from the Sun) absorbed = Energy emitted
How does CO2 affects this?
3153196
Calculate energy in
Energy in equals the incoming sunlight (W/m2) multiplied by the area (m2) to get W
NASA illustrations by Robert Simmon
= Incoming sunlight x area
r
3153196
Some of the energy in is reflected by the atmosphere
NASA illustrations by Robert Simmon
r
Albedo = the fraction of radiation reflected back to space by the atmosphere
The amount that gets through:
Reflective surface
3153196
Calculate Energy out
B) The Earth emits blackbody radiation
Energy out equals the emitted radiation (W/m2) multiplied by the area (m2) to get W
NASA illustrations by Robert Simmon
= Outgoing radiation x area
r
3153196
Energy in = Energy out
Goal 1: Calculate how the temperature is changing with increasing CO2
NASA illustrations by Robert Simmon
Reflective surface
Planetary energy balance
3153196
Calculating temperature
Goal 1: Calculate how the temperature is changing with increasing CO2
What is the Earth’s temperature?
~255 K
~-16 C
~1 F
3153196
3153196
Our atmosphere is like a blanket
without an atmosphere
Planetary energy balance
with an atmosphere
3153196
Calculating the Temperature dependence on CO2
Goal 1: Calculate how the temperature is changing with increasing CO2
CO2 is ~420 ppm (parts per million - co2.earth/daily-co2)
As CO2 increases what happens to the temperature?
3153196
Plot the results
Use the equation to calculate the increase in temperature with time due to the increase in CO2
3153196
Global warming is a climate crisis
The equation provides solutions to global warming:
Change the planetary albedo to reflect more radiation to space (increase aerosols, clouds, make surface more reflective)
Reduce greenhouse gases (CO2, Methane)
Sun-shades in space?
3153196
Changing by Alisa Singer
"As we witness our planet transforming around us we watch, listen, measure … respond."
www.environmentalgraphiti.org – 2021 Alisa Singer.
AR6 Climate Change 2021:
The Physical Science Basis
3153196
3153196
3153196
3153196
3153196
3153196
3153196
3153196
3153196
3153196
3153196
3153196
3153196
3153196
3153196
3153196
3153196
3153196
3153196
3153196
3153196
3153196
3153196
3153196
3153196
3153196
3153196
Let's check our understanding
This equation:
Shows that all climate change is due to CO2. If we stop CO2 emissions, we can stop climate change.
3153196
3153196
The given equation shows that all climate change is due to CO2. If we stop CO2 emissions, we can stop climate change.
ⓘ Start presenting to display the poll results on this slide.
3153196
3153196
Image credit: NOAA
3153196
3153196
With every increment of global warming, changes get larger
https://www.ipcc.ch/report/ar6/wg1/#FullReport
3153196
… in precipitation
https://www.ipcc.ch/report/ar6/wg1/#FullReport
CC-relationship water vapor - temperature - pressure https://www.jbarisk.com/news-blogs/the-physics-of-precipitation-in-a-warming-climate/
3153196
Our trajectory from data and models
https://raw.githubusercontent.com/BrodiePearson/IPCC_AR6_Chapter9_Figures/main/Plotting_code_and_data/Fig9_03_SST/Fig9_03_SST.png
3153196
Extremes are the new normal
3153196
Extremes are the new normal
A decade ago - scientists would argue - we can’t attribute any single weather event to climate.
In the last decade, we have all experienced major shifts in our climate through changes in our local weather and scientists have figured out ‘climate event attribution’
They look at the probability of the occurrence of an event (eg. a temperature extreme) in models run without human-influence and then compare it to the probability in models run with human-influence.
How?
https://www.nature.com/articles/d41586-021-01142-4
https://agupubs.onlinelibrary.wiley.com/doi/10.1029/2021GL092765
3153196
Extremes are the new normal
The probability of an event changes
https://www.nature.com/articles/s41467-019-09729-2/figures/1
Model runs with all forcings
Model runs with only natural
How likely is it that there will be a 2 degree anomaly?
3153196
Positive Feedbacks in the Climate System
3153196
Goal: Positive feedbacks in the climate system
The Earth is a system - a complicated game of dominos
As air temperature increases, sea ice concentration decreases…..
3153196
Goal: Arctic Amplification: a positive feedback
A positive feedback amplifies the initial perturbation
Albedo feedback:
reflectivity!
3153196
Goal: Arctic Amplification: a positive feedback
A positive feedback amplifies the initial perturbation
Cloud feedback:
3153196
Can we look at this ourselves? --- this is global data --- 3D data
….. Latitude, longitude, and time…. How do we handle that?
https://www.nature.com/articles/s41467-019-09729-2/figures/1
Model runs with all forcings
Model runs with only natural
How likely is it that there will be a 2 degree anomaly?
3153196
Learning objective: climate data analysis
3153196
ERA5 - 5th gen ECMWF atmospheric global climate ReAnalyses
An ECMWF snow depth analysis for Scandinavia using ERA5 data shows the highest levels in a decade.
3153196
Vast amount of data
3153196
Data Frames are not enough: not all data is tabular
3153196
Xarray
Xarray introduces labels in the form of dimensions, coordinates and attributes on top of raw NumPy-like multidimensional arrays, which allows for a more intuitive, more concise, and less error-prone developer experience.
‘data variables’ : temperature and precipitation “data variables”
‘coordinate variables’: they label the points along the dimensions.
3153196
Xarray: Dataset
ERA5
Xarray Datasets are essentially groups of DataArrays.
This is really valuable when you are looking at datasets that have multidimensional groups of data, for example, temperature, precipitation, cloud cover.
Some Xarray methods can be applied to all that Dataset contains.
For example, you can subset a Dataset and the subset, interpolate, calculate a mean, and it will do this across all the DataArrays the Dataset contains.
3153196
Xarray read in a Dataset
import xarray as xr
ds = xr.open_dataset('./../data/era5_monthly_2deg_aws_v20210920.nc')
ds
3153196
Explore the data
Xarray allows you easily explore the data
Look at data attributes
3153196
Coordinates versus dimensions
Text from Xarray docs http://xarray.pydata.org/en/stable/user-guide/data-structures.html
3153196
DataArray are data variables in a Dataset
ds["air_temperature_at_2_metres"]
ds.air_temperature_at_2_metres
Text from Xarray docs http://xarray.pydata.org/en/stable/user-guide/data-structures.html
3153196
Review: DataFrame access: [], loc, iloc
iloc: integer/positional
loc: Labels
[]: flexible, confusing?
[]
List
[]
Numeric Slice
[]
Name
DataFrame
DataFrame
Series
Single Column Selection
Multiple Column Selection
(Multiple) Row Selection
3153196
New: DataArray access: [], sel, isel
isel: integer/positional
sel: coordinates
[]: flexible, confusing?
point = ds.isel(time=0,
latitude=26,
longitude=119)
point = ds.air_temperature_at_2_metres[0,26,119]
point = ds.sel(time="1979-01",
latitude=37.125,
longitude=238.875)
3153196
Find data at a point or in a region:
sel: coordinates
point = ds.sel(time="1979-01",
latitude=37.125,
longitude=238.875)
region = ds.sel(time="1979-01",
latitude=slice(30,40),
longitude=slice(230,250))
Xarray helps you understand your code.
3153196
Xarray has all sort of high-level cool tricks built in
Select data and plot data in one line (using matplotlib)
ds.air_temperature_at_2_metres.sel(time="1979-01").plot()
ds.air_temperature_at_2_metres.sel(
latitude=37.125,
longitude=238.875).plot()
Select a variable
Select coordinate
Apply a method()
Select a variable
Select coordinate
Apply a method()
3153196
Methods can be called across a DataArray or a Dataset -- LAZY
Select data and plot data in one line (using matplotlib)
Same thing, but across all variables
ds.air_temperature_at_2_metres.mean("time").plot()
mean_map = ds.mean("time")
mean_map.air_temperature_at_2_metres.plot()
Select a variable
Apply a method() across a coordinate
Apply a method()
Lazy
3153196
Plot the global trend in a variable
3153196
Goal: Calculate time series
Xarray has high level methods like .mean(), .std(), etc.
ave = ds.mean("time")
ave.air_temperature_at_2_metres.plot()
Take the mean across all time
ave = ds.mean(("latitude", "longitude"))
ave.air_temperature_at_2_metres.plot()
Take the mean across all locations
Does that look right?
(279 K ~ 6 ºC ~ 43 ºF)
3153196
The map is flat - but the Earth is not - Gaussian grid
Programs aren’t smart - you are - so what went wrong?
Gridded data is nice to work with but what does it represent?
How many grid points are at 90N (the North Pole)?
How many grid points are at the Equator?
3153196
Weigh your data
Xarray provides the ability to weigh your data
weights = np.cos(np.deg2rad(ds.latitude))
weights.name = "weights"
weights.plot()
3153196
Goal: Examine average values - weighted version
Xarray methods like .weighted() can be combined with .mean()
ds_weighted = ds.weighted(weights)
weighted_mean = ds_weighted.mean()
weighted_mean
Does that look right?
3153196
Goal: Weighted global time series data
You can create means across coordinates: eg. latitude and longitude
ds_weighted = ds.weighted(weights)
weighted_mean = ds_weighted.mean(("latitude", "longitude"))
weighted_mean.air_temperature_at_2_metres.plot()
288 K ~ 15 ºC ~ 59 ºF. 👍
3153196
Take out the annual cycle using .groupby()
Use .groupby on a coordinate
3153196
Goal: Calculate annual cycle
Can use .groupby & .mean
annual_cycle = weighted_mean.groupby("time.month").mean()
annual_cycle.air_temperature_at_2_metres.plot()
3153196
Put it all together and plot the trend
Can use .groupby & .mean
weighted_mean = ds_weighted.mean(("latitude", "longitude")) #weighted mean time series
annual_cycle = weighted_mean.groupby("time.month").mean() #calculate annual cycle
annual_cycle += annual_cycle.mean() #add back in the mean value
weighted_trend = weighted_mean.groupby("time.month") - annual_cycle
weighted_mean.air_temperature_at_2_metres.plot()
weighted_trend.air_temperature_at_2_metres.plot()
3153196
Goal: Are extremes more likely? PDF analysis.
xr.plot.hist(darray,
bins=bin_array,
density=True,
alpha=.9,
color="b",
)
3153196
ERA5 temperature PDFs
bins = np.arange(284, 291)
xr.plot.hist(
weighted_mean.air_temperature_at_2_metres.sel(time=slice("1980","2000")),
bins=bins,
density=True,
alpha=.9,
color="b",
)
xr.plot.hist(
weighted_mean.air_temperature_at_2_metres.sel(time=slice("2000","2020")),
bins=bins,
density=True,
alpha=.85,
color="r",
)
plt.ylabel("Probability Density (/K)")
3153196
Goal: Can we plot the trend with our ERA5 data?
pfit = ds.air_temperature_at_2_metres.polyfit("time", 1)
pfit.polyfit_coefficients[0] *= 3.154000000101e+16
pfit.polyfit_coefficients[0].plot(cbar_kwargs={"label":"trend deg/yr"})
3153196
Goal: How about all fancy on a globe?
import cartopy.crs as ccrs
p = pfit.polyfit_coefficients[0].plot(
subplot_kws=dict(projection=ccrs.Orthographic(0, 55), facecolor="gray"),
transform=ccrs.PlateCarree(central_longitude=0),
cbar_kwargs={"label": "trend deg/yr"},
)
p.axes.coastlines()
3153196
Goal: Positive feedbacks in the climate system
The Earth is a system - a complicated game of dominos
As air temperature increases, sea ice concentration decreases…..
3153196
Models and data tell us about our weather and climate
Xarray is a powerful tool to analyze climate data.
I’ve just given some simple examples here, but really, we need more eyes on the data, more eyes on the models.
The models use ‘parameterizations’ which are approximations for all sorts of different physical processes. Each parameterization uses coefficients derived fro data science - but the experiments may be limited or imperfect. Often parameters are adjusted to compensate for an error, but then end up causing other issues, and we are all still working on this.
We need more of you, more data scientists working with climate and weather scientists to look at this data, helping to find new discoveries, amplify messages about changes to our climate and their impacts, and build machine learning models to replace old parameterizations.
3153196
(Channeling Dr. Gentemann) I’m just an oceanographer
I started off like you, I’m just an oceanographer trying to find my way through the data science world. You are all data scientists maybe trying to find something interesting to work on.
Well, we all need your help. We need minds like yours to help solve the problems our and previous generations have caused. We need your voices, backed by solid data science, to mitigate what is going on, to change our trajectory.
I’ve shown you how to take pandas and leap to another level library, Xarray, you can do tutorials, leap to Scipy, or other libraries. I hope you enjoyed this small tour of Xarray and climate science.
3153196
https://science.nasa.gov/open-science/
https://github.com/nasa/Transform-to-Open-Science
to change everything, we need everyone
2023
NASA’s Year of
Open Science
80
NASA Transform to Open Science Mission
Dr. Chelle Gentemann, Science Lead
Yvonne Ivey, Equity Lead
Cyndi Hall, Community Coordinator
Isabella Martinez, Content Coordinator
Dr. Yaitza Luna-Cruz, TOPS Program Officer
Dr. Paige Martin, TOPS Program Officer
Kevin Murphy, Chief Science Data Officer SMD
Katie Baynes, Deputy Chief Science Data Officer SMD
Dr. Steve Crawford, Science Policy Officer SMD
Andy Mitchell,
Dr. Elena Steponaitis, SMD Development Program Executive
Amy (Uyen) Truong, Chief Science Data Office Coordinator
Dr. Rachel Paseka, OSSI Program Officer
Dr. J.L. Galache, OSSI Program Officer
Dr. Demitri Muna, OSSI Program Officer
Molly Adams, OSSI Coordinator
TOPS Email List
TOPS Website
SCIENCE MISSION DIRECTORATE