# windprofile.py

## Create a fast and robust radial profile of the tropical cyclone rotating wind from inputs Vmax, R34kt, Rmax, and latitude.

#### This code uses a modified‐Rankine vortex between Rmax and R34kt and the E04 model beyond R34kt (and a quadratic profile inside the eye). It is very similar to the full physics-based wind profile model of Chavas et al. (2015) ([code here](http://doi.org/10.4231/CZ4P-D448)), but is simpler and much faster.

#### It is designed to guarantee that the profile fits both Rmax and R34kt and will be very close to the true outer radius (R0) as estimated by the full E04 outer solution. Hence, it is very firmly grounded in the known physics of the tropical cyclone wind field while also matching the input data. It is also guaranteed to be very well‐behaved for basically any input parameter combination.

#### Model basis:
#### Modified Rankine profile between Rmax and R34kt was shown to compare very well against high-quality subset of Atlantic Best Track database -- see Fig 8 of [Klotzbach et al. (2022, JGR-A)](https://doi.org/10.1029/2022JD037030)
#### Physics-based non-convecting wind field profile beyond R34kt was shown to compare very well against entire QuikSCAT database -- see Fig 6 of [Chavas et al. (2015, JAS)](https://doi.org/10.1175/JAS-D-15-0014.1)
#### Quadratic in the eye (U-shape is common)

# tcwindprofile/full_profile.py

from tcwindprofile.tc_rmax_estimatefromR34kt import predict_Rmax_from_R34kt
from tcwindprofile.tc_outer_radius_estimate import estimate_outer_radius
from tcwindprofile.tc_outer_windprofile import outer_windprofile
from tcwindprofile.windprofile import generate_wind_profile
from tcwindprofile.tc_pmin_estimatefromR34kt import predict_Pmin_from_R34kt

def run_full_wind_model(
    VmaxNHC_kt: float,
    Vtrans_kt: float,
    R34kt_quad_max_nautmi: float,
    lat: float,
    Penv_mb: float,
    plot: bool = False
):
    """
    Full TC wind profile modeling pipeline:
    - Estimate Rmax from R34kt using CK22
    - Estimate R0 using Chavas et al. (2015)
    - Generate wind profile
    - Predict Pmin using CKK25

    Returns
    -------
    dict with:
      - rr_km: radius array [km]
      - vv_ms: wind profile [m/s]
      - R0_km: estimated outer radius [km]
      - Rmax_km: estimated Rmax [km]
      - Pmin_hPa: estimated minimum pressure [hPa]
    """
    # Convert input units
    ms_per_kt = 0.5144444
    km_per_nautmi = 1.852
    VmaxNHC_ms = VmaxNHC_kt * ms_per_kt
    Vtrans_ms = Vtrans_kt * ms_per_kt
    Vmaxmean_ms = VmaxNHC_ms - 0.55 * Vtrans_ms
    R34ktmean_km = 0.85 * R34kt_quad_max_nautmi * km_per_nautmi

    # 1) Estimate Rmax (CK22)
    Rmax_km = predict_Rmax_from_R34kt(
        VmaxNHC_ms=VmaxNHC_ms,
        R34ktmean_km=R34ktmean_km,
        lat=lat
    )

    # 2) Estimate wind profile + R0 (CK22 + Emanuel04)
    # print(Vmaxmean_ms,Rmax_km,R34ktmean_km,lat,plot)
    rr_km, vv_ms, R0_km = generate_wind_profile(
        Vmaxmean_ms=Vmaxmean_ms,
        Rmax_km=Rmax_km,
        R34ktmean_km=R34ktmean_km,
        lat=lat,
        plot=plot
    )

    # 3) Estimate Pmin (CKK25)
    # print(VmaxNHC_ms,R34ktmean_km,lat,Vtrans_ms,Penv_mb)
    Pmin_estimate_mb, dP_estimate_mb = predict_Pmin_from_R34kt(
        VmaxNHC_ms=VmaxNHC_ms,
        R34ktmean_km=R34ktmean_km,
        lat=lat,
        Vtrans_ms=Vtrans_ms,
        Penv_mb=Penv_mb
    )

    return {
        "rr_km": rr_km,
        "vv_ms": vv_ms,
        "R0_km": R0_km,
        "Rmax_km": Rmax_km,
        "Pmin_mb": Pmin_estimate_mb
    }
