コード例 #1
0
 def test_image_not_found_withcode(self):
     reqex= xcpt.ImageNotFound(self.BAD_FILE, 99)
     assert reqex.error_code == 99
     rdict = reqex.to_dict()
     assert 'message' in rdict
     assert rdict.get('message') == self.BAD_FILE
     rtup = reqex.to_tuple()
     assert rtup[0] == self.BAD_FILE
     assert rtup[1] == 99
コード例 #2
0
ファイル: tasks.py プロジェクト: AstrolabeProject/cuts
def image_metadata (args):
    """ Return image metadata for a specific image by ID. """
    uid = au.parse_id_arg(args)                   # get required ID or error
    md = imgr.image_metadata(uid)
    if (md is not None):
        return jsonify(imgr.image_metadata(uid))
    else:
        errMsg = f"Image metadata for image ID '{uid}' not found in database"
        current_app.logger.error(errMsg)
        raise exceptions.ImageNotFound(errMsg)
コード例 #3
0
ファイル: tasks.py プロジェクト: AstrolabeProject/cuts
def fetch_image_by_path (args):
    """ Fetch a specific image by image path. """
    ipath = au.parse_ipath_arg(args, required=True)  # get required image path or error
    istream = imgr.fetch_image_by_path(ipath)
    if (istream is not None):
        return istream
    else:
        errMsg = f"Image with image path '{ipath}' not found in database"
        current_app.logger.error(errMsg)
        raise exceptions.ImageNotFound(errMsg)
コード例 #4
0
ファイル: tasks.py プロジェクト: AstrolabeProject/cuts
def fetch_image (args):
    """ Fetch a specific image by ID. """
    uid = au.parse_id_arg(args)                   # get required ID or error
    istream = imgr.fetch_image(uid)
    if (istream is not None):
        return istream
    else:
        errMsg = f"Image with image ID '{uid}' not found in database"
        current_app.logger.error(errMsg)
        raise exceptions.ImageNotFound(errMsg)
コード例 #5
0
 def test_image_not_found(self):
     reqex = xcpt.ImageNotFound(self.BAD_FILE)
     print(reqex)
     print(type(reqex))
     assert reqex.error_code == xcpt.ImageNotFound.ERROR_CODE
     rdict = reqex.to_dict()
     assert 'message' in rdict
     assert rdict.get('message') == self.BAD_FILE
     rtup = reqex.to_tuple()
     assert rtup[0] == self.BAD_FILE
     assert rtup[1] == xcpt.ImageNotFound.ERROR_CODE
コード例 #6
0
ファイル: tasks.py プロジェクト: AstrolabeProject/cuts
def fetch_image_by_filter (args):
    """ Fetch a specific image by filter/collection. """
    filt = au.parse_filter_arg(args, required=True)  # get required filter or error
    collection = au.parse_collection_arg(args)
    istream = imgr.fetch_image_by_filter(filt, collection=collection)
    if (istream is not None):
        return istream
    else:
        coll = f"and collection '{collection}'" if (collection) else ''
        errMsg = f"Image with filter '{filt}' {coll} not found in database"
        current_app.logger.error(errMsg)
        raise exceptions.ImageNotFound(errMsg)
コード例 #7
0
    def get_image_or_cutout(self, co_args, collection=None, filt=None):
        """
        Return an entire image or a cutout, based on the given cutout arguments and
        optional collection and filter arguments.
        """
        if (co_args.get('co_size') is
                None):  # if no size specified, return the entire image
            image_matches = self.query_coordinates(co_args,
                                                   filt=filt,
                                                   collection=collection)
            if (not image_matches):
                coll = f" in collection '{collection}'" if (collection) else ''
                fltr = f" with filter '{filt}'" if (filt) else ''
                errMsg = f"No matching image for coordinates{fltr}{coll} was found"
                current_app.logger.error(errMsg)
                raise exceptions.ImageNotFound(errMsg)
            else:  # found at least one matching image
                image_path = image_matches[-1].get(
                    'file_path')  # select last matching image
                return self.return_image_at_path(
                    image_path)  # exit and return entire image

        else:  # cutout size given, so make cutout
            image_matches = self.query_cone(co_args,
                                            filt=filt,
                                            collection=collection)
            if (not image_matches):
                coll = f" in collection '{collection}'" if (collection) else ''
                fltr = f" with filter '{filt}'" if (filt) else ''
                errMsg = f"No matching image for coordinates (in cone){fltr}{coll} was found"
                current_app.logger.error(errMsg)
                raise exceptions.ImageNotFound(errMsg)
            else:  # else make, cache, and return cutout
                image_path = image_matches[-1].get(
                    'file_path')  # select last matching image
                return self.get_cutout(image_path,
                                       co_args,
                                       filt=filt,
                                       collection=collection)
コード例 #8
0
 def return_image_at_filepath(self, filepath, mimetype=FITS_MIME_TYPE):
     """ Return the image file at the specified file path, giving it the specified MIME type. """
     if (fits_file_exists(filepath)):
         (imageDir, filename) = os.path.split(filepath)
         return send_from_directory(imageDir,
                                    filename,
                                    mimetype=mimetype,
                                    as_attachment=True,
                                    attachment_filename=filename)
     else:
         errMsg = f"Specified image file '{filepath}' not found"
         current_app.logger.error(errMsg)
         raise exceptions.ImageNotFound(errMsg)
コード例 #9
0
 def return_cutout_with_name(self,
                             co_filename,
                             co_dir=DEFAULT_CO_CACHE_DIR,
                             mimetype=FITS_MIME_TYPE):
     """ Return the named cutout file, giving it the specified MIME type. """
     if (self.is_cutout_cached(co_filename)):
         return send_from_directory(co_dir,
                                    co_filename,
                                    mimetype=mimetype,
                                    as_attachment=True,
                                    attachment_filename=co_filename)
     errMsg = f"Cached image cutout file '{co_filename}' not found in cutouts cache directory"
     current_app.logger.error(errMsg)
     raise exceptions.ImageNotFound(errMsg)