-
Notifications
You must be signed in to change notification settings - Fork 0
/
mrsos_uncertainty.py
56 lines (48 loc) · 1.53 KB
/
mrsos_uncertainty.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
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
import ilamb3.dataset as dset
import xarray as xr
from ilamb3.analysis import bias_analysis
from ilamb3.compare import trim_time
from ilamb3.models import ModelESGF
from ilamb3.regions import Regions
# Register the Koppen climate regions into ILAMB system
ilamb_regions = Regions()
regions = [
None,
] + ilamb_regions.add_netcdf("data/regions/Koppen.nc")
regions.pop(regions.index("polar"))
# Initialize the bias methodology
analysis = bias_analysis("mrsos")
# Read in and take a time mean of the reference mrsos data
ref = xr.open_dataset("data/Wang2021/mrsol_olc.nc").isel(dict(depth=0))
ref_mean = (
ref.drop_vars("time_bnds")
.weighted(dset.compute_time_measures(ref).pint.dequantify())
.mean(dim="time")
).rename_vars({"mrsol": "mrsos"})
# Initialize a model, later we will loop over them
m = ModelESGF("CanESM5-1", "r1i1p1f1", "gn")
com = m.get_variable("mrsos")
# Trim the comparison to the time span of the reference
_, com = trim_time(ref, com)
# Now we take a time mean of the comparison
com_mean = (
com.drop_vars("time_bnds")
.weighted(dset.compute_time_measures(com).pint.dequantify())
.mean(dim="time")
)
# Apply the bias analysis as it exists in ILAMB 2.7.2
df, ds_ref, ds_com = analysis(
ref_mean,
com_mean,
method="Collier2018",
regions=regions,
use_uncertainty=False,
)
# Apply the bias analysis using the uncertainty to discount error
df_uncer, ds_ref_uncer, ds_com_uncer = analysis(
ref_mean,
com_mean,
method="Collier2018",
regions=regions,
use_uncertainty=True,
)