Beispiel #1
0
def test_interpolate_nans_1d_linear():
    """Test linear interpolation of arrays with NaNs in the y-coordinate."""
    x = np.linspace(0, 20, 15)
    y = 5 * x + 3
    nan_indexes = [1, 5, 11, 12]
    y_with_nan = y.copy()
    y_with_nan[nan_indexes] = np.nan
    assert_array_almost_equal(y, interpolate_nans_1d(x, y_with_nan), 2)
Beispiel #2
0
def test_interpolate_nans_1d_log():
    """Test log interpolation of arrays with NaNs in the y-coordinate."""
    x = np.logspace(1, 5, 15)
    y = 5 * np.log(x) + 3
    nan_indexes = [1, 5, 11, 12]
    y_with_nan = y.copy()
    y_with_nan[nan_indexes] = np.nan
    assert_array_almost_equal(y, interpolate_nans_1d(x, y_with_nan, kind='log'), 2)
Beispiel #3
0
    def __init__(self, pres, temp, rh=None, td=None, u=None, v=None, wspd=None,
                 wdir=None, alt=None, station=None, time=None, fig=None, **kwargs):
        if not fig:
            fig = plt.figure(figsize=(9, 9), dpi=200)
        super().__init__(fig=fig, rotation=30)
        # Parameter conversion
        nonetype = type(None)
        if isinstance(td, nonetype):
            td = mpcalc.dewpoint_rh(temp, rh * units.percent).magnitude
        if isinstance(u, nonetype) or isinstance(v, nonetype):
            u, v = mpcalc.wind_components(wspd * units('m/s'), wdir * units.degree)
            u = u.magnitude
            v = v.magnitude
        self.kw = kwargs
        # Interpolate Nans
        xi = np.arange(0, len(pres), 1)
        self.p_i = mpi.interpolate_nans_1d(xi, pres) * units('hPa')
        self.t_i = mpi.interpolate_nans_1d(self.p_i, temp) * units.degC
        self.td_i = mpi.interpolate_nans_1d(self.p_i, td) * units.degC
        self.u_i = mpi.interpolate_nans_1d(self.p_i, u) * units('m/s')
        self.v_i = mpi.interpolate_nans_1d(self.p_i, v) * units('m/s')
        self.alt = mpi.interpolate_nans_1d(self.p_i, alt) * units('m')
        self.st = station
        self.time = time
        self.dp_idx = np.where(~np.isnan(td))[0][-1]

        self.process_skewt()
Beispiel #4
0
def test_interpolate_nans_1d_invalid():
    """Test log interpolation with invalid parameter."""
    x = np.logspace(1, 5, 15)
    y = 5 * np.log(x) + 3
    with pytest.raises(ValueError):
        interpolate_nans_1d(x, y, kind='loog')