inigodelportillo / ITU-Rpy

A python implementation of the ITU-R P. Recommendations for atmospheric attenuation modeling
http://itu-rpy.readthedocs.io/en/latest/index.html
MIT License
121 stars 163 forks source link

P.836 surface_water_vapour_density for out of range percentages #5

Closed alastairUK closed 5 years ago

alastairUK commented 6 years ago

The handling of values < 0.1% and > 99% needs to be revised as I believe you get a nan returned at present.

This is what I did locally. But note: I am not a Python programmer so apologies in advance!

    if p in available_p:
        p_below = p_above = p
        pExact = True
    else:
        if p < available_p[0]:
            p_below = p_above = available_p[0]
            pExact = True
        elif p > available_p[len(available_p) - 1]:
            p_below = p_above = available_p[len(available_p) - 1]
            pExact = True
        else:
            pExact = False
            idx = available_p.searchsorted(p, side='right') - 1
            idx = np.clip(idx, 0, len(available_p) - 1)

            p_below = available_p[idx]
            idx = np.clip(idx + 1, 0, len(available_p) - 1)
            p_above = available_p[idx]
iportillo commented 6 years ago

The ITU-R P.836 Recommendation does not define values for the water_vapour_density and the total_water_content below 0.1% and above 99%, so that's why it returns NaN.

In any case, for clarity purposes I will add a warning to let the users know it when they introduce values of 'p' smaller/larger than these quantities

From a practical standpoint, I wouldn't mind using the value for p=99% for values larger than 99% (by clipping it from above), since the difference will be really small, but using the value of p=0.1% for values below 0.1% might lead to significant errors, as the differences can be very big as these quantities have an exponential behavior when one gets to very small values of p.

In any case, most of the ITU-Recommendations do not need to compute values for the surface vapour density and total water content below these numbers, even when one wants to compute values for the total atmospheric attenuation for p<0.1. For example, Section 2.5 of ITU-R P.618 says that for p < 1%

a large part of the cloud attenuation and gaseous attenuation is already included in the rain attenuation prediction for time percentages below 1%.

This means that if you were to compute the total atmospheric attenuation for p=0.1 %, you would need the values of A_rain(p=0.1%), A_cloud(p=1%), A_gas(p=1%), and A_scintillation(p=0.1%).

alastairUK commented 6 years ago

Adding a warning is likely the best option. As you say the Rec. doesn't define values for < 0.1, > 99 so can't really do anything standard. It was just I was getting a divide by 0 error I believe when I passed in 99.9 so thought I would stop that happening with the above code change.

I have some other comments on P676. Should I raise another issue?

iportillo commented 6 years ago

Hi @alastairUK, yes, please raise a new issue. Thank you so much for the feedback.