pyird.utils package

Submodules

pyird.utils.aperture module

Class for aperture

class pyird.utils.aperture.TraceAperture(trace_function, y0, xmin, xmax, coeff, inst)

Bases: object

aperture instance for trace class

choose_aperture(fiber)

choose apertures of mmf1 (comb fiber) or mmf2 (star fiber)

Parameters:

fiber – fiber type (mmf1 or mmf2)

Returns:

updated variables (y0, xmin, xmax, coeff)

choose_even_aperture()

choose apertures for mmf2 (star fiber)

Returns:

updated variables (y0, xmin, xmax, coeff)

choose_mmf1_aperture()
choose_mmf2_aperture()
choose_odd_aperture()

choose apertures for mmf1 (comb fiber)

Returns:

updated variables (y0, xmin, xmax, coeff)

mask()

mask image

Returns:

mask image

mmf1()
mmf2()
set_single_mmf(fiber)

set mmf1 or mmf2 for single mmf

Returns:

updated variables (mmf) while not reducing the number of apertures

warn_single_mmf()

pyird.utils.class_handler module

pyird.utils.class_handler.update_attr(instance, **kwargs)

Update the attributes using kwargs

Parameters:
  • instance – Python Class

  • kwargs – keys and values to be updated

pyird.utils.datset module

Set of dat files.

class pyird.utils.datset.DatSet(dir, prefix='', extension='')

Bases: object

clean()

Clean i.e. remove files if exists.

flatpath(string=False, check=True)

get path for the normalized flat.

Returns:

path for the normalized flat

path(string=False, check=True)

get path array.

Returns:

array of paths

pyird.utils.decorators module

pyird.utils.decorators.deprecate_kwargs(renames: ~typing.Mapping[str, str], *, since: ~typing.Optional[str] = None, remove_in: ~typing.Optional[str] = None, warn_cls: ~typing.Type[Warning] = <class 'FutureWarning'>) Callable

Decorator to deprecate keyword argument names.

Parameters:
  • renames ({old_name: new_name}) – Dictionary mapping old argument names to new argument names.

  • since (str, optional) – Specify the version since when the deprecation started.

  • remove_in (str, optional) – Specify the version when the deprecated argument will be removed.

  • warn_cls (Warning subclass) – The warning class to use (default: FutureWarning).

pyird.utils.decorators.rename_kwargs(**old_to_new: str) Callable

pyird.utils.fitsset module

Set of fits files.

class pyird.utils.fitsset.FitsSet(tag, fitsdir, extension='')

Bases: object

at_list(listname='tmp')

make at list used in IRAF.

clean()

Clean i.e. remove fits files if exists.

data(indices=None)

get header and data in an array form :param indices: indices of fitsset, if None, 0 is used

Returns:

array of data

path(string=False, check=True)

get path array.

Returns:

array of paths

pyird.utils.fitsutils module

pyird.utils.fitsutils.load_fits_data_header(filen)

loads data and header from fits

Parameters:

filen (str) – filename

Returns:

data, header

pyird.utils.fitsutils.loadtermcol()
pyird.utils.fitsutils.write_fits_data_header(outpath, header, rsd)

write data to fits

Parameters:
  • outpath – path to output file

  • header – header for fits

  • rsd – image data

pyird.utils.getinfo module

get information.

pyird.utils.getinfo.get_radec(name)

Get ra and dec from name via Simbad.

Parameters:

name – object name

Returns:

ra in degree dec in degree

pyird.utils.image_widget module

class pyird.utils.image_widget.image_1Dand2D(master, order, band)

Bases: Frame

draw_canvas(fig)

set the figure on the canvas

next_botton()

place a botton on the window

quit_me()

quit and delete the window

show_emission_position(stream2D, rsd, wav, mask, pixcoord, rotim, iys_plot, iye_plot, master_path=None, hotpix_mask=None, fit=True, **kwargs)

detect emissions on the spectrum and detector image of an arbitral aperture.

Parameters:
  • Stream2D – pyird.utils.stream2D (need to have trace information)

  • rsd – Raw Spectral Detector matrix

  • wav – wavelengths matrix

  • mask – mask of trace lines

  • pixcoord – pixel coordinate of x and y direction

  • iys_plot – pixel coordinate of x and y direction

  • iye_plot – pixel coordinate of x and y direction

  • rotim – rotated image (intend to align trace orientation)

  • master_path – path to master file of the wavelength calibration

  • hotpix_mask – hotpixel mask

