Skip to content

refactor: Deprecate DataContainer and replace with xarray#168

Merged
henry2004y merged 4 commits into
mainfrom
feature-deprecate-datacontainer
Nov 18, 2025
Merged

refactor: Deprecate DataContainer and replace with xarray#168
henry2004y merged 4 commits into
mainfrom
feature-deprecate-datacontainer

Conversation

@henry2004y

@henry2004y henry2004y commented Nov 18, 2025

Copy link
Copy Markdown
Owner
  • The custom DataContainer class has been deprecated and replaced with xarray.Dataset.
  • An xarray accessor fleks has been created to house the domain-specific logic for calculating derived variables and plotting.
  • The get_slice and get_domain methods in flekspy/yt/yt.py now return xarray.Dataset objects.
  • All relevant tests have been updated to use the new xarray-based API.
  • The plot_slice method in flekspy/yt/yt.py has been updated to use the new fleks accessor.

Superceded #57

- The custom `DataContainer` class has been deprecated and replaced with `xarray.Dataset`.
- An `xarray` accessor `fleks` has been created to house the domain-specific logic for calculating derived variables and plotting.
- The `get_slice` and `get_domain` methods in `flekspy/yt/yt.py` now return `xarray.Dataset` objects.
- All relevant tests have been updated to use the new `xarray`-based API.
- The `plot_slice` method in `flekspy/yt/yt.py` has been updated to use the new `fleks` accessor.
@codecov

codecov Bot commented Nov 18, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.78832% with 91 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.55%. Comparing base (d791c90) to head (eabe081).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/flekspy/xarray/accessor.py 63.15% 77 Missing ⚠️
src/flekspy/yt/yt.py 69.56% 14 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #168      +/-   ##
==========================================
+ Coverage   68.05%   77.55%   +9.50%     
==========================================
  Files          26       27       +1     
  Lines        4232     4157      -75     
==========================================
+ Hits         2880     3224     +344     
+ Misses       1352      933     -419     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a significant and valuable refactoring that replaces the custom DataContainer with the more standard and powerful xarray.Dataset. The introduction of the fleks accessor to encapsulate domain-specific logic is an excellent design choice that improves modularity. My review focuses on a few areas where functionality appears to have been lost during the transition, particularly in the plotting methods. I've also included some suggestions to improve the robustness and maintainability of the new accessor code.

Comment thread src/flekspy/xarray/accessor.py
Comment thread src/flekspy/xarray/accessor.py Outdated
Comment thread src/flekspy/xarray/accessor.py Outdated
Comment thread src/flekspy/xarray/accessor.py Outdated
google-labs-jules Bot and others added 3 commits November 18, 2025 14:31
- The custom `DataContainer` class has been deprecated and replaced with `xarray.Dataset`.
- An `xarray` accessor `fleks` has been created to house the domain-specific logic for calculating derived variables and plotting, including `plot`, `add_contour`, and `add_stream`.
- The `get_slice` and `get_domain` methods in `flekspy/yt/yt.py` now return `xarray.Dataset` objects and propagate metadata attributes.
- The `plot` method in the `FleksAccessor` now correctly displays metadata on the plot.
- All relevant tests have been updated to use the new `xarray`-based API.
- The `plot_slice` method in `flekspy/yt/yt.py` has been updated to use the new `fleks` accessor.
- The expression for calculating `ps` in the `FleksAccessor` has been updated to use an f-string for improved readability.
- The custom `DataContainer` class has been deprecated and replaced with `xarray.Dataset`.
- An `xarray` accessor `fleks` has been created to house the domain-specific logic for calculating derived variables and plotting, including `plot`, `add_contour`, and `add_stream`.
- The `get_slice` and `get_domain` methods in `flekspy/yt/yt.py` now return `xarray.Dataset` objects and propagate metadata attributes.
- The `plot` method in the `FleksAccessor` now correctly displays metadata on the plot using the `bottomline` parameter and uses `np.isclose` for robust float comparisons.
- All relevant tests have been updated to use the new `xarray`-based API.
- The `plot_slice` method in `flekspy/yt/yt.py` has been updated to use the new `fleks` accessor.
- The expression for calculating `ps` in the `FleksAccessor` has been updated to use an f-string for improved readability.
@henry2004y

Copy link
Copy Markdown
Owner Author

/gemini summary

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

This pull request significantly refactors the data handling and plotting infrastructure by deprecating the custom DataContainer classes in favor of xarray.Dataset. This transition leverages a robust, community-maintained library for multi-dimensional labeled arrays, enhancing data interoperability and simplifying future development. A new fleks accessor for xarray.Dataset centralizes domain-specific logic for variable calculations and plotting, leading to a more consistent and maintainable API.

