-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from gaelforget/v0p1p6b
consolidate examples and interface
- Loading branch information
Showing
9 changed files
with
273 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,102 @@ | ||
# # Retrieve CMIP6 model output | ||
# # Cloud Computing Workflow | ||
# | ||
# - Access Climate Model Output Using `AWS.jl` and `Zarr.jl` | ||
# - Choose institution_id, source_id, variable_id | ||
# - Compute and plot (1) time mean global map and (2) time evolving global mean | ||
# This example relies on model output that has already been computed and made available over the internet. | ||
# It accesses model output via the `AWS.jl` and `Zarr.jl` packages as the starting point for further modeling / computation. | ||
# Workflow summary: | ||
# | ||
# - Access climate model output in cloud storage | ||
# - Choose model (`institution_id`, `source_id`, `variable_id`) | ||
# - Compute, save, and plot (_1._ global mean over time; _2._ time mean global map) | ||
|
||
using ClimateModels, Plots, Statistics, TOML, CSV, DataFrames, NetCDF | ||
|
||
# ## Model Configuration | ||
# | ||
# Here we select that we want to access temperature (`tas`) from a model run by `IPSL` as part of [CMIP6](https://www.wcrp-climate.org/wgcm-cmip/wgcm-cmip6) (Coupled Model Intercomparison Project Phase 6). | ||
|
||
parameters=Dict("institution_id" => "IPSL", "source_id" => "IPSL-CM6A-LR", "variable_id" => "tas") | ||
|
||
function GlobalAverage(x) | ||
|
||
#main computation = model run = access cloud storage + compute averages | ||
|
||
(mm,gm,meta)=cmip(x.inputs["institution_id"],x.inputs["source_id"],x.inputs["variable_id"]) | ||
|
||
#save results to files | ||
|
||
fil=joinpath(x.folder,string(x.ID),"GlobalAverages.csv") | ||
df = DataFrame(time = gm["t"], tas = gm["y"]) | ||
CSV.write(fil, df) | ||
|
||
fil=joinpath(x.folder,string(x.ID),"Details.toml") | ||
open(fil, "w") do io | ||
TOML.print(io, meta) | ||
end | ||
|
||
filename = joinpath(x.folder,string(x.ID),"MeanMaps.nc") | ||
varname = x.inputs["variable_id"] | ||
(ni,nj)=size(mm["m"]) | ||
nccreate(filename, "tas", "lon", collect(Float32.(mm["lon"][:])), "lat", collect(Float32.(mm["lat"][:])), atts=meta) | ||
ncwrite(Float32.(mm["m"]), filename, varname) | ||
|
||
return x | ||
end | ||
|
||
MC=ModelConfig(model="GlobalAverage",configuration=GlobalAverage,inputs=parameters) | ||
|
||
using ClimateModels, Plots, Statistics | ||
# ## Setup and Launch | ||
# | ||
# _Note: this step may take most time, since `launch` is where data is accessed over the internet, and computation takes place. | ||
|
||
setup(MC) | ||
launch(MC) | ||
|
||
# ## Read Output Files | ||
# | ||
# The `GlobalAverage` function, called via `launch`, should now have generated the following output: | ||
# | ||
# - Global averages in a `CSV` file | ||
# - Meta-data in a `TOML` file | ||
# - Maps + meta-data in a `NetCDF` file | ||
|
||
fil=joinpath(MC.folder,string(MC.ID),"MeanMaps.nc") | ||
lon = NetCDF.open(fil, "lon") | ||
lat = NetCDF.open(fil, "lat") | ||
tas = NetCDF.open(fil, "tas") | ||
|
||
# ## Access Model Ouput | ||
# | ||
# Here we select that we want to access temperate `tas` from a model by `IPSL`. | ||
|
||
(mm,gm,meta)=cmip("IPSL","IPSL-CM6A-LR","tas") | ||
fil=joinpath(MC.folder,string(MC.ID),"Details.toml") | ||
meta=TOML.parsefile(fil) | ||
|
||
# | ||
|
||
fil=joinpath(MC.folder,string(MC.ID),"GlobalAverages.csv") | ||
GA=CSV.read(fil,DataFrame) | ||
show(GA,truncate=8) | ||
|
||
# ## Plot Results | ||
# | ||
# Afterwards, one often uses model output for further analysis. Here we | ||
# compute and plot (1) time mean global map and (2) time evolving global mean. | ||
# Plots below are based on results from the output file(s) shown above. | ||
# | ||
# #### 1. Time Mean Seasonal Cycle | ||
|
||
nm=meta["long_name"]*" in "*meta["units"] | ||
m=heatmap(mm["lon"], mm["lat"], transpose(mm["m"]), title=nm*" (time mean)") | ||
|
||
# ### Time Mean Seasonal Cycle | ||
|
||
t=gm["t"]; y=gm["y"] | ||
ylab=meta["long_name"]*" in "*meta["units"] | ||
ny=Int(length(t)/12) | ||
a_y=fill(0.0,(ny,12)) | ||
[a_y[:,i].=y[i:12:end] for i in 1:12] | ||
ny=Int(length(GA.time)/12) | ||
y=fill(0.0,(ny,12)) | ||
[y[:,i].=GA.tas[i:12:end] for i in 1:12] | ||
|
||
s=plot([0.5:1:11.5],vec(mean(a_y,dims=1)), xlabel="month",ylabel=ylab, | ||
s=plot([0.5:1:11.5],vec(mean(y,dims=1)), xlabel="month",ylabel=nm, | ||
leg = false, title=meta["institution_id"]*" (global mean, seasonal cycle)",frmt=:png) | ||
|
||
# ### Month By Month Time Series | ||
# #### 2. Month By Month Time Series | ||
|
||
p=plot(gm["t"][1:12:end],gm["y"][1:12:end],xlabel="time",ylabel=nm, | ||
p=plot(GA.time[1:12:end],GA.tas[1:12:end],xlabel="time",ylabel=nm, | ||
title=meta["institution_id"]*" (global mean, Month By Month)",frmt=:png) | ||
[plot!(gm["t"][i:12:end],gm["y"][i:12:end], leg = false) for i in 2:12]; | ||
[plot!(GA.time[i:12:end],GA.tas[i:12:end], leg = false) for i in 2:12]; | ||
p | ||
|
||
# #### 3. Time Mean Global Map | ||
|
||
m=heatmap(lon[:], lat[:], permutedims(tas[:,:]), title=nm*" (time mean)") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.