예제 #1
0
def perform(input_filename, **kwargs):
    """
    Main calling subroutine.

    Parameters
    ----------
    input_filename : string
        Name of the input csv file containing information about the files to
        be processed

    debug : Boolean
        display all tracebacks, and debug information?

    input_custom_pars_file : str, optional
        Represents a fully specified input filename of a configuration JSON file which has been
        customized for specialized processing. This file should contain ALL the input parameters necessary
        for processing. If not specified, default configuration parameter values will be used.

    log_level : string
        The desired level of verboseness in the log statements displayed on the screen and written to the
        .log file.

    Updates
    -------
    return_value : list
        a simple status value. '0' for a successful run and '1' for a failed
        run
    """
    # set up log_level as an input to hapmultisequencer.run_mvm_processing().
    log_level_dict = {"critical": logutil.logging.CRITICAL,
                      "error": logutil.logging.ERROR,
                      "warning": logutil.logging.WARNING,
                      "info": logutil.logging.INFO,
                      "debug": logutil.logging.DEBUG}

    if 'log_level' in kwargs:
        kwargs['log_level'] = kwargs['log_level'].lower()
        if kwargs['log_level'] in log_level_dict.keys():
            kwargs['log_level'] = log_level_dict[kwargs['log_level']]
        else:
            print("Log level set to default level 'log.info'.")
            kwargs['log_level'] = logutil.logging.INFO
    else:
        print("Log level set to default level 'log.info'.")
        kwargs['log_level'] = logutil.logging.INFO

    # execute hapmultisequencer.run_mvm_processing()
    return_value = hapmultisequencer.run_mvm_processing(input_filename, **kwargs)

    return return_value
예제 #2
0
def perform(input_filename, **kwargs):
    """
    Main calling subroutine.

    Parameters
    ----------
    input_filename : string
        Name of the input csv file containing information about the files to
        be processed

    debug : Boolean
        display all tracebacks, and debug information?

    log_level : string
        The desired level of verboseness in the log statements displayed on the screen and written to the
        .log file.

    Updates
    -------
    return_value : list
        a simple status value. '0' for a successful run and '1' for a failed
        run
    """
    # set up log_level as an input to hapmultisequencer.run_mvm_processing().
    log_level_dict = {
        "critical": logutil.logging.CRITICAL,
        "error": logutil.logging.ERROR,
        "warning": logutil.logging.WARNING,
        "info": logutil.logging.INFO,
        "debug": logutil.logging.DEBUG
    }

    if 'log_level' in kwargs:
        kwargs['log_level'] = kwargs['log_level'].lower()
        if kwargs['log_level'] in log_level_dict.keys():
            kwargs['log_level'] = log_level_dict[kwargs['log_level']]
        else:
            print("Log level set to default level 'log.info'.")
            kwargs['log_level'] = logutil.logging.INFO
    else:
        print("Log level set to default level 'log.info'.")
        kwargs['log_level'] = logutil.logging.INFO

    # execute hapmultisequencer.run_mvm_processing()
    return_value = hapmultisequencer.run_mvm_processing(
        input_filename, **kwargs)

    return return_value
예제 #3
0
def perform(input_image_source,
            log_level='info',
            output_file_prefix=None,
            skip_gaia_alignment=False):
    """Main calling subroutine

    Parameters
    ----------
    input_image_source : str
        Search pattern to be used to identify images to process or the name of a text file containing a list
        of images to process.

    log_level : str, optional
        The desired level of verboseness in the log statements displayed on the screen and written to the
        .log file. The level of verboseness from left to right, and includes all log statements with a
        log_level left of the specified level. Specifying "critical" will only record/display "critical" log
        statements, and specifying "error" will record/display both "error" and "critical" log statements,
        and so on. Unless explicitly set, the default value is 'info'.

    output_file_prefix : str, optional
        'Text string that will be used as the filename prefix all files created by hapmultisequencer.py
        during the MVM custom mosaic generation process. If not explicitly specified, all output files will
        start with the following formatted text string:
        "hst-skycell-p<pppp>-ra<##>d<####>-dec<n|s><##>d<####>", where p<pppp> is the projection cell ID,
        ra<##>d<####> are the whole-number and decimal portions of the right ascention, respectively, and
        dec<n|s><##>d<####> are the whole-number and decimal portions of the declination, respectively. Note
        that the "<n|s>" denotes if the declination is north (positive) or south (negative). Example: For
        skycell = 1974, ra = 201.9512, and dec = +26.0012, The filename prefix would be
        "skycell-p1974-ra201d9512-decn26d0012".

    skip_gaia_alignment : bool, optional
        Skip alignment of all input images to known Gaia/HSC sources in the input image footprint? If set to
        'True', The existing input image alignment solution will be used instead. The default is False.

    Returns
    -------
    return_value : int
        A simple status value. '0' for a successful run or '1' for a failed run.
    """
    try:
        # optimistically pre-set return value to 0.
        return_value = 0
        log_level_dict = {
            "critical": logutil.logging.CRITICAL,
            "error": logutil.logging.ERROR,
            "warning": logutil.logging.WARNING,
            "info": logutil.logging.INFO,
            "debug": logutil.logging.DEBUG
        }
        logging_level = log_level_dict[log_level]
        log.setLevel(logging_level)
        temp_files_to_delete = []
        # Get list input fits files from input args, and raise an exception if no input images can be found.
        img_list = create_input_image_list(input_image_source)
        if not img_list:
            err_msg = "ERROR: No input images were found. Please double-check the search pattern or contents of the input list text file."
            log.critical(err_msg)
            raise Exception(err_msg)

        # get list of skycells/projection cells that observations are in
        # figure out which projection cell center is closest to the center of the observations, use that projection cell as basis for WCS
        proj_cell_dict = determine_projection_cell(img_list)

        # compute bounding rectangle limits for mosaic observations
        custom_limits = compute_mosaic_limits(proj_cell_dict)

        # Create MVM poller file
        poller_filename = create_poller_file(img_list, proj_cell_dict)
        temp_files_to_delete.append(poller_filename)

        # Execute hapmultisequencer.run_mvm_processing() with poller file
        log.debug(
            "Creating custom mosaic from the following {} input images".format(
                len(img_list)))
        for item in img_list:
            log.debug(" {}".format(item))
        log.info("Mosaic bounding box limits")
        for limit_name, limit_value in zip(
            ["X_min", "X_max", "Y_min", "Y_max"], custom_limits):
            log.debug("{}: {}".format(limit_name, int(np.rint(limit_value))))
        return_value = hapmultisequencer.run_mvm_processing(
            poller_filename,
            custom_limits=custom_limits,
            log_level=logging_level,
            output_file_prefix=output_file_prefix,
            skip_gaia_alignment=skip_gaia_alignment)

    except Exception:
        if return_value == 0:
            return_value = 1
        print("\a\a\a")
        exc_type, exc_value, exc_tb = sys.exc_info()
        traceback.print_exception(exc_type, exc_value, exc_tb, file=sys.stdout)
    finally:
        # remove any temp files like the poller file and
        if temp_files_to_delete and log_level != "debug":
            log.info("Time to delete some temporary files...")
            for filename in temp_files_to_delete:
                if os.path.exists(filename):
                    os.remove(filename)
                    log.info("Removed temporary file {}.".format(filename))
    return return_value