1

I currently have several netCDF4 files with a variable "pp" with three dimensions: pp(time, lat, lon). Each separate file has monthly soil moisture data for a year, and the time dimension stands for each month in the year. This is an example of the pp variable in the p04 file, which stores date for 2004:

p04.variables['pp']
Out[56]: 
<class 'netCDF4._netCDF4.Variable'>
int16 pp(time, lat, lon)
    _FillValue: -999.9
    units: mm
    long_name: Total precipitation
    add_offset: 19.0333409628
    scale_factor: -0.000580886924338
unlimited dimensions: 
current shape = (12, 8520, 7320)
filling on

I would like to add a fourth unlimited dimension so that the variable would have the shape pp(unl, time, lat, lon) and I could aggregate with MFDataset the multiple files from different years. I have tried to use createDimension but it erases all the information in the data.

I was looking for a way to add this extra dimension without having to re-write all the files. How would I do that? Thanks!

2 Answers 2

2

NCO's ncecat concatenates files by creating a new unlimited "glue" dimension:

ncecat -u unl in*.nc out.nc
Sign up to request clarification or add additional context in comments.

Comments

0

It might be a little late to answer, are you using 'w' mode to edit your files? The 'w' mode overwrites everything and creates new values which is why all the existing information gets erased. Please use the 'r+' mode - which will read and write to existing values / file info - and won't create an entirely new file.

Instead of ds = nc.Dataset(file,mode='w')

Use ds = nc.Dataset(file,mode='r+')

Comments

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.