Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug of simulating GPS data #267

Open
JiaxinCCC opened this issue Nov 13, 2024 · 4 comments
Open

Bug of simulating GPS data #267

JiaxinCCC opened this issue Nov 13, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@JiaxinCCC
Copy link

Hi @GeorgeEfstathiadis @hackdna,

I followed the code below to simulate GPS data.

import datetime

from forest.bonsai.simulate_gps_data import gps_to_csv, sim_gps_data
from forest.bonsai.simulate_log_data import sim_log_data
from forest.jasmine.traj2stats import Frequency, gps_stats_main
from forest.willow.log_stats import log_stats_main

# 1. If you don't have any smartphone data (yet), you can generate fake data
path_to_synthetic_gps_data = "/home/ubuntu/projects/gps/forest/tutorials/simu_gps_data"
path_to_synthetic_log_data = "/home/ubuntu/projects/gps/forest/tutorials/simu_log_data"
path_to_gps_summary = "/home/ubuntu/projects/gps/forest/tutorials/simu_gps_output"
path_to_log_summary = "/home/ubuntu/projects/gps/forest/tutorials/simu_log_output"

# Generate synthetic GPS data and communication log data as CSV files
# Define parameters for generating the data
# To conserve smartphone battery power, we typically collect location data intermittently: e.g., an on-cycle of 3 minutes followed by an off-cycle of 12 minutes. We'll generate data in this way.
# Number of persons to generate
n_persons = 1
# Location of persons to generate, format: Country_2_letter_ISO_code/City_Name
location = "GB/Bristol"
# Start date for generated trajectories
start_date = datetime.date(2021, 10, 1)
# End date for trajectories
end_date = datetime.date(2021, 10, 5)
# API key for OpenRouteService, generated from https://openrouteservice.org/
#api_key = "5b3ce3597851110001cf6248359f91eec01b4e09ae4ceced5a7d04d1"
api_key = "mock_key"
# Length of off-cycle + length of on-cycle in minutes
cycle = 15
# Length off-cycle / (length off-cycle + length on-cycle)
percentage = 0.8
# Dictionary of personal attributes for each user, set to None if random; check Attributes class for usage in simulate_gps_data module
personal_attributes = {
    "User 1": {
        "main_employment": "none",
        "vehicle": "car",
        "travelling_status": 10,
        "active_status": 7,
    },
    "Users 2-4": {
        "main_employment": "university",
        "vehicle": "bicycle",
        "travelling_status": 8,
        "active_status": 8,
        "active_status-16": 2,
    },
    "User 5": {
        "main_employment": "office",
        "vehicle": "foot",
        "travelling_status": 9,
        "travelling_status-20": 1,
        "preferred_exits": ["cafe", "bar", "cinema"],
    },
}
sample_gps_data = sim_gps_data(
    n_persons,
    location,
    start_date,
    end_date,
    cycle,
    percentage,
    api_key,
    personal_attributes,
)

However, I encountered the following error, which seems like a bug in the code.

