Commit 1e792dce authored by bepinat's avatar bepinat

argparese replaces optparse

parent f1ef23fb
......@@ -26,12 +26,13 @@ import copy
import numpy as np
import pyfits as pf
from mpfit import mpfit # python 2.7...
#import ipdb
import ipdb
#from matplotlib import pyplot as plt
from scipy import ndimage
from scipy import constants as ct
import optparse
import argparse
#import optparse
def compute_rv(z, zcosmo=None):
"""This function computes the velocity from local and global redshifts
......@@ -939,69 +940,69 @@ def usage():
def main(argv):
"""
"""
parser = optparse.OptionParser(usage=usage())
parser.add_option('--file', '-f', action="store", dest="filename", default=None, help="name of the configuration file")
parser.add_option('--plot', '-p', action="store_true", dest="plot", default=False, help="keyword to plot fits during the process (not implemented yet)")
parser.add_option('--debug', '-d', action="store_true", dest="debug", default=False, help="keyword to show debug information (not implemented yet)")
parser.add_option('--free_line_ratio', '-r', action="store_true", dest="free_ratio", default=False, help="keyword to allow unconstrained line ratio")
parser.add_option('--multi_ext', '-m', action="store_true", dest="multi_ext", default=False, help="keyword to indicate if input fits has multiple extensions")
parser.add_option('--FITSFILE', action="store", dest="FITSFILE", default=None, help="name of the input cube")
parser.add_option('--OUTPUT', action="store", dest="OUTPUT", default=None, help="generic output name")
parser.add_option('--SKYFILE', action="store", dest="SKYFILE", default=None, help="name of the variance cube (can be a sky cube)")
parser.add_option('--HALPHA', action="store_true", dest="HALPHA", default=None, help="keyword to fit Halpha line")
parser.add_option('--HBETA', action="store_true", dest="HBETA", default=None, help="keyword to fit Hbeta line")
parser.add_option('--HGAMMA', action="store_true", dest="HGAMMA", default=None, help="keyword to fit Hgamma line")
parser.add_option('--HDELTA', action="store_true", dest="HDELTA", default=None, help="keyword to fit Hdelta line")
parser.add_option('--HEPS', action="store_true", dest="HEPS", default=None, help="keyword to fit Hepsilon line")
parser.add_option('--NII6545', action="store_true", dest="NII6545", default=None, help="keyword to fit NII@6545 line")
parser.add_option('--NII6584', action="store_true", dest="NII6584", default=None, help="keyword to fit NII@6584 line")
parser.add_option('--SII6717', action="store_true", dest="SII6717", default=None, help="keyword to fit SII@6717 line")
parser.add_option('--SII6731', action="store_true", dest="SII6731", default=None, help="keyword to fit SII@6731 line")
parser.add_option('--OIII4363', action="store_true", dest="OIII4363", default=None, help="keyword to fit OIII@4363 line")
parser.add_option('--OIII4959', action="store_true", dest="OIII4959", default=None, help="keyword to fit OIII@4959 line")
parser.add_option('--OIII5007', action="store_true", dest="OIII5007", default=None, help="keyword to fit OIII@5007 line")
parser.add_option('--OII', action="store_true", dest="OII3729", default=None, help="keyword to fit OII doublet") # ['OII3729','OII3726']
parser.add_option('--OI6300', action="store_true", dest="OI6300", default=None, help="keyword to fit OI@6300 line")
parser.add_option('--HEI4471', action="store_true", dest="HeI4471", default=None, help="keyword to fit HeI@4471 line")
parser.add_option('--HEI5876', action="store_true", dest="HeI5876", default=None, help="keyword to fit HeI@5876 line")
parser.add_option('--HEII4686', action="store_true", dest="HeII4686", default=None, help="keyword to fit HeII@4686 line")
parser.add_option('--NEIII3868', action="store_true", dest="NeIII3868", default=None, help="keyword to fit NeIII@3868 line")
parser.add_option('--EXTRAL', action="append", dest="EXTRAL", default=None, type=float, help="keyword to add a new line (wavelength in angstrom) - multiple extra wavelengths can be added")
parser.add_option('--COMMW', action="store_true", dest="COMMW", default=None, help="keyword to fix common widths (in velocity) between several fitted lines")
parser.add_option('--REDSHIFT', action="store", dest="REDSHIFT", default=None, type=float, help="mean redshift of the object")
parser.add_option('--REDMIN', action="store", dest="REDMIN", default=None, type=float, help="minimum redshift allowed for fitting")
parser.add_option('--REDMAX', action="store", dest="REDMAX", default=None, type=float, help="maximum redshift allowed for fitting")
parser.add_option('--INITW', action="store", dest="INITW", default=None, type=float, help="initial linewidth in km/s")
parser.add_option('--WMIN', action="store", dest="WMIN", default=None, type=float, help="minimum width allowed for fitting in km/s")
parser.add_option('--WMAX', action="store", dest="WMAX", default=None, type=float, help="maximum width allowed for fitting in km/s")
parser.add_option('--DFIT', action="store", dest="DFIT", default=None, type=float, help="bin in km/s for searching the position of the lines")
parser.add_option('--DGCTNUM', action="store", dest="DGCTNUM", default=None, type=int, help="continuum degree")
parser.add_option('--SCLIP', action="store", dest="SCLIP", default=None, type=float, help="sigma-clipping threshold to clean the cube")
parser.add_option('--XYCLIP', action="store", dest="XYCLIP", default=None, type=int, help="width of the box to compute the median for the sigma-clipping")
parser.add_option('--NCLIP', action="store", dest="NCLIP", default=None, type=int, help="number of pass for clipping")
parser.add_option('--LSF', action="store", dest="SPSF", default=None, type=float, help="spectral PSF width in angstroms (dispersion of the gaussian)")
parser.add_option('--WSMOOTH', action="store", dest="WSMOOTH", default=None, type=float, help="width for Gaussian spectral smoothing in pixel") # options? gaussian uniquement?
parser.add_option('--SSMOOTH', action="store", dest="SSMOOTH", default=None, type=float, help="width for Gaussian spatial smoothing in pixel")
parser.add_option('--XMIN', action="store", dest="XMIN", default=None, type=int, help="lower cut window in x direction of the cube in pixel")
parser.add_option('--YMIN', action="store", dest="YMIN", default=None, type=int, help="upper cut window in x direction of the cube in pixel")
parser.add_option('--ZMIN', action="store", dest="ZMIN", default=None, type=int, help="lower cut window in y direction of the cube in pixel")
parser.add_option('--XMAX', action="store", dest="XMAX", default=None, type=int, help="upper cut window in y direction of the cube in pixel")
parser.add_option('--YMAX', action="store", dest="YMAX", default=None, type=int, help="lower cut window in z direction of the cube in pixel")
parser.add_option('--ZMAX', action="store", dest="ZMAX", default=None, type=int, help="upper cut window in z direction of the cube in pixel")
parser = argparse.ArgumentParser(description=usage())
parser.add_argument('--file', '-f', action="store", dest="filename", default=None, help="name of the configuration file")
parser.add_argument('--plot', '-p', action="store_true", dest="plot", default=False, help="keyword to plot fits during the process (not implemented yet)")
parser.add_argument('--debug', '-d', action="store_true", dest="debug", default=False, help="keyword to show debug information (not implemented yet)")
parser.add_argument('--free_line_ratio', '-r', action="store_true", dest="free_ratio", default=False, help="keyword to allow unconstrained line ratio")
parser.add_argument('--multi_ext', '-m', action="store_true", dest="multi_ext", default=False, help="keyword to indicate if input fits has multiple extensions")
parser.add_argument('--FITSFILE', action="store", dest="FITSFILE", default=None, help="name of the input cube")
parser.add_argument('--OUTPUT', action="store", dest="OUTPUT", default=None, help="generic output name")
parser.add_argument('--SKYFILE', action="store", dest="SKYFILE", default=None, help="name of the variance cube (can be a sky cube)")
parser.add_argument('--HALPHA', action="store_true", dest="HALPHA", default=None, help="keyword to fit Halpha line")
parser.add_argument('--HBETA', action="store_true", dest="HBETA", default=None, help="keyword to fit Hbeta line")
parser.add_argument('--HGAMMA', action="store_true", dest="HGAMMA", default=None, help="keyword to fit Hgamma line")
parser.add_argument('--HDELTA', action="store_true", dest="HDELTA", default=None, help="keyword to fit Hdelta line")
parser.add_argument('--HEPS', action="store_true", dest="HEPS", default=None, help="keyword to fit Hepsilon line")
parser.add_argument('--NII6545', action="store_true", dest="NII6545", default=None, help="keyword to fit NII@6545 line")
parser.add_argument('--NII6584', action="store_true", dest="NII6584", default=None, help="keyword to fit NII@6584 line")
parser.add_argument('--SII6717', action="store_true", dest="SII6717", default=None, help="keyword to fit SII@6717 line")
parser.add_argument('--SII6731', action="store_true", dest="SII6731", default=None, help="keyword to fit SII@6731 line")
parser.add_argument('--OIII4363', action="store_true", dest="OIII4363", default=None, help="keyword to fit OIII@4363 line")
parser.add_argument('--OIII4959', action="store_true", dest="OIII4959", default=None, help="keyword to fit OIII@4959 line")
parser.add_argument('--OIII5007', action="store_true", dest="OIII5007", default=None, help="keyword to fit OIII@5007 line")
parser.add_argument('--OII', action="store_true", dest="OII3729", default=None, help="keyword to fit OII doublet") # ['OII3729','OII3726']
parser.add_argument('--OI6300', action="store_true", dest="OI6300", default=None, help="keyword to fit OI@6300 line")
parser.add_argument('--HEI4471', action="store_true", dest="HeI4471", default=None, help="keyword to fit HeI@4471 line")
parser.add_argument('--HEI5876', action="store_true", dest="HeI5876", default=None, help="keyword to fit HeI@5876 line")
parser.add_argument('--HEII4686', action="store_true", dest="HeII4686", default=None, help="keyword to fit HeII@4686 line")
parser.add_argument('--NEIII3868', action="store_true", dest="NeIII3868", default=None, help="keyword to fit NeIII@3868 line")
parser.add_argument('--EXTRAL', action="append", dest="EXTRAL", default=None, type=float, help="keyword to add a new line (wavelength in angstrom) - multiple extra wavelengths can be added")
parser.add_argument('--COMMW', action="store_true", dest="COMMW", default=None, help="keyword to fix common widths (in velocity) between several fitted lines")
parser.add_argument('--REDSHIFT', action="store", dest="REDSHIFT", default=None, type=float, help="mean redshift of the object")
parser.add_argument('--REDMIN', action="store", dest="REDMIN", default=None, type=float, help="minimum redshift allowed for fitting")
parser.add_argument('--REDMAX', action="store", dest="REDMAX", default=None, type=float, help="maximum redshift allowed for fitting")
parser.add_argument('--INITW', action="store", dest="INITW", default=None, type=float, help="initial linewidth in km/s")
parser.add_argument('--WMIN', action="store", dest="WMIN", default=None, type=float, help="minimum width allowed for fitting in km/s")
parser.add_argument('--WMAX', action="store", dest="WMAX", default=None, type=float, help="maximum width allowed for fitting in km/s")
parser.add_argument('--DFIT', action="store", dest="DFIT", default=None, type=float, help="bin in km/s for searching the position of the lines")
parser.add_argument('--DGCTNUM', action="store", dest="DGCTNUM", default=None, type=int, help="continuum degree")
parser.add_argument('--SCLIP', action="store", dest="SCLIP", default=None, type=float, help="sigma-clipping threshold to clean the cube")
parser.add_argument('--XYCLIP', action="store", dest="XYCLIP", default=None, type=int, help="width of the box to compute the median for the sigma-clipping")
parser.add_argument('--NCLIP', action="store", dest="NCLIP", default=None, type=int, help="number of pass for clipping")
parser.add_argument('--LSF', action="store", dest="SPSF", default=None, type=float, help="spectral PSF width in angstroms (dispersion of the gaussian)")
parser.add_argument('--WSMOOTH', action="store", dest="WSMOOTH", default=None, type=float, help="width for Gaussian spectral smoothing in pixel") # options? gaussian uniquement?
parser.add_argument('--SSMOOTH', action="store", dest="SSMOOTH", default=None, type=float, help="width for Gaussian spatial smoothing in pixel")
parser.add_argument('--XMIN', action="store", dest="XMIN", default=None, type=int, help="lower cut window in x direction of the cube in pixel")
parser.add_argument('--YMIN', action="store", dest="YMIN", default=None, type=int, help="upper cut window in x direction of the cube in pixel")
parser.add_argument('--ZMIN', action="store", dest="ZMIN", default=None, type=int, help="lower cut window in y direction of the cube in pixel")
parser.add_argument('--XMAX', action="store", dest="XMAX", default=None, type=int, help="upper cut window in y direction of the cube in pixel")
parser.add_argument('--YMAX', action="store", dest="YMAX", default=None, type=int, help="lower cut window in z direction of the cube in pixel")
parser.add_argument('--ZMAX', action="store", dest="ZMAX", default=None, type=int, help="upper cut window in z direction of the cube in pixel")
#parser.add_option('--MFIT', action="store", dest="MFIT", default=None)
#parser.add_option('--THRES', action="store", dest="THRES", default=None, type=float)
#parser.add_option('--MEDIAN', action="store", dest="MEDIAN", default=None, type=float)
#parser.add_option('--FITSPSF', action="store", dest="FITSPSF", default=None, type=float)
#parser.add_argument('--MFIT', action="store", dest="MFIT", default=None)
#parser.add_argument('--THRES', action="store", dest="THRES", default=None, type=float)
#parser.add_argument('--MEDIAN', action="store", dest="MEDIAN", default=None, type=float)
#parser.add_argument('--FITSPSF', action="store", dest="FITSPSF", default=None, type=float)
try:
options, args = parser.parse_args()
options = parser.parse_args()
except:
sys.exit(2)
if np.size(args) < 1:
if np.size(argv) < 1:
sys.exit(2)
opts = vars(options) # this is a dictionnary
opts['OII3726'] = opts['OII3729']
camel(options.filename, plot=options.plot, debug=options.debug, free_ratio=options.free_ratio, multi_ext=options.multi_ext, config=opts)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment