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_mmf1_aperture()

choose apertures for mmf1 (comb fiber)

Returns:

updated variables (y0, xmin, xmax, coeff)

choose_mmf2_aperture()

choose apertures for mmf2 (star fiber)

Returns:

updated variables (y0, xmin, xmax, coeff)

mask()

mask image

Returns:

mask image

mmf1()
mmf2()
warn_single_mmf()

pyird.utils.class_handler module

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.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.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

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.

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)

Bases: FitsSet

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(cutrow=1000, nap=42)

extract aperture of trace from a median image of current fitsset

Parameters:
  • cutrow – cutting criterion

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

Returns:

TraceAperture instance

calibrate_wavelength(trace_path=None, 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

  • 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)

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

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

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 – master file for the wavelength calibrated ThAr file

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

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

extract_trace_info(trace_path=None)

extract parameters for trace

Parameters:

trace_path – path to trace file

Returns:

data and parameters for aperture trace

property fitsid
fitsid_decrement()

Decrease fits id +1.

fitsid_increment()

Increase fits id +1.

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

load_fits_data_header(filen)

loads data and header from fits

Parameters:

filen (str) – filename

Returns:

data, header

load_fitsset()

Load fitsset and make imcube.

Returns:

imcube

load_image(filen)

loads a fits image, if self.rotate=True, the image is rotated in 90 deg, self.inverse=True, the image is inversed along the 0-th-axis

Parameters:

filen (str) – filename

Returns:

image, header

load_rsd(filen)

loads Raw Spectral Detector matrix (RSD matrix)

Parameters:

filen (str) – filename

Returns:

rsd, header

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.

print_if_info_is_true(msg)
remove_bias(rot=None)
update_attr(instance, **kwargs)

Update the attributes using kwargs

Parameters:
  • instance – Python Class

  • kwargs – keys and values to be updated

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

write_fits_data_header(extout_noexist, header, rsd)
write_image(extout_noexist, header, img)

write an image to fits format, self.inverse=True, the image is inversed along the 0-th-axis, if self.rotate=True, the image is rotated in - 90 deg,

Parameters:
  • extout_noexist (_type_) – _description_

  • header (_type_) – _description_

  • img (_type_) – _description_

write_rsd(extout_noexist, header, rsd)

write Raw Spectral Detector matrix (RSD matrix) to fits format

Parameters:
  • extout_noexist (_type_) – _description_

  • header (_type_) – _description_

  • rsd (_type_) – _description_

pyird.utils.large_scaled module

pyird.utils.maskcheck module

pyird.utils.maskcheck.plotmask(maskfits, obj, vmin=None, vmax=None)
Parameters:
  • maskfits – fitsset of mask

  • obj – fitsset of target/flat

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