[Last Change: 15 Mar 2019 (rev 3)]
How to raytrace Lots and Lots of Sources
If you are attempting to simulate a complex field with many sources in it, there are better ways of doing this than simply repeating
point{ ... }
point{ ... }
point{ ... }
ad nauseum.
Parameters in a Lua
list
If all of your sources are points, you could do something like this:
sources = {
-- theta, phi, spectrum
{ 0, 0, 1.49},
{ {10, "arcseconds"} , 0, 6.4 },
}
for _, src in pairs(sources) do
point{ position = { theta = src[1], phi = src[2] }, spectrum = src[3] }
end
which is slightly less nauseating.
Parameters in an RDB
file
An improvement might be to store your positions and spectra in a separate file, say an
RDB formatted file . That file might have columns "theta", "phi", and "file", and "scale", where
the
file
column contains the name of a file containing a spectrum and
scale
is a scale factor to apply to the spectrum:
theta phi file scale
N N S N
0 0 spec_6.80.rdb 1.0
1 170 spec_6.80.rdb 0.5
0.5 120 spec_6.80.rdb 3.0
(Those are single tab characters between the columns, not spaces; here's the
source file and the
spectrum file)
The following code would read that file in and generate a set of point sources:
RDB = require('rdb')
srcfile = 'sources.rdb'
rdb = RDB( srcfile )
if nil == rdb then
error( "error opening up ".. srcfile )
end
row = rdb:read()
while row ~= nil do
point{ position = { theta = row.theta,
phi = row.phi },
spectrum = { { type = 'file',
format = 'rdb',
scale = row.scale,
file = row.file,
units = 'photons/s/cm2'
} }
}
row = rdb:read()
end
Parameters in an XML
file
For the ultimate in flexibility,
SAOTrace
provides the
load_sources
function, which can load sources from an
XML
formatted file
with the following code:
load_sources( 'ngc2516-small.xml', { ra_aimpt = 1.1953549452648E+02,
dec_aimpt = -6.0763660833014E+01
} )