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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Problem with NetCFD4 file from CDS #718

Open
robbestephan opened this issue Oct 30, 2024 · 1 comment
Open

BUG: Problem with NetCFD4 file from CDS #718

robbestephan opened this issue Oct 30, 2024 · 1 comment
Assignees
Labels
Bug Something isn't working Environment Enviroment Class related features

Comments

@robbestephan
Copy link

Describe the bug

I run into problems with my NetCFD4 file gathered from CDS.

To Reproduce
This is my code, the .nc file is not supported to add as an attachment here.
I gathered the data from here: https://cds.climate.copernicus.eu/datasets/reanalysis-era5-pressure-levels?tab=overview

from rocketpy import Environment
import os
dirname = os.path.dirname(__file__)

Env = Environment(
    date=(2024, 10, 21, 17),
    latitude=50.483618,
    longitude=6.181357,
    elevation=559,
)

filename = os.path.join(dirname, 'Elsenborn_pressure_levels_reanalysis_21oct24_Reanalysis.nc'),


Env.set_atmospheric_model(
    type='Reanalysis',
    file=filename,
    dictionary="ECMWF",
)

Env.plots.atmospheric_model()

Expected behavior

I expected to get plots of the atmosphere and eventually implement it into our simulations

Screenshots

Here is the data request I did from CDS:
image

Additional context

Add any other context about the problem here.

@Gui-FernandesBR Gui-FernandesBR changed the title Problem with NetCFD4 file from CDS BUG: Problem with NetCFD4 file from CDS Nov 2, 2024
@Gui-FernandesBR Gui-FernandesBR added Bug Something isn't working Environment Enviroment Class related features labels Nov 2, 2024
@Gui-FernandesBR Gui-FernandesBR self-assigned this Nov 2, 2024
@robbestephan
Copy link
Author

It seems that the NetCDF4 file I get from CDS have dict keys 'valid_time' instead of 'time' and 'pressure_level' instead of 'level' renaming them seems to have solved the problem

import xarray as xr

# Load the NetCDF file
file_path = "reanalysis.nc"
ds = xr.open_dataset(file_path)

# Rename time and pressure
ds = ds.rename({"valid_time": "time"})
ds = ds.rename({"pressure_level": "level"})

# Save the modified dataset
ds.to_netcdf("reanalysis_fix.nc")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Environment Enviroment Class related features
Projects
Status: Backlog
Development

No branches or pull requests

2 participants