In order to fill the output file, observation have to be defined and written. This is done with the ClassObservation class:
obs = pyclassfiller.ClassObservation()
The sections present should first be declared, e.g.:
obs.head.presec[:] = False # Disable all sections except... obs.head.presec[code.sec.gen] = True # GeneralCLASS will accept to write observations which provide at least the General, Position, and Spectroscopy or Continuum Drift sections.
Each section has then to be filled, e.g. the Spectroscopic section:
obs.head.spe.line = "MYLINE" obs.head.spe.restf = 123456. obs.head.spe.nchan = nchan obs.head.spe.rchan = 1. obs.head.spe.fres = 1. obs.head.spe.vres = -1. obs.head.spe.voff = 0. obs.head.spe.bad = -1000. obs.head.spe.image = 98765. obs.head.spe.vtype = code.velo.obs obs.head.spe.vconv = code.conv.rad obs.head.spe.doppler = 0.All elements should be filled, Class does not support partially filled sections. At the time this document is written, only the sections General, Position, Spectroscopy, Frequency Switch, Calibration, and continuum Drift are supported. The content of these sections, as seen from Python, is strictly equivalent to the Sic variables in R%HEAD% (i.e. see HELP SET VARIABLE in the CLASS program for the sections details).
Some elements in the Class sections are arrays. They must be defined as numpy arrays, e.g.:
import numpy obs.head.cal.count = numpy.array(range(3),dtype=numpy.float32)The numpy array must be defined with the correct size and type: for efficiency purpose (which is often needed when writing CLASS files e.g. at the telescope), the module pyclassfiller does not provide implicit conversion to the appropriate type. You must foresee it when writing your scripts.
Also, some other elements are internal codes, e.g.
from pyclassfiller import code obs.head.gen.kind = code.kind.specAgain, these codes are equivalent to the same codes in the SIC structure SIC%CODE%. They should be used when relevant according to the SET VARIABLE help.
The data array (most likely the spectrum intensities) should be also provided as a single precision numpy array, e.g.:
obs.datay = numpy.array(range(nchan),dtype=numpy.float32)
Finally, once the sections and data are filled, the observation has to be written to the output file:
obs.write()If obs.head.gen.num is 0, CLASS will automatically give the next available (unused) number in the file.
Once you are done with a ClassObservation object, you should delete it to release its memory.