def test_prepare_geo_data_dissolve(self): bel_df = _generate_dummy_data() shp_file = load_be_shp() geo_df = prepare_geo_data( df=bel_df, target="truth", cols_to_plot=None, predicted=None, dissolve_on=None, distrib="gamma", n_bins=7, geoid="INS", weight=None, shp_file=shp_file, ) bel_df_borough = bel_df.merge(geo_df[["geoid", "borough"]]) geo_df = prepare_geo_data( df=bel_df_borough, target="truth", cols_to_plot=None, predicted=None, dissolve_on="borough", distrib="gamma", n_bins=7, geoid="INS", weight=None, shp_file=shp_file, ) message = "The output df is not the right shape, the shape is {}, expected (43, 17)".format( geo_df.shape) assert geo_df.shape == (43, 17), message
def test_plot_on_map(self): bel_df = _generate_dummy_data() shp_file = load_be_shp() f = plot_on_map( df=bel_df, target="truth", dissolve_on=None, distrib="gaussian", plot_uncertainty=False, plot_weight=False, autobin=False, n_bins=7, geoid="INS", weight=None, shp_file=shp_file, figsize=(20, 6), cmap=None, normalize=True, facecolor="black", ) message = ( "not the right type, got {} but expected matplotlib.figure.Figure". format(str(type(f)))) assert isinstance(f, matplotlib.figure.Figure), message
def test_facet_map_interactive(self): bel_df = _generate_dummy_data() shp_file = load_be_shp() f = facet_map_interactive( df=bel_df, target="truth", cols_to_plot=None, predicted=None, dissolve_on=None, autobin=True, n_bins=7, geoid="INS", weight=None, shp_file=shp_file, figsize=(400, 400), ncols=2, cmap=None, normalize=False, ) message = "not the right type, got {} but expected holoviews.core.layout.Layout".format( str(type(f))) isinstance(f, holoviews.core.layout.Layout), message
def _generate_dummy_data(): # the greatest country in the world, # first military and economic power in the Universe geom_df = load_be_shp() # create correlation with the geo entities feat_1 = np.repeat(np.log10(geom_df.INS.astype(int).values), 10) feat_1 = (feat_1 - feat_1.min()) / (feat_1.max() - feat_1.min()) # dummy data bel_df = pd.DataFrame({ "geoid": np.repeat(geom_df.INS.values, 10), "truth": feat_1, "feat_2": feat_1 + np.random.beta(0.5, 0.5, size=len(feat_1)), "feat_3": feat_1 + np.random.beta(2, 5, size=len(feat_1)), "feat_4": feat_1 + np.random.beta(5, 2, size=len(feat_1)), }) return bel_df
def test_plot_on_map(self): bel_df = _generate_dummy_data() shp_file = load_be_shp() f = facet_map( df=bel_df, target="truth", cols_to_plot=["feat_2", "feat_3"], predicted=None, dissolve_on=None, autobin=True, n_bins=7, geoid="INS", weight=None, shp_file=shp_file, figsize=(12, 12), ncols=2, cmap=None, normalize=False, ) message = ( "not the right type, got {} but expected matplotlib.figure.Figure". format(str(type(f)))) assert isinstance(f, matplotlib.figure.Figure), message