Commit bb630310 authored by bepinat's avatar bepinat

Variance corrections, whitelight image creation, new keywords to only create...

Variance corrections, whitelight image creation, new keywords to only create cut/clip/smoothed cubes, changes in create_config.py to use command line
parent a6eab647
This diff is collapsed.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os, sys
import argparse
import ipdb
import numpy as np
import pyfits as pf
import astropy.wcs as wcs
......@@ -34,7 +37,7 @@ def create_config(path, cubefile, varfile, catfile, lines, suffixeout, commonw=T
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
dxyz: int
dxy: int
spatial extent around the object for cutting the cube (in pixels)
initw: float
initial guess for the line width (dispersion) in km/s
......@@ -58,7 +61,8 @@ def create_config(path, cubefile, varfile, catfile, lines, suffixeout, commonw=T
gaussian spatial smooth FWHM in pixels
'''
cat = np.genfromtxt(path + catfile, names=True)
#ipdb.set_trace()
cat = np.genfromtxt(path + catfile, names=True, case_sensitive=False)
try:
hdul = pf.open(path + cubefile)
......@@ -93,6 +97,7 @@ def create_config(path, cubefile, varfile, catfile, lines, suffixeout, commonw=T
if 'CRVAL3' in hdr.ascard.keys(): del hdr['CRVAL3']
if 'CRPIX3' in hdr.ascard.keys(): del hdr['CRPIX3']
if 'CUNIT3' in hdr.ascard.keys(): del hdr['CUNIT3']
if 'CDELT3' in hdr.ascard.keys(): del hdr['CDELT3']
if 'CD3_3' in hdr.ascard.keys(): del hdr['CD3_3']
if 'CD3_2' in hdr.ascard.keys(): del hdr['CD3_2']
if 'CD3_1' in hdr.ascard.keys(): del hdr['CD3_1']
......@@ -117,13 +122,14 @@ def create_config(path, cubefile, varfile, catfile, lines, suffixeout, commonw=T
obj = int(line['ID'])
suffixe = suffixeout + '_' + str(obj) + '_' + lines
fileout = suffixe + '.config'
fileout = suffixe + '/' + suffixe + '.config'
logger.info('Writing config ' + fileout)
print(path + fileout)
fo = open(path + fileout, 'w')
fo.write('FITSFILE= ' + cubefile + ' / path of the fits file containing the cube\n')
fo.write('OUTPUT = ' + suffixe + '/' + suffixe + ' / where to write the output (default: ./out.fits)\n')
fo.write('SKYFILE = ' + varfile + ' / path of the file containing the sky spectrum or cube\n')
fo.write('FITSFILE= ' + '../' + cubefile + ' / path of the fits file containing the cube\n')
fo.write('OUTPUT = ' + suffixe + ' / where to write the output (default: ./out.fits)\n')
fo.write('SKYFILE = ' + '../' + varfile + ' / path of the file containing the sky spectrum or cube\n')
lbda = []
if 'ha' in lines:
......@@ -161,10 +167,10 @@ def create_config(path, cubefile, varfile, catfile, lines, suffixeout, commonw=T
lbda.append(4101.73)
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('REDSHIFT= ' + str(line['Z']) + ' / initial redshift of the galaxy\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')
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')
......@@ -179,9 +185,9 @@ def create_config(path, cubefile, varfile, catfile, lines, suffixeout, commonw=T
fo.write('WSMOOTH = ' + str(wsmooth) + ' / spectral smoothing: 1 for Hanning, 2 for gaussian (FWHM=3 pixels), set 0 for no smoothing (default:0)\n')
fo.write('SSMOOTH = ' + str(ssmooth) + ' / gaussian spatial smooth FWHM in pixel, set 0 for no smoothing (default:0)\n')
ra = coord.Angle(line['ra'], unit=u.degree)
dec = coord.Angle(line['dec'], unit=u.degree)
logger.debug(' converting ra,dec %f,%f ' % (line['ra'],line['dec']) )
ra = coord.Angle(line['RA'], unit=u.degree)
dec = coord.Angle(line['DEC'], unit=u.degree)
logger.debug(' converting ra,dec %f,%f ' % (line['RA'],line['DEC']) )
xc, yc = np.round(w.wcs_world2pix(ra, dec, 0))
#xc, yc, _ = np.round(w.wcs_world2pix(ra, dec, 0, 0))
......@@ -198,8 +204,8 @@ def create_config(path, cubefile, varfile, catfile, lines, suffixeout, commonw=T
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)
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')
......@@ -211,21 +217,47 @@ def create_config(path, cubefile, varfile, catfile, lines, suffixeout, commonw=T
fo.close()
def main():
def main_byhand():
gr = '116'
#gr = '83'
#gr = '28'
#gr = '32'
path = '/home/bepinat/Instruments/MUSE/groups/kinematics/gr' + gr + '/'
cubefile = 'DATACUBE_FINAL_ZAP_COSMOS-GR' + gr + '_newWCS.fits'
varfile = cubefile
catfile = 'catalog_gr' + gr + '.txt'
suffixeout = 'gr' + gr
lines = 'o3hb'
lines = 'o2'
suffixeout = 'gr' + gr
path = '/home/bepinat/Instruments/MUSE/groups/kinematics/gr' + gr + '/' + lines + '/'
cubefile = '../DATACUBE_FINAL_ZAP_COSMOS-GR' + gr + '_newWCS.fits'
varfile = cubefile
catfile = '../catalog_gr' + gr + '.txt'
create_config(path, cubefile, varfile, catfile, lines, suffixeout)
def main(argv):
parser = argparse.ArgumentParser()
parser.add_argument('--lines', '-l', action="store", dest="lines", default="", help="name of the lines")
parser.add_argument('--suffixe', '-s', action="store", dest="suffixeout", default="", help="suffixe")
parser.add_argument('--path', '-p', action="store", dest="pathb", default="", help="initial path")
parser.add_argument('--cat', '-c', action="store", dest="catfile", default="", help="path of the catalogue with respect to initial path")
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")
try:
options = parser.parse_args()
except:
sys.exit(2)
opts = vars(options) # this is a dictionnary
#print(opts)
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']))
if __name__ == "__main__":
main()
main(sys.argv[1:])
#main_byhand()
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