Skip to content

Commit

Permalink
modified absorberutils.py for numba typing error
Browse files Browse the repository at this point in the history
  • Loading branch information
abhi0395 committed Aug 1, 2024
1 parent 36ab875 commit 8b65c42
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
42 changes: 26 additions & 16 deletions qsoabsfind/absorberutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,40 +85,50 @@ def estimate_snr_for_lines(l1, l2, lam_rest, residual, error, log):

return mean_sn1, mean_sn2

@jit(nopython=False)
@jit(nopython=True)
def group_contiguous_pixel(data, resi, avg):
"""
Arrange data into groups where successive elements differ by less than a
given average difference.
Arrange data into groups where successive elements differ by less than the average difference.
Args:
data (numpy.ndarray): Array of absorber values for each spectrum.
resi (numpy.ndarray): Corresponding residual values.
avg (float): Average difference threshold for grouping contiguous pixels.
data (np.ndarray): List of absorbers for each spectrum.
resi (np.ndarray): Corresponding residual.
avg (float): Maximum allowed difference to group data.
Returns:
tuple: A tuple containing:
- list of grouped data
- list of grouped residuals
tuple: Final list with contiguous pixels grouped, and corresponding residuals if provided.
"""
# Check if resi is provided as an array
if resi is not None:
has_residuals = True
else:
has_residuals = False

# Sort the input data
ind_srt = np.argsort(data)
sorted_data = data[ind_srt]
sorted_resi = resi[ind_srt] if isinstance(resi, np.ndarray) else None

groups = [[sorted_data[0]]]
resi_groups = [[sorted_resi[0]]] if sorted_resi is not None else None
if has_residuals:
sorted_resi = resi[ind_srt]

groups = []
resi_groups = []

groups.append([sorted_data[0]])
if has_residuals:
resi_groups.append([sorted_resi[0]])

for i in range(1, len(sorted_data)):
if sorted_data[i] - groups[-1][-1] < avg:
groups[-1].append(sorted_data[i])
if resi_groups is not None:
if has_residuals:
resi_groups[-1].append(sorted_resi[i])
else:
groups.append([sorted_data[i]])
if resi_groups is not None:
if has_residuals:
resi_groups.append([sorted_resi[i]])

if resi_groups is not None:
if has_residuals:
return groups, resi_groups
else:
return groups
Expand Down Expand Up @@ -407,7 +417,7 @@ def redshift_estimate(fitted_obs_l1, fitted_obs_l2, std_fitted_obs_l1, std_fitte
z2 = (fitted_obs_l2 / line2) - 1

err1 = (std_fitted_obs_l1 / line1)
err2 = (std_fitted_obs_l2 / line2)
err2 = (std_fitted_obs_l2 / line2)

z_corr = 0.5 * (z1 + z2) # New redshifts computed using line centers of the first and second Gaussian
z_err = np.sqrt(0.25 * (err1**2 + err2**2))
Expand Down
1 change: 0 additions & 1 deletion qsoabsfind/parallel_convolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import re
import os
import pkg_resources
import qsoabsfind

# Ensure config is imported first to set up the environment
import qsoabsfind.config as config
Expand Down

0 comments on commit 8b65c42

Please sign in to comment.