1

I am using a very big netcdf map file in python, and looking to "pull out" and save one variable in it (I don't need the rest). The orignal file is too large to open alone, I get the error "ValueError: array is too big; arr.size * arr.dtype.itemsize is larger than the maximum possible size." have to do this because the file is otherwise too big to use on my system.

I used:

ds2= netCDF4.Dataset("2020_original_Map.1.1.nc").variables['lccs_class']

This gets me the correct data in a size I can read, but then ds2 is <class 'netCDF4._netCDF4.Variable'>. I have tried all of the usual ways to save this as a netcdf, but none of them are working. Does anyone know how I save ds2 as it's own nc file, or another way to pull out 'llcs class' and save it separately? How can I make a new nc file and pass this variable into it?

Thanks a lot!

1 Answer 1

2

Using xarray, you can write :

import xarray as xr

xr.open_dataset("2020_original_Map.1.1.nc")[['lccs_class']].to_netcdf('outfile.nc')
Sign up to request clarification or add additional context in comments.

1 Comment

Unfortunately the original file is too big. I get "ValueError: array is too big; arr.size * arr.dtype.itemsize is larger than the maximum possible size."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.