Segments — Manages groups of line segments.

This module defines the Segments class.

class admit.util.Segments.Segments(st=None, en=None, nchan=None, startchan=0)[source]

Class to hold segments and convert them between different types.

Segments are defined by a beginning and ending channel (both inclusive). ADMIT gives special meaning to a segment, for example a line can be found within that segment, or a continuum has to be fitted in that segment (or group of segments).

Parameters:

st : array like

Array like object containing either the full segment list (array of two element arrays containing the start and end channel numbers for each segment), or an array of starting channel numbers. Default: None.

en : array like

An array of the ending channel number corresponding to the starting channel numbers given in st. Leave as None if st contains the full listing. Default: None.

nchan : int

The number of channels in the spectrum that the segments refer to. This is used to construct the bit mask for tracking all segments. If left as None, no bitmask will be made. Default: None.

startchan : int

The starting channel number of the spectrum that the segments refer to. Must be >= 0. Default: 0.

Methods

append(item) Method to append a new segment to the current list
chans([invert]) Method to convert the bit mask into a string of channel ranges in CASA format.
getchannels([invert]) Method to return the current list of channel numbers in the bitmask
getmask() Method to return the current bitmask
getnchan() Method to return the number of channels in the current bit mask
getsegments() Method to get the list of segments
getsegmentsaslists() Method to get the list of segments
getsegmentsastuples() Method to get the list of segments as tuples
getstartchan() Method to get the starting channel number of the current bit mask
limits() Method to return the channel range of the internal channel bit mask
merge([other]) Method to merge overlapping segments into one segment.
pop() Method to pop, or remove and return, the last segment in the list
recalcmask([test]) Method to recalculate the bit mask based on the current segment list.
remove(index) Method to remove a segment from the segment list
setnchan(nchan) Method to set the number of channels in the internal channel bit mask
setstartchan(chan) Method to set the starting channels number for the internal bit mask
append(item)[source]

Method to append a new segment to the current list

Parameters:

item : two element array

The new segment to append to the list

Returns:

None

chans(invert=False)[source]

Method to convert the bit mask into a string of channel ranges in CASA format. e.g. [3,10],[25,50] => “3~10;25~50”

Parameters:None
Returns:string containing the formatted channel ranges
getchannels(invert=False)[source]

Method to return the current list of channel numbers in the bitmask

Parameters:

invert : boolean

Return the list of channels outside the bitmask instead

Returns:

Array like object containing the (zero based) channel numbers that are in the segments

getmask()[source]

Method to return the current bitmask

Parameters:None
Returns:Array like object containing the bit current bit mask, 1 = in segment, 0 = not in segment
getnchan()[source]

Method to return the number of channels in the current bit mask

Parameters:None
Returns:int giving the number of channels
getsegments()[source]

Method to get the list of segments

Parameters:None
Returns:list of the segment end points [start, end]
getsegmentsaslists()[source]

Method to get the list of segments

Parameters:None
Returns:list of the segment end points [start, end]
getsegmentsastuples()[source]

Method to get the list of segments as tuples

Parameters:None
Returns:list of the segment end points as tuples (start, end)
getstartchan()[source]

Method to get the starting channel number of the current bit mask

Parameters:None
Returns:int containing the starting channel number
limits()[source]

Method to return the channel range of the internal channel bit mask

Parameters:None
Returns:Array like 2 element list of the segment starting and ending channels
merge(other=None)[source]

Method to merge overlapping segments into one segment. This operates on the current instance or takes a second instance or list of segments as input.

Parameters:

other : Segments instance or list of segments

If given then these segments are added to the current list and then merged, to give a single list of non-overlapping segments.

Returns:

None

pop()[source]

Method to pop, or remove and return, the last segment in the list

Parameters:

None

Returns:

Array like 2 element list of the segment starting and ending channels of the last

segment in the list

recalcmask(test=False)[source]

Method to recalculate the bit mask based on the current segment list. 1 = in segment 0 = not in segment

Parameters:

test : bool

If True then test each segment to be sure it is in the current allowed channel range. If False the do not test.

Returns:

None

remove(index)[source]

Method to remove a segment from the segment list

Parameters:

index : int

The location of the segment to remove

Returns:

None

setnchan(nchan)[source]

Method to set the number of channels in the internal channel bit mask

Parameters:

nchan : int

The number of channels in the bit mask

Returns:

None

setstartchan(chan)[source]

Method to set the starting channels number for the internal bit mask

Parameters:

chan : int

The starting channel number

Returns:

None