Open sgana1 opened 4 months ago
Where would you like to add that description? As metadata in the NetCDF file?
Yes, exactly! As metadata in the NetCDF file. Thank you.
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.
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) .tonetcdf(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.