예제 #1
0
def make_btl_mean(ssscc_list, debug=False):
    # TODO: add (some) error handling from odf_process_bottle.py
    """
    Create "bottle mean" files from continuous CTD data averaged at the bottle stops.

    Parameters
    ----------
    ssscc_list : list of str
        List of stations to convert
    debug : bool, optional
        Display verbose messages

    Returns
    -------
    boolean
        bottle averaging of mean has finished successfully
    """
    print('Generating btl_mean.pkl files')
    for ssscc in ssscc_list:
        if not Path(cfg.directory["bottle"] + ssscc +
                    "_btl_mean.pkl").exists():
            imported_df = importConvertedFile(
                cfg.directory["converted"] + ssscc + ".pkl", False)
            bottle_df = btl.retrieveBottleData(imported_df, debug=debug)
            mean_df = btl.bottle_mean(bottle_df)
            saveConvertedDataToFile(
                mean_df, cfg.directory["bottle"] + ssscc + "_btl_mean.pkl")

    return True
예제 #2
0
def process_bottle(ssscc):

    cnv_file = converted_directory + ssscc + '.pkl'
    imported_df = cnv.importConvertedFile(cnv_file, False)
    bottle_df = btl.retrieveBottleData(imported_df, False)
    if bottle_df.empty:
        #errPrint("Bottle fire data not found in converted file")
        sys.exit(1)
    else:
        total_bottles_fired = bottle_df[btl_fire_num].iloc[-1]
        bottle_num = 1

        while bottle_num <= total_bottles_fired:
            bottle_num += 1

    mean_df = btl.bottle_mean(bottle_df)

    meanfilePath = btl_data_prefix + ssscc + btl_data_postfix
    cnv.saveConvertedDataToFile(mean_df, meanfilePath)

    return
예제 #3
0
def main(argv):
    # MK: depreciated 04/27/20, use ctdcal.convert.make_btl_mean instead

    parser = argparse.ArgumentParser(
        description=
        'Process bottle fire data from a converted, csv-formatted text file')
    parser.add_argument('cnv_file',
                        metavar='cnv_file',
                        help='the converted data file to process')

    # debug messages
    parser.add_argument('-d',
                        '--debug',
                        action='store_true',
                        help='display debug messages')

    # output directory
    parser.add_argument('-o',
                        metavar='dest_dir',
                        dest='outDir',
                        help='location to save output files')

    args = parser.parse_args()
    if args.debug:
        global DEBUG
        DEBUG = True
        debugPrint("Running in debug mode")

    # Verify converted exists
    if not os.path.isfile(args.cnv_file):
        errPrint('ERROR: Input converted file:', args.cnv_file, 'not found\n')
        sys.exit(1)

    # Set the default output directory to be the same directory as the hex file
    outputDir = os.path.dirname(args.cnv_file)

    # Used later for building output file names
    filename_ext = os.path.basename(
        args.cnv_file)  # original filename with ext
    filename_base = os.path.splitext(filename_ext)[
        0]  # original filename w/o ext

    # Verify Output Directory exists
    if args.outDir:
        if os.path.isdir(args.outDir):
            outputDir = args.outDir
        else:
            errPrint('ERROR: Output directory:', args.outDir,
                     'is unreachable.\n')
            sys.exit(1)

    debugPrint("Import converted data to dataframe... ", end='')
    imported_df = cnv.importConvertedFile(args.cnv_file, False)
    debugPrint("Success!")

    debugPrint(imported_df.head())
    #debugPrint(imported_df.dtypes)

    # Retrieve the rows from the imported dataframe where the btl_fire_bool column == True
    # Returns a new dataframe
    bottle_df = btl.retrieveBottleData(imported_df, False)

    if bottle_df.empty:
        errPrint("Bottle fire data not found in converted file")
        sys.exit(1)
    else:
        total_bottles_fired = bottle_df[BOTTLE_FIRE_NUM_COL].iloc[-1]
        debugPrint(total_bottles_fired, "bottle fire(s) detected")
        bottle_num = 1

        while bottle_num <= total_bottles_fired:
            debugPrint('Bottle:', bottle_num)
            debugPrint(bottle_df.loc[bottle_df[BOTTLE_FIRE_NUM_COL] ==
                                     bottle_num].head())
            bottle_num += 1

    # # Build the filename for the bottle fire data
    # bottlefileName  = filename_base.replace(CONVERTED_SUFFIX,'') + BOTTLE_SUFFIX + '.' + FILE_EXT
    # bottlefilePath = os.path.join(outputDir, bottlefileName)
    #
    # # Save the bottle fire dataframe to file.
    # debugPrint('Saving bottle data to:', bottlefilePath + '... ', end='')
    # if not cnv.saveConvertedDataToFile(bottle_df, bottlefilePath, DEBUG):
    #     errPrint('ERROR: Could not save bottle fire data to file')
    # else:
    #     debugPrint('Success!')
    #
    mean_df = btl.bottle_mean(bottle_df)

    # Build the filename for the bottle fire mean data
    # meanfileName  = filename_base.replace(CONVERTED_SUFFIX,'') + BOTTLE_SUFFIX + MEAN_SUFFIX + '.' + FILE_EXT
    meanfileName = filename_base.replace(
        CONVERTED_SUFFIX, '') + BOTTLE_SUFFIX + MEAN_SUFFIX + '.' + EXT_PKL
    meanfilePath = os.path.join(outputDir, meanfileName)

    # Save the bottle fire mean dataframe to file.
    debugPrint('Saving mean data to:', meanfilePath + '... ', end='')
    if not cnv.saveConvertedDataToFile(mean_df, meanfilePath, DEBUG):
        errPrint('ERROR: Could not save mean fire data to file')
    else:
        debugPrint('Success!')