File [~/miniconda3/envs/gps/lib/python3.11/site-packages/forest/bonsai/simulate_gps_data.py:895](http://localhost:8888/lab/tree/Desktop/GPS_forest/~/miniconda3/envs/gps/lib/python3.11/site-packages/forest/bonsai/simulate_gps_data.py#line=894), in gen_all_traj(person, switches, start_date, end_date, api_key)
    870 """Generates trajectories for a single person.
    871 
    872 Args:
   (...)
    891     ValueError: if no offices around person's house address
    892 """
    894 if len(person.possible_destinations) < 4:
--> 895     raise ValueError("Not enough possible destinations")
    896 if (
    897     person.attributes.main_occupation != Occupation.NONE
    898     and person.office_coordinates == (0, 0)
    899 ):
    900     raise ValueError("No office coordinates")

ValueError: Not enough possible destinations

Do you have any suggestions on how I might resolve this error? Thanks for your help!

@JiaxinCCC JiaxinCCC added the bug Something isn't working label Nov 13, 2024
@hackdna
Copy link
Member

hackdna commented Nov 13, 2024

Hi @JiaxinCCC, I'll let @GeorgeEfstathiadis address the error but I've noticed that you may have exposed your API key for OpenRouteService above. If so, you should invalidate that key and generate a new one.

@JiaxinCCC
Copy link
Author

Thank you for catching that! I’ll revoke the API key and generate a new one to secure access. I appreciate the heads-up. I’ll also follow up with George about the error.

@GeorgeEfstathiadis
Copy link
Collaborator

Hi @JiaxinCCC , so I ran the code myself as is in the code segmented you provided and was not able to replicate your error. Did you perhaps modify the location or some other parameter to fit your use-case? In order to replicate the error you got I would need the exact script you ran.

This error is raised when the location of the simulated participant doesn't have more than 4 amenity type locations around it to basically simulate GPS trajectories. So it can be that either the location provided is very secluded or wrong spelling, some issue with OSM for that location or some bug in our code, but I can't be definitive right now which one it is.

@GeorgeEfstathiadis GeorgeEfstathiadis self-assigned this Nov 24, 2024
@JiaxinCCC
Copy link
Author

Hi @JiaxinCCC , so I ran the code myself as is in the code segmented you provided and was not able to replicate your error. Did you perhaps modify the location or some other parameter to fit your use-case? In order to replicate the error you got I would need the exact script you ran.

This error is raised when the location of the simulated participant doesn't have more than 4 amenity type locations around it to basically simulate GPS trajectories. So it can be that either the location provided is very secluded or wrong spelling, some issue with OSM for that location or some bug in our code, but I can't be definitive right now which one it is.

@GeorgeEfstathiadis thanks for your reply! My Python version is Python 3.11.10 and the package version is forest==0.1.1. I ran the following code, which comes from README.md:

# Currently, all imports from `forest` must be explicit.  For the below example you need to import the following
# In future, it would be great to have all functions import automatically
import datetime

from forest.bonsai.simulate_gps_data import gps_to_csv, sim_gps_data
from forest.bonsai.simulate_log_data import sim_log_data
from forest.jasmine.traj2stats import Frequency, gps_stats_main
from forest.willow.log_stats import log_stats_main

# 1. If you don't have any smartphone data (yet) you can generate fake data
path_to_synthetic_gps_data = "simu_gps_data"
path_to_synthetic_log_data = "simu_log_data"
path_to_gps_summary = "simu_gps_output"
path_to_log_summary = "simu_log_output"

# Generate fake call and text logs
# Because of the explicit imports, you don't have to precede the functions with forest.subpackage.
sim_log_data(path_to_synthetic_log_data)

# Generate synthetic gps data and communication logs data as csv files
# Define parameters for generating the data
# To save smartphone battery power, we typically collect location data intermittently: e.g. during an on-cycle of 3 minutes, followed by an off-cycle of 12 minutes. We'll generate data in this way
# number of persons to generate
n_persons = 1
# location of person to generate format: Country_2_letter_ISO_code/City_Name
location = "GB/Bristol"
# start date of generated trajectories
start_date = datetime.date(2021, 10, 1)
# end date of trajectories
end_date = datetime.date(2021, 10, 5)
# api key for openroute service, generated from https://openrouteservice.org/
api_key = "mock_api_key"
# Length of off-cycle + length of on-cycle in minutes
cycle = 15
# Length off-cycle / (length off-cycle + length on-cycle)
percentage = 0.8
# dictionary of personal attributes for each user, set to None if random, check Attributes class for usage in simulate_gps_data module.
personal_attributes = {
    "User 1":
    {
        "main_employment": "none", 
        "vehicle" : "car",
        "travelling_status": 10,
        "active_status": 7
    },

    "Users 2-4":
    {
        "main_employment": "university",
        "vehicle" : "bicycle",
        "travelling_status": 8,
        "active_status": 8,
        "active_status-16": 2 
    },

    "User 5":
    {
        "main_employment": "office",
        "vehicle" : "foot",
        "travelling_status": 9,
        "travelling_status-20": 1,
        "preferred_exits": ["cafe", "bar", "cinema"] 
    }
}
sample_gps_data = sim_gps_data(n_persons, location, start_date, end_date, cycle, percentage, api_key, personal_attributes)
# save data in format of csv files
gps_to_csv(sample_gps_data, path_to_synthetic_gps_data, start_date, end_date)

Let me know if more information is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants