Coder Social home page Coder Social logo

pbugnion / gmaps Goto Github PK

View Code? Open in Web Editor NEW
759.0 25.0 147.0 107.5 MB

Google maps for Jupyter notebooks

Home Page: https://jupyter-gmaps.readthedocs.io/en/stable/

License: Other

Python 71.88% JavaScript 26.45% CSS 1.32% Shell 0.35%
python jupyter google-maps maps jupyter-widget

gmaps's People

Contributors

carolinux avatar devmessias avatar fwahl711 avatar gatapia avatar lincolnfrias avatar mlwohls avatar npmcdn-to-unpkg-bot avatar orm011 avatar pbugnion avatar razzius avatar ruddyscent avatar shwinnn avatar stormbringer68 avatar xoolive avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gmaps's Issues

GMaps does not show up

I have tried running the simple example:

import gmaps
import gmaps.datasets

gmaps.configure(api_key="AIzaSyDOESksOPLhqEw...")

m = gmaps.Map()
m

but nothing shows up - the kernel keeps running forever. In the terminal it says:

(404 GET /static/jupyter-gmaps.js?v=20160823123004 (127.0.0.1) 9.95ms referer=http://localhost:8888/notebooks/test-gmaps.ipynb)

Room for improvement on directions interface

(from #60)

Some room for improvements, here are some reflections:

  • It would be great to be able to pass as data either lat/lon tuples or the kind of dictionaries returned by googlemaps API.
import googlemaps
import gmaps

client = googlemaps.Client(">>>> fill in your API key <<<<")
location = client.geocode("Toulouse")
print (location) # have a look!
gmaps.add_layer(Directions(data=[client.geocode("Toulouse"), client.geocode("Paris")]))
  • Also, we hardcoded the travelmode parameter which could be passed as parameter (though I have no idea how to pass something more than data). More generally, it would be great to have a close interface to googlemaps and write:
# from googlemaps documentation
directions_result = client.directions("Sydney Town Hall",
                                     "Parramatta, NSW",
                                     mode="transit",
                                     departure_time=now)
# how about this ?
gmaps.add_layer(Directions("Sydney Town Hall",
                           "Parramatta, NSW",
                           mode="transit",
                           departure_time=now))

For future references, there is a good overview of the interface here.

AttributeError: DOMWidget when trying sudo pip install gmaps

I am trying to install gmaps using pip on ubuntu 14.04

However I am getting the following issue

Collecting gmaps
  Downloading gmaps-0.1.6.tar.gz (98kB)
    100% |████████████████████████████████| 102kB 75kB/s 
    Complete output from command python setup.py egg_info:
    /usr/local/lib/python2.7/dist-packages/IPython/html.py:14: ShimWarning: The `IPython.html` package has been deprecated. You should import from `notebook` instead. `IPython.html.widgets` has moved to `ipywidgets`.
      "`IPython.html.widgets` has moved to `ipywidgets`.", ShimWarning)
    /usr/local/lib/python2.7/dist-packages/IPython/utils/traitlets.py:5: UserWarning: IPython.utils.traitlets has moved to a top-level traitlets package.
      warn("IPython.utils.traitlets has moved to a top-level traitlets package.")
    Traceback (most recent call last):
      File "<string>", line 20, in <module>
      File "/tmp/pip-build-3069XK/gmaps/setup.py", line 7, in <module>
        import gmaps
      File "gmaps/__init__.py", line 3, in <module>
        from heatmap import heatmap
      File "gmaps/heatmap.py", line 8, in <module>
        class HeatmapWidget(widgets.DOMWidget):
      File "/usr/local/lib/python2.7/dist-packages/IPython/utils/shimmodule.py", line 92, in __getattr__
        raise AttributeError(key)
    AttributeError: DOMWidget

Ability to pass Google Maps API key

I sometimes get the following error (can be stubborn, can fix itself somehow...). No idea why things sometimes work properly without an API key, but I guess it wouldn't hurt to be able to add one?

capture d ecran 2016-06-23 a 23 44 29

Ability to set centre and zoom options on basic map

It would be good to be able to set the centre and zoom on maps (cf issue #80). An interface like:

m = Map(zoom=8, centre=[-5.0, 5.0], centre_on_data=False)

would work. The centre_on_data argument is useful to stop the default behaviour which recanters the map so it always bounds the data.

Does not display output

Running the following code does not produce any output on Ipython Notebook v3.2.0 and Python 2.7.10

import gmaps

data = [ [ 37.782551,-122.445368 ],
         [ 37.782745,-122.444586 ],
         [ 37.782842,-122.443858 ] ]

gmaps.heatmap(data)

No Warnings (except for
:0: FutureWarning: IPython widgets are experimental and may change in the future.) and No Errors.

Requirements file

This package is missing a requirements.txt file. It's not a big deal, since the packages required are pretty obvious (IPython, Numpy), but we should still have one.

Improve installation / JS library loading process

There are two problems with the installation / initialisation of gmaps, AFAICT:

  1. The import command actually runs code (it imports the notebook extension), which is probably frowned upon.
  2. The installation makes setuptools think the JS libraries are data files and installs them that way. This is a pain for development because the "python setup.py install_data" commands needs to be re-run after every change.

Changing heatmap properties

Hey everyone,

I was wondering what the best way would be to go about changing the heatmap properties.
I tried using the google heatmap reference but didn't get very far.

I am sorry if this is a dumb question, I'm not very experienced.

Thanks in advance!

Build a viable pipeline for writing documentation.

This package desperately needs documentation. Unfortunately, the obvious solution of writing IPython notebooks and exporting them to HTML doesn't work. Javascript widgets are not included in the exported HTML, so you can't actually see the maps (see this, for instance).

I think that the solution will be to write a custom 'nbexport' script, but that sounds like a real pain.

Jupyter unrecognized flag

When enabling widget extension for Jupyter I get:
[EnableNBExtensionApp] CRITICAL | Bad config encountered during initialization: [EnableNBExtensionApp] CRITICAL | Unrecognized flag: '--py'
I tried to look around on Jupyter shell commands but couldn't find reference to '--py' on help pages
Am I missing some package etc?

Include a datasets module like in scikit-learn

I like the scikit-learn datasets module. It would be nice to have something like

np_array = gmaps.datasets.taxi_data.load_dataset()

We do bundle data in in the examples at the moment, but it's a pain for the user to have to search for the file in the appropriate site-packages directory.

No module named 'loader' at pip install

C:\Users\XXX\AppData\Local\Continuum\Anaconda3>pip install gmaps
Collecting gmaps
Downloading gmaps-0.1.6.tar.gz (98kB)
100% |################################| 102kB 1.5MB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 20, in
File "C:\Users\XXX\AppData\Local\Temp\pip-build-m3s6zj_3\gmaps\setup.py", line 7, in
import gmaps
File "C:\Users\XXX\AppData\Local\Temp\pip-build-m3s6zj_3\gmaps\gmaps__init__.py", line 2, in
from loader import init
ImportError: No module named 'loader'

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in C:\Users\XXX\AppData\Local\Temp\pip-build-m3s6zj_3\gmaps

Data array should accept all iterables

The data array passed to Heatmap and Directions has to be a list of lists at the moment. This goes against the expectation that duck-typing works in Python. For instance, the following should just work for any pandas data frame df:

Heatmap(data=df[["latitude", "longitude"]])

The reason this is currently broken is that data is a traitlet. Changing this to a private variable that we fill in by iterating over what the user passes would be better.

Ability to save maps as images.

It would probably be a nice thing to have something like:

import gmaps
m = gmaps.Map()
m.add_layer(...)
m.save("map.png")

Google Static Maps API may help? It would be nice to investigate.

import Error from IPython.html import widgets

When I try to type import gmaps into the terminal it gives me the following error:

----> 2 from IPython.html import widgets
3 from IPython.utils.traitlets import List, Unicode, Bool
4
5 import ipy23_compat

ImportError: cannot import name widgets

I'm using python 64 bit 2.7 on canopy gmaps version 0.1.6 and python version 2.4.1

Couldn't create a view for model id

I am getting the following error in browser console when trying the example on README.rst, what could be the most likely cause, please?

WrappedError {stack: "Error: Couldn't create a view for model id '098ff7…s-widgets/extension.js?v=20160512124824:32043:30)", message: "Couldn't create a view for model id '098ff76350694707a8ed2de25b6b3eac'", error_stack: Array[2]}
error_stack: Array[4]
0: Error: Class HeatmapView not found in registry at http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:32009:25 at Object.loadClass (http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:31970:13) at http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:32193:23
1: Error: Couldn't create a view for model id '098ff76350694707a8ed2de25b6b3eac' at new Error (native) at Error.WrappedError (http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:31936:22) at promiseRejection (http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:32043:30)
2: Error: Could not create view at new Error (native) at Error.WrappedError (http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:31936:22) at promiseRejection (http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:32043:30)
3: Error: Could not display model at new Error (native) at Error.WrappedError (http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:31936:22) at promiseRejection (http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:32043:30)
4: Error: Could not get state of widget manager at new Error (native) at Error.WrappedError (http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:31936:22) at promiseRejection (http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:32043:30)
5: Error: Could not call widget save state callback. at new Error (native) at Error.WrappedError (http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:31936:22) at promiseRejection (http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:32043:30)
message: "Could not call widget save state callback."
...

help request: importing from local csv

gmap notebook.ipynb.zip
Hello

I have attached the ipynb file that I used while working on this problem. I removed the API key.

goal: load simple local csv files directly.

I have tried many options(see below). What code would you recommend I use to get a local csv to load properly?

thank you
Dennis

import numpy as np

import gmaps
gmaps.configure(api_key="AIyourAPIKeyGoesHere")

m = gmaps.Map()

data = np.loadtxt("/home/dgd/Desktop/text.csv")
heatmap_layer = gmaps.Heatmap(data=data)
m.add_layer(heatmap_layer)
m

error

ValueError: could not convert string to float: b'lat'

import numpy as np
import gmaps

gmaps.configure(api_key="AIyourAPIKeyGoesHere")

m = gmaps.Map()

data = np.loadtxt("/home/dgd/Desktop/text.csv")
heatmap_layer = gmaps.Heatmap(data=data)
m.add_layer(heatmap_layer)
m

error:

ValueError: could not convert string to float: b'lat'

import numpy as np
import gmaps

gmaps.configure(api_key="AIyourAPIKeyGoesHere")

m = gmaps.Map()

data = np.genfromtxt("/home/dgd/Desktop/text.csv", delimiter=',')
heatmap_layer = gmaps.Heatmap(data=data)
m.add_layer(heatmap_layer)
m

error:
TraitError: The 'data' trait of a Heatmap instance must be a list, but a value of class 'numpy.ndarray' (i.e. array([[ nan, nan],
[ 38., 0.],
[ 45., 0.]])) was specified.


import csv
import gmaps

gmaps.configure(api_key="AIyourAPIKeyGoesHere")

m = gmaps.Map()

with open('/home/dgd/Desktop/text.csv', 'rb') as f:
    reader = csv.reader(f)
    data =your_list = map(tuple, reader)

heatmap_layer = gmaps.Heatmap(data=data)
m.add_layer(heatmap_layer)
m

error:

TraitError: The 'data' trait of a Heatmap instance must be a list, but a value of class 'map' (i.e. <map object at 0x7fa4ac122320>) was specified.

question big dataset

Hi,

first of all great lib.

is gmaps able to handle 200k geo points (lat/long)? How can you update the heatmap on the fly and add new datapoints?

Thanks

AttributeError: has_bounds (running example from README)

m.add_layer(gmaps.Heatmap(data=data))

yields

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
----> 1 m.add_layer(gmaps.Heatmap(data=data))

gmaps/maps.py in add_layer(self, layer)
     62 
     63     def add_layer(self, layer):
---> 64         self.layers = tuple([l for l in self.layers] + [layer])
     65 
     66     @default("layout")

traitlets/traitlets.py in __set__(self, obj, value)
    556             raise TraitError('The "%s" trait is read-only.' % self.name)
    557         else:
--> 558             self.set(obj, value)
    559 
    560     def _validate(self, obj, value):

traitlets/traitlets.py in set(self, obj, value)
    545             # we explicitly compare silent to True just in case the equality
    546             # comparison above returns something other than True/False
--> 547             obj._notify_trait(self.name, old_value, new_value)
    548 
    549     def __set__(self, obj, value):

traitlets/traitlets.py in _notify_trait(self, name, old_value, new_value)
   1091             'new': new_value,
   1092             'owner': self,
-> 1093             'type': 'change',
   1094         })
   1095 

