So I'm trying to work on my heatwave analysis and feel like I'm working in circles now. I do have hourly t2m data (.nc) for the region of germany for 15 years with a resolution of 0.25°.
What I need to do is to analyse the maximum average heatwave (consecutive tmax 30°C+ days) duration for each gridareas. So this means, let's say, in 2005 the longest heatwave was 7 days long, in 2006 9 days for a specific gridtile ... and so on, the average maximum heatwave duration for the whole time period would be 8 days in this example. At the end there should stand a new nc.file with the maximum average heatwave lenght for each grid.
What I already did and prepared: First of all, with daymax commands I generated a daymax nc file that shows the maximimum t2m value for that day; as daily resolution is sufficient for this task. With the gtc command I selected all 30°C+ values and replaced all 30+ values with 1 and all below 30 values with 0. Now I do have a nc file that shows for all gridtiles for everyday within my period 1 for heatdays and 0 for non heatdays. And this is where I'm stuck.
I would just love to count the longest series of "1" for each year and average this over my timeperiod.
All further commands I tried (different mean, counting commands) didnt suceed. Sometimes I lost my spatial reference and all the time the values were far from correct.
Does anyone of you may have some fitting commands or maybe a differnt way of solving this problem?
The key function here is consects
which calculates lengths of a condition being true. You can actually apply it on your raw temperature file (units oC) like this:
cdo consects -gtc,30.0 temperature.nc lens.nc
lens will have the length of each "heatwave" period, so now you can just apply yearmax to get the longest each year.
cdo yearmax -consects -gtc,30.0 temperature.nc longest.nc
If you want to apply it to your "binary" file then of course the condition changes:
cdo yearmax -consects -eqc,1 binary.nc longest.nc
By the way, one of my recent youtube videos was related closely to this topic, watch it for further details, but I didn't include this trick, so I'll have to add it to the video description. Nice use case!
NOTE ON YEAR BOUNDARIES
I haven't checked this but I presume the stamp of the output is placed at the last timestep of each series, so if a condition were true for the last 15 days on December and then just 3 days of the following year, this would still count as an event in the latter year in this case. I just wanted to highlight this. It might be also possible to use the command argument --timestat_date middle
with consects
, if so this would allocate the event to the year in which the majority of steps lie. I haven't tried this out though.