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

Adding description of the GFS variables in the netcdf file #15

Open
sgana1 opened this issue Jun 6, 2024 · 3 comments
Open

Adding description of the GFS variables in the netcdf file #15

sgana1 opened this issue Jun 6, 2024 · 3 comments

Comments

@sgana1
Copy link

sgana1 commented Jun 6, 2024

Dear Alberto,
I have used your notebook to extract wind and pressure data from:
gfs = f"https://nomads.ncep.noaa.gov/dods/gfs_0p25_1hr"
I have produced a netcdf file with u10m, v10m and prmsl (pressure at sea surface level) using:
with xr.open_dataset(url) as ds:
(
ds[var1]
.isel(time=slice(*time))
.sel(lat=slice(*lat), lon=lon)
.to_netcdf(f"{date}_{run:02d}_uv10prmsl.nc")
)

I woiuld like to add the description of the variables contained in the netcdf file par example:
u10m: x-component of the wind at 10m
u10m: y-componet of the wind at 10m
prmsl: atmospheric pressure at sea surface level.

How to proceed please?

Thank you.

@albertotb
Copy link
Owner

Where would you like to add that description? As metadata in the NetCDF file?

@sgana1
Copy link
Author

sgana1 commented Jun 6, 2024

Yes, exactly! As metadata in the NetCDF file. Thank you.

@albertotb
Copy link
Owner

albertotb commented Jun 6, 2024

The NetCDF should already have some metadata, although not exactly that. You can print it in the notebook with something like this:

with xr.open_dataset(url) as ds:
   ds1 = ds[var1].isel(time=slice(*time)).sel(lat=slice(*lat), lon=lon)
   # similar for the other variables
   print(ds1["u10m"].attrs)

ds1.to_netcdf(f"{date}_{run:02d}_uv10prmsl.nc")

If you want to change that metadata, you can just assign something to it:

ds1["u10m"].attrs["my_key"] = "my_arbitrary_metadata"

You can also print this metadata with external tools to Python like ncdump.

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

No branches or pull requests

2 participants