From 903f7991fa1d50a2bb709c631b1fa2b65b7ce140 Mon Sep 17 00:00:00 2001 From: gravityspy Date: Thu, 2 Aug 2018 10:35:07 -0700 Subject: [PATCH] Some more updates --- bin/update_similarity_score | 77 +++++++++++++++++++++++++++++++++++++ bin/updatescores | 4 +- 2 files changed, 79 insertions(+), 2 deletions(-) create mode 100755 bin/update_similarity_score diff --git a/bin/update_similarity_score b/bin/update_similarity_score new file mode 100755 index 0000000..416fe38 --- /dev/null +++ b/bin/update_similarity_score @@ -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') diff --git a/bin/updatescores b/bin/updatescores index 7999b97..f902394 100755 --- a/bin/updatescores +++ b/bin/updatescores @@ -54,7 +54,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] @@ -106,4 +106,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()