-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ywx649999311/pkg
Turn project to package
- Loading branch information
Showing
28 changed files
with
10,699 additions
and
10,531 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
recursive-include ipyleaflet/static *.* | ||
recursive-include ipyastroleaflet/static *.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.