#!/usr/bin/env python
# Licensed under a 3-clause BSD style license - see LICENSE.rst

from __future__ import (absolute_import, unicode_literals, division,
                        print_function)

from maltpynt.mp_rebin import mp_rebin_file
import argparse
import logging

description = 'Rebin light curves and frequency spectra. '
parser = argparse.ArgumentParser(description=description)

parser.add_argument("files", help="List of light curve files", nargs='+')
parser.add_argument("-r", "--rebin", type=float, default=1,
                    help="Rebinning to apply. Only if the quantity to" +
                    " rebin is a (C)PDS, it is possible to specify a" +
                    " non-integer rebin factor, in which case it is" +
                    " interpreted as a geometrical binning factor")

parser.add_argument("--loglevel",
                    help=("use given logging level (one between INFO, "
                          "WARNING, ERROR, CRITICAL, DEBUG; default:WARNING)"),
                    default='WARNING',
                    type=str)
parser.add_argument("--debug", help="use DEBUG logging level",
                    default=False, action='store_true')

if __name__ == '__main__':
    args = parser.parse_args()
    files = args.files

    if args.debug:
        args.loglevel = 'DEBUG'

    numeric_level = getattr(logging, args.loglevel.upper(), None)
    logging.basicConfig(filename='MPrebin.log', level=numeric_level,
                        filemode='w')
    rebin = args.rebin
    for f in files:
        mp_rebin_file(f, rebin)