ipywidgets/widgets/widget.py in notify_change(self, change)
    366                 # Send new state to front-end
    367                 self.send_state(key=name)
--> 368         LoggingConfigurable.notify_change(self, change)
    369 
    370     #-------------------------------------------------------------------------

traitlets/traitlets.py in notify_change(self, change)
   1125                 c = getattr(self, c.name)
   1126 
-> 1127             c(change)
   1128 
   1129     def _add_notifiers(self, handler, name, type):

gmaps/maps.py in _calc_bounds(self, change)
     71     def _calc_bounds(self, change):
     72         layers = change["new"]
---> 73         bounds_list = [layer.data_bounds for layer in layers if layer.has_bounds]
     74         if bounds_list:
     75             min_latitude = min(bounds[0][0] for bounds in bounds_list)

gmaps/maps.py in <listcomp>(.0)
     71     def _calc_bounds(self, change):
     72         layers = change["new"]
---> 73         bounds_list = [layer.data_bounds for layer in layers if layer.has_bounds]
     74         if bounds_list:
     75             min_latitude = min(bounds[0][0] for bounds in bounds_list)

AttributeError: 'list' object has no attribute 'has_bounds'

first demo fails: No such file or directory gmaps/datasets/metadata.json


Here is info about my python:

(dato-env)dan@nia111:~/pg/dan $ python
Python 2.7.11 |Anaconda 2.5.0 (64-bit)| (default, Dec  6 2015, 18:08:32) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> 


