-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Welcome to the wiki page for the repository. Here you will find more details on the usage and architecture of the scripts in this repository. Contact information can be found at the bottom of this page. Thank you for your interest in this code!
In this section, the usage procedure of the scripts are described. This is also found in the README of the project.
Note: This repository contains a set of R scripts which are interlinked with each other using source(). Variables created in the environment by a script is often used by another script in the future. Thus, since each script individually is not useful all the scripts need to be run together in the correct order using the wrapper script provided (main.R).
In order to use these scripts, please follow the steps outlined below:
This repository is written in R. Thus R needs to be installed on the system. R may be downloaded from the official website: https://www.r-project.org/. The scripts need the following R packages as external dependencies:
jsonlite, sp, spacetime, trajectories, Hmisc, animation
If any of the above packages are not installed, please use the following command to install it:
install.packages("<package name>")
This repository takes JSON file (having a specific structure) containing data regarding visitors' trajectories in a closed environment including coordinates, timestamps and ancilliary data. The specific structure of the JSON file should be the same as those JSONs inside the Experiments/ directory in this repository.
The JSON files on which the analysis has to be done should be in present in the directory Experiments.
Once the JSON files are available at the correct path, the wrapper script main.R may be run. It may take some time to finish for all the tracks depending on the number of tracks present in total in all the JSON files. The last line in main.R uses the function track_details() to provide summaries of individual tracks (including an interactive animated web-based interface) after all the analysis is complete. track_details() takes a track number as the input. Thus, if details about track #2 is required the call to the function should be:
track_details(2)
Alternatively, if the scripts are to be run in a more modular manner the modules (as mentioned in main.R) may be run individually but sequentially. Thus, the following set of commands may be used in the R terminal
source("import.R")
source("analyzetracks.R")
source("analyzestats.R")
to achieve the same results. Then, the summaries of a track may be viewed using the track_details() function in the manner described above.
Here you can find a brief outline of the different modules in the code of this project. The modules and the sub-modules have been arranged sequentially based on the point they are used in the workflow. Short descriptions of these modules are given for future re-usability and reference.
Detailed description of the modules, the sub-modules, the functions as well as important lines of code can be found in the code itself in the form of elaborate comments.
A global wrapper script (main.R) has been provided to run all the three modules described below sequentially. The structure presented below shows the modules called and their sub-modules, if any.
-
import.R- Module for importing data: Reads JSONs from disk, extracts metadata, syntactically correct JSONs, calls appropriate functions to prepare the trajectory data into suitable structure-
loc2glob.R- Sub-module for spatial reference systems: Creates a global spatial reference system and converts local camera coordinates to the global reference system. -
coordinates.R- Sub-sub-module (ofloc2glob.R) for coordinate values: Contains coordinates for cameras, points of interest etc. -
trajectory.R- Sub-module for creating suitable data structures for trajectories: Creates a list data structure and the visitors' trajectories are stored in that list as objects of classTrackdefined in the packagetrajectories.
-
-
analyzetracks.R- Module for analyzing tracks and removing duplicates: Analyze the set of tracks for various purposes and discard or merge tracks which are duplicates or partial duplicates of other tracks in the set-
camera_functions.R- Sub-module for commonly used functions: Contains commonly-used generic utility functions which are used a number of times at various points in the scripts -
intercamera_static.R- Sub-module to identify partially-duplicated tracks: Identifies tracks suspected to belong to the same visitor from two different cameras observed at the same time (Case: 1) -
intercamera_dynamic.R- Sub-module to identify duplicate tracks for the same visitor: Identifies tracks suspected to belong to the same visitor from two different cameras observed at subsequent times after the visitor moves out of the range of a camera and comes into the range of another camera after some time (Case: 2) -
merge3.R- Sub-module for preparing the tracks to be merged: Prepares suitable data structures containing list of tracks which are to be merged as identified by the sub-modules for Case 1 and Case 2 (described above) -
mergers.R- Sub-sub-module (ofmerge3.R) for performing the actual merging: Implements the actual merging of the tracks as listed in results frommerge3.R. Merges tracks for Case 1 first and later merges tracks for Case 2 after suitable corrections needed after merging tracks for Case 1
-
-
analyzestats.R- Module for finding stops and visualization: Acts as the starting point for statistical analysis (not in this repository) by finding regions in space where visitors made a stops and visualize it.-
floor_layout.R- Sub-module to create prettier visualizations: Contains functions to visualize the study site and trajectories in a prettier manner. Contains code to generate summaries of individual tracks and interactive webpages to view animated visitor trajectories -
find_stops.R- Sub-module for finding stops: Analyzes trajectory data, find regions in space where visitors stopped and visualize them
-
Currently, the following sources of error are known. These errors occur only for some input JSON files. The reasons have not been ascertained yet. I would be glad if these issues could be investigated and resolved by the community.
In trajectory.R: An error is sometimes thrown when creating an object of class Track (defined in the package trajectories) from a STIDF object (defined in the package spacetime) near the following lines:
#Finally create an object of class Track (from trajectories) from the STIDF object created above track_obj = Track(stidf_obj)
The error thrown is:
Error in data.frame(distance = distance, duration = duration, speed = speed, : arguments imply differing number of rows: 1, 0
Again, in analyzetracks.R or any of its dependencies, the following error is thrown in a few cases:
Error in `row.names<-.data.frame`(`*tmp*`, value = value) : invalid 'row.names' length
Apart from these, there are a few warning messages that are shown but they are mostly harmless and do not interfere with the functioning. Of course, it would be useful to resolve those for future use.
If you have any questions or suggestions, I would love to hear them. Please contact me (Pramit Ghosh) by email.