climate_indices icon indicating copy to clipboard operation
climate_indices copied to clipboard

Daily/Weekly Inputs for other indices (not just SPI and PNP)?

Open wsor330 opened this issue 3 years ago • 6 comments

Is your feature request related to a problem? Please describe. No

Describe the solution you'd like Daily and/or Weekly Inputs (Higher temporal resolution)

Describe alternatives you've considered Only use daily SPI and/or use in conjunction with monthly SPI/SPEI

Additional context Is this possible? or is it not viable at all?

wsor330 avatar Aug 19 '21 06:08 wsor330

linked to #101

wsor330 avatar Aug 19 '21 06:08 wsor330

I initially opened the issue because it is mentioned in the docs (https://climate-indices.readthedocs.io/en/latest/) that "NOTE: Only SPI and PNP support daily inputs."

When you try to compute the SPEI with rainfall and temperature inputs, you do get an error that daily inputs are not supported Like so:

spei = indices.spei(scale=scale_ci, 
                    distribution=gamma, 
                    periodicity=period, 
                    data_start_year=1985, 
                    calibration_year_initial=1985, 
                    calibration_year_final=2017, 
                    precips_mm=rain.values.flatten(),  
                    temps_celsius=temp, 
                    latitude_degrees=lats)
ValueError: Unsupported periodicity: 'daily' -- only monthly time series is supported when providing temperature and latitude inputs

However, when you compute the PET before hand, this does not seem to be the case, i.e. no errors/warnings and contradictory to the Note on the docs. Like so:

pet = indices.pet(temperature_celsius=temp, latitude_degrees=lats, data_start_year=1985)
spei = indices.spei(scale=scale_ci, 
                    distribution=gamma, 
                    periodicity=period, 
                    data_start_year=1985, 
                    calibration_year_initial=1985, 
                    calibration_year_final=2017, 
                    precips_mm=rain.values.flatten(),  
                    pet_mm=pet)

I tested this on monthly dataset, where I get exactly the same index results from both methods above. However, for the daily inputs, we get an error as expected for the first method, but not the second method.

Am I missing something?

edit: I checked the docstring of the spei() function from the list of climate indices, and it says periodicity supports both monthly/daily data?

wsor330 avatar Aug 19 '21 08:08 wsor330

Thanks for your focus on this issue, @wsor330

Bear in mind that I wrote this code years ago, so my memory is foggy. I think the reason for not being able to compute PET on a daily basis has to do with the Thornthwaite algorithm being only for monthly data?

monocongo avatar Aug 19 '21 13:08 monocongo

Hi James,

Thanks. That was what I was worried about. climate_indices.pet() assumes temperature_celsius is of monthly dataset (even if you input daily dataset, it will be treated as monthly). I would suggest then, if you like, to place a trigger for an error/warning inside climate_indices.pet(). This would then be consistent with the error given when providing daily temperature data to climate_indices.spei().

In the mean time I will also look at what @Emmadd have suggested in #101

Cheers

wsor330 avatar Aug 19 '21 13:08 wsor330

I started working out the makkink formulation for PET but found the climate_indices code too complex to start from there. I'll share the basic function here and in #101, so someone else can implement it if wanted.

def makkink_KNMI(TG, Q):
    #input in [degC] and [W/m2]
    T = TG - 273.15  #[degC]
    #1) verzadigde dampspanning tov water
    e_s = 6.107 * 10**(7.5 * (T / (237.3 + T)))   #[hPa]
    #2) verzadigde dampspanningsgradient tov water
    delta = ((7.5 * 237.3) /  (T + 237.3)**2) * np.log(10) * e_s   #[hPa/degC]
    #3) psychrometerconstante (afhankelijk van T)
    gamma = 0.646 + (0.0006 * T)   #[hPa/degC]
    #4) verdampingswarmte van water
    labda = 1000 * (2501 - (2.38 * T))   #[J/kg]
    #5) soortelijke massa van water
    rho = 1000   #[kg/m3]
    #verdamping
    Ev = ( (1000 * 0.65 * delta) / ((delta + gamma) * rho * labda) ) * Q   #[mm/day] = [kg/m2/day]
    return Ev

Documentation (sorry, in Dutch) is available here for example https://www.knmiprojects.nl/projects/handboek-waarnemingen/documents/publications/2006/01/01/h10-verdamping

Instead I was trying to work out SPEI with the Fisk (log-logistic) distribution as an option in addition to the current Gamma and PearsonIII options. I'd be really interested in daily SPEI if both these things work and starting with Fisk seemed more fit for my level of python skills ;-) I'll let you know when my branch is ready to be pulled :-)

Emmadd avatar Aug 19 '21 14:08 Emmadd

Rock on, @Emmadd. This will be related to #106 , pull requests are very welcome!

monocongo avatar Aug 20 '21 16:08 monocongo