Order Mask Algorithm

class modules.order_trace.src.alg_order_mask.OrderMaskAlg(spectrum_data, order_trace_data, order_trace_header, orderlet_names=None, start_order=0, order_mask_data=None, full_coverage=0, config=None, logger=None, logger_name=None)[source]

This module defines class ‘OrderMaskAlg’ and methods to perform order trace mask. A 2D array of the same size as that of the input spectrum data is returned and the pixels that are covered by the order traces are set to be 1 or a specified value, otherwise the pixels are set to be 0 or a specified value. The coverage is determined by the order trace location, the top and bottom edges and the horizontal range defined in the order trace data plus the origin defined in the order trace header to indicate where the trace position is related to.

Parameters:
  • spectrum_data (numpy.ndarray) – 2D spectrum raw data.

  • order_trace_data (Union[numpy.ndarray, pandas.DataFrame]) – order trace data including polynomial coefficients, top/bottom edges and horizontal coverage of the order trace.

  • order_trace_header (dict) – dict instance containing order trace info including the origin and polynomial degree to fit the trace.

  • start_order (int) – the index of the first orderlet of the first order based on the assumption that the first few traces may not be indentified by order trace process and the first trace (indexed as 0) listed in the order_trace_data may not the first orderlet of the first order. A negative number like -n means the first n traces are not included in the order_trace_data.

  • order_mask_data (numpy.ndarray) – 2D array to contain the order mask data. Defaults to None.

  • full_coverage (int) – if set order mask to cover full width for each order. Defaults to 0.

  • config (configparser.ConfigParser, optional) – config context. Defaults to None.

  • logger (logging.Logger, optional) – Instance of logging.Logger. Defaults to None.

  • logger_name (str, optional) – Name of the logger defined for the OrderMaskAlg instance.

spectrum_flux

Numpy array storing 2d spectrum data for spectral extraction. None is allowed.

Type:

numpy.ndarray

poly_order

Polynomial order for the approximation made on the order trace.

Type:

int

origin

The origin of the image from the original raw image.

Type:

list

instrument

Instrument of the observation.

Type:

str

config_ins

Instance of ConfigHandler related to section for the instrument or ‘PARAM’ section.

Type:

ConfigHandler

order_trace

Order trace results from order trace module including polynomial coefficients, top/bottom edges and area coverage of the order trace.

Type:

numpy.ndarrary

total_order

Total order in order trace object.

Type:

int

order_coeffs

Polynomial coefficients for order trace from higher to lower order.

Type:

numpy.ndarray

dim_w, dim_h

image dimension, width and height.

Type:

int

order_edges

Bottom and top edges along order trace.

Type:

numpy.ndarray

order_xrange

Left and right boundary of order trace.

Type:

numpy.ndarray

order_mask_data

order mask per spectrum flux and order trace result.

Type:

numpy.ndarray

orderlet_names

orderlet names for each order in flat file.

Type:

list

start_order

the index of the first orderlet of the first order.

Type:

int

total_trace_per_order

total orderlets (traces) per order in flat file.

Type:

int

order_mask_data

2D array to contain the order mask data.

Type:

numpy.ndarray

Raises:
  • TypeError – If there is type error for spectrum_data, or order_trace_data.

  • TypeError – If there is type error for order_trace_header.

  • TypeError – If there is no flux data for order mask.

get_config_value(prop, default='')[source]

Get defined value from the config file.

Search the value of the specified property from instrument section. The default value is returned if not found.

Parameters:
  • prop (str) – Name of the parameter to be searched.

  • default (Union[int, float, str], optional) – Default value for the searched parameter.

Returns:

Value for the searched parameter.

Return type:

Union[int, float, str]

get_order_edges(idx=0)[source]

Get the top and bottom edges of the specified order.

Parameters:

idx (int, optional) – Index of the order in the order trace array. Defaults to zero.

Returns:

Bottom and top edges of the order, idx. The first in the array is the bottom edge, and the second in the array is the top edge.

Return type:

numpy.ndarray

get_order_mask(order_name, s_width=None, trace_value=1, show_time=False, print_debug=None)[source]

From 2D flux to 2D with order masked.

Parameters:
  • order_name (str) – orderlet name

  • s_width (list) – trace widths to replace those from order trace file.

  • trace_value (number, optional) – value set for trace pixels. Default to 1.

  • show_time (bool, optional) – Show running time of the steps. Defaults to False.

  • print_debug (str, optional) – Print debug information to stdout if it is provided as empty string, a file with path print_debug if it is non empty string, or no print if it is None. Defaults to None.

Returns:

order mask result, like:

{
    'order_mask_result':  np.ndarray
}

Return type:

dict

get_order_set(order_name)[source]

Get the list of the trace index eligible for order mask process.

Parameters:

order_name (str) – Fiber name.

Returns:

list of the trace index.

Return type:

list

get_order_xrange(idx=0)[source]

Get the left and right x boundaries of the specified order.

Parameters:

idx (int, optional) – Index of the order in the order trace array. Defaults to zero.

Returns:

Left and right boundaries of order, idx. The first in the array is the left end, and the second in the array is the right end.

Return type:

numpy.ndarray

get_orderlet_index(order_name)[source]

Find the index of the order name in the orderlet name list.

Parameters:

order_name (str) – Fiber name

Returns:

index of order name in the orderlet name list. If not existing, return is 0.

Return type:

int

get_orderlet_names()[source]

Get Orderlette names defined in config.

Returns:

list of orderlet names

Return type:

list

get_total_orderlets_from_image()[source]

Get total orderlets from level 0 image, defined in config

Returns:

total orderdelettes.

Return type:

int

set_order_mask(order_idx, s_width=None, trace_value=1)[source]

Set value to order mask array.

Parameters:
  • order_idx (int) – trace order index

  • s_width (list) – reduction to trace lower and upper width. Default to None meaning no reduction.

  • trace_value (float) – order mask value for the trace pixels. Default to 1.

Returns:

2D array containing mask data on order trace pixels.

Return type:

numpy.ndarray