Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data binning #139

Open
phajy opened this issue Nov 6, 2024 · 0 comments
Open

Data binning #139

phajy opened this issue Nov 6, 2024 · 0 comments

Comments

@phajy
Copy link
Contributor

phajy commented Nov 6, 2024

We can add new grouping methods such as minimum signal-to-noise ratio.

Multiple datasets could be grouped in the same way so they can be summed for fitting or plotting purposes. In addition provide a method to copying the binning from a template spectrum.

Some existing relevant functions include the following.

function regroup!(dataset::SpectralData, grouping; safety_copy = false)
grp::typeof(grouping) = if safety_copy
copy(grouping)
else
grouping
end
itt = GroupingIterator(grp)
for i in itt
dataset.energy_low[i[1]] = dataset.energy_low[i[2]]
dataset.energy_high[i[1]] = dataset.energy_high[i[3]]
end
if has_background(dataset)
regroup!(dataset.background, grp)
end
regroup!(dataset.response, grp)
regroup!(dataset.spectrum, grp)
resize!(dataset.data_mask, length(itt))
resize!(dataset.energy_low, length(itt))
resize!(dataset.energy_high, length(itt))
# set everything to unmasked
dataset.data_mask .= 1
dataset
end
function regroup!(dataset::SpectralData; min_counts = nothing)
if !isnothing(min_counts)
group_min_counts!(dataset.spectrum, min_counts)
end
regroup!(dataset, dataset.spectrum.grouping)
end

function group_min_counts!(spectrum::Spectrum, min_counts::Int)
NEW_GRP = 1
CONTINUE_GRP = 0
function _counts(x)
if spectrum.units == u"counts"
convert(Int, x)
elseif spectrum.units == u"counts / s"
convert(Int, x * spectrum.exposure_time)
end
end
sum::Int = 0
for (i, f) in enumerate(spectrum.data)
c = _counts(f)
sum += c
if sum >= min_counts
spectrum.grouping[i] = NEW_GRP
sum = 0
else
spectrum.grouping[i] = CONTINUE_GRP
end
end
end

And the file grouping.jl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant