Skip to content

Commit

Permalink
update connection.py, astroleaflet.py docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Weixiang Yu committed Sep 11, 2017
1 parent 7317425 commit df26b2d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion vizic/astroleaflet.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def _checkInput(self, coll_name, map_dict):

if coll_name is not None and coll_name in exist_colls:
raise Exception('Collectoin name already exists, try to use a different name or use existing collection.')
df_r, self._des_crs = self._data_prep(self.max_zoom, self.df)
df_r, self._des_crs = self._data_prep(self.df)
self.x_range = self._des_crs[2]*256
self.y_range = self._des_crs[3]*256

Expand Down
38 changes: 35 additions & 3 deletions vizic/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ def show_circles(self):
return circles

def import_new(self, df, coll_name, map_dict=None):
"""Import new catalog without creating a map layer.
Args:
df: The pandas dataframe contaning the data to be imported.
coll_name(str): A string for naming the data collection in DB.
map_dict(dict): A dictionary to assign different names to
existing columns.
"""

exist_colls = self.show_catalogs()
if coll_name in exist_colls:
Expand Down Expand Up @@ -156,7 +164,14 @@ def import_new(self, df, coll_name, map_dict=None):
self._insert_data(df_r, coll)

def add_to_old(self, df, coll_name, map_dict=None):
"""Add new data to existing catalog collection.
Args:
df:The pandas dataframe contaning the data to be imported.
coll_name(str): The name of the existing collection.
map_dict(dict): A dictionary to assign different names to
existing columns.
"""
exist_colls = self.show_catalogs()
if coll_name in exist_colls:
db_meta = self.read_meta(coll_name)
Expand Down Expand Up @@ -200,6 +215,12 @@ def add_to_old(self, df, coll_name, map_dict=None):
self._insert_data(df_r, coll)

def _update_coll(self, new, old):
"""Private method to update collection meta data.
Args:
new: A collection object for the updated dataset.
old: A collection object for the existing catalog collection.
"""

xMin = new._des_crs[0] if new._des_crs[0] < old._des_crs[0] \
else old._des_crs[0]
Expand Down Expand Up @@ -228,6 +249,16 @@ def _update_coll(self, new, old):
new.cat_ct = old.cat_ct + 1

def read_meta(self, coll_name):
"""Read meta information from a existing catalog collection and stores in
a collection object.
Args:
coll_name(str): Name of the requested collection.
Returns:
A new collection object encapsulating the requested meta information.
"""

coll = Collection()
meta = self.db[coll_name].find_one({'_id': 'meta'})
Expand All @@ -251,8 +282,8 @@ def _data_prep(self, df, coll):
Args:
df: A pandas dataframe containning the catalog.
coll: The Collection object containing meta information for the new
catalog.
coll: The Collection object storing meta information for the
corresponding catalog.
Returns:
A new pandas dataframe with added columns and a list specifying
Expand Down Expand Up @@ -294,7 +325,8 @@ def _insert_data(self, df, coll):
Args:
df: A pandas dataframe with correctly formatted catalog.
coll_name: MongoDB collection name for the new catalog.
coll: The collection object storing meta information for the
corresponding catalog.
"""

df['cat_rank'] = coll.cat_ct
Expand Down

0 comments on commit df26b2d

Please sign in to comment.