Skip to content

Conversation

@ecomodeller
Copy link
Member

@ecomodeller ecomodeller commented Jan 14, 2026

Summary

Remove spectral-specific attributes from DataArray to ensure consistent API across all geometry types. Spectral information is now accessed through geometry, maintaining a clear separation of concerns.

Migration path: Deprecated properties provide backward compatibility with warnings that guide users to the new API.

Why This Change?

DataArray should have a consistent interface regardless of geometry type. Previously, DataArrays with spectral geometries had extra attributes (frequencies, directions) that weren't available for other geometry types, creating an inconsistent API.

After this change:

  • ✅ All DataArrays have the same interface
  • ✅ Geometry-specific information stays in geometry
  • ✅ Easier to understand and maintain

Migration Guide

Accessing Spectral Metadata

Spectral information is now accessed through the geometry:

# Old (deprecated, shows warning)
freq = da.frequencies
n_freq = da.n_frequencies
dirs = da.directions
n_dirs = da.n_directions

# New - access through geometry
freq = da.geometry.frequencies
n_freq = da.geometry.n_frequencies
dirs = da.geometry.directions
n_dirs = da.geometry.n_directions

The old syntax still works but shows a FutureWarning pointing you to the new API.

Changes

What Changed

Old API New API Status
da.frequencies da.geometry.frequencies Deprecated with warning
da.n_frequencies da.geometry.n_frequencies Deprecated with warning
da.directions da.geometry.directions Deprecated with warning
da.n_directions da.geometry.n_directions Deprecated with warning

What Still Works

  • ✅ Reading spectral files: mikeio.read("spectrum.dfsu")
  • ✅ Plotting spectral data: da.plot() works unchanged
  • ✅ Accessing spectral geometry: da.geometry has all spectral metadata
  • ✅ All other DataArray operations

Implementation

  • Added deprecated properties with FutureWarning to guide users to new API
  • Properties forward to geometry so code continues to work during migration
  • Moved internal Hm0 calculation to plotting module (_calc_Hm0() helper)
  • Updated notebooks to use new da.geometry.frequencies pattern
  • Clearly marked deprecated section in code for easy future removal

Spectral information (frequencies, n_frequencies, directions,
n_directions) is now only available via geometry, not directly
on DataArray. This ensures DataArray has consistent attributes
across all geometry types.

Breaking changes:
- da.frequencies -> da.geometry.frequencies
- da.n_frequencies -> da.geometry.n_frequencies
- da.directions -> da.geometry.directions
- da.n_directions -> da.geometry.n_directions
- da.to_Hm0() removed (was only used internally for plotting)
@ecomodeller ecomodeller marked this pull request as ready for review January 24, 2026 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants