|
20 | 20 | import matplotlib.pyplot as plt |
21 | 21 | import numpy as np |
22 | 22 | import scipy |
| 23 | +from cf_units import Unit |
23 | 24 | from esmvalcore.preprocessor import climate_statistics |
24 | 25 | from matplotlib import colors, gridspec |
25 | 26 | from numpy import ma |
@@ -1575,10 +1576,13 @@ def preprocess_obs_dataset(obs_dataset, config): |
1575 | 1576 |
|
1576 | 1577 | trace_gas = config["trace_gas"] |
1577 | 1578 |
|
1578 | | - # Put observations and model data on same scale for ppm/ppb |
1579 | | - obs_cube = TRACE_GASES_FACTOR[trace_gas] * obs_cube |
1580 | | - # Change units accordingly |
1581 | | - obs_cube.attributes["unit"] = TRACE_GASES_UNITS[trace_gas] |
| 1579 | + # If trace gas is N2O = units are [mol mol-1] according to the CMOR table. |
| 1580 | + # Applying the scale factor is necessary for ppb. |
| 1581 | + if trace_gas == "n2o": |
| 1582 | + obs_cube = TRACE_GASES_FACTOR[trace_gas] * obs_cube |
| 1583 | + |
| 1584 | + # Change units to ppm/ppb |
| 1585 | + obs_cube.units = Unit(TRACE_GASES_UNITS[trace_gas]) |
1582 | 1586 |
|
1583 | 1587 | # Add the clim_season and season_year coordinates. |
1584 | 1588 | iris.coord_categorisation.add_year(obs_cube, "time", name="year") |
@@ -1940,21 +1944,19 @@ def preprocess_colocated_datasets( |
1940 | 1944 | } |
1941 | 1945 |
|
1942 | 1946 | # Looping over all time steps |
1943 | | - for i, ts in enumerate(time.units.num2date(time.points)): |
| 1947 | + for i, _ts in enumerate(time.units.num2date(time.points)): |
1944 | 1948 | if "timeserie_lat" in plots_coloc: |
1945 | 1949 | # Looping over latitude slices |
1946 | 1950 | for key, _ in LATITUDE_RANGES.items(): |
1947 | 1951 | # Obs values |
1948 | | - obs_ts = obs_slices[key]["values"].extract( |
1949 | | - iris.Constraint(time=ts) |
1950 | | - ) |
| 1952 | + obs_ts = obs_slices[key]["values"][i] |
1951 | 1953 | obs_yearly = obs_slices[key]["yearly"].extract( |
1952 | 1954 | iris.Constraint(year=years_ts[i]) |
1953 | 1955 | ) |
1954 | 1956 | # Model values |
1955 | 1957 | mod_ts = model_slices[key]["values"][ |
1956 | 1958 | model_dataset |
1957 | | - ][attr["alias"]].extract(iris.Constraint(time=ts)) |
| 1959 | + ][attr["alias"]][i] |
1958 | 1960 | mod_yearly = model_slices[key]["yearly"][ |
1959 | 1961 | model_dataset |
1960 | 1962 | ][attr["alias"]].extract( |
|
0 commit comments