wiki:WriteSpectraToTextFile

Back

Write spectra to a text file

Assume that you have a scantable called scan it contains linear polarisations and cross-polarisation terms. ou now wnat to write out circular polarisations.

scan = scantable("pol.rpf")
# some processing
scan.set_unit("km/s") # to get abcissa values in km/s
# assumption that at this point there is only one scan left in the scantable
assert scan.nrow() == 4

# abscissa
x, xlabel = scan.get_abcissa(0)
sel = selector()
sel.set_pols("RR")
scan.set_selection(sel)
yrr = scan.get_spectrum(0)
sel.set_pols("LL")
scan.set_selection(sel)
yll = scan.get_spectrum(0)

# magic line to  create three columns x,yrr,ll and nchannel rows
# which is how we want ro write the data
# [ ( x[0],yrr[0],yll[0] ) , ..., ( x[n-1],yrr[n-1],yll[n-1] ) ]
columns = map(None, x, yrr, yll)


# write to a file 
myfile = open("RR-LL-spectra.txt", "w")
header = "#%s\tRR\tLL\n\n" % xlabel
myfile.write(header)
for row in columns:
   outstring = "%f\t%f\t%f\n" % row
   myfile.write()

myfile.close()

Last modified 15 years ago Last modified on 05/08/09 11:31:12