Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,6 @@ doc/_sidebar.rst.inc
*.ESMF_LogFile


#Ignore vscode AI rules
# AI
.github/instructions/codacy.instructions.md
CLAUDE.md
4 changes: 1 addition & 3 deletions esmvalcore/_recipe/from_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ def _datasets_to_recipe(datasets: Iterable[Dataset]) -> Recipe:
f"'diagnostic' facet missing from {dataset},"
"unable to convert to recipe."
)
raise RecipeError(
msg,
)
raise RecipeError(msg)

recipe = _datasets_to_raw_recipe(datasets)
diagnostics = recipe["diagnostics"].values()
Expand Down
24 changes: 6 additions & 18 deletions esmvalcore/_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,12 @@ def _py2ncl(value, var_name=""):
type_ = type(value[0])
if any(not isinstance(v, type_) for v in value):
msg = f"NCL array cannot be mixed type: {value}"
raise ValueError(
msg,
)
raise ValueError(msg)
txt += "(/{}/)".format(", ".join(_py2ncl(v) for v in value))
elif isinstance(value, dict):
if not var_name:
msg = f"NCL does not support nested dicts: {value}"
raise ValueError(
msg,
)
raise ValueError(msg)
txt += "True\n"
for key in value:
txt += f"{var_name}@{key} = {_py2ncl(value[key])}\n"
Expand Down Expand Up @@ -272,9 +268,7 @@ def initialize_provenance(self, recipe_entity):
"""Initialize task provenance activity."""
if self.activity is not None:
msg = f"Provenance of {self} already initialized"
raise ValueError(
msg,
)
raise ValueError(msg)
self.activity = get_task_provenance(self, recipe_entity)

def flatten(self):
Expand Down Expand Up @@ -445,18 +439,14 @@ def _initialize_cmd(self):
msg = (
f"{err_msg}: program '{interpreters[ext]}' not installed."
)
raise DiagnosticError(
msg,
)
raise DiagnosticError(msg)
cmd.append(interpreter)
elif not os.access(script_file, os.X_OK):
msg = (
f"{err_msg}: non-executable file with unknown extension "
f"'{script_file.suffix}'."
)
raise DiagnosticError(
msg,
)
raise DiagnosticError(msg)

cmd.extend(args.get(ext, []))
cmd.append(str(script_file))
Expand Down Expand Up @@ -674,9 +664,7 @@ def _run(self, input_files):
f"Diagnostic script {self.script} failed with return code {returncode}. See the log "
f"in {self.log}"
)
raise DiagnosticError(
msg,
)
raise DiagnosticError(msg)

def _collect_provenance(self) -> None:
"""Process provenance information provided by the diagnostic script."""
Expand Down
4 changes: 1 addition & 3 deletions esmvalcore/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@
"ESMValCore package not found, please run `pip install -e .` before "
"importing the package."
)
raise PackageNotFoundError(
msg,
) from exc
raise PackageNotFoundError(msg) from exc
4 changes: 1 addition & 3 deletions esmvalcore/cmor/_fixes/access/_base_fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ def _get_path_from_facet(self, facet):
path = Path(self.extra_facets[facet])
if not path.is_file():
msg = f"'{path}' given by facet '{facet}' does not exist"
raise FileNotFoundError(
msg,
)
raise FileNotFoundError(msg)
return path

def load_ocean_grid_data(self, facet):
Expand Down
8 changes: 2 additions & 6 deletions esmvalcore/cmor/_fixes/cordex/cordex_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ def _check_grid_differences(self, old_coord, new_coord):
"Differences between the original grid and the "
f"standardised grid are above 10e-4 {new_coord.units}."
)
raise RecipeError(
msg,
)
raise RecipeError(msg)

def _fix_rotated_coords(self, cube, domain, domain_info):
"""Fix rotated coordinates."""
Expand Down Expand Up @@ -221,8 +219,6 @@ def fix_metadata(self, cubes):
"not supported in CORDEX datasets. Must be "
"rotated_latitude_longitude or lambert_conformal_conic."
)
raise RecipeError(
msg,
)
raise RecipeError(msg)

return cubes
4 changes: 1 addition & 3 deletions esmvalcore/cmor/_fixes/emac/_base_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ def get_cube(self, cubes, var_name=None):
f"available in the input file. Please specify a valid `raw_name` "
f"in the recipe or as extra facets."
)
raise ValueError(
msg,
)
raise ValueError(msg)


