def test_fusionImages_height(self):
     latitude = "41.85"
     longitude = "-87.65"
     query_api(latitude, longitude, "tests/img.png")
     response = fusionImages("tests/img.png", "tests/plume.png",
                             "tests/fusioned.png")
     self.assertEqual(response.height, 257)
 def test_fusionImages_noError(self):
     latitude = "41.85"
     longitude = "-87.65"
     try:
         query_api(latitude, longitude, "tests/img.png")
         response = fusionImages("tests/img.png", "tests/plume.png",
                                 "tests/fusioned.png")
     except Exception:
         self.fail("Errors detected")
Exemple #3
0
def result():

     """

        **Form exploitation and Result**
        
        This function is used to manage the form submitted by the user in challengeHomePage.
        It uses 3 elements from the submitted form ::

               - latitude in the [-90,90] range

               - longitude in the [-180,180] range

               - fileupload which is the image used to overlay the satellite image from the Google API.

        With these elements, it uses the tools functions to get the satellite image and create the overlaid image.

        Once the tools are used, it simply redirects to result.html that will display the overlaid image.

        :return: redirection to result.html
    """
     data = []
     error = None
     request_file = request.files['fileupload']
     if not request_file:
          return "No file"
     request_file.save(os.path.join(app.config['UPLOAD_FOLDER'],"plume.png"))
     latitude = request.form.get('latitude')
     longitude = request.form.get('longitude')
     query_api(latitude,longitude,"./static/img.png")
     resp = fusionImages("./static/img.png","./static/plume.png","./static/fusioned.png")
     
     pp(resp)
     

     return render_template(
               'result.html',
               error=error)
Exemple #4
0
def getRequestFromImage():
     """

        **Overlaid Image RESTful API**
        
        This function is a custom made RESTful API.

        The URI is http://127.0.0.1:5000/api/image and it uses the POST method.

        It's very close to the result() function, however the returned value is different.

        It uses 3 elements from the submitted request ::
        
               - latitude in the [-90,90] range

               - longitude in the [-180,180] range

               - fileupload which is the image used to overlay the satellite image from the Google API.

        With these elements, it uses the tools functions to get the satellite image and create the overlaid image.

        Once the tools are used, it sends back the png image with send_file.

        :return: the overlaid image using send_file
    """
     request_file = request.files['fileupload']
     if not request_file:
          abort(400);
     request_file.save(os.path.join(app.config['UPLOAD_FOLDER'],"plume.png"))
     latitude = float(request.form.get('latitudeH'))
     longitude = float(request.form.get('longitudeH'))
     query_api(latitude,longitude,"./static/img.png")
     resp = fusionImages("./static/img.png","./static/plume.png","./static/fusioned.png")
     try:
          return send_file("static/fusioned.png", mimetype='image/png')
     except FileNotFoundError:
        abort(404)
Exemple #5
0
def main(argv=sys.argv):
    arg_parser = argparse.ArgumentParser(
        description=prog_desc,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    # Check for arguments. #
    if len(sys.argv[1:]) == 0:
        print('\nArguments required. Use -h option to print FULL usage.\n')

    arg_parser.add_argument('-g',
                            metavar='GROUP_FILE',
                            action='store',
                            type=os.path.abspath,
                            required=True,
                            help=('FULL path to your group csv/tsv file - '
                                  'the output from MRIQC.'),
                            dest='group_file')
    arg_parser.add_argument('-s',
                            metavar='SEARCH_PHRASE',
                            action='store',
                            type=str,
                            required=True,
                            help=('Search phrase to filter API query.'
                                  'Format: xxxx xxxxx xxxxxx xxxxxx'),
                            dest='search_phrase')
    arg_parser.add_argument('-t',
                            metavar='SCAN_TYPE',
                            action='store',
                            type=str,
                            choices=['bold', 'T1w', 'T2w'],
                            required=False,
                            default='T1w',
                            help=('Scan type to query. Can choose from bold,'
                                  ' T1w, or T2w.'),
                            dest='scan_type')
    args = arg_parser.parse_args()

    #################################################
    ## Script Argument Verification and Assignment ##
    #################################################
    if os.path.isfile(args.group_file):
        pass
    else:
        print('The groupfile you are trying to use was not found. Exiting...')
        sys.exit()

    #################################################
    ##          Global Variable Assignment         ##
    #################################################
    start_time = time.time()
    time.sleep(1)
    today_date = datetime.datetime.now().strftime('%m%d%Y')

    print('Querying API for ' + args.scan_type + ' scans.')

    ## GROUP FILE COULD TURN INTO A LIST OF FILES!!! Just need a way to keep track and name them...perhaps turn it into a tuple
    ## of (name,path) or maybe even a key: val?
    ## Check that this dataframe is the same format as the result_df output from the query_api function!!
    loaded_df = load_groupfile(args.group_file)

    # result_df = query_api(args.scan_type,'MultibandAccelerationFactor>3','RepetitionTime>1')
    # result_df = query_api(args.scan_type, ['MultibandAccelerationFactor>3', 'EchoTime>1'])
    result_df = query_api(args.scan_type,
                          'MultibandAccelerationFactor>3&EchoTime>1')

    ## Scater plot/visualization functions would go below here and pass result_df as well as loaded_df pandas dataframes
    # something like this:
    # scatter(loaded_df, result_df)

    full_runtime = time.time() - start_time
    print('\nFull Script Runtime: ', datetime.timedelta(seconds=full_runtime),
          '\n')