Skip to content

Fix xarray to grib from temporal accumulation - #799

Merged
sandorkertesz merged 6 commits into
developfrom
feature/xarray-to-grib-from-temporal-accumulation
Sep 9, 2025
Merged

Fix xarray to grib from temporal accumulation#799
sandorkertesz merged 6 commits into
developfrom
feature/xarray-to-grib-from-temporal-accumulation

Conversation

@sandorkertesz

@sandorkertesz sandorkertesz commented Sep 9, 2025

Copy link
Copy Markdown
Collaborator

Description

This PR fixes the issue when Xarray generated from GRIB data containing temporal accumulation was not correctly written back to GRIB.

The problem can be demonstrated with this code:

import earthkit.data as ekd

input_dir = "... /cama_step1/"
output_dir = "./"
 
year_str="1979"

# Load dataset
ds_snow = ekd.from_source("file", f"{input_dir}iqtn_{year_str}.grib")
   
# Convert to xarray
ds_snow_xr = ds_snow.to_xarray(time_dim_mode="valid_time")
  
# Write back to GRIB
ds_snow_xr_daily.earthkit.to_grib( f"{output_dir}snow_daily_{year_str}.grib")

It produces a GRIB file with incorrect time. E.g. in message 20 we see:

dataDate: 19790120
dataTime: 0
endSte:6
validityDate: 19790101
validityTime: 600

Contributor Declaration

By opening this pull request, I affirm the following:

  • All authors agree to the Contributor License Agreement.
  • The code follows the project's coding standards.
  • I have performed self-review and added comments where needed.
  • I have added or updated tests to verify that my changes are effective and functional.
  • I have run all existing tests and confirmed they pass.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.72%. Comparing base (1733b6f) to head (7f91337).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #799      +/-   ##
===========================================
+ Coverage    85.68%   85.72%   +0.03%     
===========================================
  Files          172      172              
  Lines        13193    13222      +29     
  Branches       637      640       +3     
===========================================
+ Hits         11305    11334      +29     
  Misses        1698     1698              
  Partials       190      190              

☔ 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.

@sandorkertesz
sandorkertesz merged commit c312172 into develop Sep 9, 2025
260 checks passed
@sandorkertesz
sandorkertesz deleted the feature/xarray-to-grib-from-temporal-accumulation branch September 9, 2025 11:50
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