Esempio n. 1
0
def gpd_to_json(data):
    """Write the data model to a .json file and return a url based data model.
    For ``geopandas.GeoDataFrame`` columns values are stored as Foreign Members
    of GeoJSON feature objects. For all other types uses function
    :py:func:`altair.to_json`."""
    if isinstance(data, gpd.GeoDataFrame):
        data = alt.utils.sanitize_dataframe(data)
        values = geopandas_to_dict(data)
        return alt.to_json({'values': values})
    else:
        return alt.to_json(data)
Esempio n. 2
0
def json_dir(data, data_dir="altairdata"):
    data_dir = Path(data_dir)
    data_dir.mkdir(exist_ok=True)
    return pipe(
        data,
        alt.to_json(filename=str(data_dir / "{prefix}-{hash}.{extension}")))
Esempio n. 3
0
    x0 = pronto_stations  # Start at pronto locations

    def score_fn(x):
        return kde.dlnprob(torch.from_numpy(x)).numpy()

    x = x0
    n_iters = svgd_iters
    x_svgd, x_svgd_list = svgd_model.update(x, score_fn, n_iter=n_iters,
                                            stepsize=svgd_step_size, bandwidth=svgd_bandwidth,
                                            alpha=0.9, debug=False)

    x_svgd_df = pd.DataFrame(columns=['iteration', 'sample_num', 'lat', 'long'])
    for idx in np.arange(x_svgd_list.shape[0]):
        iter_df = pd.DataFrame({
            'iteration': np.ones(x_svgd_list.shape[1]) * idx,
            'sample_num': np.arange(0, x_svgd_list.shape[1]),
            'lat': x_svgd_list[idx, :, 0],
            'long': x_svgd_list[idx, :, 1]
        })
        x_svgd_df = x_svgd_df.append(iter_df)
    x_svgd_df['iteration'] = x_svgd_df['iteration'].astype(np.int)

    # Save svgd as json
    alt.to_json(x_svgd_df, filename='{}_svgd.json'.format(file_name))

    # Plot interactive heat map with SVGD points
    chart = gen_map_interactive(kde.log_prob, x_svgd_df)


    chart = chart.configure_view(strokeOpacity=0)
    chart.save('{}_svgd_chart.html'.format(file_name))
Esempio n. 4
0
def test_gpd_to_json_pd():
    data = pd.DataFrame(pd.np.arange(3), columns=['param'])
    assert gpdvega.gpd_to_json(data) == alt.to_json(data)
Esempio n. 5
0
def jsonDir(data, dataDir):
    return pipe(data,
                alt.to_json(filename=dataDir + '/{prefix}-{hash}.{extension}'))