onnela-lab / forest

Forest is a library for analyzing smartphone-based high-throughput digital phenotyping data
https://forest.beiwe.org
BSD 3-Clause "New" or "Revised" License
28 stars 16 forks source link

Error when running README example #178

Closed jflournoy closed 1 year ago

jflournoy commented 1 year ago

Commit hash (the first line of output from git show): commit e22bc625de900c30f69b7932eed4f59d98d7ea14 (HEAD -> develop, origin/develop, origin/HEAD)

Describe the bug Error thrown when running README example.

To reproduce Install forest, run README code for jasmine gps analyses.

Observed behavior

gps_stats_main(
    study_folder = path_to_synthetic_gps_data,
    output_folder = path_to_gps_summary,
    tz_str = tz_str,
    frequency = frequency,
    save_traj = save_traj,
    parameters = parameters,
    places_of_interest = places_of_interest,
    save_osm_log = save_osm_log,
    osm_tags = None,
    threshold = threshold,
)
User: user_1
Read in the csv files ...
Collapse data within 10 second intervals ...
Extract flights and pauses ...
Infer unclassified windows ...
Merge consecutive pauses and bridge gaps ...
Selecting basis vectors ...
Imputing missing trajectories ...
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[2], line 21
     18 threshold = 15
     20 # 3. Impute location data and generate mobility summary metrics using the simulated data above
---> 21 gps_stats_main(
     22     study_folder = path_to_synthetic_gps_data,
     23     output_folder = path_to_gps_summary,
     24     tz_str = tz_str,
     25     frequency = frequency,
     26     save_traj = save_traj,
     27     parameters = parameters,
     28     places_of_interest = places_of_interest,
     29     save_osm_log = save_osm_log,
     30     osm_tags = None,
     31     threshold = threshold,
     32 )

File ~/.conda/envs/star_diph/lib/python3.8/site-packages/forest/jasmine/traj2stats.py:1089, in gps_stats_main(study_folder, output_folder, tz_str, frequency, save_traj, parameters, places_of_interest, save_osm_log, osm_tags, threshold, split_day_night, person_point_radius, place_point_radius, time_start, time_end, participant_ids, all_memory_dict, all_bv_set, quality_threshold)
   1087 all_memory_dict[str(participant_id)] = out_dict["memory_dict"]
   1088 try:
-> 1089     imp_table = ImputeGPS(
   1090         mobmat2, bv_set, parameters.method,
   1091         parameters.switch, parameters.num,
   1092         parameters.linearity, tz_str, pars1
   1093     )
   1094 except RuntimeError as e:
   1095     sys.stderr.write(f"Error: {e}\n")

File ~/.conda/envs/star_diph/lib/python3.8/site-packages/forest/jasmine/mobmat2traj.py:342, in ImputeGPS(MobMat, BV_set, method, switch, num, linearity, tz_str, pars)
    340 if direction == 'forward':
    341     direction =''
--> 342     I0 = I_flight(method,start_t,start_x,start_y,end_t,end_x,end_y,BV_set,switch,num,pars)
    343     if (sum(I0==1)==switch and start_s==2) or (sum(I0==0)<switch and start_s==1):
    344         weight = K1(method,start_t,start_x,start_y,flight_table,pars)

File ~/.conda/envs/star_diph/lib/python3.8/site-packages/forest/jasmine/mobmat2traj.py:103, in I_flight(method, current_t, current_x, current_y, dest_t, dest_x, dest_y, BV_set, switch, num, pars)
     93 def I_flight(method,current_t,current_x,current_y,dest_t,dest_x,dest_y,BV_set,switch,num,pars):
     94     """
     95     Args: method, string, should be 'TL', or 'GL' or 'GLC'
     96           current_t, current_x, current_y, dest_t,dest_x,dest_y are scalars
   (...)
    101     Return: 1d array of 0 and 1, of length switch, indicator of a incoming flight
    102     """
--> 103     K = K1(method,current_t,current_x,current_y,BV_set,pars)
    104     flight_K = K[BV_set[:,0]==1]
    105     pause_K = K[BV_set[:,0]==2]

File ~/.conda/envs/star_diph/lib/python3.8/site-packages/forest/jasmine/mobmat2traj.py:89, in K1(method, current_t, current_x, current_y, BV_set, pars)
     87 k1 = np.exp(-abs(current_t-mean_t)/l1)*np.exp(-(np.sin(abs(current_t-mean_t)/86400*math.pi))**2/a1)
     88 k2 = np.exp(-abs(current_t-mean_t)/l2)*np.exp(-(np.sin(abs(current_t-mean_t)/604800*math.pi))**2/a2)
---> 89 d = great_circle_dist(current_x,current_y,mean_x,mean_y)
     90 k3 = np.exp(-d/g)
     91 return b1*k1+b2*k2+b3*k3

File ~/.conda/envs/star_diph/lib/python3.8/site-packages/forest/jasmine/data2mobmat.py:70, in great_circle_dist(lat1, lon1, lat2, lon2)
     64 temp = (
     65     np.cos(lat1) * np.cos(lat2) * np.cos(lon1 - lon2)
     66     + np.sin(lat1) * np.sin(lat2)
     67 )
     69 # due to measurement errors, temp may be out of the domain of "arccos"
---> 70 temp = min(temp, 1)
     71 temp = max(temp, -1)
     73 theta = np.arccos(temp)

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()