Skip to content

Commit

Permalink
Merge pull request #1 from ywx649999311/pkg
Browse files Browse the repository at this point in the history
Turn project to package
  • Loading branch information
Weixiang Yu authored Oct 6, 2016
2 parents 0861741 + 563540a commit d5890d3
Show file tree
Hide file tree
Showing 28 changed files with 10,699 additions and 10,531 deletions.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# build files
*.egg-info/
.ipynb_checkpoints/
dist/
Expand All @@ -6,7 +7,13 @@ build/
node_modules/

# Compiled javascript
ipyleaflet/static/
ipyastroleaflet/static/

# OS X
.DS_Store

# Jupyter Notebook
.ipynb

# test files
test.py
4 changes: 3 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
The MIT License (MIT)

Copyright (c) for portions of project ipyastroleaflet are held by Brian E. Granger, 2014 as part of project ipyleaflet. All other copyright for project ipyastroleaflet are held by Weixiang Yu, 2016.

Copyright (c) 2014 Brian E. Granger

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -18,4 +20,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
recursive-include ipyleaflet/static *.*
recursive-include ipyastroleaflet/static *.*
28 changes: 9 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,33 @@
ipyleaflet
ipyastroleaflet
==========

A Jupyter / Leaflet bridge enabling interactive maps in the Jupyter notebook.

![Screenshot](/screenshot.png)
A Jupyter widget for visualizing astronomical catalog data

Note
----

This README concerns ipyleaflet version 0.2.0.
Part of the project was orginally forked from [ipyleaflet](https://github.com/ellisonbg/ipyleaflet), which is a Jupyter / Leaflet bridge enabling interactive maps in the Jupyter notebook. As a major component of ipyastroleaflet, ipyleaflet has been modified and improved in a way to better suite the needs of ipyastroleaflet.

Installation
------------

Using pip:

```
$ pip install ipyleaflet
$ jupyter nbextension enable --py --sys-prefix ipyleaflet
```

Using conda:

```
$ conda install -c conda-forge ipyleaflet
$ pip install ipyastroleaflet
$ jupyter nbextension enable --py --sys-prefix ipyastroleaflet
```

For a development installation (requires npm):

```
$ git clone https://github.com/ellisonbg/ipyleaflet.git
$ cd ipyleaflet
$ git clone https://github.com/ellisonbg/ipyastroleaflet.git
$ cd ipyastroleaflet
$ pip install -e .
$ jupyter nbextension install --py --symlink --sys-prefix ipyleaflet
$ jupyter nbextension enable --py --sys-prefix ipyleaflet
$ jupyter nbextension install --py --symlink --sys-prefix ipyastroleaflet
$ jupyter nbextension enable --py --sys-prefix ipyastroleaflet
```

Note for developers: the `--symlink` argument on Linux or OS X allows one to
modify the JavaScript code in-place. This feature is not available
with Windows.


7 changes: 4 additions & 3 deletions ipyleaflet/__init__.py → ipyastroleaflet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from ._version import version_info, __version__

from .leaflet import *
from .astroleaflet import *
from .connection import Connection

def _jupyter_nbextension_paths():
return [{
'section': 'notebook',
'src': 'static',
'dest': 'jupyter-leaflet',
'require': 'jupyter-leaflet/extension'
'dest': 'jupyter-astro-leaflet',
'require': 'jupyter-astro-leaflet/extension'
}]
2 changes: 1 addition & 1 deletion ipyleaflet/_version.py → ipyastroleaflet/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version_info = (0, 3, 0, 'dev0')
version_info = (0, 0, 1, 'dev0')
__version__ = '.'.join(map(str, version_info))
38 changes: 38 additions & 0 deletions ipyastroleaflet/astroleaflet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from ipyastroleaflet.leaflet import *
from ipywidgets import (
Widget, Layout
)
from traitlets import Unicode

class AstroMap(Map):

@default('layout')
def _default_layout(self):
return Layout(height='600px', width='600px')

scroll_wheel_zoom = Bool(True).tag(sync=True, o=True)
wheel_debounce_time = Int(80).tag(sync=True, o=True)
wheel_px_per_zoom_level = Int(80).tag(sync=True, o=True)
zoom = Int(1).tag(sync=True, o=True)
max_zoom = Int(12).tag(sync=True, o=True)

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.clear_layers()

class NotebookUrl(Widget):
_view_name = Unicode('NotebookUrlView').tag(sync=True)
_view_module = Unicode('jupyter-astro-leaflet').tag(sync=True)
nb_url = Unicode().tag(sync=True)

class GridLayer(RasterLayer):
_view_name = Unicode('LeafletGridLayerView').tag(sync=True)
_model_name = Unicode('LeafletGridLayerModel').tag(sync=True)

bottom = Bool(False).tag(sync=True)
# min_zoom = Int(0).tag(sync=True, o=True)
# max_zoom = Int(18).tag(sync=True, o=True)
# tile_size = Int(256).tag(sync=True, o=True)
# xc = Int(3).tag(sync=True, o=True)
# yc = Int(3).tag(sync=True, o=True)
# detect_retina = Bool(False).tag(sync=True, o=True)
30 changes: 30 additions & 0 deletions ipyastroleaflet/connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import pymongo as pg
import requests
from pymongo.errors import AutoReconnect, ConnectionFailure
class Connection:

def __init__(self, host="localhost", port=27017, db="vis", url='http://localhost:8888/'):

self.host = host
self.port = port
self.__url = url
try:
self.client = pg.MongoClient(host, port)
self.db = self.client[db]
self.change_db(db)
except ConnectionFailure as err:
print ('Error: Connection to MongoDB instance is refused!')
raise Exception('Check database info before initialize connection!')

def change_db(self, db):

self.db = self.client[db]
body = {
'host':self.host,
'port':self.port,
'db':db
}
path = self.__url+'connection/'
req = requests.post(path, data=body)
if req.status_code != 200:
raise Exception('Change database failed!')
27 changes: 7 additions & 20 deletions ipyleaflet/leaflet.py → ipyastroleaflet/leaflet.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def interact(self, **kwargs):
class Layer(Widget, InteractMixin):
_view_name = Unicode('LeafletLayerView').tag(sync=True)
_model_name = Unicode('LeafletLayerModel').tag(sync=True)
_view_module = Unicode('jupyter-leaflet').tag(sync=True)
_model_module = Unicode('jupyter-leaflet').tag(sync=True)
_view_module = Unicode('jupyter-astro-leaflet').tag(sync=True)
_model_module = Unicode('jupyter-astro-leaflet').tag(sync=True)

# bottom = Bool().tag(sync=True)
options = List(trait=Unicode).tag(sync=True)
Expand Down Expand Up @@ -117,18 +117,6 @@ class TileLayer(RasterLayer):
opacity = Float(1.0).tag(sync=True, o=True)
detect_retina = Bool(False).tag(sync=True, o=True)

class GridLayer(RasterLayer):
_view_name = Unicode('LeafletGridLayerView').tag(sync=True)
_model_name = Unicode('LeafletGridLayerModel').tag(sync=True)

# bottom = Bool(False).tag(sync=True)
# min_zoom = Int(0).tag(sync=True, o=True)
# max_zoom = Int(18).tag(sync=True, o=True)
# tile_size = Int(256).tag(sync=True, o=True)
# xc = Int(3).tag(sync=True, o=True)
# yc = Int(3).tag(sync=True, o=True)
# detect_retina = Bool(False).tag(sync=True, o=True)

class ImageOverlay(RasterLayer):
_view_name = Unicode('LeafletImageOverlayView').tag(sync=True)
_model_name = Unicode('LeafletImageOverlayModel').tag(sync=True)
Expand Down Expand Up @@ -263,8 +251,8 @@ class ControlException(TraitError):
class Control(Widget):
_view_name = Unicode('LeafletControlView').tag(sync=True)
_model_name = Unicode('LeafletControlModel').tag(sync=True)
_view_module = Unicode('jupyter-leaflet').tag(sync=True)
_model_module = Unicode('jupyter-leaflet').tag(sync=True)
_view_module = Unicode('jupyter-astro-leaflet').tag(sync=True)
_model_module = Unicode('jupyter-astro-leaflet').tag(sync=True)

options = List(trait=Unicode).tag(sync=True)

Expand Down Expand Up @@ -354,12 +342,12 @@ def _default_layout(self):

_view_name = Unicode('LeafletMapView').tag(sync=True)
_model_name = Unicode('LeafletMapModel').tag(sync=True)
_view_module = Unicode('jupyter-leaflet').tag(sync=True)
_model_module = Unicode('jupyter-leaflet').tag(sync=True)
_view_module = Unicode('jupyter-astro-leaflet').tag(sync=True)
_model_module = Unicode('jupyter-astro-leaflet').tag(sync=True)

# Map options
center = List(def_loc).tag(sync=True, o=True)
zoom_start = Int(12).tag(sync=True, o=True)
# zoom_start = Int(12).tag(sync=True, o=True)
zoom = Int(12).tag(sync=True, o=True)
max_zoom = Int(18).tag(sync=True, o=True)
min_zoom = Int(0).tag(sync=True, o=True)
Expand Down Expand Up @@ -532,4 +520,3 @@ def __add__(self, item):

def _handle_leaflet_event(self, _, content):
pass

1 change: 1 addition & 0 deletions ipyastroleaflet/mongo_ext/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

93 changes: 93 additions & 0 deletions ipyastroleaflet/mongo_ext/db_connect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#database util library for des data
import motor
from tornado import gen
import concurrent.futures as cfs
import time

# coll = db['des']
# mst_coll = db['mst']

# executor = cfs.ThreadPoolExecutor(max_workers=20)
class MongoConnect:

def __init__(self, host, port, db, coll='des'):
self.client = motor.motor_tornado.MotorClient(host, port)
self.db = self.client[db]
self.coll = self.db[coll]

def close(self):
self.client.close()

@gen.coroutine
def getTileData(self, xc, yc, zoom):
# multiThread is not stable
# result = executor.submit(getCoordRange, xc, yc, zoom).result()
# minR = executor.submit(getMinRadius,zoom, 0.714).result()

result = self.getCoordRange(xc, yc, zoom)
minR = self.getMinRadius(zoom, 0.714)
cursor = self.coll.find({

'$and': [
{'tile_x': {"$lt":result[0]}},
{'tile_x': {"$gt":result[1]}},
{'tile_y': {"$lt":result[2]}},
{'tile_y': {"$gt":result[3]}},
{'b': {'$gte': minR*0.3}} #a good number to use, objects smaller than this size is hard to display

]
},

{
'RA':1,
'DEC':1,
'THETA_IMAGE':1,
'COADD_OBJECTS_ID':1,
'a':1,
'b':1,
'_id':0

})

#print ('query', time.time())
return cursor

@gen.coroutine
def getVoronoi(self, tile):

coll_v = db[tile]

cursor_v = coll_v.find({},{

'_id': 0,
'RA': 1,
'DEC': 1,
})


return cursor_v


def getCoordRange(self, xc, yc, zoom):
#print (8-int(zoom))
multi = 2**(8-int(zoom))
xMin = int(xc)*multi - 1
xMax = (int(xc)+1)*multi
yMin = int(yc)*multi -1
yMax = (int(yc)+1)*multi



return (xMax, xMin, yMax, yMin)

#return result

def getMinRadius(self, zoom, mapSizeV):

return float(mapSizeV)/(256*(2**(int(zoom))))

@gen.coroutine
def getMst(self, tile):
cusor_m = mst_coll.find({'tile_id': tile}, {'_id': 0, 'tree':1})

return cusor_m
Loading

0 comments on commit d5890d3

Please sign in to comment.