pyird.image package

Submodules

pyird.image.aptrace module

pyird.image.aptrace.aptrace(dat, cutrow, nap, plot=True)

trace apertures by a polynomial function.

Parameters:
  • dat – flat data

  • cutrow – row number used to set aperture

  • nap – number of total apertures to be traced

  • plot – show figure of traced apertures

Returns:

parameters of a polynomial to trace apertures

pyird.image.aptrace.cross_section(dat, nrow, nap)

extract cross section in row direction and search peaks.

Parameters:
  • dat – flat data

  • nrow – row number to be extracted

  • nap – number of total apertures to be traced

Returns:

masked data and peaks at the cross section

pyird.image.aptrace.errfunc(coeff, x, y0, data)

calculate error function.

Parameters:
  • coeff – coefficients

  • x – x-array

  • y0 – y-offset

  • data – traced pixel data to be fitted

Returns:

residuals of data and fitting model

pyird.image.aptrace.fit_ord(x, y0, data)

optimize the fitting by using least-square method.

Parameters:
  • x – x-array

  • y0 – y-offset

  • data – traced pixel data to be fitted

Returns:

best fit parameters

pyird.image.aptrace.fitfunc(x, y0, coeff)

Legendre function to trace.

Parameters:
  • x – x-array

  • y0 – y-offset

  • coeff – Legendre polynomial coefficients

Returns:

Legendre function

pyird.image.aptrace.set_aperture(dat, cutrow, nap, plot=True)

search aperture

Parameters:
  • dat – flat data

  • cutrow – row number used to set aperture

  • nap – number of total apertures to be traced

  • plot – show figure of selected apertures

Returns:

peak position in the cross section at cutrow

pyird.image.aptrace.trace_pix(dat, cutrow, peakind, npix=2048)

trace apertures

Parameters:
  • dat – flat data of an order

  • cutrow – row number used to set aperture

  • peakind – aperture (peak position) in the cross section at cutrow

  • npix – number of pixels

Returns:

traced pixel data

pyird.image.bias module

Bias subtraction.

  • originally developed by M. Kuzuhara

pyird.image.bias.bias_subtract(channel_cube)

Bias subtraction for channel cube.

Parameters:

channel_cube – channel cube

Returns:

unbiased channel cube bias for channels

Example

>>> #this is equivalent to image_rmbias=bias_subtract_image(im)
>>> channel_cube=image_to_channel_cube(im)
>>> bias_subtracted_channel_cube, channel_bias=bias_subtract(channel_cube)
>>> image_rmbias=channel_cube_to_image(bias_subtracted_channel_cube)
pyird.image.bias.bias_subtract_image(im)

Bias subtraction for image.

Parameters:

im – image

Returns:

bias-subtracted image

Examples

>>> image_rmbias=bias_subtract_image(im)

pyird.image.channel module

pyird.image.channel.bias_region(channel_cube, margin=4)
pyird.image.channel.channel_cube_to_image(channel_cube, revert=True)

conversion of a channel cube to an image.

Parameters:
  • channel_cube – channel_cube

  • revert – if True reverting odd channels

Returns:

2D image

Return type:

image

pyird.image.channel.eopixel_combine(eop)

inverse operation of eopixel_split.

Parameters:

tensor (eo)

Returns:

channel cube

pyird.image.channel.eopixel_split(channel_cube)

Revert y direction of odd channels.

Parameters:

cube (channel)

Returns:

eo tensor (2 [e/o] x Nchannel x xsize x ysize)

pyird.image.channel.image_to_channel_cube(image, revert=True, Nch=32)

conversion of an image to a channel cube :param image: 2D image :param revert: if True reverting odd channels :param Nch: Number of the channels of a detector. For IRD Nch=32

Returns:

channel cube (Nch, ch_pix_num, 2048)

pyird.image.channel.revert_channel_cube(channel_cube)

Revert y direction of odd channels.

Parameters:

cube (channel)

Returns:

channel cube (odd channel revereted)

pyird.image.hotpix module

pyird.image.hotpix.apply_hotpixel_mask(hotpix_mask, rsd, y0, xmin, xmax, coeff, save_path=None)

correct hotpixel.

Parameters:
  • hotpix_mask – mask made from dark

  • rsd – extracted spectrum to be masked

  • y0 – trace infomation

  • xmin – trace infomation

  • xmax – trace infomation

  • coeff – trace infomation

Returns:

masked and interpolated spectrum

pyird.image.hotpix.hotpix_fits_to_dat(fitsfile, save_path)

Convert .fits to .dat so that it can be used in the RV pipeline.

