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
21 changes: 12 additions & 9 deletions environment.yml
Comment thread
jrackham-mo marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@ channels:
dependencies:
- black
- cftime
- dask=2023.11.0
- esmf=8.4.2=mpi_mpich_h2a0de38_103
- esmpy=8.4.2
- dask
- esmf=*=nompi_*
- esmpy
- f90nml
- flake8
- gdal=3.9.1
- gdal
- geovista
- iris-esmf-regrid>=0.9
- hdf5=*=nompi_*
- iris-esmf-regrid=0.15
- iris-sample-data
- iris=3.7.1
- iris
- isort
- libnetcdf!=4.9.1=nompi_*
- mo_pack
- nccmp
- netcdf-fortran=*=nompi_*
- numba
- numpy=1.26.0
- numpy=2.3.5
- pre-commit
- pydata-sphinx-theme
- pyflakes
Expand All @@ -27,11 +30,11 @@ dependencies:
- pytest-cov
- pytest-xdist
- python-stratify
- python=3.10.13
- python=3.12.12
- ruff
- setuptools
- setuptools-scm
- sphinx=7.2.6
- sphinx
- sphinx-argparse
- sphinx-copybutton
- sphinx-sitemap
Expand Down
2 changes: 1 addition & 1 deletion lib/ants/_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _bounding_box(target_x, target_y, src_crs):
src_crs = source_x.coord_system.as_ants_crs()
box = _bounding_box(target_x, target_y, src_crs)

(minx, miny, maxx, maxy) = box.bounds
minx, miny, maxx, maxy = box.bounds
slices = utils.cube.get_slices(source, [miny, maxy], [minx, maxx], pad_width)

if len(slices) > 2:
Expand Down
1 change: 1 addition & 0 deletions lib/ants/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
# This file is part of ANTS and is released under the BSD 3-Clause license.
# See LICENSE.txt in the root of the repository for full licensing details.
"""Define the fallback version to be used when ANTS is not installed into an environment.""" # noqa: E501

FALLBACK_VERSION = "3.2.0dev"
7 changes: 4 additions & 3 deletions lib/ants/analysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<https://scitools-iris.readthedocs.io/en/latest/userguide/merge_and_concat.html>`_.

"""

import warnings

import ants
Expand Down Expand Up @@ -251,7 +252,7 @@ def merge(primary_cube, alternate_cube, validity_polygon=None):
def _flood_fill_neighbour_identify(
shape, coords, seed_point, extended_neighbourhood, wraparound
):
(yy, xx) = seed_point
yy, xx = seed_point
if yy > 0:
coords.add((yy - 1, xx))
if yy < (shape[0] - 1):
Expand Down Expand Up @@ -320,7 +321,7 @@ def flood_fill(
When True, support wraparound in 'x', otherwise stop at the boundary.

"""
(y, x) = seed_point
y, x = seed_point
if array.ndim != 2:
msg = "The provided array should be 2D but that provided is {}D"
raise ValueError(msg.format(array.ndim))
Expand Down Expand Up @@ -473,7 +474,7 @@ def find_similar_region(
identified as similar.

"""
(y, x) = seed_point
y, x = seed_point
if array.ndim != 2:
msg = "The provided array should be 2D but that provided is {}D"
raise ValueError(msg.format(array.ndim))
Expand Down
1 change: 1 addition & 0 deletions lib/ants/analysis/_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
The metadata is also updated to reflect the analysis made.

"""

import abc
import logging
import warnings
Expand Down
1 change: 1 addition & 0 deletions lib/ants/cli/ancil_2anc.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<https://code.metoffice.gov.uk/doc/um/latest/papers/umdp_F03.pdf>`_

"""

import warnings

import ants
Expand Down
1 change: 1 addition & 0 deletions lib/ants/cli/ancil_create_shapefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Creates and saves a shapefile from a list of pairs of longitude, latitude
points defining a single polygon in a specified polygon file.
"""

import argparse
import json

Expand Down
1 change: 1 addition & 0 deletions lib/ants/cli/ancil_fill_n_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
missing values.

"""

import ants
import ants.io.save as save
import cartopy
Expand Down
1 change: 1 addition & 0 deletions lib/ants/cli/ancil_general_regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
is produced, regardless of the number of longitude
points in the regrid target.
"""

import ants
import ants.decomposition as decomp
import ants.io.save as save
Expand Down
1 change: 1 addition & 0 deletions lib/ants/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
see different results). This environment variable is read by cartopy directly.

"""

import argparse
import configparser
import copy
Expand Down
1 change: 1 addition & 0 deletions lib/ants/coord_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* :func:`ants.regrid.rectilinear`

"""

import copy
import re
from abc import ABCMeta, abstractmethod
Expand Down
7 changes: 4 additions & 3 deletions lib/ants/decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
See :func:`ants.utils.cube.defer_cube`.

"""

import itertools
import logging
import os
Expand Down Expand Up @@ -172,8 +173,8 @@ def _guess_split(sources, target=None):
if not isinstance(target, iris.cube.Cube):
target = target[0]
dtype = np.promote_types(dtype, target.dtype)
if (np.prod(target.shape) * np.nbytes[dtype]) > (
np.prod(source.shape) * np.nbytes[dtype]
if (np.prod(target.shape) * np.dtype(dtype).itemsize) > (
np.prod(source.shape) * np.dtype(dtype).itemsize
):
largest_array = target

Expand All @@ -186,7 +187,7 @@ def _guess_split(sources, target=None):
z_elements = np.prod(rem_shape)

# Number of points which amount to size_bytes footprint.
n_elements = int((size_bytes) / np.nbytes[dtype])
n_elements = int((size_bytes) / np.dtype(dtype).itemsize)

# Split such that ~square extracts occur for likely optimisation of saving.
shape = np.array(largest_array.shape)
Expand Down
1 change: 1 addition & 0 deletions lib/ants/fileformats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
ancillary generation. These include those supported by iris and additional
formats such as grid namelists and raster files.
"""

import warnings

import ants
Expand Down
1 change: 1 addition & 0 deletions lib/ants/fileformats/_grid_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
grid via the ants.io.load.load_grid interface.

"""

import ants
import dask.array as da
import iris
Expand Down
1 change: 1 addition & 0 deletions lib/ants/fileformats/ancil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
cube.attributes['grid_staggering'].

"""

import warnings

import ants
Expand Down
1 change: 1 addition & 0 deletions lib/ants/fileformats/ancil/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#. Create a metadata.ini file for climatology time information (write_metadata_file)

"""

import configparser
import numbers
from collections import Counter
Expand Down
3 changes: 2 additions & 1 deletion lib/ants/fileformats/ancil/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Tools for generating the template required for saving ancillary files.

"""

import itertools
import re

Expand Down Expand Up @@ -136,7 +137,7 @@ def _set_grid_definition(headers, grid, field):
headers["fixed_length_header"]["horiz_grid_type"] = horiz_grid_type

# REAL CONSTANTS
(regular_x, regular_y) = field.is_regular
regular_x, regular_y = field.is_regular
if regular_x:
headers["real_constants"]["col_spacing"] = field.bdx
# Longitude of first column in degrees (longitudes in range 0-360)
Expand Down
1 change: 1 addition & 0 deletions lib/ants/fileformats/ancil/time_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
This module provides functions related to time handling for ancillary files.

"""

import itertools

import ants
Expand Down
1 change: 1 addition & 0 deletions lib/ants/fileformats/namelist/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Module for reading Fortran namelist files and constructing Python or Iris
objects, as appropriate, from the contents.
"""

import warnings

import ants
Expand Down
3 changes: 2 additions & 1 deletion lib/ants/fileformats/namelist/umgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
definition specification.

"""

from abc import ABCMeta, abstractproperty
from collections import namedtuple

Expand Down Expand Up @@ -642,7 +643,7 @@ def __init__(self, namelist_dict):
_eta_rho.insert(0, 0.0)
# rho level above model top not in namelist. Instead, derived after
# conversion to self._brlev, so use NAN as a placeholder:
_eta_rho.append(np.NAN)
_eta_rho.append(np.nan)

self._eta_rho = np.array(_eta_rho, dtype=np.float64)
# brlev defines level_height.lower bounds
Expand Down
1 change: 1 addition & 0 deletions lib/ants/fileformats/netcdf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# This file is part of ANTS and is released under the BSD 3-Clause license.
# See LICENSE.txt in the root of the repository for full licensing details.
"""The entry point for netCDF saving is via :func:`ants.io.save.netcdf`."""

from . import cf, ukca

__all__ = [
Expand Down
1 change: 1 addition & 0 deletions lib/ants/fileformats/pp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
1. Pseudo-level order from the PP file is preserved.

"""

import collections
import itertools

Expand Down
12 changes: 11 additions & 1 deletion lib/ants/fileformats/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
information.

