简体   繁体   中英

How to split NetCDF file into multiple NetCDF files based on indices of dimension?

I have a single NetCDF file with some identically sized variables in it. I am trying to save all data into different NetCDF files based on dimensions. For example, each variable in a NetCDF file has data in one dimension called "row" with a size of 1000 datapoints. How can I create three different NetCDF files, splitting the data into the first 300 points, then 400 and the last with the final 300 points?

The data type, variables, variable full name, and units are as below respectively:

float latitude(row=1000), long_name = "Latitude", units = "degrees_north";
float longitude(row=1000), long_name = "Longitude", units = "degrees_east";
float ve(row=1000), long_name = "Eastward velocity", units = "m/s";
float vn(row=1000), long_name = "Northward velocity", :units = "m/s";
double time(row=1000), long_name = "Time", units = "seconds since 1970-01-01T00:00:00Z";
char ID(row=1000, ID_strlen=8), long_name = "Global Drifter Program Buoy ID";
int WMO(row=1000), long_name = "World Meteorological Organization buoy identification number";
etc...

The row numbers are the same across all variables. Also note that there are different types of data such as "double", "char","float", and "int". Row values like 300, 400, and 300 should appear in the output NetCDF files, and the column values should match those in the primary files for the corresponding variables. Other dimensions and parameters shouldn't change. Is it possible to do it using Python or CDO?

You can use nco to split data according to a index according to this answer :

ncks -d row,1,300 in.nc -O row1_300.nc
ncks -d row,301,700 in.nc -O row301_700.nc

etc...

ps: careful with ncks selection, if you use float values it splits using the dimension entry, not the index. If the row entry is simply counting 1,2,3,4 etc then this doesn't matter as the index and value are identical.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM