steve
steve

Reputation: 531

Python - merging netcdf files having time duplicates

I have several netCDF files from MODIS satellite data. I would like to merge those files. For that I am using the followings commands (in python):

data = data_1.merge(data_2)

or I just open the files using the following:

data = xr.open_mfdataset('MCD43A3*.nc')

My problem is that the end of 1 file is a the duplicate of the beginning of the next file. so I end up with files having duplicates:

lat;lon;time;var1;var2
10;10;2000-01-01;22;55
      2000-01-02;12;87
      2000-01-03;57;65
      2000-01-04;45;67
      2000-01-04;45;67
      2000-01-05;78;15

How can I either remove the last timestamp of the time series or merge without having duplicates?

note: the input files have a julian calendar therefore and unfortunately CDO/NCO commands does not work

Upvotes: 1

Views: 577

Answers (2)

ClimateUnboxed
ClimateUnboxed

Reputation: 8067

Were you using the CDO command "seldate" to make the selection?

You might still be able to do it using seltimestep:

cdo seltimestep,first/last in.nc out.nc 

Another option might be to try and convert the calendar first using

cdo setcalendar,standard in.nc out.nc 

and then using seldate...

Upvotes: 2

Robert Davy
Robert Davy

Reputation: 910

I think you should be able to use nco. e.g. if you have 4 timestamps and want to remove the last one,

ncks -d time,0,2 in.nc out.nc

or remove the first one:

ncks -d time,1,3 in.nc out.nc

Upvotes: 2

Related Questions