Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help tests pass #165

Merged
merged 9 commits into from
Feb 16, 2023
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
8 changes: 3 additions & 5 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ jobs:
- uses: actions/checkout@v2
- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
miniforge-variant: Mambaforge
miniforge-version: latest
python-version: 3.8
mamba-version: "*"
channels: conda-forge,defaults
channel-priority: true

- name: Show conda installation info
run: |
Expand All @@ -54,4 +52,4 @@ jobs:
pip install -e .

- name: Build documentation
run: make -C docs clean html
run: make docs
6 changes: 2 additions & 4 deletions .github/workflows/test-notebooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ jobs:

- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
miniforge-variant: Mambaforge
miniforge-version: latest
python-version: ${{ matrix.python-version }}
mamba-version: "*"
channels: conda-forge
channel-priority: true

- name: Show conda installation info
run: |
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ jobs:

- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
miniforge-variant: Mambaforge
miniforge-version: latest
python-version: ${{ matrix.python-version }}
mamba-version: "*"
channels: conda-forge,defaults
channel-priority: true

- name: Show conda installation info
run: |
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = "en"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down
2 changes: 1 addition & 1 deletion pymt/component/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def load(cls, source):
source, with_connectivities=True
)

for (name, component) in components.items():
for name, component in components.items():
for port in connectivities[name]:
mapping = get_exchange_item_mapping(port["exchange_items"])
component.connect(
Expand Down
1 change: 0 additions & 1 deletion pymt/errors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class PymtError(Exception):

pass


Expand Down
4 changes: 2 additions & 2 deletions pymt/events/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def initialize(self):
"""
if not self._initializing:
self._initializing = True
for (event, _) in self._order:
for event, _ in self._order:
try:
event.initialize()
except Exception:
Expand Down Expand Up @@ -154,7 +154,7 @@ def finalize(self):
if not self._finalizing:
self._finalizing = True
# for event in self._timeline.events:
for (event, _) in self._order[::-1]:
for event, _ in self._order[::-1]:
event.finalize()
self._initialized = False

Expand Down
2 changes: 1 addition & 1 deletion pymt/events/port.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def initialize(self):

def run(self, stop_time):
"""Map values from one port to another."""
for (dst_name, src_name) in self._vars_to_map:
for dst_name, src_name in self._vars_to_map:
src_values = self._src.get_value(
src_name, units=self._dst.get_var_units(dst_name)
)
Expand Down
1 change: 0 additions & 1 deletion pymt/framework/timeinterp.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@


class TimeInterpolator:

METHODS = (
"linear",
"nearest",
Expand Down
4 changes: 2 additions & 2 deletions pymt/grids/connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def _get_offsets(shape, ordering="cw", dtype=int):
offsets = np.array([0, 1], dtype=dtype)

strides = np.cumprod(list(shape[-1:0:-1]))
for (dim, stride) in enumerate(strides):
for dim, stride in enumerate(strides):
new_offsets = offsets + stride
if ordered and dim % 2 == 0:
offsets = np.append(offsets, new_offsets[::-1])
Expand Down Expand Up @@ -220,7 +220,7 @@ def get_connectivity(shape, **kwds):
c.append(np.array(cell, dtype=kwds["dtype"]))
else:
c = np.empty((c0.size * points_per_cell,), dtype=kwds["dtype"])
for (i, offset) in enumerate(offsets):
for i, offset in enumerate(offsets):
c[i::points_per_cell] = c0 + offset

if with_offsets:
Expand Down
4 changes: 2 additions & 2 deletions pymt/grids/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __init__(self, *args, **kwargs):

self._point = {}
last_offset = 0
for (cell_id, offset) in enumerate(self._offset):
for cell_id, offset in enumerate(self._offset):
cell = self._connectivity[last_offset:offset]
last_offset = offset

Expand All @@ -78,7 +78,7 @@ def __init__(self, *args, **kwargs):
(point_x, point_y) = (self.get_x(), self.get_y())
self._polys = []
last_offset = 0
for (cell_id, offset) in enumerate(self._offset):
for cell_id, offset in enumerate(self._offset):
cell = self._connectivity[last_offset:offset]
last_offset = offset

Expand Down
2 changes: 1 addition & 1 deletion pymt/grids/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def __init__(self, shape, spacing, origin, **kwds):
kwds.setdefault("set_connectivity", False)

xi = []
for (nx, dx, x0) in zip(shape, spacing, origin):
for nx, dx, x0 in zip(shape, spacing, origin):
xi.append(np.arange(nx, dtype=np.float64) * dx + x0)

self._spacing = np.array(spacing, dtype=np.float64)
Expand Down
2 changes: 1 addition & 1 deletion pymt/grids/unstructured.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def get_connectivity_as_matrix(self, fill_val=MAXSIZE):
offset = self._offset[0]
matrix[0, :offset] = self._connectivity[:offset]
matrix[0, offset:] = fill_val
for (cell, offset) in enumerate(self._offset[:-1]):
for cell, offset in enumerate(self._offset[:-1]):
n_vertices = nodes_per_cell[cell]
matrix[cell + 1, :n_vertices] = self._connectivity[
offset : offset + n_vertices
Expand Down
6 changes: 3 additions & 3 deletions pymt/grids/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def coordinates_to_numpy_matrix(*args):
assert_arrays_are_equal_size(*args)

coords = np.empty((len(args), len(args[0])), dtype=float)
for (dim, arg) in enumerate(args):
for dim, arg in enumerate(args):
coords[dim][:] = arg.flatten()
return coords

Expand Down Expand Up @@ -95,7 +95,7 @@ def _find_first(array, value):

def connectivity_matrix_as_array(face_nodes, bad_val):
nodes_per_face = np.empty(face_nodes.shape[0], dtype=int)
for (face_id, face) in enumerate(face_nodes):
for face_id, face in enumerate(face_nodes):
nnodes = _find_first(face, bad_val)
if nnodes > 0:
nodes_per_face[face_id] = _find_first(face, bad_val)
Expand All @@ -105,7 +105,7 @@ def connectivity_matrix_as_array(face_nodes, bad_val):

connectivity = np.empty(offsets[-1], dtype=int)
offset = 0
for (n_nodes, face) in zip(nodes_per_face, face_nodes):
for n_nodes, face in zip(nodes_per_face, face_nodes):
connectivity[offset : offset + n_nodes] = face[:n_nodes]
offset += n_nodes

Expand Down
3 changes: 1 addition & 2 deletions pymt/mappers/celltopoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def map_points_to_cells(coords, src_grid, src_point_ids, bad_val=-1):
point_to_cell_id = np.empty(len(dst_x), dtype=int)
point_to_cell_id.fill(bad_val)

for (j, point_id) in enumerate(src_point_ids):
for j, point_id in enumerate(src_point_ids):
for cell_id in src_grid.get_shared_cells(point_id):
if src_grid.is_in_cell(dst_x[j], dst_y[j], cell_id):
point_to_cell_id[j] = cell_id
Expand All @@ -21,7 +21,6 @@ def map_points_to_cells(coords, src_grid, src_point_ids, bad_val=-1):


class CellToPoint(IGridMapper):

_name = "CellToPoint"

def initialize(self, dest_grid, src_grid, **kwds):
Expand Down
3 changes: 0 additions & 3 deletions pymt/mappers/esmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@


class EsmpMapper(IGridMapper):

_name = None

@property
Expand Down Expand Up @@ -99,7 +98,6 @@ def get_dest_data(self):


class EsmpCellToCell(EsmpMapper):

_name = "CellToCell"

def init_fields(self):
Expand All @@ -117,7 +115,6 @@ def test(dst_grid, src_grid):


class EsmpPointToPoint(EsmpMapper):

_name = "PointToPoint"

def init_fields(self):
Expand Down
5 changes: 2 additions & 3 deletions pymt/mappers/pointtocell.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def map_cells_to_points(coords, dst_grid, dst_point_ids, bad_val=-1):
src_x, src_y = coords

cell_to_point_id = defaultdict(list)
for (j, point_id) in enumerate(dst_point_ids):
for j, point_id in enumerate(dst_point_ids):
for cell_id in dst_grid.get_shared_cells(point_id):
if dst_grid.is_in_cell(src_x[j], src_y[j], cell_id):
cell_to_point_id[cell_id].append(j)
Expand All @@ -21,7 +21,6 @@ def map_cells_to_points(coords, dst_grid, dst_point_ids, bad_val=-1):


class PointToCell(IGridMapper):

_name = "PointToCell"

def initialize(self, dest_grid, src_grid, **kwds):
Expand Down Expand Up @@ -53,7 +52,7 @@ def run(self, src_values, **kwds):
if dst_vals.size != self._dst_cell_count:
raise ValueError("size mismatch between destination and cell count")

for (cell_id, point_ids) in self._map.items():
for cell_id, point_ids in self._map.items():
if all(src_values[point_ids] > bad_val):
dst_vals[cell_id] = method(src_values[point_ids])

Expand Down
14 changes: 7 additions & 7 deletions pymt/printers/nc/ugrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def set_variable(self, name, *args, **kwds):
attrs = kwds.pop("attrs", {})

variable = self.data_variable(name)
for (attr, value) in attrs.items():
for attr, value in attrs.items():
variable.setncattr(attr, value)

if len(args) > 0:
Expand Down Expand Up @@ -206,7 +206,7 @@ def _set_variable_data(self):

def _set_node_variable_data(self):
point_fields = self.field.get_point_fields()
for (var_name, array) in point_fields.items():
for var_name, array in point_fields.items():
self.create_variable(
var_name,
_NP_TO_NC_TYPE[str(array.dtype)],
Expand All @@ -226,7 +226,7 @@ def _set_node_variable_data(self):

def _set_face_variable_data(self):
face_fields = self.field.get_cell_fields()
for (var_name, array) in face_fields.items():
for var_name, array in face_fields.items():
self.create_variable(
var_name,
_NP_TO_NC_TYPE[str(array.dtype)],
Expand Down Expand Up @@ -271,11 +271,11 @@ def axis_coordinates(self):

def _set_mesh_dimensions(self):
field_shape = self.field.get_shape()
for (name, axis) in zip(self.axis_coordinates, self.field_axes):
for name, axis in zip(self.axis_coordinates, self.field_axes):
self.create_dimension(name, field_shape[axis])

def _set_mesh_coordinate_data(self):
for (name, axis) in zip(self.axis_coordinates, self.field_axes):
for name, axis in zip(self.axis_coordinates, self.field_axes):
self.create_variable(name, "f8", (name,))
self.set_variable(
name,
Expand Down Expand Up @@ -313,7 +313,7 @@ def _set_mesh_dimensions(self):
def _set_mesh_coordinate_data(self):
dims = self.node_data_dimensions
# for (name, axis) in zip(self.node_coordinates, self.field_axes):
for (name, axis) in zip(self.node_data_dimensions, self.field_axes):
for name, axis in zip(self.node_data_dimensions, self.field_axes):
self.create_variable(name, "f8", dims)
self.set_variable(
name,
Expand Down Expand Up @@ -367,7 +367,7 @@ def _set_mesh_coordinate_data(self):
dims = self.node_data_dimensions
# for (name, axis) in zip(self.node_data_dimensions, self.field_axes):
# for (name, axis) in zip(self.node_coordinates, self.field_axes):
for (axis, name) in enumerate(self.node_coordinates):
for axis, name in enumerate(self.node_coordinates):
self.create_variable(name, "f8", dims)
self.set_variable(
name,
Expand Down
2 changes: 1 addition & 1 deletion pymt/services/constant/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def initialize(self, filename):
scalar_vars = yaml.safe_load(opened.read())

self._vars = {}
for (name, value) in scalar_vars.items():
for name, value in scalar_vars.items():
self._vars[name] = np.array(value, dtype=float)

self._shape = (1,)
Expand Down
4 changes: 2 additions & 2 deletions pymt/services/gridreader/interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def get_time_series_values(field, ordering="ascending", prefix=""):

names = sort_time_series_names(field, ordering=ordering, prefix=prefix)

for (var_name, ordered_names) in names.items():
for var_name, ordered_names in names.items():
for name in ordered_names:
values[var_name].append(field.get_values(name))

Expand All @@ -29,7 +29,7 @@ def create_interpolators(times, fields, prefix="", kind="linear"):

names = sort_time_series_names(fields.keys(), prefix=prefix, ordering="ascending")

for (var_name, ordered_names) in names.items():
for var_name, ordered_names in names.items():
interpolators[var_name] = create_interpolator(
fields, zip(ordered_names, times), kind=kind
)
Expand Down
2 changes: 1 addition & 1 deletion pymt/services/gridreader/time_series_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def sort_time_series_names(names, ordering="ascending", prefix=""):
time_stamps = extract_time_stamps_from_names(
names, ordering=ordering, prefix=prefix
)
for (name, stamps) in time_stamps.items():
for name, stamps in time_stamps.items():
ordered_names[name] = [unsplit(name, stamp) for stamp in stamps]

return ordered_names
Expand Down
2 changes: 1 addition & 1 deletion pymt/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def add_recurring_events(self, events):
except AttributeError:
event_items = events

for (event, interval) in event_items:
for event, interval in event_items:
self.add_recurring_event(event, interval)

def add_recurring_event(self, event, interval):
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ landlab>=2
matplotlib
model_metadata>=0.7
netcdf4
numpy
numpy<1.24 # for Ku
pyyaml
scipy
shapely
scipy<1.9 # see #162
shapely<2 # see #164
xarray
# cfunits
# esmpy
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from setuptools import setup

setup()
setup(
name="pymt", # for GitHub dependency graph
)
Loading