Commit f6608ee0 authored by bepinat's avatar bepinat

Ajout logger

parent e2fde158
......@@ -31,6 +31,11 @@ from scipy import ndimage
from scipy import constants as ct
import argparse
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('CAMEL')
def compute_rv(z, zcosmo=None):
"""This function computes the velocity from local and global redshifts
......@@ -493,6 +498,7 @@ def buildmaps(conf, cube, hdr, var=None, plot=False, debug=False, free_ratio=Fal
zmax = conf['REDMAX']
zmin = conf['REDMIN']
zrange = zmax - zmin
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]
linefit = np.array([els.lines[i].fit for i in els.lines])[argsorted]
......@@ -564,6 +570,7 @@ def buildmaps(conf, cube, hdr, var=None, plot=False, debug=False, free_ratio=Fal
#Parameters contraints and informations
params = np.zeros(1 + els.index * 3 + conf['DGCTNUM'] + 1)
parbase = {'value':0., 'fixed':1, 'limited':[0,0], 'limits':[0.,0.], 'tied':'', 'mpmaxstep':0, 'mpminstep':0, 'parname':''}
parinfo = []
for i in range(len(params)):
......@@ -669,6 +676,7 @@ def buildmaps(conf, cube, hdr, var=None, plot=False, debug=False, free_ratio=Fal
#parinfo[2 * els.index + 1 + i]['value'] = params[2 * els.index + 1 + i] = 1
#parinfo[els.index + 1 + i]['fixed'] = 0
#ipdb.set_trace()
logger.info(' Buildmaps: initial parameters % s' % (str(params)) )
#Continuum parametres
for i in range(conf['DGCTNUM'] + 1):
......
......@@ -7,6 +7,11 @@ import astropy.wcs as wcs
import astropy.coordinates as coord
import astropy.units as u
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):
'''
This function enables to create a configuration file for camel.
......@@ -56,6 +61,7 @@ def create_config(path, cubefile, varfile, catfile, lines, suffixeout, commonw=T
cat = np.genfromtxt(path + catfile, names=True)
hdul = pf.open(path + cubefile)
logger.info(' using cube %s ' % (path + cubefile) )
cube = hdul[1].data
hdr = hdul[1].header
......@@ -63,7 +69,11 @@ def create_config(path, cubefile, varfile, catfile, lines, suffixeout, commonw=T
crpix = hdr['CRPIX3']
crval = hdr['CRVAL3']
cdelt = hdr['CD3_3']
#print(cunit,crpix,crval,cdelt)
try:
cdelt = hdr['CD3_3']
except:
cdelt = hdr['CDELT3']
logger.debug(" wcs check: %s %d %.4f %.6f " % (cunit,crpix,crval,cdelt))
if 'CTYPE3' in hdr.ascard.keys(): del hdr['CTYPE3']
if 'CRVAL3' in hdr.ascard.keys(): del hdr['CRVAL3']
......@@ -74,17 +84,24 @@ def create_config(path, cubefile, varfile, catfile, lines, suffixeout, commonw=T
if 'CD3_1' in hdr.ascard.keys(): del hdr['CD3_1']
if 'CD2_3' in hdr.ascard.keys(): del hdr['CD2_3']
if 'CD1_3' in hdr.ascard.keys(): del hdr['CD1_3']
wlim = np.zeros(np.shape(cube)[1:])
hdu = pf.PrimaryHDU(data=wlim, header=hdr)
hdul1 = pf.HDUList(hdu)
hdr = hdul1[0].header
w = wcs.WCS(hdr[:28], hdul1)
logger.debug(' Naxis %d ' % (w.naxis))
lc = np.size(cat)
logger.debug(" catatalog length %s " % (str(lc)) )
for line in cat:
obj = int(line['ID'])
suffixe = suffixeout + '_' + str(obj) + '_' + lines
fileout = suffixe + '.config'
logger.info('Writing config ' + fileout)
fo = open(path + fileout, 'w')
fo.write('FITSFILE= ' + cubefile + ' / path of the fits file containing the cube\n')
......@@ -128,8 +145,12 @@ 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')
fo.write('REDMIN = ' + str(line['z'] - dz) + ' / minimum redshift\n')
fo.write('REDMAX = ' + str(line['z'] + dz) + ' / maximum redshift\n')
if dz is not None:
fo.write('REDMIN = ' + str(line['z'] - dz) + ' / minimum redshift\n')
fo.write('REDMAX = ' + str(line['z'] + dz) + ' / maximum redshift\n')
else:
logger.error('dz 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')
fo.write('WMAX = ' + str(wmax) + ' / maximum linewidth in km/s\n')
......@@ -143,19 +164,32 @@ def create_config(path, cubefile, varfile, catfile, lines, suffixeout, commonw=T
ra = coord.Angle(line['ra'], unit=u.degree)
dec = coord.Angle(line['dec'], unit=u.degree)
xc, yc = np.round(w.wcs_world2pix(ra, dec, 0))
logger.debug(' converting ra,dec %f,%f ' % (line['ra'],line['dec']) )
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)
zmax = np.round((maxlbda - crval) / cdelt + crpix - 1)
#xc, yc = np.round(w.wcs_world2pix(ra, dec, 0))
xc, yc, _ = np.round(w.wcs_world2pix(ra, dec, 0, 0))
logger.debug(' converting x,y %f %f ' % (xc,yc) )
fo.write('XMIN = ' + str(xc - dxy) + ' / X minimum value for spatial cut of the input cube (pixel)\n')
fo.write('XMAX = ' + str(xc + dxy) + ' / X maximum value for spatial cut of the input cube (pixel)\n')
fo.write('YMIN = ' + str(yc - dxy) + ' / Y minimum value for spatial cut of the input cube (pixel)\n')
fo.write('YMAX = ' + str(yc + dxy) + ' / Y maximum value for spatial cut of the input cube (pixel)\n')
fo.write('ZMIN = ' + str(zmin) + ' / Z minimum value for spectral cut of the input cube (spectral channel, integer)\n')
fo.write('ZMAX = ' + str(zmax) + ' / Z maximum value for spectral cut of the input cube (spectral channel, integer)')
if dxy is not None:
fo.write('XMIN = ' + str(xc - dxy) + ' / X minimum value for spatial cut of the input cube (pixel)\n')
fo.write('XMAX = ' + str(xc + dxy) + ' / X maximum value for spatial cut of the input cube (pixel)\n')
fo.write('YMIN = ' + str(yc - dxy) + ' / Y minimum value for spatial cut of the input cube (pixel)\n')
fo.write('YMAX = ' + str(yc + dxy) + ' / Y maximum value for spatial cut of the input cube (pixel)\n')
else:
fo.write('XMIN = None / X minimum value for spatial cut of the input cube (pixel)\n')
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:
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)
zmax = np.round((maxlbda - crval) / cdelt + crpix - 1)
fo.write('ZMIN = ' + str(zmin) + ' / Z minimum value for spectral cut of the input cube (spectral channel, integer)\n')
fo.write('ZMAX = ' + str(zmax) + ' / Z maximum value for spectral cut of the input cube (spectral channel, integer)')
else:
fo.write('ZMIN = None / Z minimum value for spectral cut of the input cube (spectral channel, integer)\n')
fo.write('ZMAX = None / Z maximum value for spectral cut of the input cube (spectral channel, integer)')
fo.close()
......
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