GeosPy: Geolocation Inference Made Easy

GeosPy is a python 3 library written to make geolocation inference easy. Geolocation inference is the identification of the real-world geographic location of an object on Earth based off of available data. GeosPy currently only supports network based inference methods.


In [1]:
from GeosPy import Geos
geosPy = Geos()

Basic Example

The standard use case of GeosPy is trying to find a user's location given various data.

To use GeosPy, the first thing we need to do is see what models are available.


In [2]:
print(geosPy.models)


frozenset({'jakartr', 'backstrom'})

Now that we know the available models, we'll make the choice to use Backstrom model (see Jurgens et al. (2015) for the pros and cons of various models).

We can then select our model by calling the set_model method.


In [7]:
backstrom = geosPy.set_model('backstrom')

Now that we have our GeosPy class instantiated with an appropriate model, we need to gather our data (this is where you come in!) and put it in the appropriate format, a dictionary of objects mapping to location (in latitude and longitude).

In this example we'll use people mapped to their home locations.


In [8]:
user_location_dict = {'Tyler': (44, -71.5), 'Tim': (45.5, -73.5), 'Gwyn': (44.5, -89.5),'Conor':(55.0, -106.0), 
                      'Sam': (25.7, -80.2), 'OffTheGrid': None}

Now this user_location_dict only gives us so much information. To make a meaningful inference, we need to provide the model with another peice of information, a dictionary of objects mapping to a list of other objects, where the objects are contained in the first dictionary.

For this example, we happen to have a dictionary user_friend_dict that maps OffTheGrid to a list of his friends.


In [5]:
user_friend_dict = {'OffTheGrid': ['Tyler', 'Sam', 'Gwyn', 'Conor', 'Tim']}

Finally with our instantiated and set class, and our two dictionaries we can run the model!


In [6]:
print(geosPy.locate(user_location_dict, user_friend_dict))


{'Conor': (55.0, -106.0), 'OffTheGrid': (45.5, -73.5), 'Tyler': (44, -71.5), 'Tim': (45.5, -73.5), 'Sam': (25.7, -80.2), 'Gwyn': (44.5, -89.5)}

Thus we see that OffTheGrid is most probably located at (45.5, -73.5) using the Backstrom model.


In [ ]: