Skip to content

Commit

Permalink
Merge branch 'main' into python312
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriupredoi committed Sep 13, 2024
2 parents 81e1128 + 8d15ce2 commit aa6295f
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 192 deletions.
305 changes: 155 additions & 150 deletions conda-linux-64.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies:
- cftime
- cmocean
- cython
- dask
- dask !=2024.8.0 # https://github.com/dask/dask/issues/11296
- distributed
- ecmwf-api-client
- eofs
Expand Down
2 changes: 1 addition & 1 deletion environment_osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies:
- cftime
- cmocean
- cython
- dask
- dask !=2024.8.0 # https://github.com/dask/dask/issues/11296
- distributed
- ecmwf-api-client
- eofs
Expand Down
38 changes: 22 additions & 16 deletions esmvaltool/cmorizers/data/formatters/datasets/nsidc_g02202_sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
import re

import numpy as np

import iris
from cf_units import Unit
from iris.coords import AuxCoord

from esmvalcore.cmor._fixes.common import OceanFixGrid
from esmvalcore.cmor.fixes import get_time_bounds
from esmvaltool.cmorizers.data import utilities as utils


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -71,7 +73,7 @@ def _create_coord(cubes, var_name, standard_name):
standard_name=standard_name,
long_name=cube.long_name,
var_name=var_name,
units='degrees' # cube.units,
units='degrees'
)
return coord

Expand All @@ -85,24 +87,27 @@ def _extract_variable(raw_var, cmor_info, attrs, filepath, out_dir, latlon):
cube = cubes.concatenate_cube()
iris.util.promote_aux_coord_to_dim_coord(cube, 'projection_y_coordinate')
iris.util.promote_aux_coord_to_dim_coord(cube, 'projection_x_coordinate')
cube.coord('projection_y_coordinate').rename('y')
cube.coord('projection_x_coordinate').rename('x')

cube.add_aux_coord(latlon[0], (1, 2))
cube.add_aux_coord(latlon[1], (1, 2))

# add coord typesi
area_type = AuxCoord([1.0], standard_name='area_type', var_name='type',
long_name='Sea Ice area type')
cube.add_aux_coord(area_type)

# cube.convert_units(cmor_info.units)
cube.units = '%'
cube.data[cube.data > 100] = np.nan
cube = cube * 100

# utils.fix_coords(cube) #latlon multidimensional
utils.fix_var_metadata(cube, cmor_info)
utils.set_global_atts(cube, attrs)
# latlon are multidimensional, create bounds
siconc = OceanFixGrid(cmor_info)
cube = siconc.fix_metadata(cubes=[cube])[0]
# time bounds
cube.coord('time').bounds = get_time_bounds(cube.coord('time'),
cmor_info.frequency)

utils.save_variable(cube,
var,
Expand Down Expand Up @@ -133,8 +138,9 @@ def _create_areacello(cfg, in_dir, sample_cube, glob_attrs, out_dir):
long_name=var_info.long_name,
var_name=var_info.short_name,
units='m2',
dim_coords_and_dims=[(sample_cube.coord('y'), 0),
(sample_cube.coord('x'), 1)])
# time is index 0, add cell index dim
dim_coords_and_dims=[(sample_cube.coords()[1], 0),
(sample_cube.coords()[2], 1)])
cube.add_aux_coord(lat_coord, (0, 1))
cube.add_aux_coord(sample_cube.coord('longitude'), (0, 1))
utils.fix_var_metadata(cube, var_info)
Expand All @@ -152,15 +158,17 @@ def cmorization(in_dir, out_dir, cfg, cfg_user, start_date, end_date):
cubesaux = iris.load(os.path.join(in_dir, 'G02202-cdr-ancillary-sh.nc'))
lat_coord = _create_coord(cubesaux, 'lat', 'latitude')
lon_coord = _create_coord(cubesaux, 'lon', 'longitude')

year = 1978
# split by year..
sample_cube = None
while year <= 2022:
for year in range(1979, 2022, 1):

filepaths = _get_filepaths(in_dir, cfg['filename'], year)

if len(filepaths) > 0:
logger.info("Found %d files in '%s'", len(filepaths), in_dir)
logger.info("Year %d: Found %d files in '%s'",
year, len(filepaths), in_dir)

for (var, var_info) in cfg['variables'].items():
logger.info("CMORizing variable '%s'", var)
Expand All @@ -173,10 +181,8 @@ def cmorization(in_dir, out_dir, cfg, cfg_user, start_date, end_date):
lon_coord])

else:
logger.info("No files found ")
logger.info("year: %d basename: %s", year, cfg['filename'])

year += 1
logger.info("No files found year: %d basename: %s",
year, cfg['filename'])

if sample_cube is not None:
_create_areacello(cfg, in_dir, sample_cube, glob_attrs, out_dir)
if sample_cube is not None:
_create_areacello(cfg, in_dir, sample_cube, glob_attrs, out_dir)
70 changes: 47 additions & 23 deletions esmvaltool/diag_scripts/monitor/multi_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,11 @@
:func:`~datetime.datetime.strftime` format string that is used to format
the time axis using :class:`matplotlib.dates.DateFormatter`. If ``None``,
use the default formatting imposed by the iris plotting function.
time_on: str, optional (default: y-axis)
Optional switch to change the orientation of the plot so that time is on
the x-axis ``time_on: x-axis``. Default orientation is time on y-axis and
lat/lon on x-axis.
.. hint::
Expand Down Expand Up @@ -851,6 +856,7 @@ def __init__(self, config):
'show_x_minor_ticks', True
)
self.plots[plot_type].setdefault('time_format', None)
self.plots[plot_type].setdefault('time_on', 'y-axis')

# Check that facet_used_for_labels is present for every dataset
for dataset in self.input_data:
Expand Down Expand Up @@ -1650,6 +1656,10 @@ def _plot_hovmoeller_time_vs_lat_or_lon_with_ref(self, plot_func, dataset,
ref_cube = ref_dataset['cube']
dim_coords_dat = self._check_cube_dimensions(cube, plot_type)
self._check_cube_dimensions(ref_cube, plot_type)
if 'latitude' in dim_coords_dat:
non_time_label = 'latitude [°N]'
else:
non_time_label = 'longitude [°E]'

# Create single figure with multiple axes
with mpl.rc_context(self._get_custom_mpl_rc_params(plot_type)):
Expand All @@ -1664,16 +1674,23 @@ def _plot_hovmoeller_time_vs_lat_or_lon_with_ref(self, plot_func, dataset,
# Plot dataset (top left)
axes_data = fig.add_subplot(gridspec[0:2, 0:2])
plot_kwargs['axes'] = axes_data
coord_names = [coord[0].name() for coord in cube.dim_coords]
if coord_names[0] == "time":
coord_names.reverse()
plot_kwargs['coords'] = coord_names
if self.plots[plot_type]['time_on'] == 'x-axis':
plot_kwargs['coords'] = list(dim_coords_dat)
x_label = 'time'
y_label = non_time_label
time_axis = axes_data.get_xaxis()
else:
plot_kwargs['coords'] = list(reversed(dim_coords_dat))
x_label = non_time_label
y_label = 'time'
time_axis = axes_data.get_yaxis()
plot_data = plot_func(cube, **plot_kwargs)
axes_data.set_title(self._get_label(dataset), pad=3.0)
axes_data.set_ylabel('time')
axes_data.set_ylabel(y_label)
if self.plots[plot_type]['time_format'] is not None:
axes_data.get_yaxis().set_major_formatter(mdates.DateFormatter(
self.plots[plot_type]['time_format']))
time_axis.set_major_formatter(mdates.DateFormatter(
self.plots[plot_type]['time_format']
))
if self.plots[plot_type]['show_y_minor_ticks']:
axes_data.get_yaxis().set_minor_locator(AutoMinorLocator())
if self.plots[plot_type]['show_x_minor_ticks']:
Expand Down Expand Up @@ -1705,17 +1722,14 @@ def _plot_hovmoeller_time_vs_lat_or_lon_with_ref(self, plot_func, dataset,
plot_kwargs_bias = self._get_plot_kwargs(plot_type, dataset,
bias=True)
plot_kwargs_bias['axes'] = axes_bias
plot_kwargs_bias['coords'] = coord_names
plot_kwargs_bias['coords'] = plot_kwargs['coords']
plot_bias = plot_func(bias_cube, **plot_kwargs_bias)
axes_bias.set_title(
f"{self._get_label(dataset)} - {self._get_label(ref_dataset)}",
pad=3.0,
)
axes_bias.set_ylabel('time')
if 'latitude' in dim_coords_dat:
axes_bias.set_xlabel('latitude [°N]')
elif 'longitude' in dim_coords_dat:
axes_bias.set_xlabel('longitude [°E]')
axes_bias.set_xlabel(x_label)
axes_bias.set_ylabel(y_label)
cbar_kwargs_bias = self._get_cbar_kwargs(plot_type, bias=True)
cbar_bias = fig.colorbar(plot_bias, ax=axes_bias,
**cbar_kwargs_bias)
Expand Down Expand Up @@ -1756,6 +1770,10 @@ def _plot_hovmoeller_time_vs_lat_or_lon_without_ref(self, plot_func,
# Make sure that the data has the correct dimensions
cube = dataset['cube']
dim_coords_dat = self._check_cube_dimensions(cube, plot_type)
if 'latitude' in dim_coords_dat:
non_time_label = 'latitude [°N]'
else:
non_time_label = 'longitude [°E]'

# Create plot with desired settings
with mpl.rc_context(self._get_custom_mpl_rc_params(plot_type)):
Expand All @@ -1764,8 +1782,17 @@ def _plot_hovmoeller_time_vs_lat_or_lon_without_ref(self, plot_func,
plot_kwargs = self._get_plot_kwargs(plot_type, dataset)
plot_kwargs['axes'] = axes

# Make sure time is on y-axis
plot_kwargs['coords'] = list(reversed(dim_coords_dat))
# Put time on desired axis
if self.plots[plot_type]['time_on'] == 'x-axis':
plot_kwargs['coords'] = list(dim_coords_dat)
x_label = 'time'
y_label = non_time_label
time_axis = axes.get_xaxis()
else:
plot_kwargs['coords'] = list(reversed(dim_coords_dat))
x_label = non_time_label
y_label = 'time'
time_axis = axes.get_yaxis()
plot_hovmoeller = plot_func(cube, **plot_kwargs)

# Setup colorbar
Expand All @@ -1779,15 +1806,12 @@ def _plot_hovmoeller_time_vs_lat_or_lon_without_ref(self, plot_func,
# Customize plot
axes.set_title(self._get_label(dataset))
fig.suptitle(dataset['long_name'])
if 'latitude' in dim_coords_dat:
axes.set_xlabel('latitude [°N]')
elif 'longitude' in dim_coords_dat:
axes.set_xlabel('longitude [°E]')
axes.set_ylabel('time')
axes.set_xlabel(x_label)
axes.set_ylabel(y_label)
if self.plots[plot_type]['time_format'] is not None:
axes.get_yaxis().set_major_formatter(mdates.DateFormatter(
self.plots[plot_type]['time_format'])
)
time_axis.set_major_formatter(mdates.DateFormatter(
self.plots[plot_type]['time_format']
))
if self.plots[plot_type]['show_y_minor_ticks']:
axes.get_yaxis().set_minor_locator(AutoMinorLocator())
if self.plots[plot_type]['show_x_minor_ticks']:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
'cf-units',
'cftime',
'cmocean',
'dask',
'dask!=2024.8.0', # https://github.com/dask/dask/issues/11296
'distributed',
'ecmwf-api-client',
'eofs',
Expand Down

0 comments on commit aa6295f

Please sign in to comment.