(dato-env)dan@nia111:~/pg/dan $ jupyter --version
4.1.0
(dato-env)dan@nia111:~/pg/dan $ 

I did 

pip install gmaps
pip install ipywidgets
jupyter notebook

I see this:

import gmaps

data = gmaps.datasets.load_dataset('taxi_rides')

IOError: [Errno 2] No such file or directory: '/home/dan/anaconda3/envs/dato-env/lib/python2.7/site-packages/gmaps/datasets/metadata.json'

I am disappointed that it failed so early in the demo.

Ability to export map to static HTML

It would be useful to be able to export a map to a static HTML / JS file. I think we could do this by:

  1. Having the javascript source available on a CDN.
  2. Building up a JS version of the model programatically from the values of the traitlets in the Python model.
  3. Putting all of this in a Jinja2 template.

This is somewhat related to issue #62 (saving maps as images).

Save created map as an image

It would be wonderful to be able to save the displayed map as an image (png or whatever). Is it already feasible with the current version? If not do you think it can be added?

support only about 1500 points. Doesn't work for more points

I have a list of 200,000 lat,lon pairs. The heatmap works fine until 1500 points. When set to 2000, it just show a regular map without heat. Is that there's a limit on how many points can be supported?

The code is running on jupyter in datascientist workbench with spark

import gmaps

longitude_list = sqlContext.sql("SELECT lon From table_15_1")
latitude_list = sqlContext.sql("SELECT lat From table_15_1")
data = []
for lat,lon in zip(latitude_list.collect()[:2000], longitude_list.collect()[:2000]):
point = []
point.append(lat)
point.append(lon)
data.append(point)
gmaps.heatmap(data)

Get rid of the init function.

Maybe either use the "require.js" format to import google, or a matplotlib style "%matplotlib inline" cell magic.

Shape of the `data` array

At the moment, layers accept a data array that is a list of (latitude, longitude) pairs. An alternative interface would be to have a pair of latitude, longitude arrays.

The motivation for passing in two arrays, one with latitude and one with longitude values, is that most modellers, data scientists etc. are used to dealing with tabular data, e.g. through a pandas dataframe. They might have a column of latitudes and a column of longitudes in their data frame.

Given that this is a major breaking change in the API if implemented, it's important to resolve this as early as possible.

Website

This project is really visual. It would therefore benefit from having a decent website.

Maybe use Github pages as a stopgap?

This is related to #22.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.