diff --git a/examples/benchmarking_of_stop_detection_algorithms.ipynb b/examples/benchmarking_of_stop_detection_algorithms.ipynb index 0d3ea257..02740864 100644 --- a/examples/benchmarking_of_stop_detection_algorithms.ipynb +++ b/examples/benchmarking_of_stop_detection_algorithms.ipynb @@ -50,7 +50,7 @@ "city = gpd.read_parquet(data_dir / 'garden-city-buildings-mercator.parquet')\n", "outer_box = box(*city.total_bounds).buffer(15, join_style='mitre')\n", "\n", - "filepath_root = 'gc_data_long/'\n", + "filepath_root = data_dir / \"gc_data_long\"\n", "tc = {\n", " \"user_id\": \"gc_identifier\",\n", " \"timestamp\": \"unix_ts\",\n", diff --git a/examples/benchmarking_of_stop_detection_algorithms.py b/examples/benchmarking_of_stop_detection_algorithms.py index cc3dcd79..6e2d504f 100644 --- a/examples/benchmarking_of_stop_detection_algorithms.py +++ b/examples/benchmarking_of_stop_detection_algorithms.py @@ -46,7 +46,7 @@ city = gpd.read_parquet(data_dir / 'garden-city-buildings-mercator.parquet') outer_box = box(*city.total_bounds).buffer(15, join_style='mitre') -filepath_root = 'gc_data_long/' +filepath_root = data_dir / "gc_data_long" tc = { "user_id": "gc_identifier", "timestamp": "unix_ts", diff --git a/examples/dbstop_demo.ipynb b/examples/dbstop_demo.ipynb index 2c798aff..4e10585c 100644 --- a/examples/dbstop_demo.ipynb +++ b/examples/dbstop_demo.ipynb @@ -47,7 +47,7 @@ "city = gpd.read_parquet(data_dir / 'garden-city-buildings-mercator.parquet')\n", "outer_box = box(*city.total_bounds)\n", "\n", - "filepath_root = 'gc_data_long/'\n", + "filepath_root = data_dir / \"gc_data_long\"\n", "tc = {\"user_id\": \"gc_identifier\", \"x\": \"dev_x\", \"y\": \"dev_y\", \"timestamp\": \"unix_ts\"}\n", "\n", "# Density based stop detection (Temporal DBSCAN)\n", diff --git a/examples/generate_synthetic_trajectories.ipynb b/examples/generate_synthetic_trajectories.ipynb index 72bff19f..f3d618ff 100644 --- a/examples/generate_synthetic_trajectories.ipynb +++ b/examples/generate_synthetic_trajectories.ipynb @@ -2,243 +2,77 @@ "cells": [ { "cell_type": "markdown", - "id": "10e2517a", "metadata": {}, - "source": [ - "# Synthetic Trajectory Generation with Nomad\n", - "\n", - "This notebook demonstrates how to generate realistic synthetic human mobility trajectories." - ] + "source": "# Synthetic Trajectory Generation with Nomad\n\nThis notebook demonstrates how to generate realistic synthetic human mobility trajectories." }, { "cell_type": "code", "execution_count": null, - "id": "58d68e64", "metadata": {}, "outputs": [], - "source": [ - "import pandas as pd\n", - "import numpy as np\n", - "import matplotlib.pyplot as plt\n", - "import time\n", - "from pathlib import Path\n", - "from joblib import Parallel, delayed\n", - "\n", - "from nomad.city_gen import City\n", - "from nomad.traj_gen import Agent, Population\n", - "from nomad.stop_detection.viz import plot_pings, plot_time_barcode" - ] + "source": "import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport time\nfrom pathlib import Path\nfrom joblib import Parallel, delayed\n\nimport nomad.data as data_folder\nfrom nomad.city_gen import City\nfrom nomad.traj_gen import Agent, Population\nfrom nomad.stop_detection.viz import plot_pings, plot_time_barcode" }, { "cell_type": "code", "execution_count": null, - "id": "9860e901", "metadata": {}, "outputs": [], - "source": [ - "city = City.from_geopackage('garden-city.gpkg')\n", - "city._build_hub_network(hub_size=16)\n", - "city.compute_gravity(exponent=2.0)\n", - "city.compute_shortest_paths(callable_only=True)\n", - "\n", - "print(f\"City: {city.name}\")\n", - "print(f\"Dimensions: {city.dimensions}\")\n", - "print(f\"Buildings: {len(city.buildings_gdf)}\")" - ] + "source": "data_dir = Path(data_folder.__file__).parent\ncity = City.from_geopackage(data_dir / \"garden-city.gpkg\")\ncity._build_hub_network(hub_size=16)\ncity.compute_gravity(exponent=2.0)\ncity.compute_shortest_paths(callable_only=True)\n\nprint(f\"City: {city.name}\")\nprint(f\"Dimensions: {city.dimensions}\")\nprint(f\"Buildings: {len(city.buildings_gdf)}\")" }, { "cell_type": "markdown", - "id": "9ff8ddec", "metadata": {}, - "source": [ - "## Part 1: Effect of Sampling Parameters on Sparsity\n", - "\n", - "Generate 3 agents with 2-day trajectories, varying beta_duration and beta_start \n", - "to show their effect on sparsity (q = observed points / ground truth points)." - ] + "source": "## Part 1: Effect of Sampling Parameters on Sparsity\n\nGenerate 3 agents with 2-day trajectories, varying beta_duration and beta_start \nto show their effect on sparsity (q = observed points / ground truth points)." }, { "cell_type": "code", "execution_count": null, - "id": "b6336cc1", "metadata": {}, "outputs": [], - "source": [ - "population = Population(city)\n", - "population.generate_agents(N=3, seed=42, name_count=2)\n", - "\n", - "# Vary beta_duration and beta_start to target different sparsity levels\n", - "sampling_params = [\n", - " {'beta_ping': 5, 'beta_start': 100, 'beta_durations': 60}, \n", - " {'beta_ping': 5, 'beta_start': 250, 'beta_durations': 150}, \n", - " {'beta_ping': 5, 'beta_start': 400, 'beta_durations': 240} \n", - "]\n", - "\n", - "# Generate 2-day trajectories for quick visualization\n", - "for i, (agent_id, agent) in enumerate(population.roster.items()):\n", - " agent.generate_trajectory(\n", - " datetime=pd.Timestamp(\"2024-01-01T07:00-04:00\"),\n", - " end_time=pd.Timestamp(\"2024-01-03T07:00-04:00\"),\n", - " seed=i\n", - " )\n", - "\n", - " agent.sample_trajectory(\n", - " **sampling_params[i],\n", - " replace_sparse_traj=True,\n", - " seed=i\n", - " )\n", - " \n", - " q = len(agent.sparse_traj) / len(agent.trajectory)\n", - " print(f\"Agent {i}: q={q:.3f}, beta_start={sampling_params[i]['beta_start']}, \"\n", - " f\"beta_dur={sampling_params[i]['beta_durations']}\")" - ] + "source": "population = Population(city)\npopulation.generate_agents(N=3, seed=42, name_count=2)\n\n# Vary beta_duration and beta_start to target different sparsity levels\nsampling_params = [\n {'beta_ping': 5, 'beta_start': 100, 'beta_durations': 60}, \n {'beta_ping': 5, 'beta_start': 250, 'beta_durations': 150}, \n {'beta_ping': 5, 'beta_start': 400, 'beta_durations': 240} \n]\n\n# Generate 2-day trajectories for quick visualization\nfor i, (agent_id, agent) in enumerate(population.roster.items()):\n agent.generate_trajectory(\n datetime=pd.Timestamp(\"2024-01-01T07:00-04:00\"),\n end_time=pd.Timestamp(\"2024-01-03T07:00-04:00\"),\n seed=i\n )\n\n agent.sample_trajectory(\n **sampling_params[i],\n replace_sparse_traj=True,\n seed=i\n )\n \n q = len(agent.sparse_traj) / len(agent.trajectory)\n print(f\"Agent {i}: q={q:.3f}, beta_start={sampling_params[i]['beta_start']}, \"\n f\"beta_dur={sampling_params[i]['beta_durations']}\")" }, { "cell_type": "code", "execution_count": null, - "id": "0e4b20fa", - "metadata": { - "lines_to_next_cell": 1 - }, + "metadata": {}, "outputs": [], - "source": [ - "fig, axes = plt.subplots(2, 3, figsize=(15, 10), \n", - " gridspec_kw={'height_ratios': [10, 1]})\n", - "\n", - "for i, (agent_id, agent) in enumerate(population.roster.items()):\n", - " ax_map = axes[0, i]\n", - " ax_barcode = axes[1, i]\n", - " \n", - " city.plot_city(ax=ax_map, doors=False, address=False)\n", - " \n", - " traj = agent.sparse_traj\n", - " plot_pings(traj, ax=ax_map, s=15, point_color='red', \n", - " x='x', y='y', timestamp='timestamp')\n", - " \n", - " plot_time_barcode(traj['timestamp'], ax=ax_barcode, set_xlim=True)\n", - " \n", - " q = len(traj) / len(agent.trajectory)\n", - " ax_map.set_title(f\"Agent {i}: {len(traj)} obs (q={q:.2f})\\n\"\n", - " f\"beta_start={sampling_params[i]['beta_start']}, \"\n", - " f\"beta_dur={sampling_params[i]['beta_durations']}\")\n", - " ax_map.set_axis_off()\n", - "\n", - "plt.tight_layout()\n", - "plt.savefig('data/trajectories_visualization.png', dpi=150, bbox_inches='tight')\n", - "plt.show()" - ] + "source": "fig, axes = plt.subplots(2, 3, figsize=(15, 10), \n gridspec_kw={'height_ratios': [10, 1]})\n\nfor i, (agent_id, agent) in enumerate(population.roster.items()):\n ax_map = axes[0, i]\n ax_barcode = axes[1, i]\n \n city.plot_city(ax=ax_map, doors=False, address=False)\n \n traj = agent.sparse_traj\n plot_pings(traj, ax=ax_map, s=15, point_color='red', \n x='x', y='y', timestamp='timestamp')\n \n plot_time_barcode(traj['timestamp'], ax=ax_barcode, set_xlim=True)\n \n q = len(traj) / len(agent.trajectory)\n ax_map.set_title(f\"Agent {i}: {len(traj)} obs (q={q:.2f})\\n\"\n f\"beta_start={sampling_params[i]['beta_start']}, \"\n f\"beta_dur={sampling_params[i]['beta_durations']}\")\n ax_map.set_axis_off()\n\nplt.tight_layout()\nplt.savefig('data/trajectories_visualization.png', dpi=150, bbox_inches='tight')\nplt.show()" }, { "cell_type": "markdown", - "id": "dc7b266a", "metadata": {}, - "source": [ - "## Part 2: Parallel Generation at Scale\n", - "\n", - "Generate trajectories for 15 users using parallelization." - ] + "source": "## Part 2: Parallel Generation at Scale\n\nGenerate trajectories for 15 users using parallelization." }, { "cell_type": "code", "execution_count": null, - "id": "5238c745", - "metadata": { - "lines_to_next_cell": 1 - }, + "metadata": {}, "outputs": [], - "source": [ - "def generate_agent_trajectory(args):\n", - " \"\"\"Worker function for parallel generation.\"\"\"\n", - " identifier, home, work, seed = args\n", - " city = City.from_geopackage('garden-city.gpkg')\n", - " city._build_hub_network(hub_size=16)\n", - " city.compute_gravity(exponent=2.0)\n", - " city.compute_shortest_paths(callable_only=True)\n", - " agent = Agent(identifier=identifier, city=city, home=home, workplace=work)\n", - " \n", - " agent.generate_trajectory(\n", - " datetime=pd.Timestamp(\"2024-01-01T07:00-04:00\"),\n", - " end_time=pd.Timestamp(\"2024-01-08T07:00-04:00\"),\n", - " seed=seed\n", - " )\n", - " agent.sample_trajectory(\n", - " beta_ping=5,\n", - " replace_sparse_traj=True,\n", - " seed=seed\n", - " )\n", - " sparse_df = agent.sparse_traj.copy()\n", - " sparse_df['user_id'] = identifier\n", - " sparse_df['home'] = home\n", - " sparse_df['workplace'] = work\n", - " return sparse_df" - ] + "source": "def generate_agent_trajectory(args):\n \"\"\"Worker function for parallel generation.\"\"\"\n identifier, home, work, seed = args\n data_dir = Path(data_folder.__file__).parent\n city = City.from_geopackage(data_dir / \"garden-city.gpkg\")\n city._build_hub_network(hub_size=16)\n city.compute_gravity(exponent=2.0)\n city.compute_shortest_paths(callable_only=True)\n agent = Agent(identifier=identifier, city=city, home=home, workplace=work)\n \n agent.generate_trajectory(\n datetime=pd.Timestamp(\"2024-01-01T07:00-04:00\"),\n end_time=pd.Timestamp(\"2024-01-08T07:00-04:00\"),\n seed=seed\n )\n agent.sample_trajectory(\n beta_ping=5,\n replace_sparse_traj=True,\n seed=seed\n )\n sparse_df = agent.sparse_traj.copy()\n sparse_df['user_id'] = identifier\n sparse_df['home'] = home\n sparse_df['workplace'] = work\n return sparse_df" }, { "cell_type": "code", "execution_count": null, - "id": "aa1b6112", "metadata": {}, "outputs": [], - "source": [ - "n_agents = 15\n", - "rng = np.random.default_rng(100)\n", - "homes = city.buildings_gdf[city.buildings_gdf['building_type'] == 'home']['id'].to_numpy()\n", - "workplaces = city.buildings_gdf[city.buildings_gdf['building_type'] == 'workplace']['id'].to_numpy()\n", - "\n", - "agent_params = [\n", - " (f'agent_{i:04d}',\n", - " rng.choice(homes),\n", - " rng.choice(workplaces),\n", - " i)\n", - " for i in range(n_agents)\n", - "]" - ] + "source": "n_agents = 15\nrng = np.random.default_rng(100)\nhomes = city.buildings_gdf[city.buildings_gdf['building_type'] == 'home']['id'].to_numpy()\nworkplaces = city.buildings_gdf[city.buildings_gdf['building_type'] == 'workplace']['id'].to_numpy()\n\nagent_params = [\n (f'agent_{i:04d}',\n rng.choice(homes),\n rng.choice(workplaces),\n i)\n for i in range(n_agents)\n]" }, { "cell_type": "code", "execution_count": null, - "id": "a0364bc9", "metadata": {}, "outputs": [], - "source": [ - "print(f\"Generating {n_agents} agents in parallel...\")\n", - "start_time = time.time()\n", - "\n", - "results = Parallel(n_jobs=-1, verbose=10)(\n", - " delayed(generate_agent_trajectory)(params) for params in agent_params\n", - ")\n", - "\n", - "generation_time = time.time() - start_time\n", - "print(f\"Generated {n_agents} agents in {generation_time:.2f}s ({generation_time/n_agents:.2f}s per agent)\")" - ] + "source": "print(f\"Generating {n_agents} agents in parallel...\")\nstart_time = time.time()\n\nresults = Parallel(n_jobs=-1, verbose=10)(\n delayed(generate_agent_trajectory)(params) for params in agent_params\n)\n\ngeneration_time = time.time() - start_time\nprint(f\"Generated {n_agents} agents in {generation_time:.2f}s ({generation_time/n_agents:.2f}s per agent)\")" }, { "cell_type": "code", "execution_count": null, - "id": "e8a48448", "metadata": {}, "outputs": [], - "source": [ - "parallel_population = Population(city)\n", - "for df, params in zip(results, agent_params):\n", - " identifier, home, work, seed = params\n", - " agent = Agent(identifier=identifier, city=city, home=home, workplace=work, seed=seed)\n", - " agent.sparse_traj = df.drop(columns=['home', 'workplace'])\n", - " parallel_population.add_agent(agent, verbose=False)\n", - "\n", - "output_path = 'data/trajectories_15_users'\n", - "parallel_population.save_pop(\n", - " sparse_path=str(output_path),\n", - " fmt='parquet'\n", - ")\n", - "print(f\"Saved sparse trajectories to {output_path}\")" - ] + "source": "parallel_population = Population(city)\nfor df, params in zip(results, agent_params):\n identifier, home, work, seed = params\n agent = Agent(identifier=identifier, city=city, home=home, workplace=work, seed=seed)\n agent.sparse_traj = df.drop(columns=['home', 'workplace'])\n parallel_population.add_agent(agent, verbose=False)\n\nparallel_population.reproject_to_mercator(sparse_traj=True)\n\noutput_path = 'data/trajectories_15_users'\nparallel_population.save_pop(\n sparse_path=str(output_path),\n fmt='parquet'\n)\nprint(f\"Saved sparse trajectories to {output_path}\")" } ], "metadata": { - "jupytext": { - "formats": "ipynb,py:percent" - }, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", diff --git a/examples/generate_synthetic_trajectories.py b/examples/generate_synthetic_trajectories.py index 86daec55..56a12165 100644 --- a/examples/generate_synthetic_trajectories.py +++ b/examples/generate_synthetic_trajectories.py @@ -26,12 +26,14 @@ from pathlib import Path from joblib import Parallel, delayed +import nomad.data as data_folder from nomad.city_gen import City from nomad.traj_gen import Agent, Population from nomad.stop_detection.viz import plot_pings, plot_time_barcode # %% -city = City.from_geopackage('garden-city.gpkg') +data_dir = Path(data_folder.__file__).parent +city = City.from_geopackage(data_dir / "garden-city.gpkg") city._build_hub_network(hub_size=16) city.compute_gravity(exponent=2.0) city.compute_shortest_paths(callable_only=True) @@ -110,7 +112,8 @@ def generate_agent_trajectory(args): """Worker function for parallel generation.""" identifier, home, work, seed = args - city = City.from_geopackage('garden-city.gpkg') + data_dir = Path(data_folder.__file__).parent + city = City.from_geopackage(data_dir / "garden-city.gpkg") city._build_hub_network(hub_size=16) city.compute_gravity(exponent=2.0) city.compute_shortest_paths(callable_only=True) @@ -165,6 +168,8 @@ def generate_agent_trajectory(args): agent.sparse_traj = df.drop(columns=['home', 'workplace']) parallel_population.add_agent(agent, verbose=False) +parallel_population.reproject_to_mercator(sparse_traj=True) + output_path = 'data/trajectories_15_users' parallel_population.save_pop( sparse_path=str(output_path), diff --git a/examples/grid_based_demo.ipynb b/examples/grid_based_demo.ipynb index afa912ef..37594608 100644 --- a/examples/grid_based_demo.ipynb +++ b/examples/grid_based_demo.ipynb @@ -48,7 +48,7 @@ "city = gpd.read_parquet(data_dir / 'garden-city-buildings-mercator.parquet')\n", "outer_box = box(*city.total_bounds)\n", "\n", - "filepath_root = 'gc_data_long/'\n", + "filepath_root = data_dir / \"gc_data_long\"\n", "tc = {\"user_id\": \"gc_identifier\", \"x\": \"dev_x\", \"y\": \"dev_y\", \"timestamp\": \"unix_ts\"}\n", "\n", "users = ['admiring_brattain']\n", diff --git a/examples/grid_based_demo.py b/examples/grid_based_demo.py index 4d667bbd..d4f74ad3 100644 --- a/examples/grid_based_demo.py +++ b/examples/grid_based_demo.py @@ -45,7 +45,7 @@ city = gpd.read_parquet(data_dir / 'garden-city-buildings-mercator.parquet') outer_box = box(*city.total_bounds) -filepath_root = 'gc_data_long/' +filepath_root = data_dir / "gc_data_long" tc = {"user_id": "gc_identifier", "x": "dev_x", "y": "dev_y", "timestamp": "unix_ts"} users = ['admiring_brattain'] diff --git a/examples/hdbscan_demo.ipynb b/examples/hdbscan_demo.ipynb index ea22abcd..aed3e3c2 100644 --- a/examples/hdbscan_demo.ipynb +++ b/examples/hdbscan_demo.ipynb @@ -41,7 +41,7 @@ "city = gpd.read_parquet(data_dir / 'garden-city-buildings-mercator.parquet')\n", "outer_box = box(*city.total_bounds)\n", "\n", - "filepath_root = 'gc_data_long/'\n", + "filepath_root = data_dir / \"gc_data_long\"\n", "tc = {\"user_id\": \"gc_identifier\", \"x\": \"dev_x\", \"y\": \"dev_y\", \"timestamp\": \"unix_ts\"}\n", "\n", "users = ['admiring_brattain']\n", diff --git a/examples/hdbscan_demo.py b/examples/hdbscan_demo.py index fcef411f..1f3ec6e1 100644 --- a/examples/hdbscan_demo.py +++ b/examples/hdbscan_demo.py @@ -39,7 +39,7 @@ city = gpd.read_parquet(data_dir / 'garden-city-buildings-mercator.parquet') outer_box = box(*city.total_bounds) -filepath_root = 'gc_data_long/' +filepath_root = data_dir / "gc_data_long" tc = {"user_id": "gc_identifier", "x": "dev_x", "y": "dev_y", "timestamp": "unix_ts"} users = ['admiring_brattain'] diff --git a/examples/lachesis_colored_pings.png b/examples/lachesis_colored_pings.png deleted file mode 100644 index 7eefc017..00000000 Binary files a/examples/lachesis_colored_pings.png and /dev/null differ diff --git a/examples/lachesis_demo.ipynb b/examples/lachesis_demo.ipynb new file mode 100644 index 00000000..cf2b76c6 --- /dev/null +++ b/examples/lachesis_demo.ipynb @@ -0,0 +1,49 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": "# Lachesis Stop Detection" + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": "The first stop detection algorithm implemented in ```nomad``` is a sequential algorithm insipired by the one in _Project Lachesis: Parsing and Modeling Location Histories_ (Hariharan & Toyama). This algorithm for extracting stays is dependent on two parameters: the roaming distance and the stay duration. \n\n* Roaming distance represents the maximum distance an object can move away from a point location and still be considered to be staying at that location.\n* Stop duration is the minimum amount of time an object must spend within the roaming distance of a location to qualify as a stop.\n\nThe algorithm identifies stops as contiguous sequences of pings that stay within the roaming distance for at least the duration of the stop duration.\n\nThis algorithm has the following parameters, which determine the size of the resulting stops:\n* ```dur_min```: Minimum duration for a stay in minutes.\n* ```dt_max```: Maximum time gap permitted between consecutive pings in a stay in minutes (dt_max should be greater than dur_min).\n* ```delta_roam```: Maximum roaming distance for a stay in meters." + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": "# %matplotlib inline\nimport matplotlib\nimport matplotlib.pyplot as plt\n\n# Imports\nimport nomad.io.base as loader\nimport geopandas as gpd\nfrom shapely.geometry import box\nfrom nomad.stop_detection.viz import plot_stops_barcode, plot_time_barcode, plot_stops, plot_pings\nimport nomad.stop_detection.lachesis as LACHESIS\nimport nomad.data as data_folder\nfrom pathlib import Path\n\n# Load data\ndata_dir = Path(data_folder.__file__).parent\ncity = gpd.read_parquet(data_dir / 'garden-city-buildings-mercator.parquet')\nouter_box = box(*city.total_bounds)\n\nfilepath_root = data_dir / \"gc_data_long\"\ntc = {\"user_id\": \"gc_identifier\", \"x\": \"dev_x\", \"y\": \"dev_y\", \"timestamp\": \"unix_ts\"}\n\nusers = ['admiring_brattain']\ntraj = loader.sample_from_file(filepath_root, format='parquet', users=users, filters=('date','==', '2024-01-01'), traj_cols=tc)\n\n# Lachesis (sequential stop detection)\nstops = LACHESIS.lachesis(traj, delta_roam=20, dt_max = 60, dur_min=5, complete_output=True, keep_col_names=True, traj_cols=tc)" + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": "fig, (ax_map, ax_barcode) = plt.subplots(2, 1, figsize=(6,6.5),\n gridspec_kw={'height_ratios':[10,1]})\n\ngpd.GeoDataFrame(geometry=[outer_box], crs='EPSG:3857').plot(ax=ax_map, color='#d3d3d3')\ncity.plot(ax=ax_map, edgecolor='white', linewidth=1, color='#8c8c8c')\n\nplot_stops(stops, ax=ax_map, cmap='Blues')\nplot_pings(traj, ax=ax_map, s=6, color='black', alpha=0.5, traj_cols=tc)\nax_map.set_axis_off()\n\nplot_time_barcode(traj['unix_ts'], ax=ax_barcode, set_xlim=True)\nplot_stops_barcode(stops, ax=ax_barcode, cmap='Blues', set_xlim=False, timestamp='unix_ts')\n\nplt.tight_layout(pad=0.1)\nplt.show()" + } + ], + "metadata": { + "kernelspec": { + "display_name": "base", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/examples/lachesis_demo.py b/examples/lachesis_demo.py index 133cf364..44e6b8e2 100644 --- a/examples/lachesis_demo.py +++ b/examples/lachesis_demo.py @@ -47,7 +47,7 @@ city = gpd.read_parquet(data_dir / 'garden-city-buildings-mercator.parquet') outer_box = box(*city.total_bounds) -filepath_root = 'gc_data_long/' +filepath_root = data_dir / "gc_data_long" tc = {"user_id": "gc_identifier", "x": "dev_x", "y": "dev_y", "timestamp": "unix_ts"} users = ['admiring_brattain'] diff --git a/examples/seqscan_demo.ipynb b/examples/seqscan_demo.ipynb index 01df55bf..37881506 100644 --- a/examples/seqscan_demo.ipynb +++ b/examples/seqscan_demo.ipynb @@ -44,7 +44,7 @@ "city = gpd.read_parquet(data_dir / 'garden-city-buildings-mercator.parquet')\n", "outer_box = box(*city.total_bounds)\n", "\n", - "filepath_root = 'gc_data_long/'\n", + "filepath_root = data_dir / \"gc_data_long\"\n", "tc = {\"user_id\": \"gc_identifier\", \"x\": \"dev_x\", \"y\": \"dev_y\", \"timestamp\": \"unix_ts\"}\n", "\n", "users = ['admiring_brattain']\n", diff --git a/examples/sequential_demo.ipynb b/examples/sequential_demo.ipynb index cb4c6aa0..2ce39489 100644 --- a/examples/sequential_demo.ipynb +++ b/examples/sequential_demo.ipynb @@ -51,7 +51,7 @@ "city = gpd.read_parquet(data_dir / 'garden-city-buildings-mercator.parquet')\n", "outer_box = box(*city.total_bounds)\n", "\n", - "filepath_root = 'gc_data_long/'\n", + "filepath_root = data_dir / \"gc_data_long\"\n", "tc = {\"user_id\": \"gc_identifier\", \"x\": \"dev_x\", \"y\": \"dev_y\", \"timestamp\": \"unix_ts\"}\n", "\n", "users = ['admiring_brattain']\n", diff --git a/examples/tadbscan_demo.ipynb b/examples/tadbscan_demo.ipynb index 3a2d5ea3..122a8819 100644 --- a/examples/tadbscan_demo.ipynb +++ b/examples/tadbscan_demo.ipynb @@ -47,7 +47,7 @@ "city = gpd.read_parquet(data_dir / 'garden-city-buildings-mercator.parquet')\n", "outer_box = box(*city.total_bounds)\n", "\n", - "filepath_root = 'gc_data_long/'\n", + "filepath_root = data_dir / \"gc_data_long\"\n", "tc = {\"user_id\": \"gc_identifier\", \"x\": \"dev_x\", \"y\": \"dev_y\", \"timestamp\": \"unix_ts\"}\n", "\n", "# Density based stop detection (Temporal DBSCAN)\n", diff --git a/examples/tadbscan_demo.py b/examples/tadbscan_demo.py index 7b6eb0d3..5ba575e7 100644 --- a/examples/tadbscan_demo.py +++ b/examples/tadbscan_demo.py @@ -45,7 +45,7 @@ city = gpd.read_parquet(data_dir / 'garden-city-buildings-mercator.parquet') outer_box = box(*city.total_bounds) -filepath_root = 'gc_data_long/' +filepath_root = data_dir / "gc_data_long" tc = {"user_id": "gc_identifier", "x": "dev_x", "y": "dev_y", "timestamp": "unix_ts"} # Density based stop detection (Temporal DBSCAN) diff --git a/examples/test_anim.ipynb b/examples/test_anim.ipynb index 7195c3d6..8dac5ad4 100644 --- a/examples/test_anim.ipynb +++ b/examples/test_anim.ipynb @@ -46,10 +46,9 @@ "}\n", "\n", "data_dir = Path(data_folder.__file__).parent\n", - "repo_root = Path(data_folder.__file__).resolve().parents[2]\n", "\n", "traj = loader.sample_from_file(\n", - " repo_root / \"examples\" / \"gc_data_long\",\n", + " data_dir / \"gc_data_long\",\n", " format=\"parquet\",\n", " users=[\"admiring_brattain\"],\n", " filters=(\"date\", \"==\", \"2024-01-01\"),\n", diff --git a/examples/gc_data_long/date=2024-01-01/part-0.parquet b/nomad/data/gc_data_long/date=2024-01-01/part-0.parquet similarity index 100% rename from examples/gc_data_long/date=2024-01-01/part-0.parquet rename to nomad/data/gc_data_long/date=2024-01-01/part-0.parquet diff --git a/examples/gc_data_long/date=2024-01-02/part-0.parquet b/nomad/data/gc_data_long/date=2024-01-02/part-0.parquet similarity index 100% rename from examples/gc_data_long/date=2024-01-02/part-0.parquet rename to nomad/data/gc_data_long/date=2024-01-02/part-0.parquet diff --git a/examples/gc_data_long/date=2024-01-03/part-0.parquet b/nomad/data/gc_data_long/date=2024-01-03/part-0.parquet similarity index 100% rename from examples/gc_data_long/date=2024-01-03/part-0.parquet rename to nomad/data/gc_data_long/date=2024-01-03/part-0.parquet