def main():

    parser = argparse.ArgumentParser()
    parser.add_argument('input_files', nargs='+', help="""
                        The input data files in NetCDF format. These files can
                        be given in any order. They MUST appear before any other
                        arguments/options.""")
    parser.add_argument('output_file', default='ocean_monthly.nc', help="""
                        The name of the output file.""")
    parser.add_argument('--overall_mean_file', default=None, help="""
                        Calculate the overall mean and save with the given 
                        file name. This is the same as executing ncra
                        <output_file> <overall_mean_file>. This command
                        uses a lot less memory than ncra - it loads one
                        variable into memory at a time.""")
    parser.add_argument('--vars', default=['temp', 'dzt'], nargs='+',
                        help='A list of the variables to average.')

    args = parser.parse_args()

    # Create the output file by copying accross variables from one of
    # the inputs.
    other_vars = ['geolat_t', 'geolat_c', 'geolon_t', 'geolon_c', 'time_bounds']
    create_output_file(args.input_files[0], other_vars + args.vars, args.output_file)
    calc_monthly_mean(args.input_files, args.vars, args.output_file)
    update_file_history(args.output_file, ' '.join(sys.argv))

    if args.overall_mean_file:
        create_output_file(args.input_files[0], other_vars + args.vars,
                           args.overall_mean_file)
        calc_overall_mean([args.output_file], args.vars, args.overall_mean_file) 
        update_file_history(args.overall_mean_file, ' '.join(sys.argv))

    return 0
Exemple #2
0
def mom_monthly_mean(input_files, output_file, vars, overall_mean_file=None, force=False):

    if os.path.exists(output_file) and not force:
        return 0

    # Create the output file by copying accross variables from one of
    # the inputs.
    other_vars = ["geolat_t", "geolat_c", "geolon_t", "geolon_c", "time_bounds"]
    create_output_file(input_files[0], other_vars + vars, output_file)
    calc_monthly_mean(input_files, vars, output_file)

    if overall_mean_file:
        create_output_file(input_files[0], other_vars + vars, overall_mean_file)
        calc_overall_mean([output_file], vars, overall_mean_file)

    return 0
def main():

    parser = argparse.ArgumentParser()
    parser.add_argument('input_files', nargs='+', help="""
                        The input data files in NetCDF format. These files can
                        be given in any order. They MUST appear before any other
                        arguments/options.""")
    parser.add_argument('output_file', default='ice_monthly.nc', help="""
                        The name of the output file.""")
    parser.add_argument('--vars', default=None, nargs='+',
                        help='A list of the variables to average.')
    parser.add_argument('--copy_vars', default=[], nargs='+',
                        help="""A list of the variables copy across but not
                                included in the averaging.""")

    args = parser.parse_args()

    create_output_file(args.input_files[0], args.vars + args.copy_vars,
                       args.output_file)
    calc_monthly_mean(args.input_files, args.vars, args.output_file)
    update_file_history(args.output_file, ' '.join(sys.argv))

    return 0