Exemplo n.º 1
0
 def test_dist_approx_pass(self):
     """Test against matlab reference."""
     lats1 = 45.5
     lons1 = -32.2
     cos_lats1 = np.cos(np.radians(lats1))
     lats2 = 14
     lons2 = 56
     self.assertAlmostEqual(
         7709.827814738594,
         interp.dist_approx(lats1, lons1, cos_lats1, lats2, lons2))
Exemplo n.º 2
0
def _wind_per_node(coastal_centr, track, v_trans, model):
    """ Compute sustained winds at each centroid.

    Parameters:
        coastal_centr (2d np.array): centroids
        track (xr.Dataset): track latitudes
        v_trans (np.array): track translational velocity
        model (int): Holland model selection according to MODEL_VANG

    Returns:
        2d np.array
    """

    t_lat, t_lon = track.lat.values, track.lon.values
    t_rad, t_env = track.radius_max_wind.values, track.environmental_pressure.values
    t_cen, t_tstep = track.central_pressure.values, track.time_step.values

    centr_cos_lat = np.cos(np.radians(coastal_centr[:, 0]))
    intensity = np.zeros((coastal_centr.shape[0], ))

    n_nodes = t_lat.size
    if 'n_nodes' in track.attrs:
        n_nodes = track.attrs['n_nodes']

    for i_node in range(1, n_nodes):
        # compute distance to all centroids
        r_arr = dist_approx(coastal_centr[:, 0], coastal_centr[:, 1], \
            centr_cos_lat, t_lat[i_node], t_lon[i_node])

        # Choose centroids that are close enough
        close_centr = np.argwhere(r_arr < CENTR_NODE_MAX_DIST_KM).reshape(-1, )
        r_arr = r_arr[close_centr]

        # translational component
        if i_node < t_lat.size - 1:
            v_trans_corr = _vtrans_correct(t_lat[i_node:i_node+2], \
                t_lon[i_node:i_node+2], t_rad[i_node], \
                coastal_centr[close_centr, :], r_arr)
        else:
            v_trans_corr = np.zeros((r_arr.size, ))

        # angular component
        v_ang = _vang_sym(t_env[i_node], t_cen[i_node - 1:i_node + 1],
                          t_lat[i_node], t_tstep[i_node], t_rad[i_node], r_arr,
                          v_trans[i_node - 1], model)

        v_full = v_trans[i_node - 1] * v_trans_corr + v_ang
        v_full[np.isnan(v_full)] = 0
        v_full[v_full < TropCyclone.intensity_thres] = 0

        # keep maximum instantaneous wind
        intensity[close_centr] = np.maximum(intensity[close_centr], v_full)

    return intensity
Exemplo n.º 3
0
def _vtrans(t_lat, t_lon, t_tstep, ureg):
    """ Translational spped at every track node.

    Parameters:
        t_lat (np.array): track latitudes
        t_lon (np.array): track longitudes
        t_tstep (np.array): track time steps
        ureg (UnitRegistry): units handler

    Returns:
        np.array
    """
    v_trans = dist_approx(t_lat[:-1], t_lon[:-1], np.cos(np.radians(
        t_lat[:-1])), t_lat[1:], t_lon[1:]) / t_tstep[1:]
    v_trans = (v_trans * ureg.km / ureg.hour).to(ureg.meter /
                                                 ureg.second).magnitude

    # nautical miles/hour, limit to 30 nmph
    v_max = (30 * ureg.knot).to(ureg.meter / ureg.second).magnitude
    v_trans[v_trans > v_max] = v_max
    return v_trans