From fa32be8a7a4a2068fd854535254d34e159958a7a Mon Sep 17 00:00:00 2001 From: Alexandra Tetarenko Date: Mon, 5 Feb 2018 13:36:13 -0700 Subject: [PATCH] fixes to uvfitting --- casa_timing_script.py | 32 +++++++++++++++++++++----------- param_description.txt | 3 ++- uv_init_example.txt | 6 ++++-- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/casa_timing_script.py b/casa_timing_script.py index a87a8ec..71b2945 100644 --- a/casa_timing_script.py +++ b/casa_timing_script.py @@ -7,20 +7,20 @@ (2) Lightcurve data file--> saved in [path_dir]/data_products (3) (optional) Lomb-Scarge periodogram plot and basic variability properties file --> saved in [path_dir]/data_products NOTES: - This script is theoretically compatible with any data that can be imported into a CASA MS, - but has only been tested with VLA, SMA, and NOEMA data. + but has only been tested with VLA, ATCA, ALMA, SMA, and NOEMA data. Written by: C. Gough (original version), additions and updates by A. Tetarenko & E. Koch Last Updated: Feb 2018 +Tested on: CASA version 5.1.2 TO RUN SCRIPT-->casa -c casa_timing_script.py [path_to_param_file] [path_dir] [path_to_repo] -Uncomment at line 557 if you dont want time-bins printed to screen -Uncomment at line 1039 if you dont want results printed to screen. +Uncomment at line 590 if you want time-bins printed to screen. +Uncomment at line 1077 if you want light curve results printed to screen. NOTE: path_dir is path to input/output directory of your choice -MS's need to be in path_dir/data, -all output goes to path_dir/data_products (this directory is created by script) -Make sure to including trailing / in [path_to_repo_dir] & [path_dir]!!! --Remember to put Aegean directory location in python path if using object detection. ''' #MODULES USED: @@ -42,6 +42,7 @@ import astroML.time_series import imp import warnings +import analysisUtils as au warnings.filterwarnings('ignore') import sys @@ -53,7 +54,6 @@ from utils import (convert_param_format,initial_clean,run_aegean, var_analysis,lomb_scargle,chi2_calc,errf) -from Aegean_ObjDet import objdet ################################## #Setup @@ -209,6 +209,10 @@ '''OBJECT DETECTION AND SELECTION PARAMETERS''' mask_option=data_params["mask_option"] if runObj == 'T': + try: + from Aegean_ObjDet import objdet + except ImportError: + raise ImportError('Please install Aegean, if you intend to use object detection.') tables = outputPath+label+'whole_dataset_objdet_comp.tab' out_file0=outputPath+label+'whole_dataset_aegean.txt' catalog_input_name=outputPath+label+'whole_dataset_objdet.tab' @@ -358,15 +362,19 @@ if runClean=='U': uv_fit='T' #only point sources right now -uv_num=data_params["uv_num"] +uv_num=int(data_params["uv_num"]) uv_initp=data_params["uv_initp"] phcen_rad=vishead(vis=visibility,mode='get',hdkey='ptcs') +print 'Phase center set to:' phcen=au.rad2radec(phcen_rad[0]['r1'][0][0][0],phcen_rad[0]['r1'][1][0][0],hmsdms=True).replace(',','') if uv_initp != '': initp_array=np.loadtxt(uv_initp) init_uv=[] - for jj in range(0,uv_num): - init_uv.extend([initp_array[i,0],initp_array[i,1],initp_array[i,2]]) + if uv_num==1: + init_uv.extend([initp_array[0],initp_array[1],initp_array[2]]) + else: + for jj in range(0,uv_num): + init_uv.extend([initp_array[jj,0],initp_array[jj,1],initp_array[jj,2]]) else: init_uv=[] comp_uv=[] @@ -691,10 +699,11 @@ os.system('sudo rm -rf '+outputPath+label+intervalString+'.*') #uvfitting if requested if uv_fit =='T': + print 'UV fitting interval: ', interval if np.where(np.array(timeIntervals)==interval)[0][0]==0: combuv=visibility_uv.strip('.ms') mstransform(vis=visibility_uv,outputvis=combuv+'_mstransform.ms',combinespws=True,spw='',datacolumn='data') - fit=uvm.uvmultifit(vis=combuv+'_mstransform.ms', MJDrange=[time_uv-(intervalSizeH/24.+intervalSizeM/(24.*60.)+intervalSizeS/(24.*60.*60.)),time_uv],spw=spw_choice, column = "data", uniform=False, model=[comp_uv],stokes = stokes_param,var=[uv_var], p_ini=[float(src_uv_init.split(',')[0]),float(src_uv_init.split(',')[1]),float(src_uv_init.split(',')[2])],outfile = outputPath+'uvfit_'+target+'_'+refFrequency+'_'+obsDate+'_'+intervalString+'.txt',OneFitPerChannel=False ,cov_return=False, finetune=False, method="levenberg") + fit=uvm.uvmultifit(vis=combuv+'_mstransform.ms', MJDrange=[time_uv-(intervalSizeH/24.+intervalSizeM/(24.*60.)+intervalSizeS/(24.*60.*60.)),time_uv],spw=spw_choice, column = "data", uniform=False, model=comp_uv,stokes = stokes_param, var=uv_var,p_ini=init_uv, phase_center =phcen,outfile = outputPath+'uvfit_'+target+'_'+refFrequency+'_'+obsDate+'_'+intervalString+'.txt',OneFitPerChannel=False ,cov_return=False, finetune=False, method="levenberg") else: fit.MJDrange=[time_uv-(intervalSizeH/24.+intervalSizeM/(24.*60.)+intervalSizeS/(24.*60.*60.)),time_uv] fit.fit(redo_fixed=False,reinit_model=False) @@ -776,6 +785,7 @@ timeIntervals.remove(interval) mjdTimes.remove(time) if uv_fit =='T': + print 'UV fitting interval: ', interval if np.where(np.array(timeIntervals)==interval)[0][0]==0: combuv=visibility_uv.strip('.ms') mstransform(vis=visibility_uv,outputvis=combuv+'_mstransform.ms',combinespws=True,spw='',datacolumn='data') @@ -1371,9 +1381,9 @@ if power_spec=='T': print 'Creating Power Spectrum' if float(intervalSizeDelta.seconds)==0.0: - sig95,sig99=lomb_scargle(mjdTimes,fluxvar,fluxerrvar,float(intervalSizeDelta.microseconds)/1e6,labelP,'lin') + sig95,sig99=lomb_scargle(mjdTimes,fluxvar,fluxerrvar,float(intervalSizeDelta.microseconds)/1e6,labelP) else: - sig95,sig99=lomb_scargle(mjdTimes,fluxvar,fluxerrvar,float(intervalSizeDelta.seconds),labelP,'lin') + sig95,sig99=lomb_scargle(mjdTimes,fluxvar,fluxerrvar,float(intervalSizeDelta.seconds),labelP) print labelP+' is saved.' var_file.write('{0} {1} {2}\n'.format('Weighted Mean/Error',wm,wmerr)) var_file.write('{0} {1} {2}\n'.format('Chi2 with weighted mean/dof',chi_tot,dof)) diff --git a/param_description.txt b/param_description.txt index 2574055..62aa174 100644 --- a/param_description.txt +++ b/param_description.txt @@ -70,7 +70,8 @@ uv_num: if doing uv fitting, the number of point sources for fitting; integer uv_initp: if doing uv fitting, provide the path to the intial guess file for uv fitting; string Format of this file is a row for each point source, with ra offset from phase center (arcsec), -dec offset from phase center (arcsec), and flux (Jy) on each row (see uv_init_example.txt for example). +dec offset from phase center (arcsec), and flux (Jy) on each row. Target MUST be first source in file +(see uv_init_example.txt for example). def_times: toggle to manually define start and end times (next 6 params), default is start and end of observation; string, options are 'T' or 'F' diff --git a/uv_init_example.txt b/uv_init_example.txt index 6e94218..aa89f7c 100644 --- a/uv_init_example.txt +++ b/uv_init_example.txt @@ -1,2 +1,4 @@ -#example uv initial parameters file -0 0 700e-3 \ No newline at end of file +#example uv initial parameters file, first line is target! +0 0 700e-3 +1 1 500e-3 +2 2 400e-3 \ No newline at end of file