-3

I would appreciate it if someone can assist with a code to calculate the "specific number of heatwaves days where relative humidity > 66% and < 33%". (whereas, a heatwave event is defined as one in which temperatures exceeded the 90th percentile of the daily mean temperature for at least three consecutive days, respectively).

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
Farhan
  • 3
  • 1
  • 1
    Welcome to SO. When asking questions please provide evidence that you have tried to solve the problem yourself. Do not simply ask for people to provide you with code. This website is not supposed to be a free code writing service – Robert Wilson Aug 10 '22 at 07:15
  • 1
    I had the same comment in fact... – ClimateUnboxed Aug 10 '22 at 08:48

1 Answers1

1

Ok well here is a solution

# temperature percentile
cdo timpctl,90 infile -timmin infile -timmax t2m.nc t2m_pcen90.nc

# mask the temperature
cdo ge t2m.nc t2m_pcen90.nc mask.nc

# Need to make sure we have three consecutive days
cdo --timestat_date last runmean,3 mask.nc mask3.nc
cdo gec,1 mask3.nc heatwave_T.nc 

# Now filter for dry heatwaves, assuming RH is %, change X if fraction
cdo lec,33 rh.nc rhdry.nc
cdo mul heatwave_T.nc rhdry.nc heatwave_dry.nc 

# and same for wet
cdo gec,66 rh.nc rhwet.nc
cdo mul heatwave_T.nc rhwet.nc heatwave_wet.nc 

Each file should have a 1 in it for each location/time when you are in a heatwave according to your definition. Of course the metadata is appropriate for T2m not the index, use NCO to change that if required. I have several video guides that would help with this question, the key one being the one on masking (it doesn't include the running mean part though). Note also that the RH criterion is applied ONLY on the day (no running mean) but that is how you write the definition in your question. Duplicate the running mean part if needed.

ps: In general it is good to show that you have attempted a solution yourself, before asking, SO guidelines are that questions are of a debugging nature, or can be a request for a one-liner, but not coding requests like "write me a code that does X or Y" - I think that is why you were getting downvoted.

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
  • 1
    Similar to something I coded recently. I fixed the runmean line. Is percentile correct? This seems to be incorrectly defined in the OP. Terrestrial heat waves are typically defined in reference to the 90th percentile of the hottest day of the year. It's not clear what the OP's baseline is – Robert Wilson Aug 10 '22 at 07:27
  • hmmm, I was coding according to the definition in the question, but I think I saw several talks at a workshop we held in India where the definition was in terms of the daily temperature but for the summer months only, and was assuming the OP was using summer data only... I think that 90%tile of the hottest day of the year for 3 days running would be extremely strict, you would get a heatwave once every couple of decades no? I need to read a bit of literature, but super snowed under at the moment unfortunately :-( – ClimateUnboxed Aug 10 '22 at 08:47
  • 1
    ps: I forgot to say thanks for catching my runmean bug :-) – ClimateUnboxed Aug 10 '22 at 08:54
  • 1
    That's roughly how it's done. Though typically rolling time windows are used. First you calculate the 90th percentile within a window, then you calculate the maximum of that to get the threshold. See Fig . 4 here https://rmets.onlinelibrary.wiley.com/doi/pdf/10.1002/wea.3629. Though I only work on marine heat waves where heat waves can occur any time of year – Robert Wilson Aug 10 '22 at 09:13
  • Thanks for reference interesting... But they also base their index on the daily data, as per this questions definition (i.e. not the hottest day of the year), the only difference is that they use the daily T_max instead of daily T_mean. Their thresholds are 90%tile of July days, but I think I've seen some use a longer summer window. They also put in an arbitrary minimum threshold of 25C, so I expect heatwaves are virtually absent in the north in their def. Nice. – ClimateUnboxed Aug 10 '22 at 12:50
  • Hi AdrianTompkins and Robert Wilson, thank you for the help and for providing the code, next time I will also share the code with error messages. I am sorry for the late response, thanks once again. Regards, Farhan – Farhan Oct 11 '22 at 15:06