show_spec_to_image(rsd, wav, mask, pixcoord, rotim, iys_plot, iye_plot, master_path=None, hotpix_mask=None, **kwargs)

figures of 1d spectrum and 2d detector image

Parameters:
  • rsd – Raw Spectral Detector matrix

  • wav – wavelengths matrix

  • mask – mask of trace lines

  • pixcoord – pixel coordinate of x and y direction

  • iys_plot – pixel coordinate of x and y direction

  • iye_plot – pixel coordinate of x and y direction

  • rotim – rotated image (intend to align trace orientation)

  • master_path – path to master file of the wavelength calibration

  • hotpix_mask – hotpixel mask

title_emission_position()
title_spec_to_image()

pyird.utils.irdstream module

File stream for IRD analysis.

class pyird.utils.irdstream.Stream1D(streamid, rawdir, anadir, fitsid=None, prefix='', extension='', inst='IRD')

Bases: DatSet

Class for post-processing 1D spectra.

remove_fringe()

removing periodic noise (fringe) in REACH spectrum

specmedian(method='mean')

take spectrum mean or median.

Returns:

dataframe including median spectrum

class pyird.utils.irdstream.Stream2D(streamid, rawdir, anadir, fitsid=None, rawtag='IRDA000', inst='IRD', rotate=False, inverse=False, detector_artifact=False, band=None, not_ignore_warning=True)

Bases: FitsSet, StreamCommon

Class for processing 2D spectral images and reducing them to 1D spectra.

apext_flatfield(df_flatn, extout='_fln', extin=None, hotpix_mask=None, width=None)

aperture extraction and flat fielding (c.f., hdsis_ecf.cl)

Parameters:
  • df_flatn

  • extout – extension of output files

  • extin – extension of input files

  • hotpix_mask – hotpix masked spectrum (‘extout’ to be automatically ‘_flnhp’)

  • width – list of aperture widths ([width_start,width_end])

apnormalize(rsd=None, hotpix_mask=None, ignore_orders=None, **kwargs_continuum)

normalize 2D apertures by 1D functions

Returns:

dictionary of pandas DataFrames of extracted and normalized spectra in each pixel

aptrace(search_start_row=1000, num_aperture=42, ign_ord=[])

extract aperture of trace from a median image of current fitsset

Parameters:
  • search_start_row – starting row number to search apertures

  • num_aperture – number of apertures, num_aperture = 42 ## 42 for H band, 102 for YJ band

Returns:

TraceAperture instance

calibrate_wavelength(trace_path=None, channelfile_path=None, ign_ord=[], maxiter=30, std_threshold=0.001, npix=2048, width=None, force_rotate=False)

wavelength calibration usgin Th-Ar.

Parameters:
  • trace_path – path to the trace file

  • channelfile_path – path to the channel file

  • ign_ord – orders to be ignored

  • maxiter – maximum number of iterations

  • std_threshold – When the std of fitting residuals reaches this value, the iteration is terminated.

  • npix – number of pixels

  • width – list of aperture widths ([width_start,width_end])

  • force_rotate – forces rotating the detector, when the number of the order is not standard values (i.e. 21 or 51)

clean_pattern(trace_mask=None, hotpix_mask=None, extout='_cp', extin=None)
Parameters:
  • trace_mask – trace mask (from iraf, use image.mask.trace_from_iraf_trace_file)

  • hotpix_mask – hot pixel mask

  • extout – output extension

  • extin – input extension

detector_handling(img, mode='load')

apply rotation and/or inverse to image

Parameters:
  • img – image data

  • mode – load or write

Returns:

rotated and/or inversed image

dispcor(extin='_fl', prefix='w', master_path=None, blaze=True)

dispersion correct and resample spectra

Parameters:
  • extin – extension of input files

  • prefix – prefix for output files

  • master_path – path to the directory containing the master ThAr file

  • blaze – set True for blaze function

extract_trace_info(trace_path=None)

extract parameters for trace

Parameters:

trace_path – path to trace file

Returns:

data and parameters for aperture trace

