Skip to content

Commit

Permalink
clean up before merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Morris committed Jul 30, 2024
1 parent 6adc90e commit 98c008d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 47 deletions.
6 changes: 2 additions & 4 deletions src/blop/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(
dofs: Sequence[DOF],
objectives: Sequence[Objective],
db: Broker = None,
detectors: Sequence[Signal] = [],
detectors: Sequence[Signal] = None,
acquistion_plan=default_acquisition_plan,
digestion: Callable = default_digestion_function,
digestion_kwargs: dict = {},
Expand Down Expand Up @@ -128,7 +128,7 @@ def __init__(

self.dofs = DOFList(list(np.atleast_1d(dofs)))
self.objectives = ObjectiveList(list(np.atleast_1d(objectives)))
self.detectors = list(np.atleast_1d(detectors))
self.detectors = list(np.atleast_1d(detectors or []))

_validate_dofs_and_objs(self.dofs, self.objectives)

Expand Down Expand Up @@ -838,8 +838,6 @@ def _set_hypers(self, hypers):
self.validity_constraint.load_state_dict(hypers["validity_constraint"])

def constraint(self, x):
# x = self.dofs(active=True).transform(x)

p = torch.ones(x.shape[:-1])
for obj in self.objectives(active=True):
# if the targeting constraint is non-trivial
Expand Down
42 changes: 1 addition & 41 deletions src/blop/digestion/__init__.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,6 @@
import numpy as np
import pandas as pd
import scipy as sp


def get_beam_stats(image, threshold=0.5):
ny, nx = image.shape

fim = image.copy()
fim -= np.median(fim, axis=0)
fim -= np.median(fim, axis=1)[:, None]

fim = sp.ndimage.median_filter(fim, size=3)
fim = sp.ndimage.gaussian_filter(fim, sigma=1)

m = fim > threshold * fim.max()
area = m.sum()

cs_x = np.cumsum(m.sum(axis=0)) / area
cs_y = np.cumsum(m.sum(axis=1)) / area

q_min, q_max = [0.15865, 0.84135] # one sigma
q_min, q_max = [0.05, 0.95] # 90%

x_min, x_max = np.interp([q_min, q_max], cs_x, np.arange(nx))
y_min, y_max = np.interp([q_min, q_max], cs_y, np.arange(ny))

stats = {
"max": fim.max(),
"sum": fim.sum(),
"area": area,
"cen_x": (x_min + x_max) / 2,
"cen_y": (y_min + y_max) / 2,
"wid_x": x_max - x_min,
"wid_y": y_max - y_min,
"x_min": x_min,
"x_max": x_max,
"y_min": y_min,
"y_max": y_max,
"bbox": [[x_min, x_max, x_max, x_min, x_min], [y_min, y_min, y_max, y_max, y_min]],
}

return stats
from ..utils import get_beam_stats


def default_digestion_function(df: pd.DataFrame) -> pd.DataFrame:
Expand Down
3 changes: 1 addition & 2 deletions src/blop/sim/beamline.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ def unstage(self):
def collect_asset_docs(self):
items = list(self._asset_docs_cache)
self._asset_docs_cache.clear()
for item in items:
yield item
yield from items

def generate_beam(self, noise: bool = True):
nx, ny = self.image_shape.get()
Expand Down
4 changes: 4 additions & 0 deletions src/blop/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def get_beam_stats(image, threshold=0.5):
"cen_y": (y_min + y_max) / 2,
"wid_x": x_max - x_min,
"wid_y": y_max - y_min,
"x_min": x_min,
"x_max": x_max,
"y_min": y_min,
"y_max": y_max,
"bbox": [[x_min, x_max, x_max, x_min, x_min], [y_min, y_min, y_max, y_max, y_min]],
}

Expand Down

0 comments on commit 98c008d

Please sign in to comment.