Skip to content

from_ugrid_conventions crashes with opaque TypeError for extra variables with unsupported dimension layouts #2674

@fluidnumericsJoe

Description

@fluidnumericsJoe

Parcels version

v4

Description

When ingesting a ux.UxDataset, the loop in FieldSet.from_ugrid_conventions that handles non-U/V/W variables (src/parcels/_core/fieldset.py:223) passes the result of _select_uxinterpolator straight into Field(...):

  for varname in set(ds.data_vars) - set(fields.keys()):
      fields[varname] = Field(str(varname), ds[varname], grid, _select_uxinterpolator(ds[varname]))

_select_uxinterpolator only supports four (vertical, lateral) dimension pairs (zc/zf × n_face/n_node). For any other layout (e.g. an edge-registered variable on n_edge) it returns None, and that None is used as the field's interp_method. The Field constructor then fails in assert_same_function_signature with:

  TypeError: None is not a callable object

The error gives no indication of which variable or dimension caused it.

Code sample

  import numpy as np
  import uxarray as ux

  from parcels import FieldSet
  from parcels._datasets.unstructured.generic import datasets
  from parcels.convert import icon_to_ugrid

  ds = icon_to_ugrid(datasets["icon_square_delaunay_uniform_z_coordinate"].copy(deep=True))

  # Add an edge-registered tracer -> (zc, n_edge) has no supported interpolator
  ds = ds.assign(
      edge_tracer=ux.UxDataArray(
          data=np.ones((ds.sizes["time"], ds.sizes["zc"], ds.uxgrid.n_edge)),
          dims=["time", "zc", "n_edge"],
          coords={"time": ds.time, "zc": ds.zc},
          uxgrid=ds.uxgrid,
      )
  )

  FieldSet.from_ugrid_conventions(ds, mesh="flat")
  INFO: Using known vertical dimension mapping: 'depth_2' (interfaces) and 'depth' (centers).
  INFO: Renaming vertical dimensions: {'depth_2': 'zf', 'depth': 'zc'}
  Traceback (most recent call last):
    File "/tmp/repro.py", line 20, in <module>
      FieldSet.from_ugrid_conventions(ds, mesh="flat")  # TypeError: None is not a callable object
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
    File ".../src/parcels/_core/fieldset.py", line 224, in from_ugrid_conventions
      fields[varname] = Field(str(varname), ds[varname], grid, _select_uxinterpolator(ds[varname]))
                        ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File ".../src/parcels/_core/field.py", line 132, in __init__
      assert_same_function_signature(interp_method, ref=ZeroInterpolator, context="Interpolation")
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File ".../src/parcels/_python.py", line 30, in assert_same_function_signature
      sig = inspect.signature(f)
    File ".../lib/python3.14/inspect.py", line 3323, in signature
      return Signature.from_callable(obj, follow_wrapped=follow_wrapped, ...)
    File ".../lib/python3.14/inspect.py", line 3038, in from_callable
      return _signature_from_callable(obj, sigcls=cls, ...)
    File ".../lib/python3.14/inspect.py", line 2436, in _signature_from_callable
      raise TypeError('{!r} is not a callable object'.format(obj))
  TypeError: None is not a callable object

Metadata

Metadata

Labels

bugneeds-triageIssue that has not been reviewed by a Parcels team memberunstructured gridsDevelopment of unstructured grids supportv4

Type

No type
No fields configured for issues without a type.

Projects

Status
Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions