Skip to content

Commit

Permalink
Merge branch 'semantic_index' of https://github.com/Gravity-Spy/Gravi…
Browse files Browse the repository at this point in the history
…tySpy into semantic_index
  • Loading branch information
scottcoughlin2014 committed Aug 13, 2018
2 parents e21eeca + 903f799 commit 00d7234
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
77 changes: 77 additions & 0 deletions bin/update_similarity_score
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env python

# ---- Import standard modules to the python path.

from gravityspy.API.project import GravitySpyProject
import gravityspy.ML.read_image as read_image
import gravityspy.ML.labelling_test_glitches as label_glitches
from gravityspy.utils import log
import argparse
import pandas as pd
import os
from sqlalchemy.engine import create_engine

def parse_commandline():
"""Parse the arguments given on the command-line.
"""
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--Filename1", help="Path To File1",
required=True, nargs='+')
parser.add_argument("--Filename2", help="Path To File2",
required=True, nargs='+')
parser.add_argument("--Filename3", help="Path To File 3",
required=True, nargs='+')
parser.add_argument("--Filename4", help="Path to File 4",
required=True, nargs='+')
parser.add_argument("--pathToModel",
help="Path to folder containing trained model",
required=True)
args = parser.parse_args()

return args

args = parse_commandline()

logger = log.Logger('Gravity Spy: Update Similarity Sore')
# Since we created the images in a special temporary directory we can run os.listdir to get there full
# names so we can convert the images into ML readable format.
list_of_images_all = [args.Filename1,
args.Filename2,
args.Filename3,
args.Filename4]

list_of_images_all = zip(list_of_images_all[0],list_of_images_all[1],list_of_images_all[2],list_of_images_all[3])

for list_of_images in list_of_images_all:
ID = list_of_images[0].split('/')[-1].split('_')[1]
pathToModel = args.pathToModel

logger.info('Converting image to RGB ML readable...')

image_dataDF = pd.DataFrame()
for idx, image in enumerate(list_of_images):
logger.info('Converting {0}'.format(image))
image_data_r, image_data_g, image_data_b = read_image.read_rgb(image,
resolution=0.3)

image_dataDF[image] = [[image_data_r, image_data_g, image_data_b]]

image_dataDF['uniqueID'] = ID

# Now label the image
logger.info('Obtaining feature space of image...')
features = label_glitches.get_multiview_feature_space(image_data=image_dataDF,
semantic_model_adr='{0}'.format(pathToModel),
image_size=[140, 170],
verbose=False)

features = pd.DataFrame(features)
features['uniqueID'] = ID
logger.info('Uploading to database...')
engine = create_engine(
'postgresql://{0}:{1}'\
.format(os.environ['GRAVITYSPY_DATABASE_USER'],os.environ['GRAVITYSPY_DATABASE_PASSWD'])\
+ '@gravityspy.ciera.northwestern.edu:5432/gravityspy')
features.to_sql('updated_similarity_index', engine, index=False, if_exists='append')
engine.dispose()
logger.info('Done')
4 changes: 2 additions & 2 deletions bin/updatescores
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ for list_of_images in list_of_images_all:
image_dataDF = pd.DataFrame()
for idx, image in enumerate(list_of_images):
logger.info('Converting {0}'.format(image))
image_data = make_pickle.main(image,
image_data = read_image.read_grayscale(image,
resolution=0.3)
image_dataDF[image] = [image_data]

Expand Down Expand Up @@ -105,4 +105,4 @@ for list_of_images in list_of_images_all:
SQLCommand = SQLCommand + '''\"{0}\" = {1}, '''.format(Column,columnDict[Column])
SQLCommand = SQLCommand[:-2] + ' WHERE \"uniqueID\" = \'' + scoresTable.uniqueID.iloc[0] + "'"
engine.execute(SQLCommand)
>>>>>>> origin/develop
engine.dispose()

0 comments on commit 00d7234

Please sign in to comment.