Commit f09c56d3 authored by bepinat's avatar bepinat

Update of create config to use a dv (km/s) rather than a dz to determine REDMIN and REDMAX

parent 5a9c380e
......@@ -7,6 +7,7 @@ import ipdb
import numpy as np
#import pyfits as pf
import astropy.io.fits as fits
import astropy.constants as ct
import astropy.wcs as wcs
import astropy.coordinates as coord
import astropy.units as u
......@@ -16,7 +17,7 @@ import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('CAMEL')
def create_config(path, cubefile, varfile, catfile, lines, suffixeout, commonw=True, dz=0.005, dxy=15, initw=50., wmin=30., wmax=250., dfit=100, degcont=0, sclip=10, xyclip=3, nclip=3, wsmooth=0, ssmooth=2):
def create_config(path, cubefile, varfile, catfile, lines, suffixeout, commonw=True, dv=1000., dxy=15, initw=50., wmin=30., wmax=250., dfit=100, degcont=0, sclip=10, xyclip=3, nclip=3, wsmooth=0, ssmooth=2):
'''
This function enables to create a configuration file for camel.
......@@ -36,8 +37,8 @@ def create_config(path, cubefile, varfile, catfile, lines, suffixeout, commonw=T
suffixe for the output configuration file name
commonw: bool
specifies if a common width has to be used for the various lines
dz: float
interval of redshift around the systemic redshift (from the catalogue) to search for lines and for cutting the cube spectrally
dv: float
interval of velocity around the systemic redshift (from the catalogue) to search for lines and for cutting the cube spectrally
dxy: int
spatial extent around the object for cutting the cube (in pixels)
initw: float
......@@ -114,7 +115,7 @@ def create_config(path, cubefile, varfile, catfile, lines, suffixeout, commonw=T
w = wcs.WCS(hdr, hdul1)
#w = wcs.WCS(hdr[:28], hdul1)
logger.debug(' Naxis %d ' % (w.naxis))
logger.debug(' Naxis %d ' % (w.naxis))
lc = np.size(cat)
if lc == 1: cat = [cat]
......@@ -170,13 +171,14 @@ def create_config(path, cubefile, varfile, catfile, lines, suffixeout, commonw=T
fo.write('COMMW = ' + str(commonw) + ' / do we use a common width (default: FALSE)\n')
fo.write('REDSHIFT= ' + str(line['Z']) + ' / initial redshift of the galaxy\n')
if dz is not None:
if dv is not None:
dz = dv / ct.c.to('km/s').value * (1 + line['Z'])
fo.write('REDMIN = ' + str(line['Z'] - dz) + ' / minimum redshift\n')
fo.write('REDMAX = ' + str(line['Z'] + dz) + ' / maximum redshift\n')
else:
fo.write('REDMIN = ' + str(line['Z'] - 0.1) + ' / minimum redshift\n')
fo.write('REDMAX = ' + str(line['Z'] + 0.1) + ' / maximum redshift\n')
logger.error('dz must be not None and non-zero')
logger.error('dv must be not None and non-zero')
fo.write('INITW = ' + str(initw) + ' / initial linewidth in km/s during the line fitting process \n')
fo.write('WMIN = ' + str(wmin) + ' / minimum linewidth in km/s\n')
......@@ -207,7 +209,7 @@ def create_config(path, cubefile, varfile, catfile, lines, suffixeout, commonw=T
fo.write('XMAX = None / X maximum value for spatial cut of the input cube (pixel)\n')
fo.write('YMIN = None / Y minimum value for spatial cut of the input cube (pixel)\n')
fo.write('YMAX = None / Y maximum value for spatial cut of the input cube (pixel)\n')
if dz is not None:
if dv is not None:
minlbda = np.min(np.array(lbda)) * (1 + line['Z'] - 1.5 * dz)
maxlbda = np.max(np.array(lbda)) * (1 + line['Z'] + 1.5 * dz)
zmin = np.round((minlbda - crval) / cdelt + crpix - 1)
......@@ -247,6 +249,7 @@ def main(argv):
parser.add_argument('--data', '-d', action="store", dest="cubefile", default="", help="path of the cube with respect to initial path")
parser.add_argument('--var', '-v', action="store", dest="varfile", default=None, help="path of the variance with respect to initial path")
parser.add_argument('--dxy', action="store", dest="dxy", default='15', help="size in pixels around the center")
parser.add_argument('--dv', action="store", dest="dv", default='1000.', help="velocity difference in km/s to determine redshift range for fit")
try:
options = parser.parse_args()
except:
......@@ -259,7 +262,7 @@ def main(argv):
if opts['varfile'] is None:
opts['varfile'] = opts['cubefile']
create_config(opts['pathb'], opts['cubefile'], opts['varfile'], opts['catfile'], opts['lines'], opts['suffixeout'], dxy=int(opts['dxy']))
create_config(opts['pathb'], opts['cubefile'], opts['varfile'], opts['catfile'], opts['lines'], opts['suffixeout'], dxy=int(opts['dxy']), dv=dv)
if __name__ == "__main__":
......
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