Parameters:
  • fitsfile – .fits file of hot pixel mask

  • save_path – save path for .dat file

Returns:

hot pixel mask in .dat file {pixels, orders, intensity}

pyird.image.hotpix.identify_hotpix(im, threshold=10.0)

Identification of hotpixels using sep.

Parameters:
  • im – image

  • threshold – threshold of sep

Returns:

hot pixel mask obj: sep object

Return type:

hotpix_mask

pyird.image.hotpix.identify_hotpix_sigclip(im, sigma=4, maxiters=5, frac=0.005)

Identification of hotpixels using sigma clip.

Parameters:
  • im – image

  • sigma – maximum value of sigma exploration range

  • maxiters – maximum value of iterations

  • frac – mask percentage target value (empirically 0.5%)

Returns:

hot pixel mask

Return type:

hotpix_mask

pyird.image.mask module

pyird.image.mask.trace(trace_func, y0, xmin, xmax, coeff, mask_shape=None, inst='IRD', width=None)

make mask for trace parameters for multiorder.

Parameters:
  • trace_func – trace function

  • x – x-array

  • y0 – y-offset

  • xmin – xmin

  • xmax – xmax

  • coeff – coefficients

  • mask_shape – (optional) shape of mask, c.f. np.shape(image)

  • inst – IRD or REACH

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

Returns:

mask image (same shape as im)

Examples

>>> from pyird.image.trace_function import trace_legendre
>>> mask=trace(im, trace_legendre, y0, xmin, xmax, coeff)
pyird.image.mask.trace_from_iraf_trace_file(pathlist, mask_shape=None)

make mask from the iraf trace file.

Parameters:
  • pathlist – trace files path list

  • mask_shape – (optional) shape of mask, c.f. np.shape(image)

Returns:

mask image (same shape as im)

Note

Currently, Only legendre is supported.

pyird.image.oned_extract module

pyird.image.oned_extract.flatten(im, trace_func, y0, xmin, xmax, coeff, inst='IRD', onepix=False, npix=2048, width=None, force_rotate=False)

make mask for trace parameters for multiorder.

Parameters:
  • im – image

  • trace_func – trace function

  • x – x-array

  • y0 – y-offset

  • xmin – xmin

  • xmax – xmax

  • coeff – coefficients

  • inst – instrument (IRD or REACH)

  • onepix – extract the spectrum pixel by pixel in an aperture

  • npix – number of pixels

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

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

Returns:

raw multiorder spectra and multiorder pixel coordinate if onepix is True, return pandas DataFrame of spectra in each pixel

pyird.image.oned_extract.sum_weighted_apertures(im, df_flatn, y0, xmin, xmax, coeff, width, inst)

taking waighted sum of the counts in aperture pixels (refer to hdsis_ecf for HDS/Subaru data)

Parameters:
  • im – image

  • df_flatn – apnormalized flat spectrum

  • y0 – y-offset

  • xmin – xmin

  • xmax – xmax

  • coeff – coefficients

  • inst – instrument (IRD or REACH)

  • onepix – extract the spectrum pixel by pixel in an aperture

  • npix – number of pixels

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

Returns:

1D spectrum

pyird.image.operator module

image operator for imcube.

  • imcube has a shape of [N x Ny x Nx], where N is the number of images.

pyird.image.operator.imcombine(imcube, mode='median')

combine images to a image.

Parameters:
  • imcube – imcube

  • mode – median or mean

Returns:

image

pyird.image.pattern_model module

pyird.image.pattern_model.cal_nct(nctrend_im, margin_npixel=4, Ncor=64, sigma=0.1, xscale=32, yscale=64, cube=False)
pyird.image.pattern_model.median_XY_profile(calim0, rm_nct=True, margin_npixel=4)

a simple readout pattern model. (revised by Y.K., May 2023)

Note:

This function assumes model = cmosub_med X-Y + cmo, where cmos_med=cmo-subtracted median and cmo=channel median offset. When rm_cnt=True option corrects non-common trends of channels using a 2D GP. See #10 (https://github.com/prvjapan/pyird/issues/10).

Args:

calim0: masked image for read pattern calibration rm_nct: remove non-common trends of channel using a GP margin_npixel: # of pixels for detector margin

Returns:

model pattern image

pyird.image.trace_function module

pyird.image.trace_function.trace_legendre(x, y0, xmin, xmax, coeff)

trace Legendre function.

Parameters:
  • x – x-array

  • y0 – y-offset

  • xmin – xmin

  • xmax – xmax

  • coeff – Legendre polynomial coefficients

Module contents