Ejemplo n.º 1
0
def test_moran_loc_bv_scatterplot():
    link_to_data = examples.get_path('Guerry.shp')
    gdf = gpd.read_file(link_to_data)
    x = gdf['Suicids'].values
    y = gdf['Donatns'].values
    w = Queen.from_dataframe(gdf)
    w.transform = 'r'
    # Calculate Univariate and Bivariate Moran
    moran_loc = Moran_Local(y, w)
    moran_loc_bv = Moran_Local_BV(x, y, w)
    # try with p value so points are colored
    fig, _ = _moran_loc_bv_scatterplot(moran_loc_bv)
    plt.close(fig)

    # try with p value and different figure size
    fig, _ = _moran_loc_bv_scatterplot(moran_loc_bv,
                                       p=0.05,
                                       aspect_equal=False)
    plt.close(fig)

    assert_raises(ValueError, _moran_loc_bv_scatterplot, moran_loc, p=0.5)
    assert_warns(UserWarning,
                 _moran_loc_bv_scatterplot,
                 moran_loc_bv,
                 p=0.5,
                 scatter_kwds=dict(c='r'))
Ejemplo n.º 2
0
def test_moran_loc_scatterplot():
    columbus = examples.load_example('Columbus')
    link_to_data = columbus.get_path('columbus.shp')
    df = gpd.read_file(link_to_data)

    x = df['INC'].values
    y = df['HOVAL'].values
    w = Queen.from_dataframe(df)
    w.transform = 'r'

    moran_loc = Moran_Local(y, w)
    moran_bv = Moran_BV(x, y, w)

    # try without p value
    fig, _ = _moran_loc_scatterplot(moran_loc)
    plt.close(fig)

    # try with p value and different figure size
    fig, _ = _moran_loc_scatterplot(moran_loc,
                                    p=0.05,
                                    aspect_equal=False,
                                    fitline_kwds=dict(color='#4393c3'))
    plt.close(fig)

    # try with p value and zstandard=False
    fig, _ = _moran_loc_scatterplot(moran_loc,
                                    p=0.05,
                                    zstandard=False,
                                    fitline_kwds=dict(color='#4393c3'))
    plt.close(fig)

    # try without p value and zstandard=False
    fig, _ = _moran_loc_scatterplot(moran_loc,
                                    zstandard=False,
                                    fitline_kwds=dict(color='#4393c3'))
    plt.close(fig)

    assert_raises(ValueError, _moran_loc_scatterplot, moran_bv, p=0.5)
    assert_warns(UserWarning,
                 _moran_loc_scatterplot,
                 moran_loc,
                 p=0.5,
                 scatter_kwds=dict(c='#4393c3'))
Ejemplo n.º 3
0
def test_make_graph_warning_duplicate_endogenous_variable():
    with assert_warns(Warning) as cm:
        FSIC.optimise.order.make_graph([
            'self.H_s[period] = self.H_s[period-1] + self.G_d[period] - self.T_d[period]',
            'self.H_h[period] = self.H_h[period-1] + self.YD[period] - self.C_d[period]',
            'self.H_h[period] = self.H_s[period]'
        ])
    assert str(
        cm.warning
    ) == 'An endogenous variable appears as the left hand-side variable in more than one equation'
Ejemplo n.º 4
0
def assert_warns(exception=Warning,
                 *args,
                 glob=None,
                 regex=None,
                 match_case=None,
                 **kwargs):

    if glob is None and regex is None:
        return tools.assert_warns(exception, *args, **kwargs)

    pattern = get_pattern(glob, regex, match_case)
    return tools.assert_warns_regex(exception, pattern, *args, **kwargs)
Ejemplo n.º 5
0
 def test_warn_unsafe_type():
     with n.assert_warns(UserWarning):
         parse({'one', 'two', 'three'})
Ejemplo n.º 6
0
 def test_warn_unsafe_type():
     with n.assert_warns(UserWarning):
         parse({'one','two','three'})
Ejemplo n.º 7
0
def test_surface():
    volume = np.random.uniform(10, 100)
    tau = np.random.uniform(.5, 5.)

    x = np.atleast_2d([tau, 0., 0.])
    sigma = np.atleast_2d([volume/tau, 0., 0.])
    v = np.zeros((1, 2))

    surf = Surface(x, sigma, v)

    assert surf.boost_invariant, 'Surface should be boost-invariant.'

    assert_almost_equal(
        surf.volume, volume, delta=1e-12,
        msg='incorrect volume'
    )

    ymax = np.random.uniform(.5, 2.)
    surf = Surface(x, sigma, v, ymax=ymax)

    assert_almost_equal(
        surf.volume, 2*ymax*volume, delta=1e-12,
        msg='incorrect volume'
    )

    x = np.random.uniform(0, 10, size=(1, 4))
    sigma = np.random.uniform(0, 10, size=(1, 4))
    v = np.random.uniform(-.5, .5, size=(1, 3))

    surf = Surface(x, sigma, v)

    assert not surf.boost_invariant, 'Surface should not be boost-invariant.'

    gamma = 1/np.sqrt(1 - (v*v).sum())
    u_ = np.empty(4)
    u_[0] = gamma
    u_[1:] = -gamma*v

    volume = np.inner(sigma, u_)

    assert_almost_equal(
        surf.volume, volume, delta=1e-12,
        msg='incorrect volume'
    )

    with assert_warns(Warning):
        Surface(x, sigma, v, ymax=1.)

    with assert_raises(ValueError):
        Surface(
            np.ones((1, 1)),
            np.ones((1, 1)),
            np.ones((1, 1)),
        )

    with assert_raises(ValueError):
        Surface(
            np.ones((1, 4)),
            np.ones((1, 3)),
            np.ones((1, 2)),
        )

    with assert_raises(ValueError):
        Surface(
            np.ones((2, 4)),
            np.ones((2, 4)),
            np.ones((3, 3)),
        )