<commit_before>﻿import math
import numba
from numba import jit


"""
SPH: Standard Project Hurricane
PMH: Probable Maximum Hurricane

Pressure profile equation

(p-Cp)/(Pw - Cp) = e ^ (-R/r)

Pw: Peripheral Pressure, pressure at edge of storm, should be a bit below MSLP
Cp: Central Pressure (P0 in paper)
Rmax: Radius of Maximum Winds (R in paper)
Fspeed: Forward speed of hurricane center (T in paper)
Dir: Track direction
Vgx: Maximum Gradient Winds
Rho0: Surace air density
r: distance (radius) from hurricane center
fcorr: Coriolis parameter, dependant on latitude
Vx: Observed maximum 10-m, 10-min winds over open water.  75% to 105% of Vgx.  Standard is 95%
    For moving hurricane: Vx = 0.95 * Vgx + (1.5 * T ^ 0.63 * To ^ 0.37 * cos(beta)
Vpt: 10m, 10min winds at a point (V in paper)
"""
Pw_SPH_kPa = 100.8
Pw_PMH_kPa = 102.0
Pw_SPH_inhg = 29.77
Pw_PMH_inhg = 30.12
Rho0_kPa = 101.325  # Mean Sea Level Pressure
KmToNmi = 0.539957
MpsToKts = 1.94384
KpaToInhg = 0.2953
MbToInhg = 0.02953

@jit(nopython=True,cache=True)
def linear_interpolation(x, x1, x2, y1, y2):
    """

    :param x:
    :param x1:
    :param x2:
    :param y1:
    :param y2:
    :return:
    """
    return ((y2 - y1) / (x2 - x1)) * (x - x1)

@jit(nopython=True,cache=True)
def radial_decay(r_nmi, rmax_nmi):
    """
    Calculates the radial decay factor for a given radius.
    Rmax_nmi < r_nmi: NWS 23 pdf page 53, page 27, Figure 2.12, empirical fit
    Rmax_nmi > r_nmi: NWS 23 pdf page 54, page 28, Figure 2.13, empirical fit (logistic regression)
    :param r_nmi: int Point radius from center of storm in nautical miles
    :param rmax_nmi: int Radius of maximum winds in nautical miles
    :return: float 0 <= radial decay <= 1
    """

    # ret = 0
    if r_nmi >= rmax_nmi:
        # NWS 23 pdf page 53
        slope = (-0.051 * math.log(rmax_nmi)) - 0.1757
        intercept = (0.4244 * math.log(rmax_nmi)) + 0.7586
        ret = (slope * math.log(r_nmi)) + intercept
    else:
        # NWS 23 pdf page 54
        # ret = 1.01231578 / (1 + math.exp(-8.612066494 * ((r_nmi / float(rmax_nmi)) - 0.678031222)))
        ret = 1 # this is a concession for modeling time series, where everything within the max wind radius is expected to experience the max wind radius while the storm translates

    # keep radial decay between 0 and 1
    ret = max(min(ret, 1), 0)
    return ret

@jit(nopython=True,cache=True)
def coriolis_frequency(lat_deg):<commit_msg>Fixing linear interpolation bug<commit_after>﻿import math
import numba
from numba import jit


"""
SPH: Standard Project Hurricane
PMH: Probable Maximum Hurricane

Pressure profile equation

(p-Cp)/(Pw - Cp) = e ^ (-R/r)

Pw: Peripheral Pressure, pressure at edge of storm, should be a bit below MSLP
Cp: Central Pressure (P0 in paper)
Rmax: Radius of Maximum Winds (R in paper)
Fspeed: Forward speed of hurricane center (T in paper)
Dir: Track direction
Vgx: Maximum Gradient Winds
Rho0: Surace air density
r: distance (radius) from hurricane center
fcorr: Coriolis parameter, dependant on latitude
Vx: Observed maximum 10-m, 10-min winds over open water.  75% to 105% of Vgx.  Standard is 95%
    For moving hurricane: Vx = 0.95 * Vgx + (1.5 * T ^ 0.63 * To ^ 0.37 * cos(beta)
Vpt: 10m, 10min winds at a point (V in paper)
"""
Pw_SPH_kPa = 100.8
Pw_PMH_kPa = 102.0
Pw_SPH_inhg = 29.77
Pw_PMH_inhg = 30.12
Rho0_kPa = 101.325  # Mean Sea Level Pressure
KmToNmi = 0.539957
MpsToKts = 1.94384
KpaToInhg = 0.2953
MbToInhg = 0.02953

@jit(nopython=True,cache=True)
def linear_interpolation(x, x1, x2, y1, y2):
    """

    :param x:
    :param x1:
    :param x2:
    :param y1:
    :param y2:
    :return:
    """
    return (((y2 - y1) / (x2 - x1)) * (x - x1)) + y1

@jit(nopython=True,cache=True)
def radial_decay(r_nmi, rmax_nmi):
    """
    Calculates the radial decay factor for a given radius.
    Rmax_nmi < r_nmi: NWS 23 pdf page 53, page 27, Figure 2.12, empirical fit
    Rmax_nmi > r_nmi: NWS 23 pdf page 54, page 28, Figure 2.13, empirical fit (logistic regression)
    :param r_nmi: int Point radius from center of storm in nautical miles
    :param rmax_nmi: int Radius of maximum winds in nautical miles
    :return: float 0 <= radial decay <= 1
    """

    # ret = 0
    if r_nmi >= rmax_nmi:
        # NWS 23 pdf page 53
        slope = (-0.051 * math.log(rmax_nmi)) - 0.1757
        intercept = (0.4244 * math.log(rmax_nmi)) + 0.7586
        ret = (slope * math.log(r_nmi)) + intercept
    else:
        # NWS 23 pdf page 54
        # ret = 1.01231578 / (1 + math.exp(-8.612066494 * ((r_nmi / float(rmax_nmi)) - 0.678031222)))
        ret = 1 # this is a concession for modeling time series, where everything within the max wind radius is expected to experience the max wind radius while the storm translates

    # keep radial decay between 0 and 1
    ret = max(min(ret, 1), 0)
    return ret

@jit(nopython=True,cache=True)
def coriolis_frequency(lat_deg):
{'fraction_non_alphanumeric': 0.1049746192893401, 'fraction_numerical': 0.06964467005076141, 'mean_word_length': 3.1534569983136596, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2222791', 'n_tokens_mistral': 2133, 'n_tokens_neox': 1835, 'n_words': 639}