Highlights

  • Data Container Deprecation: The custom DataContainer class and its 1D, 2D, and 3D variants have been entirely removed from flekspy.util, streamlining the data handling architecture.
  • Xarray Integration: xarray.Dataset is now utilized as the primary data structure for managing simulation data, leveraging a robust, community-maintained library.
  • Flekspy Xarray Accessor: A new fleks accessor has been introduced for xarray.Dataset objects, centralizing domain-specific logic for variable evaluation, plotting, and the addition of stream and contour lines.
  • API Updates: The get_slice and get_domain methods in flekspy/yt/yt.py now consistently return xarray.Dataset objects, aligning with the new data structure.
  • Plotting Enhancements: The plotting functionality, including plot, add_contour, and add_stream, has been re-implemented within the fleks accessor, improving consistency and leveraging xarray's capabilities.
  • Test Suite Modernization: All relevant tests have been updated to align with the new xarray-based API and the fleks accessor, ensuring correctness and compatibility.
  • Documentation Alignment: Notebook examples in docs/amrex_data.ipynb have been updated to reflect the new fleks accessor usage for plotting and data access.
Changelog
  • docs/amrex_data.ipynb
    • Updated plotting examples to use the new dc.fleks.plot, dc.fleks.add_stream, and dc.fleks.add_contour methods.
    • Modified data access from dc.x.value to dc.X.values and dc.fleks.evaluate_expression.
    • Removed an 'Advanced Example: Slicing with Range Limits' section.
  • src/flekspy/util/init.py
    • Removed imports for DataContainer, DataContainer1D, DataContainer2D, and DataContainer3D.
  • src/flekspy/util/data_container.py
    • This file, containing the deprecated DataContainer classes, has been removed.
  • src/flekspy/xarray/init.py
    • New file introduced to import FleksAccessor.
  • src/flekspy/xarray/accessor.py
    • New file defining FleksAccessor, an xarray.Dataset accessor.
    • Includes methods for evaluate_expression, get_variable, analyze_variable_string, plot, add_contour, and add_stream, replicating and enhancing previous DataContainer functionality.
    • Incorporates np.isclose for robust floating-point comparisons in plotting.
    • Adds attributes like time, nstep, cut_norm, cut_loc, and filename to plot titles and figure text.
  • src/flekspy/yt/yt.py
    • Modified get_slice and get_domain methods to return xarray.Dataset objects instead of DataContainer instances.
    • Removed the plot_slice method, as plotting is now handled by the fleks accessor.
    • Updated imports to include xarray and flekspy.xarray.
    • Adjusted type hints to reflect xarray.Dataset returns.
  • tests/test_evaluate_expression.py
    • Updated calls to evaluate_expression to use amrex_dataset.fleks.evaluate_expression.
    • Adjusted assertions to compare against xarray.Dataset data variables (amrex_dataset["Bx"]) and their values (.values).
    • Removed matplotlib import.
  • tests/test_fleks.py
    • Updated test_pic to check for particle_id in dc.data_vars and access particle ID values using .item().
    • Added test_amrex_plot to verify the functionality of dc.fleks.plot, dc.fleks.add_contour, and dc.fleks.add_stream.
Activity
  • Gemini Code Assist provided an initial summary of the pull request.
  • Codecov reported a patch coverage of 66.78%, with 91 lines missing coverage, primarily in src/flekspy/xarray/accessor.py and src/flekspy/yt/yt.py.
  • Gemini Code Assist provided several review comments:
  • A high-priority comment noted the absence of add_contour and add_stream methods in the new FleksAccessor, suggesting a regression in plotting functionality. This has been addressed by re-implementing these methods.
  • A medium-priority comment recommended using f-strings for improved readability in variable expression construction, which was incorporated.
  • Another medium-priority comment highlighted that the bottomline parameter was unused and that previous functionality for displaying time, nstep, and filename on plots was missing. This was addressed by propagating attributes to xarray.Dataset and updating the plot method.
  • A final medium-priority comment suggested using np.isclose for more robust floating-point comparisons in plotting logic, which was implemented.
  • The author, henry2004y, requested a new summary from Gemini Code Assist.

Repository owner deleted a comment from gemini-code-assist Bot Nov 18, 2025
@henry2004y henry2004y merged commit 75fc771 into main Nov 18, 2025
2 of 3 checks passed
@henry2004y henry2004y deleted the feature-deprecate-datacontainer branch November 18, 2025 16:24
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.

1 participant