1

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?

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
  • 1
    As you've tagged the question [tag:fortran], do you know how to write a Fortran program which reads a NetCDF variable? How to write a Fortran program which creates a NetCDF file? How to refer to parts of a Fortran array? How to write a Fortran program which writes a variable to a NetCDF file? If you can do all of those, you can do your whole task; if there's one of those you can't do, ask for specific details on that. (If you can do none, then this question is likely too broad for useful answers.) – francescalus Aug 10 '22 at 13:26
  • you need to specify what the dimension is... if the 1000 dimension is time then this is easy to do in cdo or nco in one line – ClimateUnboxed Aug 10 '22 at 14:30
  • This question needs more clarity. You have tagged cdo, but CDO does not deal with dimensions in the abstract, instead it works with space and time . As suggested above revise the question to state what the dimension is – Robert Wilson Aug 10 '22 at 18:36
  • HI @francescalus. thank you for your valuable comment. I am not familiar with writing data into nc file using Fortran so, I have updated the question and asked with specific detail. – Vijay Kumar Sagar Aug 11 '22 at 12:49
  • Hi @AdrianTompkins and thanks for your detailed comment. I have specified the dimensions detail in the question. – Vijay Kumar Sagar Aug 11 '22 at 12:55
  • Hi @RobertWilson, thanks for your detailed comment. I have added more detail to the question as per the suggestions. I need some hints to solve this problem – Vijay Kumar Sagar Aug 11 '22 at 12:57
  • @VijayKumarSagar I am still not clear on what the dimensions/coordinates actually are. I asked above what they were, but you haven't added them to the question. Do you want to subset timesteps? This kind of info will help us provide an answer – Robert Wilson Aug 11 '22 at 13:39
  • @RobertWilson if I understood correctly, this is an unstructured grid for drifter data, so there is only one dimension "row", and then the lat, lon and data are all variables that are a function of "row"... I attempt a nco solution based on that premise – ClimateUnboxed Aug 11 '22 at 14:21
  • also update the question to this effect, I hope I interpreted it correctly. – ClimateUnboxed Aug 11 '22 at 14:26
  • 1
    @AdrianTompkins I think you are correct. In that case there is probably no CDO solution. NCO is likely the way to go. – Robert Wilson Aug 11 '22 at 14:37
  • Thank you @AdrianTompkins for suggestions and editing the question for correct interpretations. – Vijay Kumar Sagar Aug 12 '22 at 07:32

1 Answers1

2

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.

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
  • 1
    This is what I was expecting and it is very helpful. You have added extra words "https://https" in the referred link. Please edit it. Thank you. – Vijay Kumar Sagar Aug 12 '22 at 07:47