class NegateData(EmacFix):
Expand Down
4 changes: 1 addition & 3 deletions esmvalcore/cmor/_fixes/emac/emac.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ def _fix_plev(self, cube):
f"'{self.vardef.short_name}', searched for Z-coordinates with "
f"units that are convertible to Pa"
)
raise ValueError(
msg,
)
raise ValueError(msg)

@staticmethod
def _fix_alevel(cube, cubes):
Expand Down
24 changes: 6 additions & 18 deletions esmvalcore/cmor/_fixes/icon/_base_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,7 @@ def _get_grid_url(self, cube: Cube) -> tuple[str, str]:
f"necessary to download the ICON horizontal grid file:\n"
f"{cube}"
)
raise ValueError(
msg,
)
raise ValueError(msg)
grid_url = cube.attributes[self.GRID_FILE_ATTR]
parsed_url = urlparse(grid_url)
grid_name = Path(parsed_url.path).name
Expand Down Expand Up @@ -223,9 +221,7 @@ def _get_path_from_facet(
f"relative to the auxiliary_data_dir "
f"'{self.session['auxiliary_data_dir']}')"
)
raise FileNotFoundError(
msg,
)
raise FileNotFoundError(msg)
path = new_path
return path

Expand Down Expand Up @@ -650,9 +646,7 @@ def _add_coord_from_grid_file(self, cube: Cube, coord_name: str) -> None:
f"'{coord_name}', cube does not contain a single unnamed "
f"dimension:\n{cube}"
)
raise ValueError(
msg,
)
raise ValueError(msg)
coord_dims: tuple[()] | tuple[int] = ()
for idx in range(cube.ndim):
if not cube.coords(dimensions=idx, dim_coords=True):
Expand All @@ -678,9 +672,7 @@ def _add_time(self, cube: Cube, cubes: CubeList) -> Cube:
f"'{self.vardef.short_name}', cube and other cubes in file do not "
f"contain it"
)
raise ValueError(
msg,
)
raise ValueError(msg)

def _get_z_coord(
self,
Expand Down Expand Up @@ -987,9 +979,7 @@ def _get_previous_timestep(self, datetime_point: datetime) -> datetime:
f"got {datetime_point}. Use `shift_time=false` in the "
f"recipe to disable this feature"
)
raise ValueError(
msg,
)
raise ValueError(msg)

# Decadal data
if "dec" in freq:
Expand Down Expand Up @@ -1082,9 +1072,7 @@ def _fix_invalid_time_units(time_coord: Coord) -> None:
f"Expected time units '{time_format}' in input file, got "
f"'{t_unit}'"
)
raise ValueError(
msg,
)
raise ValueError(msg)
new_t_units = Unit(
"days since 1850-01-01",
calendar="proleptic_gregorian",
Expand Down
8 changes: 2 additions & 6 deletions esmvalcore/cmor/_fixes/native_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ def fix_var_metadata(self, cube: Cube) -> None:
f"Failed to fix invalid units '{invalid_units}' for "
f"variable '{self.vardef.short_name}'"
)
raise ValueError(
msg,
) from exc
raise ValueError(msg) from exc
safe_convert_units(cube, self.vardef.units)

# Fix attributes
Expand Down Expand Up @@ -132,9 +130,7 @@ def get_cube(
f"Variable '{var_name}' used to extract "
f"'{self.vardef.short_name}' is not available in input file"
)
raise ValueError(
msg,
)
raise ValueError(msg)
return cubes.extract_cube(NameConstraint(var_name=var_name))

def fix_regular_time(
Expand Down
28 changes: 7 additions & 21 deletions esmvalcore/cmor/_fixes/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ def add_aux_coords_from_cubes(cube, cubes, coord_dict):
f"Expected exactly one coordinate cube '{coord_name}' in "
f"list of cubes {cubes}, got {len(coord_cube):d}"
)
raise ValueError(
msg,
)
raise ValueError(msg)
coord_cube = coord_cube[0]
aux_coord = cube_to_aux_coord(coord_cube)
cube.add_aux_coord(aux_coord, coord_dims)
Expand Down Expand Up @@ -137,9 +135,7 @@ def add_plev_from_altitude(cube):
"Cannot add 'air_pressure' coordinate, 'altitude' coordinate not "
"available"
)
raise ValueError(
msg,
)
raise ValueError(msg)


def add_altitude_from_plev(cube):
Expand Down Expand Up @@ -185,9 +181,7 @@ def add_altitude_from_plev(cube):
"Cannot add 'altitude' coordinate, 'air_pressure' coordinate not "
"available"
)
raise ValueError(
msg,
)
raise ValueError(msg)


def add_scalar_depth_coord(cube, depth=0.0):
Expand Down Expand Up @@ -355,16 +349,12 @@ def get_bounds_cube(cubes, coord_var_name):
return cube[0]
if len(cube) > 1:
msg = f"Multiple cubes with var_name '{bound_var}' found"
raise ValueError(
msg,
)
raise ValueError(msg)
msg = (
f"No bounds for coordinate variable '{coord_var_name}' available in "
f"cubes\n{cubes}"
)
raise ValueError(
msg,
)
raise ValueError(msg)


@cache
Expand Down Expand Up @@ -544,16 +534,12 @@ def get_time_bounds(time: Coord, freq: str) -> np.ndarray:
f"For `n`-hourly data, `n` must be a divisor of 24, got "
f"'{freq}'"
)
raise NotImplementedError(
msg,
)
raise NotImplementedError(msg)
min_bound = date - timedelta(hours=n_hours / 2.0)
max_bound = date + timedelta(hours=n_hours / 2.0)
else:
msg = f"Cannot guess time bounds for frequency '{freq}'"
raise NotImplementedError(
msg,
)
raise NotImplementedError(msg)
bounds.append([min_bound, max_bound])

return date2num(np.array(bounds), time.units, time.dtype)
8 changes: 2 additions & 6 deletions esmvalcore/cmor/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ def _get_alternative_generic_lev_coord(
f"Found no valid alternative coordinate for generic level coordinate "
f"'{coord_name}'"
)
raise ValueError(
msg,
)
raise ValueError(msg)


def _get_generic_lev_coord_names(
Expand Down Expand Up @@ -204,9 +202,7 @@ def _get_single_cube(
f"but none of their var_names match the expected.\nFull list of "
f"cubes encountered: {cube_list}"
)
raise ValueError(
msg,
)
raise ValueError(msg)
logger.warning(
"Found variable %s%s, but there were other present in the file. Those "
"extra variables are usually metadata (cell area, latitude "
Expand Down
8 changes: 2 additions & 6 deletions esmvalcore/experimental/recipe_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ def __init__(self, filename: str) -> None:
f"{self.__class__.__name__} cannot handle bibtex files "
"with more than 1 entry."
)
raise NotImplementedError(
msg,
)
raise NotImplementedError(msg)

self._bib_data = bib_data
self._key, self._entry = next(iter(bib_data.entries.items()))
Expand Down Expand Up @@ -202,8 +200,6 @@ def render(self, renderer: str = "html") -> str:
rendered = formatter.text.render(backend)
except Exception as err: # noqa: BLE001
msg = f"Could not render {self._key!r}: {err}"
raise RenderError(
msg,
) from None
raise RenderError(msg) from None

return rendered
4 changes: 1 addition & 3 deletions esmvalcore/io/esgf/_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,7 @@ def _download(self, local_file, url):
f" downloaded from {url}: expected {checksum}, but got"
f" {local_checksum}. Try downloading the file again."
)
raise DownloadError(
msg,
)
raise DownloadError(msg)

shutil.move(tmp_file, local_file)
log_speed(url, self.size, duration.total_seconds())
Expand Down
4 changes: 1 addition & 3 deletions esmvalcore/io/esgf/_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,7 @@ def find_files(*, project, short_name, dataset, **facets):
f"Unable to download from ESGF, because project {project} is not"
" on it or is not supported by the esmvalcore.io.esgf module."
)
raise ValueError(
msg,
)
raise ValueError(msg)

# The project is required for the function to work.
facets["project"] = project
Expand Down
8 changes: 2 additions & 6 deletions esmvalcore/iris_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,7 @@ def safe_convert_units(cube: Cube, units: str | Unit) -> Cube:
f"standard_name changed from '{old_standard_name}' to "
f"'{cube.standard_name}'"
)
raise ValueError(
msg,
)
raise ValueError(msg)
return cube


Expand Down Expand Up @@ -624,9 +622,7 @@ def dataset_to_iris(
f"Expected type ncdata.NcData or xr.Dataset for dataset, got "
f"type {type(dataset)}"
)
raise TypeError(
msg,
)
raise TypeError(msg)

with ignore_warnings_context(ignore_warnings):
cubes = conversion_func(dataset)
Expand Down
Loading