API Documentation
Subpackages
Submodules
pykoala.ancillary module
Utility functions.
Many of them are partially implemented. They were in the old, non-modular version of PyKOALA and have not been included in the current modular scheme.
- pykoala.ancillary.centre_of_mass(w, x, y)[source]
Compute the centre of mass of a given image. :param w: (n,) weights computing the centre of mass. :type w: np.ndarray(float) :param x: (n,) Coordinates corresponding to the x-axis (columns). :type x: np.ndarray(float) :param y: (n,) Coordinates corresponding to the y-axis (rows). :type y: np.ndarray(float)
- Returns
x_com (float)
y_com (float)
- pykoala.ancillary.cumulative_1d_moffat(r2, l_star, alpha2, beta)[source]
Cumulative Moffat ligth profile.
- Parameters
- Returns
cum_moffat_prof – Cumulative Moffat profile
- Return type
np.array(float)
- pykoala.ancillary.cumulative_1d_moffat_sky(r2, l_star, alpha2, beta, sky_brightness)[source]
Combined model of cumulative_1d_moffat and cumulative_1d_sky.
- pykoala.ancillary.cumulative_1d_sky(r2, sky_brightness)[source]
1D cumulative sky brightness. F_sky = 4*pi*r2 * B_sky
- pykoala.ancillary.detect_edge(rss)[source]
Detect the edges of a RSS. Returns the minimum and maximum wavelength that determine the maximum interval with valid (i.e. no masked) data in all the spaxels.
- Parameters
rss (RSS object.) –
- Returns
min_w (float) – The lowest value (in units of the RSS wavelength) with valid data in all spaxels.
min_index (int) – Index of min_w in the RSS wavelength variable.
max_w (float) – The higher value (in units of the RSS wavelength) with valid data in all spaxels.
max_index (int) – Index of max_w in the RSS wavelength variable.
- pykoala.ancillary.fit_moffat(r2_growth_curve, f_growth_curve, f_guess, r2_half_light, r_max, plot=False)[source]
Fits a Moffat profile to a flux growth curve as a function of radius squared, cutting at to r_max (in units of the half-light radius), provided an initial guess of the total flux and half-light radius squared.
# TODO :param r2_growth_curve: DESCRIPTION. :type r2_growth_curve: TYPE :param F_growth_curve: DESCRIPTION. :type F_growth_curve: TYPE :param F_guess: DESCRIPTION. :type F_guess: TYPE :param r2_half_light: DESCRIPTION. :type r2_half_light: TYPE :param r_max: DESCRIPTION. :type r_max: TYPE :param plot: If True generates and shows the plots. The default is False. :type plot: Boolean, optional
- Returns
fit – DESCRIPTION.
- Return type
TYPE
- pykoala.ancillary.flux_conserving_interpolation(new_wavelength, wavelength, spectra, **interp_args)[source]
Flux-conserving linear interpolation.
Linear interpolation of a spectrum \(I_\lambda(\labmda)\) as a function of wavelength \(\lambda\), ensuring that the integrated flux math:: F(lambda_a, lambda_b) = int_{lambda_a}^{lambda_b} I_lambda(labmda) dlambda$
is conserved for any \((\lambda_a, \lambda_b)\).
np.nan values become zero.
- Parameters
new_wavelength (ndarray) – New values of the x coordinate (wavelength) \(\lambda_{new}\).
wavelength (ndarray) – Old values of the x coordinate (wavelength) \(\lambda\).
spectra (ndarray) – Old values of the y coordinate (spectrum) \(I_\lambda(\labmda)\).
**interp_args (dict, optional) – Additional parameters to be passed to np.interp
- Returns
Interpolated spectra \(I_\lambda(\labmda_{new})\).
- Return type
ndarray
Notes
The function computes the cumulative flux with np.nancumsum, calls np.interp, and differentiates back.
- pykoala.ancillary.growth_curve_2d(image, x0=None, y0=None)[source]
Compute the curve of growth of an array f with respect to a given point (x0, y0).
- Parameters
- Returns
r2 (np.ndarray) – Vector containing the square radius with respect to (x0, y0).
growth_curve (np.ndarray) – Curve of growth centered at (x0, y0).
- pykoala.ancillary.in_rectangle(pos, rectangle_pos)[source]
Check if a point lies in the perimeter of a rectangle.
- pykoala.ancillary.interpolate_image_nonfinite(image)[source]
Use scipy.interpolate.NearestNDInterpolator to replace NaN values.
- Parameters
image (-) – 2D array to be interpolated
Returnrs –
-------- –
interpolated_image (-) –
- pykoala.ancillary.mask_lines(wave_array, width=30, lines=dict_values([3970.1, 4101.7, 4340.4, 4861.3, 6562.79, 3934.777, 3969.588, 5176.7, 5895.6, 8500.36, 8544.44, 8664.52]))[source]
- pykoala.ancillary.pixel_in_circle(pixel_pos, pixel_size, circle_pos, circle_radius)[source]
Compute the area of a pixel within a circle.
- Parameters
pixel_pos (-) – Position of the lower left corner of the pixel
pixel_size (-) – Size of the pixel.
circle_pos (-) – Position of the circle centre
circle_raidus (-) – Radius of the circle.
- Returns
- area_pixel – Area of the pixel contained within the circle
- area_fraction – Fration of the circle area that overlaps with the pixel.
- pykoala.ancillary.running_mean(x, n_window)[source]
This function calculates the running mean of an array.
- Parameters
x ((n,) np.ndarray) – This is the given array.
n_window (Int) – Number of neighbours for computing the running mean.
- Returns
running_mean_x – Running mean array.
- Return type
(n - n_window,) np.ndarray
- pykoala.ancillary.smooth_spectrum(wlm, s, wave_min=0, wave_max=0, step=50, exclude_wlm=[[0, 0]], order=7, weight_fit_median=0.5, plot=False, verbose=False, fig_size=12)[source]
THIS IS NOT EXACTLY THE SAME THING THAT applying signal.medfilter()
This needs to be checked, updated, and combine (if needed) with task fit_smooth_spectrum. The task gets the median value in steps of “step”, gets an interpolated spectrum, and fits a 7-order polynomy.
It returns fit_median + fit_median_interpolated (each multiplied by their weights).
Tasks that use this: get_telluric_correction
- pykoala.ancillary.update_wcs_coords(wcs, ra_dec_val=None, ra_dec_offset=None)[source]
Update the celestial reference values of a WCS.
Update the celestial coordinates of a WCS using new central values of RA and DEC or relative offsets expressed in degree.
- Parameters
wcs (-) – Target WCS to update.
ra_dec_val (-) – New CRVAL of RA and DEC.
ra_dec_offset (-) – Relative offset that will be applyied to CRVAL of RA and DEC axis. If ra_dec_val is privided, this will be ignored.
- Returns
- correct_wcs – A copy of the original WCS with the reference values updated.
- Return type
astropy.wcs.WCS