Tramline API#
Tramline map (TLM) generation: detecting fibre traces on the detector, linking them via multi-target tracking, and matching traces to physical fibre IDs. See the TLM stage theory for background.
Tramline map generation using astropy-based I/O.
This module provides functions for generating tramline maps from FITS images, replacing the Fortran TDFIO functions with astropy-based equivalents.
TODO: check the usage of the arguments in the function calls.
- kspecdr.tlm.make_tlm.convert_fibre_types_to_trace_status(instrument_code: int, fibre_types: ndarray, nf: int) ndarray[source]#
Convert fibre types to trace status.
- kspecdr.tlm.make_tlm.convert_traces_to_tramline_map(traces: ndarray, match_vector: ndarray, nf: int) ndarray[source]#
Convert identified traces to fibre tramline map array.
- Parameters:
traces (np.ndarray) – Detected traces
match_vector (np.ndarray) – Vector matching fibre numbers to trace numbers
nf (int) – Number of fibres
- Returns:
Tramline map array
- Return type:
np.ndarray
- kspecdr.tlm.make_tlm.detect_traces(img_data: ndarray, nspec: int, nspat: int, max_ntraces: int, nf: int, order: int = 4, sparse_fibs: bool = False, experimental: bool = False, pk_search_mthd: int = 0, dodist: bool = True) Tuple[int, ndarray, ndarray, ndarray][source]#
Detect fiber traces across an image.
This function examines IMG_DATA(NSPAT, NSPEC) for identifiable fibre traces and creates a traces pathlist array. It returns a representation of a spatial profile slice and peak list that can be used for other analysis.
This function replaces the Fortran LOCATE_TRACES call.
- Parameters:
img_data (np.ndarray) – Image data of shape (nspat, nspec) - Horizontal Dispersion
nspec (int) – Dimensions of the image (spectral, spatial)
nspat (int) – Dimensions of the image (spectral, spatial)
max_ntraces (int) – Maximum number of traces to return
nf (int) – Number of fibers in instrument
order (int, optional) – Order of polynomial fitting (default: 4)
sparse_fibs (bool, optional) – If there is only a sparse number of fibers (default: False)
experimental (bool, optional) – If to use experimental restrictions for blurred data (default: False)
pk_search_mthd (int, optional) – Peak search method: 0=standard, 1=local peaks, 2=wavelet (default: 0)
dodist (bool, optional) – Whether to do distortion modeling (default: True)
- Returns:
ntraces (int) – Number of traces found.
tracea (np.ndarray) – Trace array of shape (nspec, max_ntraces).
rep_slice (np.ndarray) – Representation profile slice of shape (nspat,).
rep_pkpos (np.ndarray) – Representation slice peak list of shape (nspat,).
- kspecdr.tlm.make_tlm.get_fibre_separation(instrument_code: int) float[source]#
Get nominal fibre separation for instrument.
- kspecdr.tlm.make_tlm.interpolate_tramlines(tramline_map: ndarray, match_vector: ndarray, sep: float) None[source]#
Interpolate missing fibre traces.
- Parameters:
tramline_map (np.ndarray) – Tramline map array
match_vector (np.ndarray) – Vector matching fibre numbers to trace numbers
sep (float) – Nominal separation between fibres
- kspecdr.tlm.make_tlm.interpolate_tramlines_taipan(tramline_map: ndarray, match_vector: ndarray, nominal_positions: ndarray) None[source]#
Interpolate missing fibre traces for TAIPAN instrument.
- Parameters:
tramline_map (np.ndarray) – Tramline map array
match_vector (np.ndarray) – Vector matching fibre numbers to trace numbers
nominal_positions (np.ndarray) – Nominal fibre positions
- kspecdr.tlm.make_tlm.make_tlm(args: Dict[str, Any]) None[source]#
Generate a tramline map from an image file.
This function replaces the Fortran MAKE_TLM subroutine.
- Parameters:
args (dict) – Dictionary containing method arguments including: - ‘IMAGE_FILENAME’: Input image file path - ‘TLMAP_FILENAME’: Output tramline map file path (optional)
- kspecdr.tlm.make_tlm.make_tlm_from_im(im_file: ImageFile, tlm_fname: str, args: Dict[str, Any]) None[source]#
Generate tramline map from an opened image file.
This function replaces the Fortran MAKE_TLM_FROM_IM subroutine.
- kspecdr.tlm.make_tlm.make_tlm_other(im_file: ImageFile, tlm_fname: str, instrument_code: int, args: Dict[str, Any]) None[source]#
Generate tramline map for non-2DF instruments.
This function replaces the Fortran MAKE_TLM_OTHER subroutine.
- kspecdr.tlm.make_tlm.match_traces_to_fibres(instrument_code: int, traces: ndarray, fibre_types: ndarray, pk_posn: ndarray, args: Dict[str, Any]) Tuple[ndarray, ndarray][source]#
Match detected traces to fibre indices.
- kspecdr.tlm.make_tlm.predict_wavelength(im_file: ImageFile, tramline_map: ndarray, args: Dict[str, Any]) ndarray[source]#
Predict wavelength for each pixel along each fibre.
- kspecdr.tlm.make_tlm.predict_wavelength_from_dispersion(im_file: ImageFile, nspec: int, nf: int) ndarray[source]#
Predict wavelength from dispersion and central wavelength in the header.
- kspecdr.tlm.make_tlm.predict_wavelength_taipan(im_file: ImageFile, nspec: int, nf: int) ndarray[source]#
Predict wavelength for TAIPAN instrument (Fortran WLA_TAIPAN equivalent). Reads LAMBDAC and DISPERS from FITS header and computes wavelength for each pixel/fibre.
- kspecdr.tlm.make_tlm.read_instrument_data(im_file: ImageFile, instrument_code: int, args: Dict[str, Any]) Tuple[ndarray, ndarray, ndarray][source]#
Read instrument data from image file.
- kspecdr.tlm.make_tlm.set_instrument_specific_params(instrument_code: int, args: Dict[str, Any]) Tuple[int, int, bool, bool, bool, bool][source]#
Set instrument-specific parameters.
- kspecdr.tlm.make_tlm.write_tramline_data(tlm_fname: str, tramline_map: ndarray, instrument_code: int, im_file: ImageFile) None[source]#
Write tramline data to output file.
- kspecdr.tlm.make_tlm.write_wavelength_data(tlm_fname: str, wavelength_data: ndarray) None[source]#
Write wavelength data to tramline map file.
- Parameters:
tlm_fname (str) – Tramline map filename
wavelength_data (np.ndarray) – Wavelength array
Fiber matching routines for KSPEC.
This module provides functions to match detected traces to physical fibers for various instruments (TAIPAN, ISOPLANE).
- kspecdr.tlm.match_fibers.match_fibers_isoplane(nf: int, pk_posn: ndarray) Tuple[ndarray, ndarray][source]#
Simple 1-to-1 fiber matching for ISOPLANE.
Traces are assumed ordered by increasing y (trace 1 = lowest y). Fiber table row 1 corresponds to highest y, so mapping is reversed: fiber 0 is assigned the last (highest-y) trace, fiber 1 the second-to-last, etc.
- kspecdr.tlm.match_fibers.match_fibers_taipan(nf: int, fibre_types: ndarray, pk_posn: ndarray, ar_posn: ndarray, max_del: float = 4.1) Tuple[ndarray, ndarray][source]#
Match traces to fibers for TAIPAN using LAP (Linear Assignment Problem).
- Parameters:
- Returns:
(match_vector, modelled_positions) match_vector: Array of size NF, where match_vector[fib_idx] = trace_idx (1-based) modelled_positions: Array of size NF with fitted positions
- Return type: