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

Moved where zeros are filtered to next to where this is needed (when applying nested sampling) #127

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions hogben/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ def nested_sampling(self,
model.bkg = background_level
model.dq = 2
data = SimulateReflectivity(model, angle_times).simulate()
# filter zeros as nested sampling doesn't deal with these well
data = data[:, (data[1] != 0)]

dataset = refnx.dataset.ReflectDataset(
[data[0], data[1], data[2]]
Expand Down
2 changes: 2 additions & 0 deletions hogben/models/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ def nested_sampling(self,
for structure in self.structures:
model = refnx.reflect.ReflectModel(structure)
data = SimulateReflectivity(model, angle_times).simulate()
# filter zeros as nested sampling doesn't deal with these well
data = data[:, (data[1] != 0)]
objective = Objective(model, data)
objectives.append(objective)
global_objective = GlobalObjective(objectives)
Expand Down
3 changes: 0 additions & 3 deletions hogben/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ def simulate(self, polarised: bool = False) -> \
self._run_experiment(*condition, polarised) for condition in self.angle_times
])

# filter zeros
simulation = simulation[:, (simulation[1] != 0)]

# order by q
simulation = simulation[:, np.argsort(simulation[0])]

Expand Down
19 changes: 19 additions & 0 deletions hogben/tests/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,25 @@ def test_incident_flux_data(self):

sim_not_in_pol._incident_flux_data(polarised=True)

def test_number_of_points(self, refnx_model):
"""
Tests that the number of points generated in the
simulation is what we define (even when many are zero)
"""
NPOINTS = 100
angle_times = [(0.3, NPOINTS, 10000)]
sim = SimulateReflectivity(refnx_model,
angle_times=angle_times).simulate()
assert len(sim[0]) == NPOINTS
angle_times = [(0.3, NPOINTS, 5)]
sim = SimulateReflectivity(refnx_model,
angle_times=angle_times).simulate()
assert len(sim[0]) == NPOINTS
angle_times = [(0.3, NPOINTS, 5), (2.0, NPOINTS, 50)]
sim = SimulateReflectivity(refnx_model,
angle_times=angle_times).simulate()
assert len(sim[0]) == NPOINTS * 2

def test_reflectivity(self, refnx_model):
"""
Checks that a refnx model reflectivity generated through
Expand Down
Loading