Gildas CLASS files

Pyspeckit is capable of reading files from some versions of CLASS. The CLASS developers have stated that the GILDAS file format is private and will remain so, and therefore there are no guarantees that the CLASS reader will work for your file.

Nonetheless, if you want to develop in python instead of SIC, the read_class module is probably the best way to access CLASS data.

The CLASS file specification is incomplete, so much of the data reading is hacked together. The code style is based off of Tom Robitaille’s idlsave package.

An example usage. Note that telescope and line are NOT optional keyword arguments, they are just specified as such for clarity

n2hp = class_to_obsblocks(fn1, telescope=['SMT-F1M-HU','SMT-F1M-VU'],
    line=['N2HP(3-2)','N2H+(3-2)'])

This will generate a ObsBlock from all data tagged with the ‘telescope’ flags listed and lines matching either of those above. The data selection is equivalent to a combination of

find /telescope SMT-F1M-HU
find /telescope SMT-F1M-VU
find /line N2HP(3-2)
find /line N2H+(3-2)

ALL of the data matching those criteria will be included in an ObsBlock. They will then be accessible through the ObsBlock’s speclist attribute, or just by indexing the ObsBlock directly.

An essentially undocumented API

GILDAS CLASS file reader

Read a CLASS file into an pyspeckit.spectrum.ObsBlock

class pyspeckit.spectrum.readers.read_class.LazyItem(parent)[source] [github] [bitbucket]

Simple lazy spectrum-retriever wrapper

pyspeckit.spectrum.readers.read_class.class_to_obsblocks(*arg, **kwargs)[source] [github] [bitbucket]

Load an entire CLASS observing session into a list of ObsBlocks based on matches to the ‘telescope’, ‘line’ and ‘source’ names

Parameters

filename : string

The Gildas CLASS data file to read the spectra from.

telescope : list

List of telescope names to be matched.

line : list

List of line names to be matched.

source : list (optional)

List of source names to be matched. Defaults to None.

imagfreq : bool

Create a SpectroscopicAxis with the image frequency.

pyspeckit.spectrum.readers.read_class.class_to_spectra(*arg, **kwargs)[source] [github] [bitbucket]

Load each individual spectrum within a CLASS file into a list of Spectrum objects

pyspeckit.spectrum.readers.read_class.downsample_1d(myarr, factor, estimator=<function mean>, weight=None)[source] [github] [bitbucket]

Downsample a 1D array by averaging over factor pixels. Crops right side if the shape is not a multiple of factor.

This code is pure numpy and should be fast.

keywords:
estimator - default to mean. You can downsample by summing or

something else if you want a different estimator (e.g., downsampling error: you want to sum & divide by sqrt(n))

weight: np.ndarray

An array of weights to use for the downsampling. If None, assumes uniform 1

pyspeckit.spectrum.readers.read_class.ensure_bytes(string)[source] [github] [bitbucket]

Ensure a given string is in byte form

pyspeckit.spectrum.readers.read_class.filedescv2_nw1 = 14
GENERAL

integer(kind=obsnum_length) :: num ! [ ] Observation number integer(kind=4) :: ver ! [ ] Version number integer(kind=4) :: teles(3) ! [ ] Telescope name integer(kind=4) :: dobs ! [MJD-60549] Date of observation integer(kind=4) :: dred ! [MJD-60549] Date of reduction integer(kind=4) :: typec ! [ code] Type of coordinates integer(kind=4) :: kind ! [ code] Type of data integer(kind=4) :: qual ! [ code] Quality of data integer(kind=4) :: subscan ! [ ] Subscan number integer(kind=obsnum_length) :: scan ! [ ] Scan number ! Written in the entry real(kind=8) :: ut ! 1-2 [ rad] UT of observation real(kind=8) :: st ! 3-4 [ rad] LST of observation real(kind=4) :: az ! 5 [ rad] Azimuth real(kind=4) :: el ! 6 [ rad] Elevation real(kind=4) :: tau ! 7 [neper] Opacity real(kind=4) :: tsys ! 8 [ K] System temperature real(kind=4) :: time ! 9 [ s] Integration time ! Not in this section in file integer(kind=4) :: xunit ! [ code] X unit (if X coordinates section is present) ! NOT in data — character(len=12) :: cdobs ! [string] Duplicate of dobs character(len=12) :: cdred ! [string] Duplicate of dred

pyspeckit.spectrum.readers.read_class.gi8_dicho(ninp, lexn, xval, ceil=True)[source] [github] [bitbucket]

! @ public ! Find ival such as ! X(ival-1) < xval <= X(ival) (ceiling mode) ! or ! X(ival) <= xval < X(ival+1) (floor mode) ! for input data ordered. Use a dichotomic search for that. call gi8_dicho(nex,file%desc%lexn,entry_num,.true.,kex,error)

pyspeckit.spectrum.readers.read_class.is_ascii(s)[source] [github] [bitbucket]

Check if there are non-ascii characters in Unicode string

Parameters

s : str

The string to be checked

Returns

is_ascii : bool

Returns True if all characters in the string are ascii. False otherwise.

pyspeckit.spectrum.readers.read_class.make_axis(header, imagfreq=False)[source] [github] [bitbucket]

Create a pyspeckit.spectrum.units.SpectroscopicAxis from the CLASS “header”

pyspeckit.spectrum.readers.read_class.print_timing(func)[source] [github] [bitbucket]

Prints execution time of decorated function. Included here because CLASS files can take a little while to read; this should probably be replaced with a progressbar

pyspeckit.spectrum.readers.read_class.read_class(*arg, **kwargs)[source] [github] [bitbucket]

Read a binary class file. Based on the GILDAS CLASS file type Specification

Parameters

filename: str :

downsample_factor: None or int :

Factor by which to downsample data by averaging. Useful for overresolved data.

sourcename: str or list of str :

Source names to match to the data (uses regex)

telescope: str or list of str :

‘XTEL’ or ‘TELE’ parameters: the telescope & instrument

line: str or list of str :

The line name

posang: tuple of 2 floats :

The first float is the minimum value for the position angle. The second float is the maximum value for the position angle.

verbose: bool :

Log messages with severity INFO

flag_array: np.ndarray :

An array with the same shape as the data used to flag out (remove) data when downsampling. True = flag out

pyspeckit.spectrum.readers.read_class.tests()[source] [github] [bitbucket]

Tests are specific to the machine on which this code was developed.

[edit this page on github]

[edit this page on bitbucket]