diff --git a/docs/recipes/index.html b/docs/recipes/index.html index 3e051434a4..af5e9d496a 100644 --- a/docs/recipes/index.html +++ b/docs/recipes/index.html @@ -28,6 +28,21 @@ + + + + + + + + + + + + + + + diff --git a/docs/recipes/plot_01_recipe.html b/docs/recipes/plot_01_recipe.html index be6356336c..db70fc0f18 100644 --- a/docs/recipes/plot_01_recipe.html +++ b/docs/recipes/plot_01_recipe.html @@ -148,8 +148,8 @@

Related Topics

  1. Read the field constructs:

-
f = cf.read("~/recipes/cru_ts4.06.1901.2021.tmp.dat.nc")
-print(f)
+
f = cf.read("~/recipes/cru_ts4.06.1901.2021.tmp.dat.nc")
+print(f)
 
[<CF Field: ncvar%stn(long_name=time(1452), long_name=latitude(360), long_name=longitude(720))>,
@@ -159,8 +159,8 @@ 

Related Topics

  1. Select near surface temperature by index and look at its contents:

-
temp = f[1]
-print(temp)
+
temp = f[1]
+print(temp)
 
Field: long_name=near-surface temperature (ncvar%tmp)
@@ -174,14 +174,14 @@ 

Related Topics

  1. Select latitude and longitude dimensions by identities, with two different techniques:

-
lon = temp.coordinate("long_name=longitude")
-lat = temp.coordinate("Y")
+
lon = temp.coordinate("long_name=longitude")
+lat = temp.coordinate("Y")
 
  1. Print the description of near surface temperature using the dump method to show properties of all constructs:

-
temp.dump()
+
 
-----------------------------------------------------
@@ -229,9 +229,9 @@ 

Related Topics

  1. Latitude and longitude dimension coordinate cell bounds are absent, which are created and set:

-
a = lat.create_bounds()
-lat.set_bounds(a)
-lat.dump()
+
 
Dimension coordinate: long_name=latitude
@@ -242,9 +242,9 @@ 

Related Topics

Bounds:Data(360, 2) = [[-90.0, ..., 90.0]] degrees_north
-
b = lon.create_bounds()
-lon.set_bounds(b)
-lon.dump()
+
 
Dimension coordinate: long_name=longitude
@@ -255,7 +255,7 @@ 

Related Topics

Bounds:Data(720, 2) = [[-180.0, ..., 180.0]] degrees_east
-
print(b.array)
+
print(b.array)
 
[[-180.  -179.5]
@@ -270,10 +270,10 @@ 

Related Topics

  1. Time dimension coordinate cell bounds are similarly created and set for cell sizes of one calendar month:

-
time = temp.coordinate("long_name=time")
-c = time.create_bounds(cellsize=cf.M())
-time.set_bounds(c)
-time.dump()
+
time = temp.coordinate("long_name=time")
+c = time.create_bounds(cellsize=cf.M())
+time.set_bounds(c)
+time.dump()
 
Dimension coordinate: long_name=time
@@ -289,16 +289,16 @@ 

Related Topics

  1. Calculate and plot the area weighted mean surface temperature for each time:

-
global_avg = temp.collapse("area: mean", weights=True)
-cfp.lineplot(global_avg, color="red", title="Global mean surface temperature")
+
global_avg = temp.collapse("area: mean", weights=True)
+cfp.lineplot(global_avg, color="red", title="Global mean surface temperature")
 
Global mean surface temperature
  1. Calculate and plot the annual global mean surface temperature:

-
annual_global_avg = global_avg.collapse("T: mean", group=cf.Y())
-cfp.lineplot(
-    annual_global_avg,
+
annual_global_avg = global_avg.collapse("T: mean", group=cf.Y())
+cfp.lineplot(
+    annual_global_avg,
     color="red",
     title="Annual global mean surface temperature",
 )
diff --git a/docs/recipes/plot_02_recipe.html b/docs/recipes/plot_02_recipe.html
index 9751eac31e..b7a0437707 100644
--- a/docs/recipes/plot_02_recipe.html
+++ b/docs/recipes/plot_02_recipe.html
@@ -148,8 +148,8 @@ 

Related Topics

  1. Read the field constructs:

-
f = cf.read("~/recipes/cru_ts4.06.1901.2021.tmp.dat.nc")
-print(f)
+
f = cf.read("~/recipes/cru_ts4.06.1901.2021.tmp.dat.nc")
+print(f)
 
[<CF Field: ncvar%stn(long_name=time(1452), long_name=latitude(360), long_name=longitude(720))>,
@@ -159,8 +159,8 @@ 

Related Topics

  1. Select near surface temperature by index and look at its contents:

-
temp = f[1]
-print(temp)
+
temp = f[1]
+print(temp)
 
Field: long_name=near-surface temperature (ncvar%tmp)
@@ -174,14 +174,14 @@ 

Related Topics

  1. Select latitude and longitude dimensions by identities, with two different techniques:

-
lon = temp.coordinate("long_name=longitude")
-lat = temp.coordinate("Y")
+
lon = temp.coordinate("long_name=longitude")
+lat = temp.coordinate("Y")
 
  1. Print the description of near surface temperature to show properties of all constructs:

-
temp.dump()
+
 
-----------------------------------------------------
@@ -229,9 +229,9 @@ 

Related Topics

  1. Latitude and longitude dimension coordinate cell bounds are absent, which are created and set:

-
a = lat.create_bounds()
-lat.set_bounds(a)
-lat.dump()
+
 
Dimension coordinate: long_name=latitude
@@ -242,9 +242,9 @@ 

Related Topics

Bounds:Data(360, 2) = [[-90.0, ..., 90.0]] degrees_north
-
b = lon.create_bounds()
-lon.set_bounds(b)
-lon.dump()
+
 
Dimension coordinate: long_name=longitude
@@ -255,7 +255,7 @@ 

Related Topics

Bounds:Data(720, 2) = [[-180.0, ..., 180.0]] degrees_east
-
print(b.array)
+
print(b.array)
 
[[-180.  -179.5]
@@ -270,10 +270,10 @@ 

Related Topics

  1. Time dimension coordinate cell bounds are similarly created and set for cell sizes of one calendar month:

-
time = temp.coordinate("long_name=time")
-c = time.create_bounds(cellsize=cf.M())
-time.set_bounds(c)
-time.dump()
+
time = temp.coordinate("long_name=time")
+c = time.create_bounds(cellsize=cf.M())
+time.set_bounds(c)
+time.dump()
 
Dimension coordinate: long_name=time
@@ -289,22 +289,22 @@ 

Related Topics

  1. Calculate the area weighted mean surface temperature for each time using the collapse method:

-
global_avg = temp.collapse("area: mean", weights=True)
+
global_avg = temp.collapse("area: mean", weights=True)
 
  1. Calculate the annual global mean surface temperature:

-
annual_global_avg = global_avg.collapse("T: mean", group=cf.Y())
+
 
  1. The temperature values are averaged for the climatological period of 1961-1990 by defining a subspace within these years using cf.wi query instance over subspace and doing a statistical collapse with the collapse method:

-
annual_global_avg_61_90 = annual_global_avg.subspace(
-    T=cf.year(cf.wi(1961, 1990))
+
 
Field: long_name=near-surface temperature (ncvar%tmp)
@@ -316,8 +316,8 @@ 

Related Topics

: long_name=longitude(1) = [0.0] degrees_east
-
temp_clim = annual_global_avg_61_90.collapse("T: mean")
-print(temp_clim)
+
 
Field: long_name=near-surface temperature (ncvar%tmp)
@@ -332,9 +332,9 @@ 

Related Topics

  1. The temperature anomaly is then calculated by subtracting these climatological temperature values from the annual global average temperatures and plotted:

-
temp_anomaly = annual_global_avg - temp_clim
-cfp.lineplot(
-    temp_anomaly,
+
temp_anomaly = annual_global_avg - temp_clim
+cfp.lineplot(
+    temp_anomaly,
     color="red",
     title="Global Average Temperature Anomaly (1901-2021)",
     ylabel="1961-1990 climatology difference ",
diff --git a/docs/recipes/plot_03_recipe.html b/docs/recipes/plot_03_recipe.html
index 222121715a..3163f5a4e8 100644
--- a/docs/recipes/plot_03_recipe.html
+++ b/docs/recipes/plot_03_recipe.html
@@ -148,8 +148,8 @@ 

Related Topics

  1. Read the field constructs:

-
f = cf.read("~/recipes/cru_ts4.06.1901.2021.tmp.dat.nc")
-print(f)
+
f = cf.read("~/recipes/cru_ts4.06.1901.2021.tmp.dat.nc")
+print(f)
 
[<CF Field: ncvar%stn(long_name=time(1452), long_name=latitude(360), long_name=longitude(720))>,
@@ -159,8 +159,8 @@ 

Related Topics

  1. Select near surface temperature by index and look at its contents:

-
temp = f[1]
-print(temp)
+
temp = f[1]
+print(temp)
 
Field: long_name=near-surface temperature (ncvar%tmp)
@@ -174,13 +174,13 @@ 

Related Topics

  1. Average the monthly mean surface temperature values by the time axis using the collapse method:

-
global_avg = temp.collapse("mean", axes="long_name=time")
+
global_avg = temp.collapse("mean", axes="long_name=time")
 
  1. Plot the global mean surface temperatures:

-
cfp.con(global_avg, lines=False, title="Global mean surface temperature")
+
cfp.con(global_avg, lines=False, title="Global mean surface temperature")
 
plot 03 recipe

Total running time of the script: ( 0 minutes 8.465 seconds)

diff --git a/docs/recipes/plot_04_recipe.html b/docs/recipes/plot_04_recipe.html index b251ea5b7b..f5c4b36e99 100644 --- a/docs/recipes/plot_04_recipe.html +++ b/docs/recipes/plot_04_recipe.html @@ -146,18 +146,18 @@

Related Topics

  1. Read the field constructs:

-
obs = cf.read("~/recipes/cru_ts4.06.1901.2021.tmp.dat.nc", chunks=None)
-print(obs)
+
obs = cf.read("~/recipes/cru_ts4.06.1901.2021.tmp.dat.nc", chunks=None)
+print(obs)
 
[<CF Field: ncvar%stn(long_name=time(1452), long_name=latitude(360), long_name=longitude(720))>,
  <CF Field: long_name=near-surface temperature(long_name=time(1452), long_name=latitude(360), long_name=longitude(720)) degrees Celsius>]
 
-
model = cf.read(
+
model = cf.read(
     "~/recipes/tas_Amon_HadGEM3-GC3-1_hist-1p0_r3i1p1f2_gn_185001-201412.nc"
 )
-print(model)
+print(model)
 
[<CF Field: air_temperature(time(1980), latitude(144), longitude(192)) K>]
@@ -166,8 +166,8 @@ 

Related Topics

  1. Select observation and model temperature fields by identity and index respectively, and look at their contents:

-
obs_temp = obs.select_field("long_name=near-surface temperature")
-print(obs_temp)
+
obs_temp = obs.select_field("long_name=near-surface temperature")
+print(obs_temp)
 
Field: long_name=near-surface temperature (ncvar%tmp)
@@ -178,8 +178,8 @@ 

Related Topics

: long_name=longitude(720) = [-179.75, ..., 179.75] degrees_east
-
model_temp = model[0]
-print(model_temp)
+
 
Field: air_temperature (ncvar%tas)
@@ -196,8 +196,8 @@ 

Related Topics

  1. Regrid observational data to that of the model data and create a new low resolution observational data using bilinear interpolation:

-
obs_temp_regrid = obs_temp.regrids(model_temp, method="linear")
-print(obs_temp_regrid)
+
 
Field: long_name=near-surface temperature (ncvar%tmp)
diff --git a/docs/recipes/plot_05_recipe.html b/docs/recipes/plot_05_recipe.html
index cf6c8d447e..2504418710 100644
--- a/docs/recipes/plot_05_recipe.html
+++ b/docs/recipes/plot_05_recipe.html
@@ -148,22 +148,22 @@ 

Related Topics

  1. Read the field constructs:

-
f1 = cf.read("~/recipes/northward.nc")
-print(f1)
+
f1 = cf.read("~/recipes/northward.nc")
+print(f1)
 
[<CF Field: northward_wind(time(1980), latitude(144), longitude(192)) m s-1>]
 
-
f2 = cf.read("~/recipes/eastward.nc")
-print(f2)
+
f2 = cf.read("~/recipes/eastward.nc")
+print(f2)
 
[<CF Field: eastward_wind(time(1980), latitude(144), longitude(192)) m s-1>]
 
-
f3 = cf.read("~/recipes/monthly_precipitation.nc")
-print(f3)
+
f3 = cf.read("~/recipes/monthly_precipitation.nc")
+print(f3)
 
[<CF Field: long_name=precipitation(long_name=time(1452), latitude(144), longitude(192)) mm/month>]
@@ -172,8 +172,8 @@ 

Related Topics

  1. Select wind vectors and precipitation data by index and look at their contents:

-
v = f1[0]
-print(v)
+
v = f1[0]
+print(v)
 
Field: northward_wind (ncvar%vas)
@@ -186,8 +186,8 @@ 

Related Topics

: height(1) = [10.0] m
-
u = f2[0]
-print(u)
+
u = f2[0]
+print(u)
 
Field: eastward_wind (ncvar%uas)
@@ -200,8 +200,8 @@ 

Related Topics

: height(1) = [10.0] m
-
pre = f3[0]
-print(pre)
+
pre = f3[0]
+print(pre)
 
Field: long_name=precipitation (ncvar%pre)
@@ -215,23 +215,23 @@ 

Related Topics

  1. Plot the wind vectors on top of precipitation data for June 1995 by creating a subspace with a date-time object and using cfplot.con. Here cfplot.gopen is used to define the parts of the plot area, which is closed by cfplot.gclose; cfplot.cscale is used to choose one of the colour maps amongst many available; cfplot.levs is used to set the contour levels for precipitation data; and cfplot.vect is used to plot the wind vectors for June 1995:

-
june_95 = cf.year(1995) & cf.month(6)
-cfp.gopen()
-cfp.cscale("precip4_11lev")
-cfp.levs(step=100)
-cfp.con(
-    pre.subspace(T=june_95),
+
june_95 = cf.year(1995) & cf.month(6)
+cfp.gopen()
+cfp.cscale("precip4_11lev")
+cfp.levs(step=100)
+cfp.con(
+    pre.subspace(T=june_95),
     lines=False,
     title="June 1995 monthly global precipitation",
 )
-cfp.vect(
-    u=u.subspace(T=june_95),
-    v=v.subspace(T=june_95),
+cfp.vect(
+    u=u.subspace(T=june_95),
+    v=v.subspace(T=june_95),
     key_length=10,
     scale=35,
     stride=5,
 )
-cfp.gclose()
+cfp.gclose()
 
plot 05 recipe

Total running time of the script: ( 0 minutes 6.138 seconds)

diff --git a/docs/recipes/plot_06_recipe.html b/docs/recipes/plot_06_recipe.html index f40a3fbc55..d3827a91b2 100644 --- a/docs/recipes/plot_06_recipe.html +++ b/docs/recipes/plot_06_recipe.html @@ -148,8 +148,8 @@

Related Topics

  1. Read the field constructs using read function:

-
f = cf.read("~/recipes/au952a.pd20510414.pp")
-print(f)
+
f = cf.read("~/recipes/au952a.pd20510414.pp")
+print(f)
 
[<CF Field: id%UM_m01s03i463_vn1006(time(8), grid_latitude(432), grid_longitude(444))>]
@@ -158,8 +158,8 @@ 

Related Topics

  1. Select the field by index and print its description to show properties of all constructs:

-
gust = f[0]
-gust.dump()
+
gust = f[0]
+gust.dump()
 
-----------------------------------------------------------
@@ -246,7 +246,7 @@ 

Related Topics

  1. Access the time coordinate of the gust field and retrieve the datetime values of the time coordinate:

-
print(gust.coordinate("time").datetime_array)
+
print(gust.coordinate("time").datetime_array)
 
[cftime.Datetime360Day(2051, 4, 14, 1, 30, 0, 0, has_year_zero=True)
@@ -262,8 +262,8 @@ 

Related Topics

  1. Create a new instance of the cf.dt class with a specified year, month, day, hour, minute, second and microsecond. Then store the result in the variable test:

-
test = cf.dt(2051, 4, 14, 1, 30, 0, 0)
-print(test)
+
test = cf.dt(2051, 4, 14, 1, 30, 0, 0)
+print(test)
 
2051-04-14 01:30:00
@@ -272,15 +272,15 @@ 

Related Topics

  1. Plot the wind gust by creating a subspace for the specified variable test using cfplot.con. Here cfplot.mapset is used to set the mapping parameters like setting the map resolution to 50m:

-
cfp.mapset(resolution="50m")
-cfp.con(gust.subspace(T=test), lines=False)
+
cfp.mapset(resolution="50m")
+cfp.con(gust.subspace(T=test), lines=False)
 
plot 06 recipe
  1. To see the rotated pole data on the native grid, the above steps are repeated and projection is set to rotated in cfplot.mapset:

-
cfp.mapset(resolution="50m", proj="rotated")
-cfp.con(gust.subspace(T=test), lines=False)
+
cfp.mapset(resolution="50m", proj="rotated")
+cfp.con(gust.subspace(T=test), lines=False)
 
plot 06 recipe

8. Create dimension coordinates for the destination grid with the latitude and @@ -291,9 +291,9 @@

Related Topics

The method also takes an argument 'linear' which specifies the type of regridding method to use. The description of the regridded_data is finally printed to show properties of all its constructs:

-
target_domain = cf.Domain.create_regular((-25, 45, 10), (32, 72, 10))
-regridded_data = gust.regrids(target_domain, "linear")
-regridded_data.dump()
+
target_domain = cf.Domain.create_regular((-25, 45, 10), (32, 72, 10))
+regridded_data = gust.regrids(target_domain, "linear")
+regridded_data.dump()
 
-----------------------------------------------------------
@@ -355,8 +355,8 @@ 

Related Topics

  1. Step 6 is similarly repeated for the regridded_data to plot the wind gust on a regular latitude-longitude domain:

-
cfp.mapset(resolution="50m")
-cfp.con(regridded_data.subspace(T=test), lines=False)
+
cfp.mapset(resolution="50m")
+cfp.con(regridded_data.subspace(T=test), lines=False)
 
plot 06 recipe

Total running time of the script: ( 0 minutes 27.364 seconds)

diff --git a/docs/recipes/plot_07_recipe.html b/docs/recipes/plot_07_recipe.html index 5ee9d2e41c..8a4619b92e 100644 --- a/docs/recipes/plot_07_recipe.html +++ b/docs/recipes/plot_07_recipe.html @@ -148,8 +148,8 @@

Related Topics

  1. Read the field constructs using read function and store it in the variable f. The * in the filename is a wildcard character which means the function reads all files in the directory that match the specified pattern. [0:5] selects the first five elements of the resulting list:

-
f = cf.read("~/recipes/realization/PRMSL.1941_mem*.nc")[0:5]
-print(f)
+
f = cf.read("~/recipes/realization/PRMSL.1941_mem*.nc")[0:5]
+print(f)
 
[<CF Field: long_name=Pressure reduced to MSL(time(2920), latitude(256), longitude(512)) Pa>,
@@ -162,7 +162,7 @@ 

Related Topics

  1. The description of one of the fields from the list shows 'realization' as a property by which the members of the model ensemble are labelled:

-
f[1].dump()
+
f[1].dump()
 
------------------------------------------------------
@@ -222,10 +222,10 @@ 

Related Topics

  1. An ensemble of the members is then created by aggregating the data in f along a new 'realization' axis using the cf.aggregate function, and storing the result in the variable ensemble. 'relaxed_identities=True' allows for missing coordinate identities to be inferred. [0] selects the first element of the resulting list. id%realization now shows as an auxiliary coordinate for the ensemble:

-
ensemble = cf.aggregate(
-    f, dimension=("realization",), relaxed_identities=True
+
ensemble = cf.aggregate(
+    f, dimension=("realization",), relaxed_identities=True
 )[0]
-print(ensemble)
+print(ensemble)
 
Field: long_name=Pressure reduced to MSL (ncvar%PRMSL)
@@ -240,7 +240,7 @@ 

Related Topics

  1. To see the constructs for the ensemble, print the constructs attribute:

-
print(ensemble.constructs)
+
 
Constructs:
@@ -256,19 +256,19 @@ 

Related Topics

6. Loop over the realizations in the ensemble using the range function and the domain_axis to determine the size of the realization dimension. For each realization, extract a subspace of the ensemble using the subspace method and the 'id%realization' keyword argument along a specific latitude and longitude and plot the realizations from the 4D field using cfplot.lineplot. A moving average of the ensemble along the time axis, with a window size of 90 (i.e. an approximately 3-month moving average) is calculated using the moving_window method. The mode='nearest' parameter is used to specify how to pad the data outside of the time range. The squeeze method removes any dimensions of size 1 from the field to produce a 2D field:

-
cfp.gopen()
+
cfp.gopen()
 
-for realization in range(1, ensemble.domain_axis("id%realization").size + 1):
-    cfp.lineplot(
-        ensemble.subspace(
-            **{"id%realization": realization}, latitude=[0], longitude=[0]
+for realization in range(1, ensemble.domain_axis("id%realization").size + 1):
+    cfp.lineplot(
+        ensemble.subspace(
+            **{"id%realization": realization}, latitude=[0], longitude=[0]
         ).squeeze(),
-        label=f"Member {realization}",
+        label=f"Member {realization}",
         linewidth=1.0,
     )
 
-cfp.lineplot(
-    ensemble.moving_window(
+cfp.lineplot(
+    ensemble.moving_window(
         method="mean", window_size=90, axis="T", mode="nearest"
     )[0, :, 0, 0].squeeze(),
     label="Ensemble mean",
@@ -277,7 +277,7 @@ 

Related Topics

title="Model Ensemble Pressure", ) -cfp.gclose() +cfp.gclose()
Model Ensemble Pressure

Total running time of the script: ( 1 minutes 4.205 seconds)

diff --git a/docs/recipes/plot_08_recipe.html b/docs/recipes/plot_08_recipe.html index d94ba24d48..c3ae90167f 100644 --- a/docs/recipes/plot_08_recipe.html +++ b/docs/recipes/plot_08_recipe.html @@ -153,8 +153,8 @@

Related Topics

  • linear_trend(data, time_axis): This function calculates the linear regression slope and p-value for the input data along the time axis. It takes two arguments: 'data', which represents the temperature anomalies or any other data you want to analyse, and 'time_axis', which represents the corresponding time points for the data. The function uses the stats.linregress method from the scipy.stats library to calculate the slope and p-value of the linear regression. It returns these two values as a tuple:

-
def linear_trend(data, time_axis):
-    slope, _, _, p_value, _ = stats.linregress(time_axis, data)
+
def linear_trend(data, time_axis):
+    slope, _, _, p_value, _ = stats.linregress(time_axis, data)
     return slope, p_value
 
@@ -170,20 +170,20 @@

Related Topics

  • process_subsets(subset_mask): This function processes the subsets of data by applying the linear_trend function along a specified axis. It takes one argument, 'subset_mask', which is a boolean mask representing the time points to be considered in the analysis. The function first extracts the masked subset of data and then applies the linear_trend function along the time axis (axis 0) using the numpy.ma.apply_along_axis function. The result is an array containing the slope and p-value for each grid point in the dataset:

-
def process_subsets(subset_mask):
-    subset_data = masked_data[subset_mask, :, :]
-    return np.ma.apply_along_axis(
-        linear_trend, 0, subset_data, time_axis[subset_mask]
+
def process_subsets(subset_mask):
+    subset_data = masked_data[subset_mask, :, :]
+    return np.ma.apply_along_axis(
+        linear_trend, 0, subset_data, time_axis[subset_mask]
     )
 
  1. Read the field constructs:

-
temperature_data = cf.read(
+
temperature_data = cf.read(
     "~/recipes/HadCRUT.5.0.1.0.analysis.anomalies.ensemble_mean.nc"
 )[0]
-print(temperature_data)
+print(temperature_data)
 
Field: long_name=blended air_temperature_anomaly over land with sea_water_temperature_anomaly (ncvar%tas_mean)
@@ -199,34 +199,34 @@ 

Related Topics

  1. Calculate the annual mean temperature anomalies. The 'weights=True' argument is used take the varying lengths of months into account which ensures that the calculated mean is more accurate. A masked array is created for the annual mean temperature anomalies, masking any invalid values:

-
annual_temperature = temperature_data.collapse(
-    "T: mean", weights=True, group=cf.Y()
+
 
  1. Define two time periods for analysis: 1850-2020 and 1980-2020, along with a significance level (alpha) of 0.05:

-
time_periods = [(1850, 2020, "sub_1850_2020"), (1980, 2020, "sub_1980_2020")]
-alpha = 0.05
-results = {}
+
time_periods = [(1850, 2020, "sub_1850_2020"), (1980, 2020, "sub_1980_2020")]
+alpha = 0.05
+results = {}
 
  1. Loop through the time periods, processing the subsets, calculating trend p-values, and creating stipple objects. For each time period, the script calculates the trends and p-values using the process_subsets function. If the p-value is less than the significance level (alpha = 0.05), a stippling mask is created. The script then creates a new object for the trend and stippling mask using the create_trend_stipple_obj function:

-
for start, end, prefix in time_periods:
-    subset_mask = (time_axis >= start) & (time_axis <= end)
-    subset_trend_pvalue = process_subsets(subset_mask)
-    results[prefix + "_trend_pvalue"] = subset_trend_pvalue
-    results[prefix + "_stipple"] = subset_trend_pvalue[1] < alpha
-    results[prefix + "_trend"] = create_trend_stipple_obj(
-        temperature_data, subset_trend_pvalue[0]
+
for start, end, prefix in time_periods:
+    subset_mask = (time_axis >= start) & (time_axis <= end)
+    subset_trend_pvalue = process_subsets(subset_mask)
+    results[prefix + "_trend_pvalue"] = subset_trend_pvalue
+    results[prefix + "_stipple"] = subset_trend_pvalue[1] < alpha
+    results[prefix + "_trend"] = create_trend_stipple_obj(
+        temperature_data, subset_trend_pvalue[0]
     )
-    results[prefix + "_stipple_obj"] = create_trend_stipple_obj(
-        temperature_data, results[prefix + "_stipple"]
+    results[prefix + "_stipple_obj"] = create_trend_stipple_obj(
+        temperature_data, results[prefix + "_stipple"]
     )
 
@@ -239,20 +239,20 @@

Related Topics

cfplot.cscale is used to choose one of the colour maps amongst many available; cfplot.levs is used to set the contour levels; and cfplot.stipple is used to add stippling to show statistically significant areas:

-
cfp.gopen(rows=2, columns=1, bottom=0.2)
-
-cfp.gpos(1)
-cfp.mapset(proj="robin")
-cfp.cscale("temp_19lev")
-cfp.levs(min=-1, max=1, step=0.1)
-cfp.con(
-    results["sub_1850_2020_trend"] * 10,
+
cfp.gopen(rows=2, columns=1, bottom=0.2)
+
+cfp.gpos(1)
+cfp.mapset(proj="robin")
+cfp.cscale("temp_19lev")
+cfp.levs(min=-1, max=1, step=0.1)
+cfp.con(
+    results["sub_1850_2020_trend"] * 10,
     lines=False,
     colorbar=None,
     title="Temperature Trend 1850-2020",
 )
-cfp.stipple(
-    results["sub_1850_2020_stipple_obj"],
+cfp.stipple(
+    results["sub_1850_2020_stipple_obj"],
     min=1,
     max=1,
     size=5,
@@ -260,20 +260,20 @@ 

Related Topics

marker=".", ) -cfp.gpos(2) -cfp.mapset(proj="robin") -cfp.cscale("temp_19lev") -cfp.levs(min=-1, max=1, step=0.1) -cfp.con( - results["sub_1980_2020_trend"] * 10, +cfp.gpos(2) +cfp.mapset(proj="robin") +cfp.cscale("temp_19lev") +cfp.levs(min=-1, max=1, step=0.1) +cfp.con( + results["sub_1980_2020_trend"] * 10, lines=False, title="Temperature Trend 1980-2020", colorbar_position=[0.1, 0.1, 0.8, 0.02], colorbar_orientation="horizontal", colorbar_title="K/decade", ) -cfp.stipple( - results["sub_1980_2020_stipple_obj"], +cfp.stipple( + results["sub_1980_2020_stipple_obj"], min=1, max=1, size=5, @@ -281,7 +281,7 @@

Related Topics

marker=".", ) -cfp.gclose() +cfp.gclose()
plot 08 recipe
Warning - boolean data found - converting to integers
diff --git a/docs/recipes/plot_09_recipe.html b/docs/recipes/plot_09_recipe.html
index 9d11321197..61a9d5730c 100644
--- a/docs/recipes/plot_09_recipe.html
+++ b/docs/recipes/plot_09_recipe.html
@@ -150,8 +150,8 @@ 

Related Topics

  1. Read the field constructs using read function:

-
f = cf.read("~/recipes/levtype_sfc.nc")
-print(f)
+
f = cf.read("~/recipes/levtype_sfc.nc")
+print(f)
 
[<CF Field: long_name=Total Aerosol Optical Depth at 550nm(long_name=time(6), long_name=latitude(241), long_name=longitude(480)) ~>,
@@ -162,8 +162,8 @@ 

Related Topics

3. Select the PM2.5 mass concentration and 2-metre temperature fields by index and print the description to show properties of all constructs:

-
pm25_field = f[2]
-pm25_field.dump()
+
 
---------------------------------------------------------------------------------
@@ -204,8 +204,8 @@ 

Related Topics

Data(long_name=longitude(480)) = [0.0, ..., 359.25] degrees_east
-
temp_field = f[3]
-temp_field.dump()
+
 
------------------------------------------------
@@ -248,8 +248,8 @@ 

Related Topics

  1. Convert the units to degree celsius for the temperature field:

-
temp_field.units = "degC"
-temp_field.get_property("units")
+
 
'degC'
@@ -259,46 +259,46 @@ 

Related Topics

This step counts the number of values in each of the 10 equally sized bins spanning the range of the values. The 'return_bins=True' argument makes sure that the calculated bins are also returned:

-
pm25_indices, pm25_bins = pm25_field.digitize(10, return_bins=True)
-temp_indices, temp_bins = temp_field.digitize(10, return_bins=True)
+
pm25_indices, pm25_bins = pm25_field.digitize(10, return_bins=True)
+temp_indices, temp_bins = temp_field.digitize(10, return_bins=True)
 
  1. Create a joint histogram of the digitized fields:

-
joint_histogram = cf.histogram(pm25_indices, temp_indices)
+
 
  1. Get histogram data from the joint_histogram:

-
histogram_data = joint_histogram.array
+
 
  1. Calculate bin centers for PM2.5 and temperature bins:

-
pm25_bin_centers = [(a + b) / 2 for a, b in pm25_bins]
-temp_bin_centers = [(a + b) / 2 for a, b in temp_bins]
+
pm25_bin_centers = [(a + b) / 2 for a, b in pm25_bins]
+temp_bin_centers = [(a + b) / 2 for a, b in temp_bins]
 

9. Create grids for PM2.5 and temperature bins using numpy.meshgrid:

-
temp_grid, pm25_grid = np.meshgrid(temp_bin_centers, pm25_bin_centers)
+
 

10. Plot the joint histogram using matplotlib.pyplot.pcolormesh. Use cf.Field.unique to get the unique data array values and show the bin boundaries as ticks on the plot. 'style='plain' in matplotlib.axes.Axes.ticklabel_format disables the scientific notation on the y-axis:

-
plt.pcolormesh(temp_grid, pm25_grid, histogram_data, cmap="viridis")
-plt.xlabel("2-metre Temperature (degC)")
-plt.ylabel("PM2.5 Mass Concentration (kg m**-3)")
-plt.xticks(temp_bins.unique().array, rotation=45)
-plt.yticks(pm25_bins.unique().array)
-plt.colorbar(label="Frequency")
-plt.title("Joint Histogram of PM2.5 and 2-metre Temperature", y=1.05)
-plt.ticklabel_format(style="plain")
-plt.show()
+
plt.pcolormesh(temp_grid, pm25_grid, histogram_data, cmap="viridis")
+plt.xlabel("2-metre Temperature (degC)")
+plt.ylabel("PM2.5 Mass Concentration (kg m**-3)")
+plt.xticks(temp_bins.unique().array, rotation=45)
+plt.yticks(pm25_bins.unique().array)
+plt.colorbar(label="Frequency")
+plt.title("Joint Histogram of PM2.5 and 2-metre Temperature", y=1.05)
+plt.ticklabel_format(style="plain")
+plt.show()
 
Joint Histogram of PM2.5 and 2-metre Temperature

Total running time of the script: ( 0 minutes 4.643 seconds)

diff --git a/docs/recipes/plot_10_recipe.html b/docs/recipes/plot_10_recipe.html index 19db2ebfa0..aa3a2c9f08 100644 --- a/docs/recipes/plot_10_recipe.html +++ b/docs/recipes/plot_10_recipe.html @@ -153,8 +153,8 @@

Related Topics

  1. Read the field constructs:

-
f = cf.read("~/recipes/ERA5_monthly_averaged_pressure_levels.nc")
-print(f)
+
f = cf.read("~/recipes/ERA5_monthly_averaged_pressure_levels.nc")
+print(f)
 
[<CF Field: divergence_of_wind(long_name=time(3), long_name=expver(2), long_name=latitude(721), long_name=longitude(1440)) s**-1>,
@@ -165,8 +165,8 @@ 

Related Topics

  1. Select wind components and look at their contents:

-
u = f.select_field("eastward_wind")
-print(u)
+
u = f.select_field("eastward_wind")
+print(u)
 
Field: eastward_wind (ncvar%u)
@@ -178,8 +178,8 @@ 

Related Topics

: long_name=longitude(1440) = [0.0, ..., 359.75] degrees_east
-
v = f.select_field("northward_wind")
-print(v)
+
v = f.select_field("northward_wind")
+print(v)
 
Field: northward_wind (ncvar%v)
@@ -194,7 +194,7 @@ 

Related Topics

  1. Create a date-time object for the required time period:

-
jan_2023 = cf.year(2023) & cf.month(1)
+
jan_2023 = cf.year(2023) & cf.month(1)
 

5. The relative vorticity is calculated using cf.curl_xy and @@ -215,11 +215,11 @@

Related Topics

2023 and one of the experiment versions using the dictionary unpacking operator (**) as there is an equal to sign in the identifier ("long_name=expver"):

-
with cf.relaxed_identities(True):
-    rv = cf.curl_xy(u, v, radius="earth")
+
with cf.relaxed_identities(True):
+    rv = cf.curl_xy(u, v, radius="earth")
 
-cfp.con(
-    rv.subspace(T=jan_2023, **{"long_name=expver": 1}),
+cfp.con(
+    rv.subspace(T=jan_2023, **{"long_name=expver": 1}),
     lines=False,
     title="Relative Vorticity",
 )
@@ -233,17 +233,17 @@ 

Related Topics

while calculating the relative vorticity. Setting rv.units = "s-1", ensures that the units of the relative vorticity field are consistent with the calculation and the physical interpretation of the quantity:

-
print(v.coordinate("X").has_bounds())
+
print(v.coordinate("X").has_bounds())
 
False
 
-
with cf.relaxed_identities(True):
-    rv = cf.curl_xy(u, v, x_wrap=True, radius="earth")
+
with cf.relaxed_identities(True):
+    rv = cf.curl_xy(u, v, x_wrap=True, radius="earth")
 
-rv.units = "s-1"
-print(rv)
+rv.units = "s-1"
+print(rv)
 
Field: long_name=Horizontal curl of (eastward_wind, northward_wind) (ncvar%u)
@@ -255,8 +255,8 @@ 

Related Topics

: longitude(1440) = [0.0, ..., 359.75] degrees_east
-
cfp.con(
-    rv.subspace(T=jan_2023, **{"long_name=expver": 1}),
+
cfp.con(
+    rv.subspace(T=jan_2023, **{"long_name=expver": 1}),
     lines=False,
     title="Relative Vorticity",
 )
diff --git a/docs/recipes/plot_11_recipe.html b/docs/recipes/plot_11_recipe.html
index 8f633be94c..be9fda5e73 100644
--- a/docs/recipes/plot_11_recipe.html
+++ b/docs/recipes/plot_11_recipe.html
@@ -152,10 +152,10 @@ 

Related Topics

  1. Read the field constructs:

-
temperature_data = cf.read(
+
temperature_data = cf.read(
     "~/recipes/HadCRUT.5.0.1.0.analysis.anomalies.ensemble_mean.nc"
 )[0]
-print(temperature_data)
+print(temperature_data)
 
Field: long_name=blended air_temperature_anomaly over land with sea_water_temperature_anomaly (ncvar%tas_mean)
@@ -171,73 +171,73 @@ 

Related Topics

3. Calculate the annual mean temperature anomalies. The 'weights=True' argument is used to take the varying lengths of months into account which ensures that the calculated mean is more accurate:

-
annual_temperature = temperature_data.collapse(
-    "T: mean", weights=True, group=cf.Y()
+
annual_temperature = temperature_data.collapse(
+    "T: mean", weights=True, group=cf.Y()
 )
 
  1. Select the data from 1850 to 2022:

-
period = annual_temperature.subspace(T=cf.year(cf.wi(1850, 2022)))
+
 
  1. Calculate the global average temperature for each year:

-
global_temperature = period.collapse("X: Y: mean")
+
 
  1. Get the global average temperature and squeeze it to remove the size 1 axis:

-
global_avg_temp = global_temperature.array.squeeze()
+
 

7. Create a normalization function that maps the interval from the minimum to the maximum temperature to the interval [0, 1] for colouring:

-
norm_global = plt.Normalize(global_avg_temp.min(), global_avg_temp.max())
+
 
  1. Set the colormap instance:

-
cmap = plt.get_cmap("RdBu_r")
+
cmap = plt.get_cmap("RdBu_r")
 

9. Create the figure and the axes for the global plot. Loop over the selected years, plot a colored vertical stripe for each and remove the axes:

-
fig_global, ax_global = plt.subplots(figsize=(10, 2))
+
fig_global, ax_global = plt.subplots(figsize=(10, 2))
 
-for i in range(global_avg_temp.shape[0]):
-    ax_global.axvspan(
-        xmin=i - 0.5, xmax=i + 0.5, color=cmap(norm_global(global_avg_temp[i]))
+for i in range(global_avg_temp.shape[0]):
+    ax_global.axvspan(
+        xmin=i - 0.5, xmax=i + 0.5, color=cmap(norm_global(global_avg_temp[i]))
     )
 
-ax_global.axis("off")
+ax_global.axis("off")
 
-plt.show()
+plt.show()
 
plot 11 recipe

10. For the regional warming stripes, steps 5 to 9 are repeated for the specific region. Here, we define the bounding box for UK by subspacing over a domain spanning 49.9 to 59.4 degrees north and -10.5 to 1.8 degrees east:

-
uk_temperature = period.subspace(X=cf.wi(-10.5, 1.8), Y=cf.wi(49.9, 59.4))
-uk_avg_temperature = uk_temperature.collapse("X: Y: mean")
-uk_avg_temp = uk_avg_temperature.array.squeeze()
-norm_uk = plt.Normalize(uk_avg_temp.min(), uk_avg_temp.max())
+
-
fig_uk, ax_uk = plt.subplots(figsize=(10, 2))
+
fig_uk, ax_uk = plt.subplots(figsize=(10, 2))
 
-for i in range(uk_avg_temp.shape[0]):
-    ax_uk.axvspan(
-        xmin=i - 0.5, xmax=i + 0.5, color=cmap(norm_uk(uk_avg_temp[i]))
+for i in range(uk_avg_temp.shape[0]):
+    ax_uk.axvspan(
+        xmin=i - 0.5, xmax=i + 0.5, color=cmap(norm_uk(uk_avg_temp[i]))
     )
 
-ax_uk.axis("off")
+ax_uk.axis("off")
 
-plt.show()
+plt.show()
 
plot 11 recipe

Total running time of the script: ( 0 minutes 21.115 seconds)

diff --git a/docs/recipes/plot_12_recipe.html b/docs/recipes/plot_12_recipe.html index 431d500499..941b265df7 100644 --- a/docs/recipes/plot_12_recipe.html +++ b/docs/recipes/plot_12_recipe.html @@ -152,10 +152,10 @@

Related Topics

  1. Read the field constructs:

-
fl = cf.read(
+
fl = cf.read(
     "~/recipes/JRR-AOD_v3r0_npp_s202012310752331_e202012310753573_c202100000000000.nc"
 )
-print(fl)
+print(fl)
 
[<CF Field: long_name=AOT at 0.55 micron for both ocean and land(ncdim%Rows(768), ncdim%Columns(3200)) 1>,
@@ -190,8 +190,8 @@ 

Related Topics

  1. Select AOD from the field list by identity and look at the contents:

-
aod = fl.select_field("long_name=AOT at 0.55 micron for both ocean and land")
-print(aod)
+
aod = fl.select_field("long_name=AOT at 0.55 micron for both ocean and land")
+print(aod)
 
Field: long_name=AOT at 0.55 micron for both ocean and land (ncvar%AOD550)
@@ -204,8 +204,8 @@ 

Related Topics

  1. Select AOD retrieval quality by index and look at the quality flags:

-
quality = fl[13]
-print(quality)
+
quality = fl[13]
+print(quality)
 
Field: long_name=Retrieval quality:  0: high; 1: medium; 2: low; 3: no retrieval (ncvar%QCAll)
@@ -217,15 +217,15 @@ 

Related Topics

5. Select latitude and longitude dimensions by identities, with two different techniques:

-
lon = aod.coordinate("long_name=Longitude")
-lat = aod.coordinate("Y")
+
lon = aod.coordinate("long_name=Longitude")
+lat = aod.coordinate("Y")
 

6. Plot the AOD for all the retrievals using cfplot.con. Here the argument 'ptype' specifies the type of plot to use (latituide-longitude here) and the argument 'lines=False' does not draw contour lines:

-
cfp.con(f=aod.array, x=lon.array, y=lat.array, ptype=1, lines=False)
+
cfp.con(f=aod.array, x=lon.array, y=lat.array, ptype=1, lines=False)
 
plot 12 recipe

7. Create a mask for AOD based on the quality of the retrieval. The @@ -233,7 +233,7 @@

Related Topics

create a mask where all the high-quality AOD points (with the flag 0) are marked as False, and all the other data points (medium quality, low quality, or no retrieval) are marked as True:

-
mask = quality.array.__ne__(0)
+
mask = quality.array.__ne__(0)
 

8. Apply the mask to the AOD dataset. The 'where' function takes the @@ -242,7 +242,7 @@

Related Topics

In this case, all AOD values that are not of high-quality (since they were marked as True in the mask) are masked. This means that the high variable contains only the AOD data that was retrieved with high-quality:

-
high = aod.where(mask, cf.masked)
+
high = aod.where(mask, cf.masked)
 

9. Now plot both the AOD from high-quality retrieval and all other retrievals @@ -265,26 +265,26 @@

Related Topics

import cartopy.feature as cfeature
 
-cfp.gopen(rows=1, columns=2, bottom=0.2)
-plt.suptitle("AOD for both ocean and land", fontsize=20)
-cfp.gpos(1)
-cfp.mapset(resolution="50m", lonmin=68, lonmax=98, latmin=7, latmax=36)
-cfp.con(
-    f=aod.array,
-    x=lon.array,
-    y=lat.array,
+cfp.gopen(rows=1, columns=2, bottom=0.2)
+plt.suptitle("AOD for both ocean and land", fontsize=20)
+cfp.gpos(1)
+cfp.mapset(resolution="50m", lonmin=68, lonmax=98, latmin=7, latmax=36)
+cfp.con(
+    f=aod.array,
+    x=lon.array,
+    y=lat.array,
     ptype=1,
     lines=False,
     title="All retrievals",
     colorbar=None,
 )
 cfp.plotvars.mymap.add_feature(cfeature.BORDERS)
-cfp.gpos(2)
-cfp.mapset(resolution="50m", lonmin=68, lonmax=98, latmin=7, latmax=36)
-cfp.con(
-    f=high.array,
-    x=lon.array,
-    y=lat.array,
+cfp.gpos(2)
+cfp.mapset(resolution="50m", lonmin=68, lonmax=98, latmin=7, latmax=36)
+cfp.con(
+    f=high.array,
+    x=lon.array,
+    y=lat.array,
     ptype=1,
     lines=False,
     title="High quality retrieval",
@@ -293,7 +293,7 @@ 

Related Topics

colorbar_title="AOD at 0.55 $\mu$", ) cfp.plotvars.mymap.add_feature(cfeature.BORDERS) -cfp.gclose() +cfp.gclose()
AOD for both ocean and land

Total running time of the script: ( 1 minutes 2.707 seconds)

diff --git a/docs/recipes/plot_13_recipe.html b/docs/recipes/plot_13_recipe.html index b5fd34456a..fa319b3ac9 100644 --- a/docs/recipes/plot_13_recipe.html +++ b/docs/recipes/plot_13_recipe.html @@ -154,8 +154,8 @@

Related Topics

  1. Read and select the SST by index and look at its contents:

-
sst = cf.read("~/recipes/ERA5_monthly_averaged_SST.nc")[0]
-print(sst)
+
sst = cf.read("~/recipes/ERA5_monthly_averaged_SST.nc")[0]
+print(sst)
 
Field: long_name=Sea surface temperature (ncvar%sst)
@@ -169,13 +169,13 @@ 

Related Topics

  1. Set the units from Kelvin to degrees Celsius:

-
sst.Units = cf.Units("degreesC")
+
sst.Units = cf.Units("degreesC")
 

4. SST is subspaced for the Niño 3.4 region (5N-5S, 170W-120W) and as the dataset is using longitudes in 0-360 degrees East format, they are subtracted from 360 to convert them:

-
region = sst.subspace(X=cf.wi(360 - 170, 360 - 120), Y=cf.wi(-5, 5))
+
region = sst.subspace(X=cf.wi(360 - 170, 360 - 120), Y=cf.wi(-5, 5))
 
    @@ -203,18 +203,18 @@

    Related Topics

    import cartopy.crs as ccrs
     import matplotlib.patches as mpatches
     
    -cfp.gopen()
    -cfp.mapset(proj="cyl", lonmin=0, lonmax=360, latmin=-90, latmax=90)
    -cfp.setvars(land_color="grey")
    -cfp.cscale(scale="scale1")
    -cfp.con(
    -    region.subspace(T=cf.dt(2022, 12, 1, 0, 0, 0, 0)),
    +cfp.gopen()
    +cfp.mapset(proj="cyl", lonmin=0, lonmax=360, latmin=-90, latmax=90)
    +cfp.setvars(land_color="grey")
    +cfp.cscale(scale="scale1")
    +cfp.con(
    +    region.subspace(T=cf.dt(2022, 12, 1, 0, 0, 0, 0)),
         lines=False,
         title="Niño Index Regions",
     )
     
     # Niño 3.4 region(5N-5S, 170W-120W):
    -rectangle = mpatches.Rectangle(
    +rectangle = mpatches.Rectangle(
         (-170, -5),
         50,
         10,
    @@ -223,7 +223,7 @@ 

    Related Topics

    edgecolor="black", transform=ccrs.PlateCarree(), ) -cfp.plotvars.mymap.add_patch(rectangle) +cfp.plotvars.mymap.add_patch(rectangle) cfp.plotvars.mymap.text( -145, 7, @@ -235,7 +235,7 @@

    Related Topics

    ) # Niño 1+2 region (0-10S, 90W-80W): -rectangle = mpatches.Rectangle( +rectangle = mpatches.Rectangle( (-90, 0), 10, 10, @@ -246,7 +246,7 @@

    Related Topics

    alpha=0.3, transform=ccrs.PlateCarree(), ) -cfp.plotvars.mymap.add_patch(rectangle) +cfp.plotvars.mymap.add_patch(rectangle) cfp.plotvars.mymap.text( -85, 3, @@ -258,7 +258,7 @@

    Related Topics

    ) # Niño 3 region (5N-5S, 150W-90W): -rectangle = mpatches.Rectangle( +rectangle = mpatches.Rectangle( (-150, -5), 60, 10, @@ -269,7 +269,7 @@

    Related Topics

    alpha=0.3, transform=ccrs.PlateCarree(), ) -cfp.plotvars.mymap.add_patch(rectangle) +cfp.plotvars.mymap.add_patch(rectangle) cfp.plotvars.mymap.text( -120, -3, @@ -281,7 +281,7 @@

    Related Topics

    ) # Niño 4 region (5N-5S, 160E-150W): -rectangle = mpatches.Rectangle( +rectangle = mpatches.Rectangle( (-200, -5), 50, 10, @@ -292,7 +292,7 @@

    Related Topics

    alpha=0.3, transform=ccrs.PlateCarree(), ) -cfp.plotvars.mymap.add_patch(rectangle) +cfp.plotvars.mymap.add_patch(rectangle) cfp.plotvars.mymap.text( -175, -3, @@ -302,14 +302,14 @@

    Related Topics

    weight="bold", transform=ccrs.PlateCarree(), ) -cfp.gclose() +cfp.gclose()
    plot 13 recipe

    6. Calculate the Niño 3.4 index and standardize it to create an anomaly index. The collapse method is used to calculate the mean over the longitude (X) and latitude (Y) dimensions:

    -
    nino34_index = region.collapse("X: Y: mean")
    +
    nino34_index = region.collapse("X: Y: mean")
     

    7. The result, nino34_index, represents the average SST in the defined @@ -319,9 +319,9 @@

    Related Topics

    The variables climatology and std_dev include the mean and the standard deviation over the time (T) dimension of the base_period data respectively:

    -
    base_period = nino34_index.subspace(T=cf.year(cf.wi(1961, 1990)))
    -climatology = base_period.collapse("T: mean")
    -std_dev = base_period.collapse("T: sd")
    +
     

    8. The line for variable nino34_anomaly calculates the standardized @@ -331,7 +331,7 @@

    Related Topics

    3.4 region deviates from the 1961-1990 average, in units of standard deviations. This is a common way to quantify climate anomalies like El Niño and La Niña events:

    -
    nino34_anomaly = (nino34_index - climatology) / std_dev
    +
     

    9. A moving average of the nino34_anomaly along the time axis, with a @@ -342,7 +342,7 @@

    Related Topics

    data outside of the time range. The resulting nino34_rolling variable represents a smoothed version of the nino34_anomaly data. It removes short-term fluctuations and highlights longer-term trends or cycles:

    -
    nino34_rolling = nino34_anomaly.moving_window(
    +
    nino34_rolling = nino34_anomaly.moving_window(
         method="mean", window_size=5, axis="T", mode="nearest"
     )
     
    @@ -371,14 +371,14 @@

    Related Topics

    cfplot.plotvars.plot.legend is used to add a legend in the end:

    -
    elnino = nino34_rolling >= 0.4
    -lanina = nino34_rolling <= -0.4
    +
    elnino = nino34_rolling >= 0.4
    +lanina = nino34_rolling <= -0.4
     
    -cfp.gset(xmin="1940-1-1", xmax="2022-12-31", ymin=-3, ymax=3)
    +cfp.gset(xmin="1940-1-1", xmax="2022-12-31", ymin=-3, ymax=3)
     
    -cfp.gopen(figsize=(10, 6))
    -cfp.lineplot(
    -    nino34_rolling,
    +cfp.gopen(figsize=(10, 6))
    +cfp.lineplot(
    +    nino34_rolling,
         color="black",
         title="SST Anomaly in Niño 3.4 Region (5N-5S, 120-170W)",
         ylabel="Temperature anomaly ($\degree C$)",
    @@ -392,23 +392,23 @@ 

    Related Topics

    ) cfp.plotvars.plot.axhline(0, color="black", linestyle="-", linewidth=1) cfp.plotvars.plot.fill_between( - nino34_rolling.coordinate("T").array, + nino34_rolling.coordinate("T").array, 0.4, - nino34_rolling.array.squeeze(), - where=elnino.squeeze(), + nino34_rolling.array.squeeze(), + where=elnino.squeeze(), color="red", alpha=0.3, ) cfp.plotvars.plot.fill_between( - nino34_rolling.coordinate("T").array, + nino34_rolling.coordinate("T").array, -0.4, - nino34_rolling.array.squeeze(), - where=lanina.squeeze(), + nino34_rolling.array.squeeze(), + where=lanina.squeeze(), color="blue", alpha=0.3, ) cfp.plotvars.plot.legend(frameon=False, loc="lower center", ncol=2) -cfp.gclose() +cfp.gclose()
    SST Anomaly in Niño 3.4 Region (5N-5S, 120-170W)

    Total running time of the script: ( 5 minutes 17.754 seconds)

    diff --git a/docs/recipes/plot_14_recipe.html b/docs/recipes/plot_14_recipe.html index 83c2723131..da305ef543 100644 --- a/docs/recipes/plot_14_recipe.html +++ b/docs/recipes/plot_14_recipe.html @@ -151,8 +151,8 @@

    Related Topics

    1. Read and select the 200 hpa geopotential by index and look at its contents:

    -
    gp = cf.read("~/recipes/ERA5_monthly_averaged_z200.nc")[0]
    -print(gp)
    +
    gp = cf.read("~/recipes/ERA5_monthly_averaged_z200.nc")[0]
    +print(gp)
     
    Field: geopotential (ncvar%z)
    @@ -165,12 +165,12 @@ 

    Related Topics

    3. Convert the geopotential data to geopotential height by dividing it by the acceleration due to gravity (approximated as 9.81 \(m \cdot {s}^{-2}\)):

    -
    gph = gp / 9.81
    +
    gph = gp / 9.81
     

    4. Subset the geopotential height to extract data specifically for July 2018, a significant month due to heat extremes and heavy rainfall:

    -
    gph_july = gph.subspace(T=cf.month(7) & cf.year(2018)).squeeze()
    +
    gph_july = gph.subspace(T=cf.month(7) & cf.year(2018)).squeeze()
     
      @@ -199,12 +199,12 @@

      Related Topics

      then finally visualises the Earth’s surface in cf-plot’s cfp.plotvars.mymap plot object:

      -
      cfp.gopen()
      -cfp.mapset(proj="npstere")
      -cfp.setvars(continent_thickness=0.5)
      +
      cfp.gopen()
      +cfp.mapset(proj="npstere")
      +cfp.setvars(continent_thickness=0.5)
       
      -cfp.con(
      -    f=gph_july,
      +cfp.con(
      +    f=gph_july,
           fill=False,
           lines=True,
           line_labels=False,
      @@ -213,9 +213,9 @@ 

      Related Topics

      colorbar=False, ) -cfp.levs(manual=[12000, 12300]) -cfp.con( - f=gph_july, +cfp.levs(manual=[12000, 12300]) +cfp.con( + f=gph_july, fill=False, lines=True, colors="black", @@ -224,14 +224,14 @@

      Related Topics

      ) cfp.plotvars.mymap.stock_img() -cfp.gclose() +cfp.gclose()
      plot 14 recipe
      1. Read and select the 2-metre temperature by index and look at its contents:

      -
      t2m = cf.read("~/recipes/ERA5_monthly_averaged_t2m.nc")[0]
      -print(t2m)
      +
      t2m = cf.read("~/recipes/ERA5_monthly_averaged_t2m.nc")[0]
      +print(t2m)
       
      Field: long_name=2 metre temperature (ncvar%t2m)
      @@ -245,20 +245,20 @@ 

      Related Topics

      1. Set the units from Kelvin to degrees Celsius:

      -
      t2m.Units = cf.Units("degreesC")
      +
      t2m.Units = cf.Units("degreesC")
       
      1. Extract a subset for July across the years for t2m:

      -
      t2m_july = t2m.subspace(T=cf.month(7))
      +
       

      9. The 2-meter temperature climatology is then calculated for the month of July over the period from 1981 to 2010, which provides a baseline against which anomalies in later years are compared:

      -
      t2m_july_climatology = t2m_july.subspace(
      -    T=cf.year(cf.wi(1981, 2010))
      +
      t2m_july_climatology = t2m_july.subspace(
      +    T=cf.year(cf.wi(1981, 2010))
       ).collapse("T: mean")
       
      @@ -266,8 +266,8 @@

      Related Topics

      relative to the climatological baseline (t2m_july_climatology). This indicates how much the temperatures for that month in that year deviated from the long-term average for July across the 1981-2010 period:

      -
      t2m_july_anomaly_2018 = (
      -    t2m_july.subspace(T=cf.year(2018)).squeeze() - t2m_july_climatology
      +
      @@ -298,28 +298,28 @@ 

      Related Topics

      lines representing the 200 hpa geopotential height values, the approximate polar-front jet and subtropical jet from Step 5 are repeated:

      -
      cfp.gopen()
      -cfp.mapset(proj="robin")
      -cfp.setvars(
      +
      cfp.gopen()
      +cfp.mapset(proj="robin")
      +cfp.setvars(
           continent_thickness=0.5,
           master_title="July 2018",
           master_title_fontsize=22,
           master_title_location=[0.53, 0.83],
       )
       
      -cfp.levs(min=-2, max=2, step=0.5)
      -cfp.cscale("temp_19lev")
      -cfp.con(
      -    f=t2m_july_anomaly_2018,
      +cfp.levs(min=-2, max=2, step=0.5)
      +cfp.cscale("temp_19lev")
      +cfp.con(
      +    f=t2m_july_anomaly_2018,
           lines=False,
           colorbar_title="Temperature anomaly relative to 1981-2010 ($\degree C$)",
           colorbar_fontsize=13,
           colorbar_thick=0.04,
       )
       
      -cfp.levs()
      -cfp.con(
      -    f=gph_july,
      +cfp.levs()
      +cfp.con(
      +    f=gph_july,
           fill=False,
           lines=True,
           line_labels=False,
      @@ -328,9 +328,9 @@ 

      Related Topics

      colorbar=False, ) -cfp.levs(manual=[12000, 12300]) -cfp.con( - f=gph_july, +cfp.levs(manual=[12000, 12300]) +cfp.con( + f=gph_july, fill=False, lines=True, colors="black", @@ -338,7 +338,7 @@

      Related Topics

      colorbar=False, ) -cfp.gclose() +cfp.gclose()
      plot 14 recipe

      Total running time of the script: ( 1 minutes 30.051 seconds)

      diff --git a/docs/recipes/plot_15_recipe.html b/docs/recipes/plot_15_recipe.html index b28d154afe..cb559a392e 100644 --- a/docs/recipes/plot_15_recipe.html +++ b/docs/recipes/plot_15_recipe.html @@ -163,8 +163,8 @@

      Related Topics

      1. Read and select land use data by index and see properties of all constructs:

      -
      f = cf.read("~/recipes/output.tif.nc")[0]
      -f.dump()
      +
      f = cf.read("~/recipes/output.tif.nc")[0]
      +f.dump()
       
      -------------------------------------------------
      @@ -235,17 +235,17 @@ 

      Related Topics

      resolution="10m", category="cultural", name="admin_0_countries" ) reader = shpreader.Reader(shpfilename) - country = [ - country - for country in reader.records() - if country.attributes["NAME_LONG"] == country_name + country = [ + country + for country in reader.records() + if country.attributes["NAME_LONG"] == country_name ][0] - lon_min, lat_min, lon_max, lat_max = country.bounds + lon_min, lat_min, lon_max, lat_max = country.bounds - f = cf.read("~/recipes/output.tif.nc")[0] - f = f.subspace(X=cf.wi(lon_min, lon_max), Y=cf.wi(lat_min, lat_max)) + f = cf.read("~/recipes/output.tif.nc")[0] + f = f.subspace(X=cf.wi(lon_min, lon_max), Y=cf.wi(lat_min, lat_max)) - return f + return f

      4. Define a function to plot a histogram of land use distribution for a @@ -285,9 +285,9 @@

      Related Topics

      input parameters.

      def plot_histogram(field, ax, label, ylim, xlim):
      -    digitized, bins = field.digitize(np.linspace(0, 50, 51), return_bins=True)
      +    digitized, bins = field.digitize(np.linspace(0, 50, 51), return_bins=True)
       
      -    h = cf.histogram(digitized)
      +    h = cf.histogram(digitized)
           bin_counts = h.array.squeeze()
       
           total_valid_sub_cells = bin_counts.sum()
      @@ -298,18 +298,18 @@ 

      Related Topics

      bin_indices = (bins.array[:-1, 0] + bins.array[1:, 0]) / 2 - ax.bar(bin_indices, percentages, label=label) - ax.set_title(label) - ax.set_xlabel("Land Use Flag") - ax.set_ylabel("Percentage") - ax.set_ylim(ylim) - ax.set_xlim(xlim) + ax.bar(bin_indices, percentages, label=label) + ax.set_title(label) + ax.set_xlabel("Land Use Flag") + ax.set_ylabel("Percentage") + ax.set_ylim(ylim) + ax.set_xlim(xlim)
      1. Define the countries of interest:

      -
      countries = ["Ireland", "Belgium", "Switzerland"]
      +
      countries = ["Ireland", "Belgium", "Switzerland"]
       
        @@ -327,15 +327,15 @@

        Related Topics

        properly spaced within the figure and finally, the plt.show function displays the figure with the histograms.

        -
        fig, axs = plt.subplots(3, 1, figsize=(8, 10))
        +
        fig, axs = plt.subplots(3, 1, figsize=(8, 10))
         
        -for i, country in enumerate(countries):
        -    ax = axs[i]
        -    data = extract_data(country)
        -    plot_histogram(data, ax, label=country, ylim=(0, 50), xlim=(0, 50))
        +for i, country in enumerate(countries):
        +    ax = axs[i]
        +    data = extract_data(country)
        +    plot_histogram(data, ax, label=country, ylim=(0, 50), xlim=(0, 50))
         
        -plt.tight_layout()
        -plt.show()
        +plt.tight_layout()
        +plt.show()
         
        Ireland, Belgium, Switzerland

        Total running time of the script: ( 7 minutes 52.733 seconds)