Commit a74e92c9 authored by bepinat's avatar bepinat

merge of versions

parent 4a492681
......@@ -40,6 +40,26 @@ logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('CAMEL')
def dz_from_dv(dv, z):
'''
This function enables to compute the redshift interval corresponding to a given velocity interval
Parameters
----------
dv: float
velocity interval in km/s
z: float
mean redshift of the source
Returns
-------
dz: float
corresponding redshift interval
'''
dz = dv * 1e3 / ct.c * (1 + z)
return dz
def compute_rv(z, zcosmo=None):
"""This function computes the velocity from local and global redshifts
......@@ -145,7 +165,7 @@ def readconfig(filename, config):
# XXX or give an error message but in that case, must test that the keywords have correct values
# XXX more keywords? add default values?
needed_keys = ['FITSFILE', 'OUTPUT', 'SKYFILE', 'HALPHA', 'NII6548', 'NII6583', 'SII6716', 'SII6731', 'OIII4959', 'OIII5007', 'HBETA', 'OII3729', 'OII3726', 'EXTRAL', 'COMMW', 'REDSHIFT', 'REDMIN', 'REDMAX', 'INITW', 'WMIN', 'WMAX', 'DFIT', 'DGCTNUM', 'MFIT', 'SCLIP', 'XYCLIP', 'NCLIP', 'SPSF', 'WSMOOTH', 'SSMOOTH', 'THRES', 'MEDIAN', 'FITSPSF', 'XMIN', 'YMIN', 'ZMIN', 'XMAX', 'YMAX', 'ZMAX']
needed_keys = ['FITSFILE', 'OUTPUT', 'SKYFILE', 'HALPHA', 'NII6548', 'NII6583', 'SII6716', 'SII6731', 'OIII4959', 'OIII5007', 'HBETA', 'OII3729', 'OII3726', 'EXTRAL', 'COMMW', 'REDSHIFT', 'REDMIN', 'REDMAX', 'ZRMIN', 'ZRMAX', 'INITW', 'WMIN', 'WMAX', 'DFIT', 'DGCTNUM', 'MFIT', 'SCLIP', 'XYCLIP', 'NCLIP', 'SPSF', 'WSMOOTH', 'SSMOOTH', 'THRES', 'MEDIAN', 'FITSPSF', 'XMIN', 'YMIN', 'ZMIN', 'XMAX', 'YMAX', 'ZMAX']
for key in needed_keys:
if not(key in conf.keys()):
conf[key] = None
......@@ -157,6 +177,12 @@ def readconfig(filename, config):
if conf['COMMW'] is None:
conf['COMMW'] = False
# XXX or give an error message but in that case, must test that the keywords have correct values
if conf['ZRMIN'] is None:
deltared = conf['REDMAX'] - conf['REDMIN']
conf['ZRMIN'] = conf['REDMIN'] - deltared / 2.
if conf['ZRMAX'] is None:
deltared = conf['REDMAX'] - conf['REDMIN']
conf['ZRMAX'] = conf['REDMAX'] + deltared / 2.
return conf
......@@ -600,7 +626,6 @@ def build_parinfo_lines(els, linename, conf, free_ratio, comind, multi_comp=1):
zcosmo = conf['REDSHIFT']
zmax = conf['REDMAX']
zmin = conf['REDMIN']
#xxx ICI redefinir zmin et zmax avec le nouveau mot clé pour définir les limites et idem utiliser ce nouveau zmin, zmax pour explorer en z les parametres initiaux
parbase = {'value': 0., 'fixed': 1, 'limited': [0, 0], 'limits': [0., 0.], 'tied': '', 'mpmaxstep': 0, 'mpminstep': 0, 'parname': ''}
parinfo = []
......@@ -743,11 +768,8 @@ def buildmaps(conf, cube, hdr, var=None, plot=False, debug=False, free_ratio=Fal
#Condition on the wavelength to be within the redshift cuts
#XXX try zmin > zmax?
#xxx CES zmin, zmax sont bien ceux à utiliser pour les bornes en lbda
zcosmo = conf['REDSHIFT']
zmax = conf['REDMAX']
zmin = conf['REDMIN']
zrange = zmax - zmin
zmax = conf['ZRMAX']
zmin = conf['ZRMIN']
argsorted = np.argsort(np.array([els.lines[i].index for i in els.lines]))
lineindex = np.array([els.lines[i].index for i in els.lines])[argsorted]
......@@ -762,8 +784,8 @@ def buildmaps(conf, cube, hdr, var=None, plot=False, debug=False, free_ratio=Fal
for i in range(linefit.size):
if (not linefit[i]):
continue
linf = np.max([(zmin - zrange / 2. + 1) * linewave[i], np.min(wave0)])
lsup = np.min([(zmax + zrange / 2. + 1) * linewave[i], np.max(wave0)])
linf = np.max([(zmin + 1) * linewave[i], np.min(wave0)])
lsup = np.min([(zmax + 1) * linewave[i], np.max(wave0)])
condo = np.where((wave0 >= linf) & (wave0 <= lsup))
if np.size(condo) != 0:
firstind0[i] = condo[0][0]
......@@ -775,8 +797,8 @@ def buildmaps(conf, cube, hdr, var=None, plot=False, debug=False, free_ratio=Fal
for i in range(linefit.size):
if (not linefit[i]):
continue
linf = np.max([(zmin - zrange / 2. + 1) * linewave[i], np.min(wave0)])
lsup = np.min([(zmax + zrange / 2. + 1) * linewave[i], np.max(wave0)])
linf = np.max([(zmin + 1) * linewave[i], np.min(wave0)])
lsup = np.min([(zmax + 1) * linewave[i], np.max(wave0)])
condo = np.where((wave >= linf) & (wave <= lsup))
if np.size(condo) != 0:
firstind[i] = condo[0][0]
......@@ -819,14 +841,19 @@ def buildmaps(conf, cube, hdr, var=None, plot=False, debug=False, free_ratio=Fal
if var.ndim == 3:
weight = ((1. / np.sqrt(var)) / np.sum(1. / np.sqrt(var), axis=0)) * var.shape[0]
#XXX try zmin > zmax?
zcosmo = conf['REDSHIFT']
zmax = conf['REDMAX']
zmin = conf['REDMIN']
#Redshift step
zstep = (conf['DFIT'] * 1e3 / ct.c + zcosmo) / (1 - conf['DFIT'] * 1e3 / ct.c) - zcosmo
zstep = dz_from_dv(conf['DFIT'], zcosmo)
#zstep = (conf['DFIT'] * 1e3 / ct.c + zcosmo) / (1 - conf['DFIT'] * 1e3 / ct.c) - zcosmo
#if zstep >= (zmax - zmin) / 2: zstep = (zmax - zmin) / 2.
zmean = (zmax + zmin) / 2.
zzmax = zmean + np.floor((zmax - zmean) / zstep + 1) * zstep
zzmin = zmean + np.ceil((zmin - zmean) / zstep) * zstep
#xxx ici utiliser le nouveau zmin, zmax (nouveau mot clé), car cela définit les bornes de l'exploration en z
#Parameters contraints and informations: each line has z, sigma, intensity and ratio constraint
......@@ -1386,7 +1413,9 @@ def main(argv):
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('--ZRMIN', action="store", dest="ZRMIN", default=None, type=float, help="minimum redshift for spectral range considered around lines")
parser.add_argument('--ZRMAX', action="store", dest="ZRMAX", default=None, type=float, help="maximum redshift for spectral range considered around lines")
parser.add_argument('--INITW', action="store", dest="INITW", default=None, type=float, help="initial line width 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")
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -41,6 +41,26 @@ logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('CAMEL')
def dz_from_dv(dv, z):
'''
This function enables to compute the redshift interval corresponding to a given velocity interval
Parameters
----------
dv: float
velocity interval in km/s
z: float
mean redshift of the source
Returns
-------
dz: float
corresponding redshift interval
'''
dz = dv * 1e3 / ct.c * (1 + z)
return dz
def compute_rv(z, zcosmo=None):
"""This function computes the velocity from local and global redshifts
......@@ -145,7 +165,7 @@ def readconfig(filename, config):
conf[key] = None
# XXX or give an error message but in that case, must test that the keywords have correct values
# XXX more keywords? add default values?
needed_keys = ['FITSFILE', 'OUTPUT', 'SKYFILE', 'HALPHA', 'NII6548', 'NII6583', 'SII6716', 'SII6731', 'OIII4959', 'OIII5007', 'HBETA', 'OII3729', 'OII3726', 'EXTRAL', 'COMMW', 'REDSHIFT', 'REDMIN', 'REDMAX', 'INITW', 'WMIN', 'WMAX', 'DFIT', 'DGCTNUM', 'MFIT', 'SCLIP', 'XYCLIP', 'NCLIP', 'SPSF', 'WSMOOTH', 'SSMOOTH', 'THRES', 'MEDIAN', 'FITSPSF', 'XMIN', 'YMIN', 'ZMIN', 'XMAX', 'YMAX', 'ZMAX']
needed_keys = ['FITSFILE', 'OUTPUT', 'SKYFILE', 'HALPHA', 'NII6548', 'NII6583', 'SII6716', 'SII6731', 'OIII4959', 'OIII5007', 'HBETA', 'OII3729', 'OII3726', 'EXTRAL', 'COMMW', 'REDSHIFT', 'REDMIN', 'REDMAX', 'ZRMIN', 'ZRMAX', 'INITW', 'WMIN', 'WMAX', 'DFIT', 'DGCTNUM', 'MFIT', 'SCLIP', 'XYCLIP', 'NCLIP', 'SPSF', 'WSMOOTH', 'SSMOOTH', 'THRES', 'MEDIAN', 'FITSPSF', 'XMIN', 'YMIN', 'ZMIN', 'XMAX', 'YMAX', 'ZMAX']
for key in needed_keys:
if not(key in conf.keys()):
conf[key] = None
......@@ -157,6 +177,12 @@ def readconfig(filename, config):
if conf['COMMW'] is None:
conf['COMMW'] = False
# XXX or give an error message but in that case, must test that the keywords have correct values
if conf['ZRMIN'] is None:
deltared = conf['REDMAX'] - conf['REDMIN']
conf['ZRMIN'] = conf['REDMIN'] - deltared / 2.
if conf['ZRMAX'] is None:
deltared = conf['REDMAX'] - conf['REDMIN']
conf['ZRMAX'] = conf['REDMAX'] + deltared / 2.
return conf
......@@ -579,10 +605,8 @@ def buildmaps(conf, data, hdr, var=None, plot=False, debug=False, free_ratio=Fal
#Condition on the wavelength to be within the redshift cuts
#XXX try zmin > zmax?
zcosmo = conf['REDSHIFT']
zmax = conf['REDMAX']
zmin = conf['REDMIN']
zrange = zmax - zmin
zmax = conf['ZRMAX']
zmin = conf['ZRMIN']
argsorted = np.argsort(np.array([els.lines[i].index for i in els.lines]))
lineindex = np.array([els.lines[i].index for i in els.lines])[argsorted]
......@@ -597,8 +621,8 @@ def buildmaps(conf, data, hdr, var=None, plot=False, debug=False, free_ratio=Fal
for i in range(linefit.size):
if (not linefit[i]):
continue
linf = np.max([(zmin - zrange / 2. + 1) * linewave[i], np.min(wave0)])
lsup = np.min([(zmax + zrange / 2. + 1) * linewave[i], np.max(wave0)])
linf = np.max([(zmin + 1) * linewave[i], np.min(wave0)])
lsup = np.min([(zmax + 1) * linewave[i], np.max(wave0)])
condo = np.where((wave0 >= linf) & (wave0 <= lsup))
if np.size(condo) != 0:
firstind0[i] = condo[0][0]
......@@ -610,8 +634,8 @@ def buildmaps(conf, data, hdr, var=None, plot=False, debug=False, free_ratio=Fal
for i in range(linefit.size):
if (not linefit[i]):
continue
linf = np.max([(zmin - zrange / 2. + 1) * linewave[i], np.min(wave0)])
lsup = np.min([(zmax + zrange / 2. + 1) * linewave[i], np.max(wave0)])
linf = np.max([(zmin + 1) * linewave[i], np.min(wave0)])
lsup = np.min([(zmax + 1) * linewave[i], np.max(wave0)])
condo = np.where((wave >= linf) & (wave <= lsup))
if np.size(condo) != 0:
firstind[i] = condo[0][0]
......@@ -622,8 +646,14 @@ def buildmaps(conf, data, hdr, var=None, plot=False, debug=False, free_ratio=Fal
var = np.ones(data.shape, dtype='>f4')
weight = ((1. / np.sqrt(var)) / np.sum(1. / np.sqrt(var), axis=0)) * var.shape[0]
#XXX try zmin > zmax?
zcosmo = conf['REDSHIFT']
zmax = conf['REDMAX']
zmin = conf['REDMIN']
#Redshift step
zstep = (conf['DFIT'] * 1e3 / ct.c + zcosmo) / (1 - conf['DFIT'] * 1e3 / ct.c) - zcosmo
zstep = dz_from_dv(conf['DFIT'], zcosmo)
#zstep = (conf['DFIT'] * 1e3 / ct.c + zcosmo) / (1 - conf['DFIT'] * 1e3 / ct.c) - zcosmo
#if zstep >= (zmax - zmin) / 2: zstep = (zmax - zmin) / 2.
zmean = (zmax + zmin) / 2.
......@@ -1115,7 +1145,9 @@ def main(argv):
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('--ZRMIN', action="store", dest="ZRMIN", default=None, type=float, help="minimum redshift for spectral range considered around lines")
parser.add_argument('--ZRMAX', action="store", dest="ZRMAX", default=None, type=float, help="maximum redshift for spectral range considered around lines")
parser.add_argument('--INITW', action="store", dest="INITW", default=None, type=float, help="initial line width 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")
......
This diff is collapsed.
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