Skip to content

Commit d28bbf1

Browse files
committed
Remove the old SPA context
1 parent 0f59d2e commit d28bbf1

File tree

10 files changed

+15
-238
lines changed

10 files changed

+15
-238
lines changed

src/murfey/client/analyser.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from murfey.client.context import Context
1818
from murfey.client.contexts.clem import CLEMContext
19-
from murfey.client.contexts.spa import SPAContext, SPAModularContext
19+
from murfey.client.contexts.spa import SPAModularContext
2020
from murfey.client.contexts.spa_metadata import SPAMetadataContext
2121
from murfey.client.contexts.tomo import TomographyContext
2222
from murfey.client.instance_environment import MurfeyInstanceEnvironment
@@ -159,23 +159,7 @@ def _find_context(self, file_path: Path) -> bool:
159159
if split_file_name[0].startswith("FoilHole"):
160160
if not self._context:
161161
logger.info("Acquisition software: EPU")
162-
if self._environment:
163-
try:
164-
cfg = get_machine_config_client(
165-
str(self._environment.url.geturl()),
166-
instrument_name=self._environment.instrument_name,
167-
demo=self._environment.demo,
168-
)
169-
except Exception as e:
170-
logger.error(f"Exception encountered: {e}")
171-
cfg = {}
172-
else:
173-
cfg = {}
174-
self._context = (
175-
SPAModularContext("epu", self._basepath)
176-
if cfg.get("modular_spa")
177-
else SPAContext("epu", self._basepath)
178-
)
162+
self._context = SPAModularContext("epu", self._basepath)
179163
self.parameters_model = ProcessingParametersSPA
180164
return True
181165

