Coverage for /wheeldirectory/casa-6.7.0-12-py3.10.el8/lib/py/lib/python3.10/site-packages/casatasks/private/predictcomp_helper.py: 15%
55 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-10-31 18:48 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-10-31 18:48 +0000
1import shutil
2import os
4from casatools import componentlist, measures, quanta, ms, table
5from casatasks import casalog
6from .setjy_helper import testerrs
7from . import solar_system_setjy as SSSetjy
9_qa = quanta()
11def predictSolarObjectCompList(objname, epoch, freqs, prefix):
12 """
13 predictcomp functionality using the new models
14 set flux density of a solar system object using Bryan Butler's new
15 python model calculation code.
16 """
17 retval = True
18 cleanupcomps = False # leave genenerated cl files
19 nfreqs=-1
21 myms = ms( )
22 mytb = table( )
23 mycl = componentlist( )
24 myme = measures( )
26 #freqinc=freqs[0]*1e-6
27 if len(freqs) == 1:
28 freqinc=freqs[0]*1e-4
29 else:
30 freqinc=abs(freqs[1]-freqs[0])*1e-2
31 freqlist=[]
32 for freq in freqs:
33 minf = freq-freqinc
34 maxf = freq+freqinc
35 freqlist.append([minf,maxf])
36 #mepoch = myme.epoch('UTC', epoch)
37 if epoch['m0']['value']==0.0:
38 casalog.post('Invalid epoch, '+str(epoch['m0']['value'])+str(epoch['m0']['unit']),'SEVERE');
39 raise Exception("Error")
40 epochv = epoch['m0']['value']
43 # turn user input epoch to mjd
45 #casalog.post("sending objname={} epochv={} freqlist={}".format(objname, epochv, freqlist)
46 observatory='ALMA'
47 ss_setjy=SSSetjy.solar_system_setjy()
48 (errcodes, fluxes, fluxerrs, sizes, dirs)=\
49 ss_setjy.solar_system_fd(source_name=objname, MJDs=[epochv], frequencies=freqlist, observatory=observatory, casalog=casalog)
51 #casalog.post("fluxes from ss_setjy={}".format(fluxes))
52 #if errcodes[0][0] > 0:
53 # raise ValueError("cannot determined flux")
55 reterr=testerrs(errcodes[0],objname)
56 if reterr == 2:
57 #raise Exception, "Error"
58 casalog.post("Flux densities cannot be determined","SEVERE")
59 raise Exception
61 dirstring = [dirs[0]['refer'],_qa.tos(dirs[0]['m0']),_qa.tos(dirs[0]['m1'])]
62 # setup componentlists
63 # need to set per dir
64 # if scalebychan=F, len(freqs) corresponds to nspw selected
66 #clpath='/tmp/'
67 clpath='./'
68 # use the first input frequency
69 freqlabel = '%.3fGHz' % (freqs[0]/1.e9)
70 tmlabel = '%.1fd' % epoch['m0']['value']
71 clabel = objname+'_spw0_'+freqlabel+'_'+tmlabel
72 clname = clabel+'.cl'
73 if prefix: clname=prefix+clname
75 if(os.path.exists(clname)):
76 casalog.post("Removing previous cl file, {}".format(clname))
77 try:
78 shutil.rmtree(clname)
79 except:
80 casalog.post("shutil.rmtree failed")
81 index= 2.0
82 sptype = 'spectral index'
83 #index= 0.0
84 #sptype = 'constant'
86 #casalog.post("fluxes={}".format(fluxes))
87 #casalog.post("fluxerrs-={}".format(fluxerrs))
88 #casalog.post("sizes={}".format(sizes))
89 #casalog.post("dirs={}".format(dirs))
90 mycl.addcomponent(flux=fluxes[0][0],fluxunit='Jy', polarization="Stokes", dir=dirs[0],
91 shape='disk', majoraxis=str(sizes[0][0])+'arcsec', minoraxis=str(sizes[0][1])+'arcsec',
92 # positionangle=str(sizes[0][2])+'arcsec', freq=['LSRK',str(freqs[0])+'Hz'],
93 positionangle=str(sizes[0][2])+'arcsec', freq=['TOPO',str(freqs[0])+'Hz'],
94 spectrumtype=sptype, index=index, label=clabel)
95 # set tabular, use original input freqs
96 if len(freqs)>1:
97 mycl.setspectrum(which=0, type='tabular', tabularfreqs=freqs, tabularflux=fluxes[0],
98 tabularframe='TOPO')
100 mycl.rename(clname)
101 mycl.close(False)
102 return (clname)