making time series mask file from single time threshold
Added by Heidrun Matthes over 1 year ago
Hi everyone,
I have a file cointaining daily snow data for several years. I computed the first day of snow in winter using the muldoy functionality
cdo yearmin -selmonth,7/12 -setctomiss,0 -muldoy -gtc,0.0 daily_snow.nc doy_of_first_snow.nc
What I now need is a mask that sets all days before this day to zero, and all days afterwards to 1. I do have a solution where I split up my files into seperate years, then apply muldoy to a file conatining only ones for each time step to create a day of year time series, and then mask this with the result in doy_of first_snow.nc for that year.
#create file with time steps of daily_snow containing only ones
cdo gec,0.0 daily_snow.nc ones.nc
#create file containing day of year for every time step
cdo muldoy ones.nc doy.nc
#year loop
for iyear in years do
#create file for one year containing day of first snow in every time step
cdo mul -selyear,$iyear doy_of_first_snow.nc -selyear,${iyear} ones.nc doy_first_snow_fill_${iyear}.nc
#create mask
cdo gt -selyear,${iyear} doy.nc doy_first_snow_fill_${iyear}.nc mask_doy_first_snow_${iyear}.nc
done
#merge mask files into one file
cdo mergetime mask_doy_first_snow_????.nc mask_doy_first_snow.nc
However, for long time series, this is rather tedious, slow and creates many interim files. I played around with piping commands to reduce the number of intermediate files, but mul is rather picky with what kinds of pipes arguments can have, so I could not make it shorter than what I have above. I wonder if there is a more streamline solution?
Thanks for your help!
Best, Heidrun
Replies (2)
RE: making time series mask file from single time threshold - Added by Estanislao Gavilan over 1 year ago
Hi Heidrun,
The only thing that I would change from that script would be cat intead of mergetime. I think you could also see the problem with a different point of view. You can use part of you script to find the specific date, then extract them into a new file.
Kind regards,
Estanislao
RE: making time series mask file from single time threshold - Added by Heidrun Matthes over 1 year ago
Dear Estanislao,
thank you for your comment! This is actually a simplified example of what I try to do. The snow data is gridded data, so the first day of snow will be different for every grid point. I don't see how I could use the doy_of_first_snow to extract the time steps I want, since they would be different for each grid point. Also, that approach still requires a split of the time series into seperate years. Maybe there really is no way around that.
Best, Heidrun