"""

import copy
import warnings

Expand Down Expand Up @@ -64,7 +65,16 @@ def __init__(self, shape, dtype, path, raster_band_index, fill_value):
# the saving of netcdf3 output properly (auto type-casting etc.)
dtype = np.dtype(dtype)
if dtype.name.startswith("uint"):
dtype = np.dtype(np.sctypeDict[dtype.num + 1])
if (dtype.name) == "uint8":
dtype = np.dtype("int16")
elif (dtype.name) == "uint16":
dtype = np.dtype("int32")
elif (dtype.name) == "uint32":
dtype = np.dtype("int64")
elif (dtype.name) == "uint64":
dtype = np.dtype("int128")
else:
raise TypeError(f"Cannot cast {dtype.name} from unsigned to signed int")
self.dtype = dtype
self.path = path
self.raster_band_index = raster_band_index
Expand Down
1 change: 1 addition & 0 deletions lib/ants/io/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
:func:`ants.fileformats.namelist.load_um_vertical`

"""

import copy
import warnings
from contextlib import contextmanager
Expand Down
1 change: 1 addition & 0 deletions lib/ants/io/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
specifying ``saver='ukca'`` (see :func:`ants.io.save.ukca_netcdf`).

"""

import os
import sys
import warnings
Expand Down
1 change: 1 addition & 0 deletions lib/ants/regrid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
For further details see the user guide.

"""

import logging
import sys

Expand Down
12 changes: 0 additions & 12 deletions lib/ants/regrid/esmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,33 +412,27 @@ def __init__(self, src_cube, target_cube, **kwargs):
if keywarg_diff:
msg = "unexpected keyword argument {}"
raise ValueError(msg.format(keywarg_diff))

if esmpy is None:
raise _ESMPY_IMPORT_ERROR
_supported_cube_check(src_cube)
_supported_cube_check(target_cube)

# Set some parameters.
self.handle = None
self.coordSystem = esmpy.api.constants.CoordSys.SPH_DEG
self.method = esmpy.api.constants.RegridMethod.CONSERVE
self.stagger = esmpy.StaggerLoc.CENTER

method = kwargs.get("method", "areaweighted")
if method.lower() != "areaweighted":
raise ValueError("Currently only area weighted regridding " "supported.")

# Simply return if the src and tgt grids are identical.
if (src_cube.coord(axis="x") == target_cube.coord(axis="x")) and (
src_cube.coord(axis="y") == target_cube.coord(axis="y")
):
return
_source_cube_sanity_check(src_cube)

# Build the 2D esmf grid and field objects.
self.esmpy_src_grid, self.esmpy_src_field = self._build_field(src_cube)
self.esmpy_tgt_grid, self.esmpy_tgt_field = self._build_field(target_cube)

# Compute/read the weights following ESMPy weights tutorial. See
# ESMPy docs for details of arguments.
self._cache_fnme = self._gen_cache_filename([src_cube, target_cube])
Expand Down Expand Up @@ -872,7 +866,6 @@ def _build_field(self, cube):
#
# Build the esmpy field object.
#

staggering = "corner"
if self.method != esmpy.api.constants.RegridMethod.CONSERVE:
# Need to pass corner coordinates in all cases. When the field is
Expand All @@ -884,20 +877,16 @@ def _build_field(self, cube):
extractor = _LatLonExtractor(cube, staggering)
lats = extractor.get_latitude()
lons = extractor.get_longitude()

# Create the grid.
cellDims = np.array([lons.shape[0] - 1, lats.shape[1] - 1])
grid = esmpy.Grid(max_index=cellDims, coord_sys=self.coordSystem)

# Allocate space for the vertices, esmpy wants the first coordinate to
# be longitudes.
grid.add_coords(staggerloc=esmpy.StaggerLoc.CORNER, coord_dim=0)
# No need to add lats, it will be added automatically with lons

# Get pointers to the esmf coordinates.
lonPoint = grid.get_coords(coord_dim=0, staggerloc=esmpy.StaggerLoc.CORNER)
latPoint = grid.get_coords(coord_dim=1, staggerloc=esmpy.StaggerLoc.CORNER)

# When esmpy runs in parallel, the start/end indices may be other than
# 0,-1.
# CP: Is esmpy running in parallel being tested?? I suggest just
Expand All @@ -909,7 +898,6 @@ def _build_field(self, cube):
iend0 = grid.upper_bounds[esmpy.StaggerLoc.CORNER][0]
ibeg1 = grid.lower_bounds[esmpy.StaggerLoc.CORNER][1]
iend1 = grid.upper_bounds[esmpy.StaggerLoc.CORNER][1]

lonPoint[...] = lons[ibeg0:iend0, ibeg1:iend1]
latPoint[...] = lats[ibeg0:iend0, ibeg1:iend1]

Expand Down
Loading