flatten(trace_path=None, extout='_fl', extin=None, hotpix_mask=None, width=None, check=False, master_path=None)
Parameters:
  • trace_path – trace file to be used in flatten

  • extout – output extension

  • extin – input extension

  • hotpix_mask – hotpix masked spectrum (‘extout’ to be automatically ‘_hp’)

  • width – list of aperture widths ([width_start,width_end])

  • check – if True, return the extracted spectrum

  • master_path – if this set the path to wavelength reference file with check=True, return wavelength allocated spectrum

immedian(extension=None)

take image median.

Returns:

median image

init_band_IRD(rawtag, band)

initialize band for IRD/REACH data

Parameters:
  • rawtag – prefix of file name, such as “IRDA000”, “IRDAD000”, or “IRDBD000

  • band – band of the data, “y” or “h”, requires fitsid

load_fitsset()

Load fitsset and make imcube.

Returns:

imcube

normalize1D(flatid='blaze', master_path=None, readout_noise_mode='default', skipLFC=None, **kwargs_normalize)

combine orders and normalize spectrum

Parameters:
  • flatid – streamid for flat data

  • master_path – path to the directory containing the calibrated flat file

  • readout_noise_mode – ‘real’ or ‘default’. ‘real’ calculates the readout noise based on the observed LFC spectrum.

Note

If readout_noise_mode=’real’, mmf1 data for Y/J band should be reduced at first.

write_df_spec_wav(spec_m2, reference, save_path)

write spectrum and wavelengths to pandas.DataFrame format

Parameters:
  • spec_m2 – spectrum not yet allocated wavelength

  • reference – wavelength reference

  • save_path – path to .csv file

class pyird.utils.irdstream.StreamCommon(streamid, rawdir, anadir, inst)

Bases: object

Common Stream class for 1D and 2D.

streamid

ID for stream

rawdir

directory where the raw data are

anadir

directory in which the processed file will put

fitsid

fitsid list, such as [10301,10303]

rawtag

prefix of file name, such as “IRDA000”, “IRDAD000”, or “IRDBD000”

rotate

If True, the image is rotated in 90 deg (for old detector). See #80 in GitHub

Type:

boolen

inverse

If True, the image is inversed along y axis. See #80 in GitHub

Type:

boolen

detector_artifact

If True, fill the gaps seen in the old detector. See #80 in GitHub

Type:

boolen

band

band of the data, “y” or “h”

imcomb

If True, the median combine is applied to the data

tocvsargs

arguments for to_csv

info

If True, print the information

inst

instrument name, “IRD” or “REACH”

fitsid_already_increment

If True, the fitsid is already incremented

check_existence(extin, extout)

check files do not exist or not.

Parameters:
  • extin – extension of input files

  • extout – extension of output files

Returns:

input file name w/ no exist output file name w/ no exist

extclean(extension)

Clean i.e. remove fits files if exists.

Parameters:

extension – extension of which files to be removed

extpath(extension, string=False, check=True)

path to file with extension.

Parameters:

extension – extension

Returns:

path array of fits files w/ extension

property fitsid
fitsid_decrement()

Decrease fits id -1.

fitsid_increment()

Increase fits id +1. Only one time increment is allowed.

print_if_info_is_true(msg)
remove_bias(rot=None)

set extension when loading an image whose bias is removed by IRD_bias_sub.py

pyird.utils.large_scaled module

pyird.utils.maskcheck module

pyird.utils.maskcheck.plotmask(maskfits, obj, vmin=None, vmax=None)

pyird.utils.remove_fringe module

pyird.utils.remove_fringe.ls_periodogram(wav, flux, search=None)

Lomb-Scargle periodogram

Parameters:
  • wav – wavelength [nm]

  • flux – flux

  • search – if True, the output includes the frequencies corresponding to the three strongest peaks

Returns:

results of periodogram

pyird.utils.remove_fringe.mk_model(ls, freqs, x_fit)

make a sinusoidal model with given frequencies

Parameters:
  • ls – astropy LombScargle class

  • freqs – friquencies

  • x_fit – x array for fitting

Returns:

model and offset

pyird.utils.remove_fringe.remove_fringe_order(df_flat, df_target, order, mask=True)

remove periodic noise for one order

Parameters:
  • df_flat – DataFrame of flat (normalized flat)

  • df_target – DataFrame of target (normalized flux)

  • order – use order

  • mask – if True, mask outliers in a flat spectrum

Returns:

fringe removed spectrum

Module contents