@@ -325,8 +309,7 @@ def _analyse(self):
325309
"form": dc_metadata,
326310
"dependencies": (
327311
spa_form_dependencies
328-
if isinstance(self._context, SPAContext)
329-
or isinstance(
312+
if isinstance(
330313
self._context, SPAModularContext
331314
)
332315
else {}
@@ -385,8 +368,7 @@ def _analyse(self):
385368
"form": dc_metadata,
386369
"dependencies": (
387370
spa_form_dependencies
388-
if isinstance(self._context, SPAContext)
389-
or isinstance(
371+
if isinstance(
390372
self._context, SPAModularContext
391373
)
392374
else {}

src/murfey/client/contexts/spa.py

Lines changed: 1 addition & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def _get_xml_list_index(key: str, xml_list: list) -> int:
285285
raise ValueError(f"Key not found in XML list: {key}")
286286

287287

288-
class _SPAContext(Context):
288+
class SPAModularContext(Context):
289289
user_params = [
290290
ProcessingParameter(
291291
"dose_per_frame",
@@ -558,8 +558,6 @@ def gather_metadata(
558558
) or True
559559
return metadata
560560

561-
562-
class SPAModularContext(_SPAContext):
563561
def _position_analysis(
564562
self,
565563
transferred_file: Path,
@@ -856,104 +854,3 @@ def _launch_spa_pipeline(
856854
url: str = "",
857855
):
858856
return
859-
860-
861-
class SPAContext(_SPAContext):
862-
def _register_data_collection(
863-
self,
864-
tag: str,
865-
url: str,
866-
data: dict,
867-
environment: MurfeyInstanceEnvironment,
868-
):
869-
logger.info(f"registering data collection with data {data}")
870-
environment.id_tag_registry["data_collection"].append(tag)
871-
image_directory = str(environment.default_destinations[Path(tag)])
872-
json = {
873-
"voltage": data["voltage"],
874-
"pixel_size_on_image": data["pixel_size_on_image"],
875-
"experiment_type": data["experiment_type"],
876-
"image_size_x": data["image_size_x"],
877-
"image_size_y": data["image_size_y"],
878-
"file_extension": data["file_extension"],
879-
"acquisition_software": data["acquisition_software"],
880-
"image_directory": image_directory,
881-
"tag": tag,
882-
"source": tag,
883-
"magnification": data["magnification"],
884-
"total_exposed_dose": data.get("total_exposed_dose"),
885-
"c2aperture": data.get("c2aperture"),
886-
"exposure_time": data.get("exposure_time"),
887-
"slit_width": data.get("slit_width"),
888-
"phase_plate": data.get("phase_plate", False),
889-
}
890-
capture_post(url, json=json)
891-
892-
def post_transfer(
893-
self,
894-
transferred_file: Path,
895-
environment: MurfeyInstanceEnvironment | None = None,
896-
**kwargs,
897-
) -> bool:
898-
return True
899-
900-
def _register_processing_job(
901-
self,
902-
tag: str,
903-
environment: MurfeyInstanceEnvironment,
904-
parameters: Dict[str, Any] | None = None,
905-
):
906-
logger.info(f"registering processing job with parameters: {parameters}")
907-
parameters = parameters or {}
908-
environment.id_tag_registry["processing_job"].append(tag)
909-
proc_url = f"{str(environment.url.geturl())}/visits/{environment.visit}/{environment.murfey_session}/register_processing_job"
910-
machine_config = get_machine_config_client(
911-
str(environment.url.geturl()),
912-
instrument_name=environment.instrument_name,
913-
demo=environment.demo,
914-
)
915-
image_directory = str(
916-
Path(machine_config.get("rsync_basepath", "."))
917-
/ environment.default_destinations[Path(tag)]
918-
)
919-
if self._acquisition_software == "epu":
920-
import_images = f"{Path(image_directory).resolve()}/GridSquare*/Data/*{parameters['file_extension']}"
921-
else:
922-
import_images = (
923-
f"{Path(image_directory).resolve()}/*{parameters['file_extension']}"
924-
)
925-
msg: Dict[str, Any] = {
926-
"tag": tag,
927-
"source": tag,
928-
"recipe": "ispyb-relion",
929-
"parameters": {
930-
"acquisition_software": parameters["acquisition_software"],
931-
"voltage": parameters["voltage"],
932-
"gain_ref": parameters["gain_ref"],
933-
"dose_per_frame": parameters["dose_per_frame"],
934-
"eer_grouping": parameters["eer_fractionation"],
935-
"import_images": import_images,
936-
"angpix": float(parameters["pixel_size_on_image"]) * 1e10,
937-
"symmetry": parameters["symmetry"],
938-
"boxsize": parameters["boxsize"],
939-
"downscale": parameters["downscale"],
940-
"small_boxsize": parameters["small_boxsize"],
941-
"mask_diameter": parameters["mask_diameter"],
942-
"use_cryolo": parameters["use_cryolo"],
943-
"estimate_particle_diameter": parameters["estimate_particle_diameter"],
944-
},
945-
}
946-
if parameters["particle_diameter"]:
947-
msg["parameters"]["particle_diameter"] = parameters["particle_diameter"]
948-
capture_post(proc_url, json=msg)
949-
950-
def _launch_spa_pipeline(
951-
self,
952-
tag: str,
953-
jobid: int,
954-
environment: MurfeyInstanceEnvironment,
955-
url: str = "",
956-
):
957-
environment.id_tag_registry["auto_proc_program"].append(tag)
958-
data = {"job_id": jobid}
959-
capture_post(url, json=data)

src/murfey/client/instance_environment.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,6 @@ def dc_callback(cls, v, values):
8686
l(k)
8787
return v
8888

89-
@validator("processing_job_ids")
90-
def job_callback(cls, v, values):
91-
with global_env_lock:
92-
for l in values.get("listeners", {}).get("processing_job_ids", []):
93-
for k in v.keys():
94-
if k not in values["id_tag_registry"]["auto_proc_program"]:
95-
l(k, v[k]["ispyb-relion"])
96-
return v
97-
9889
@validator("autoproc_program_ids")
9990
def app_callback(cls, v, values):
10091
# logger.info(f"autoproc program ids validator: {v}")

src/murfey/client/multigrid_control.py

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import murfey.client.websocket
1515
from murfey.client.analyser import Analyser
16-
from murfey.client.contexts.spa import SPAContext, SPAModularContext
16+
from murfey.client.contexts.spa import SPAModularContext
1717
from murfey.client.contexts.tomo import TomographyContext
1818
from murfey.client.instance_environment import MurfeyInstanceEnvironment
1919
from murfey.client.rsync import RSyncer, RSyncerUpdate, TransferResult
@@ -443,7 +443,7 @@ def _start_dc(self, json, from_form: bool = False):
443443
)
444444
log.info("tomography processing flushed")
445445

446-
elif isinstance(context, SPAContext) or isinstance(context, SPAModularContext):
446+
elif isinstance(context, SPAModularContext):
447447
url = f"{str(self._environment.url.geturl())}/visits/{str(self._environment.visit)}/{self.session_id}/register_data_collection_group"
448448
dcg_data = {
449449
"experiment_type": "single particle",
@@ -515,31 +515,6 @@ def _start_dc(self, json, from_form: bool = False):
515515
f"{self._environment.url.geturl()}/visits/{self._environment.visit}/{self.session_id}/flush_spa_processing",
516516
json={"tag": str(source)},
517517
)
518-
if isinstance(context, SPAContext):
519-
url = f"{str(self._environment.url.geturl())}/visits/{str(self._environment.visit)}/{self.session_id}/start_data_collection"
520-
self._environment.listeners["data_collection_group_ids"] = {
521-
partial(
522-
context._register_data_collection,
523-
url=url,
524-
data=json,
525-
environment=self._environment,
526-
)
527-
}
528-
self._environment.listeners["data_collection_ids"] = {
529-
partial(
530-
context._register_processing_job,
531-
parameters=json,
532-
environment=self._environment,
533-
)
534-
}
535-
url = f"{str(self._environment.url.geturl())}/visits/{str(self._environment.visit)}/spa_processing"
536-
self._environment.listeners["processing_job_ids"] = {
537-
partial(
538-
context._launch_spa_pipeline,
539-
url=url,
540-
environment=self._environment,
541-
)
542-
}
543518

544519
def _increment_file_count(
545520
self, observed_files: List[Path], source: str, destination: str

src/murfey/client/tui/app.py

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from textual.widgets import Button, Input
1616

1717
from murfey.client.analyser import Analyser
18-
from murfey.client.contexts.spa import SPAContext, SPAModularContext
18+
from murfey.client.contexts.spa import SPAModularContext
1919
from murfey.client.contexts.tomo import TomographyContext
2020
from murfey.client.instance_environment import MurfeyInstanceEnvironment
2121
from murfey.client.rsync import RSyncer, RSyncerUpdate, TransferResult
@@ -552,7 +552,7 @@ def _start_dc(self, json, from_form: bool = False):
552552
json={"rsync_source": str(source)},
553553
)
554554
log.info("tomography processing flushed")
555-
elif isinstance(context, SPAContext) or isinstance(context, SPAModularContext):
555+
elif isinstance(context, SPAModularContext):
556556
url = f"{str(self._url.geturl())}/visits/{str(self._visit)}/{self._environment.murfey_session}/register_data_collection_group"
557557
dcg_data = {
558558
"experiment_type": "single particle",
@@ -629,31 +629,6 @@ def _start_dc(self, json, from_form: bool = False):
629629
f"{self.app._environment.url.geturl()}/visits/{self.app._environment.visit}/{self.app._environment.murfey_session}/flush_spa_processing",
630630
json={"tag": str(source)},
631631
)
632-
if isinstance(context, SPAContext):
633-
url = f"{str(self._url.geturl())}/visits/{str(self._visit)}/{self._environment.murfey_session}/start_data_collection"
634-
self._environment.listeners["data_collection_group_ids"] = {
635-
partial(
636-
context._register_data_collection,
637-
url=url,
638-
data=json,
639-
environment=self._environment,
640-
)
641-
}
642-
self._environment.listeners["data_collection_ids"] = {
643-
partial(
644-
context._register_processing_job,
645-
parameters=json,
646-
environment=self._environment,
647-
)
648-
}
649-
url = f"{str(self._url.geturl())}/visits/{str(self._visit)}/spa_processing"
650-
self._environment.listeners["processing_job_ids"] = {
651-
partial(
652-
context._launch_spa_pipeline,
653-
url=url,
654-
environment=self._environment,
655-
)
656-
}
657632

658633
def _set_request_destination(self, response: str):
659634
if response == "y":

src/murfey/client/tui/screens.py

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
from werkzeug.utils import secure_filename
4848

4949
from murfey.client.analyser import Analyser, spa_form_dependencies
50-
from murfey.client.contexts.spa import SPAContext, SPAModularContext
50+
from murfey.client.contexts.spa import SPAModularContext
5151
from murfey.client.contexts.tomo import TomographyContext
5252
from murfey.client.gain_ref import determine_gain_ref
5353
from murfey.client.instance_environment import (
@@ -257,18 +257,8 @@ def __init__(
257257
super().__init__(*args, **kwargs)
258258
self._selected_dir = basepath
259259
self._add_basepath = add_basepath
260-
cfg = get_machine_config_client(
261-
str(self.app._environment.url.geturl()),
262-
instrument_name=self.app._environment.instrument_name,
263-
demo=self.app._environment.demo,
264-
)
265-
self._context: (
266-
Type[SPAModularContext] | Type[SPAContext] | Type[TomographyContext]
267-
)
268-
if cfg.get("modular_spa"):
269-
self._context = SPAContext
270-
else:
271-
self._context = SPAModularContext
260+
self._context: Type[SPAModularContext] | Type[TomographyContext]
261+
self._context = SPAModularContext
272262

273263
def compose(self):
274264
machine_data = requests.get(
@@ -975,7 +965,7 @@ class DestinationSelect(Screen):
975965
def __init__(
976966
self,
977967
transfer_routes: Dict[Path, str],
978-
context: Type[SPAContext] | Type[SPAModularContext] | Type[TomographyContext],
968+
context: Type[SPAModularContext] | Type[TomographyContext],
979969
*args,
980970
dependencies: Dict[str, FormDependency] | None = None,
981971
destination_overrides: Optional[Dict[Path, str]] = None,
@@ -994,9 +984,7 @@ def __init__(
994984
def compose(self):
995985
bulk = []
996986
with RadioSet():
997-
yield RadioButton(
998-
"SPA", value=self._context in (SPAContext, SPAModularContext)
999-
)
987+
yield RadioButton("SPA", value=self._context is SPAModularContext)
1000988
yield RadioButton("Tomography", value=self._context is TomographyContext)
1001989
if self.app._multigrid:
1002990
machine_config = get_machine_config_client(
@@ -1142,15 +1130,7 @@ def on_switch_changed(self, event):
11421130

11431131
def on_radio_set_changed(self, event: RadioSet.Changed) -> None:
11441132
if event.index == 0:
1145-
cfg = get_machine_config_client(
1146-
str(self.app._environment.url.geturl()),
1147-
instrument_name=self.app._environment.instrument_name,
1148-
demo=self.app._environment.demo,
1149-
)
1150-
if cfg.get("modular_spa"):
1151-
self._context = SPAContext
1152-
else:
1153-
self._context = SPAModularContext
1133+
self._context = SPAModularContext
11541134
else:
11551135
self._context = TomographyContext
11561136
self.app.pop_screen()

src/murfey/server/api/__init__.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@
9898
Sample,
9999
SessionInfo,
100100
SPAProcessFile,
101-
SPAProcessingParameters,
102101
SuggestedPathParameters,
103102
TiltInfo,
104103
TiltSeriesGroupInfo,
@@ -1058,16 +1057,6 @@ async def send_murfey_message(instrument_name: str, msg: RegistrationMessage):
10581057
)
10591058

10601059

1061-
@router.post("/visits/{visit_name}/spa_processing")
1062-
async def request_spa_processing(visit_name: str, proc_params: SPAProcessingParameters):
1063-
zocalo_message = {
1064-
"parameters": {"ispyb_process": proc_params.job_id},
1065-
"recipes": ["ispyb-relion"],
1066-
}
1067-
if _transport_object:
1068-
_transport_object.send("processing_recipe", zocalo_message)
1069-
1070-
10711060
@router.post("/visits/{visit_name}/{session_id}/spa_preprocess")
10721061
async def request_spa_preprocessing(
10731062
visit_name: str,

0 commit comments

Comments
 (0)