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

Saving a subset of a file #268

Closed
nicholasbalasus opened this issue Sep 25, 2024 · 1 comment
Closed

Saving a subset of a file #268

nicholasbalasus opened this issue Sep 25, 2024 · 1 comment

Comments

@nicholasbalasus
Copy link

Not a bug but a question... Is there a simple way to save a subset of a file? For example, how to save ds_subset as a new netCDF here (or modify the existing in-place):

using NCDatasets

src = "https://www.unidata.ucar.edu/software/netcdf/examples/tos_O1_2001-2002.nc"
dst = "tos_O1_2001-2002.nc"
download(src, dst)

ds = NCDataset("tos_O1_2001-2002.nc", "r")
ds_subset = NCDatasets.@select(ds, -10 <= lon <= 10 && -10 <= lat <= 10)
@nicholasbalasus
Copy link
Author

I can't get it to work with the example above, but the following works for my specific netCDF file so I'll close this for now (based on this).

using NCDatasets

src = "http://geoschemdata.wustl.edu/ExtData/GEOS_0.5x0.625/MERRA2/2018/05/MERRA2.20180501.A1.05x0625.nc4"
dst = "MERRA2.20180501.A1.05x0625.nc4"
download(src, dst)

ds_all = NCDataset(dst, "r")
ds_afr = NCDataset(replace(dst, ".nc4" => ".crop.nc4"), "c")
write(ds_afr, NCDatasets.@select(ds_all,
      -21.25 <= lon <= 55.0 && -38.5 <= lat <= 42.0))
close(ds_afr)
close(ds_all)

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

1 participant