Last active
October 13, 2025 01:09
-
-
Save deton/bc960d410d2f35e7edab83ea9bdb87a9 to your computer and use it in GitHub Desktop.
出発地点が、時間帯によって、vendor間の違いがあるか、グラフ化して見る。https://colab.research.google.com/drive/1huNXbUTTg57sJf7jLb1Rs00yUR3WHb75?usp=sharing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import marimo | |
| __generated_with = "0.16.5" | |
| app = marimo.App(width="full") | |
| @app.cell | |
| def _(mo): | |
| mo.md( | |
| r""" | |
| ## 出発地点が、時間帯によって、vendor間の違いがあるか、グラフ化して見る | |
| https://colab.research.google.com/drive/1huNXbUTTg57sJf7jLb1Rs00yUR3WHb75?usp=sharing | |
| """ | |
| ) | |
| return | |
| @app.cell | |
| def _(): | |
| import marimo as mo | |
| return (mo,) | |
| @app.cell | |
| def _(): | |
| import geopandas as gpd | |
| import pandas as pd | |
| EPSG= "WGS84" | |
| df = pd.read_json("https://github.com/visgl/deck.gl-data/raw/refs/heads/master/examples/trips/trips-v7.json") | |
| df["lonlat"] = df["path"].apply(lambda path: path[0]) | |
| df["lon"] = df["lonlat"].apply(lambda lonlat: lonlat[0]) | |
| df["lat"] = df["lonlat"].apply(lambda lonlat: lonlat[1]) | |
| df["tm"] = df["timestamps"].apply(lambda timestamps: int(timestamps[0] / 100)) | |
| df = df.drop(columns=["timestamps", "path", "lonlat"]) | |
| gdf = gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(df["lon"], df["lat"])).set_crs(EPSG) | |
| return EPSG, gdf, gpd | |
| @app.cell | |
| def _(gdf): | |
| import plotly.express as px | |
| figlon = px.box(gdf.drop(columns=["geometry"]), x="tm", y="lon", color="vendor") | |
| figlon.show() | |
| figlat = px.box(gdf.drop(columns=["geometry"]), x="tm", y="lat", color="vendor") | |
| figlat.show() | |
| return (px,) | |
| @app.cell | |
| def _(mo): | |
| mo.md(r"### 重心地点からの距離と方位角をグラフ化してみる") | |
| return | |
| @app.cell | |
| def _(EPSG, gdf, gpd): | |
| # Centroid for points | |
| # cf. https://stackoverflow.com/a/70088741 | |
| import shapely | |
| utmcrs = gdf.estimate_utm_crs() | |
| gdfutm = gdf.to_crs(utmcrs) | |
| mp = shapely.geometry.MultiPoint(gdfutm.geometry) | |
| centroidutm = mp.centroid | |
| centroid = gpd.GeoSeries([centroidutm], crs=utmcrs).to_crs(EPSG)[0] | |
| # centroid = gdfutm.geometry.union_all().centroid | |
| # print(gpd.GeoSeries([centroid], crs=utmcrs).to_crs(EPSG)) | |
| return (centroid,) | |
| @app.cell | |
| def _(centroid, gdf): | |
| import pyproj | |
| geod = pyproj.Geod(ellps="WGS84") | |
| gdf["bearing"], _, gdf["distance"] = geod.inv([centroid.x] * len(gdf), [centroid.y] * len(gdf), gdf.geometry.x, gdf.geometry.y) | |
| #gdf.drop(columns=["lon", "lat"], inplace=True) | |
| return | |
| @app.cell | |
| def _(gdf): | |
| gdf.groupby("vendor").describe() | |
| return | |
| @app.cell | |
| def _(gdf, px): | |
| fig = px.box(gdf.drop(columns=["geometry"]), x="tm", y="bearing", color="vendor") | |
| fig.show() | |
| return | |
| @app.cell | |
| def _(gdf, px): | |
| fig2 = px.box(gdf.drop(columns=["geometry"]), x="tm", y="distance", color="vendor") | |
| fig2.show() | |
| return | |
| if __name__ == "__main__": | |
| app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment