pyird.image package
Submodules
pyird.image.aptrace module
- pyird.image.aptrace.aptrace(dat, search_start_row, num_aperture, ign_ord=[], plot=True)
trace apertures by a polynomial function.
- Parameters:
dat – flat data
search_start_row – starting row number to search apertures
num_aperture – number of total apertures to be traced
ign_ord – orders to be ignored, using when num_aperture is set to a non-default value
plot – show figure of traced apertures
- Returns:
parameters of a polynomial to trace apertures
Note
the apertures begin its search at
search_row, which is the row number of the detector (wavelength direction), and continue in the direction of increasing numbers until it matches the appropriate number of apertures. You may as well change the value ofsearch_rowif the aperture trace is failed.
- pyird.image.aptrace.cross_section(dat, nrow, num_aperture)
extract cross section in row direction and search peaks.
- Parameters:
dat – flat data
nrow – row number to be extracted
num_aperture – 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, search_start_row, num_aperture, ign_ord=[], plot=True)
search aperture
- Parameters:
dat – flat data
search_start_row – starting row number to search apertures
num_aperture – number of total apertures to be traced
ign_ord – orders to be ignored
plot – show figure of selected apertures
- Returns:
peak position in the cross section at search_row
- pyird.image.aptrace.trace_pix(dat, search_row, peakind, npix=2048)
trace apertures
- Parameters:
dat – flat data of an order
search_row – row number used to set aperture
peakind – aperture (peak position) in the cross section at search_row
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
Notes
See also issue #121 for a comparison among identify_hotpix, identify_hotpix_sigclip, and another method.
- 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
Notes
See also issue #121 for a comparison among identify_hotpix, identify_hotpix_sigclip, and another method.
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)
Calculate the non-common trend model using Gaussian Process.
- Parameters:
nctrend_im (ndarray) – Input image for calculating non-common trend.
margin_npixel (int) – Margin pixels to be excluded.
Ncor (int) – Coarsening factor.
sigma (float) – Sigma parameter for GP.
xscale (int) – Scale factor for X-axis.
yscale (int) – Scale factor for Y-axis.
cube (bool) – If True, coarsen with cube structure.
- Returns:
Non-common trend model.
- Return type:
nctrend_model (ndarray)
- 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.pattern_model.median_profile_xy(cal_eotensor_filtered, channel_median_offset, channel_axis=1)
Calculate the median profile of all even/odd channels while preserving the characteristics of each pixel.
- Parameters:
cal_eotensor_filtered – numpy array, input tensor.
channel_median_offset – numpy array, offset to subtract from each channel.
channel_axis – int, axis representing the channels (default is 1).
- Returns:
numpy array, input tensor with channel median offset subtracted. xyprofile_offset_subtracted_model: numpy array, median profile model preserving pixel profiles.
- Return type:
offset_subtracted
- pyird.image.pattern_model.pad_nans_with_xy_median(offset_subtracted, channel_median_offset, image_pattern_model_eotensor, channel_axis=1, x_axis=2, y_axis=3)
Pad NaN values in the input tensor with the median profile calculated from x and y axes.
- Parameters:
offset_subtracted – numpy array, input tensor with subtracted offset.
channel_median_offset – numpy array, offset to add back to the channels.
image_pattern_model_eotensor – numpy array, tensor with NaNs to be filled.
channel_axis – int, axis representing the channels (default is 1).
x_axis – int, axis representing the x-axis (default is 2).
y_axis – int, axis representing the y-axis (default is 3).
- Returns:
numpy array, tensor with NaNs filled.
- Return type:
image_pattern_model_eotensor
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