Skip to content

Commit 6e08588

Browse files
committed
Always yse tomo metadata function for tomo dcgs
1 parent a9249da commit 6e08588

File tree

2 files changed

+35
-37
lines changed

2 files changed

+35
-37
lines changed

src/murfey/client/contexts/tomo.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import murfey.util.eer
1111
from murfey.client.context import Context, ProcessingParameter
12+
from murfey.client.contexts.tomo_metadata import ensure_tomo_dcg_exists
1213
from murfey.client.instance_environment import (
1314
MovieID,
1415
MovieTracker,
@@ -101,21 +102,10 @@ def register_tomography_data_collections(
101102
)
102103
return
103104
try:
104-
dcg_data = {
105-
"experiment_type_id": 36, # Tomo
106-
"tag": str(self._basepath),
107-
"atlas": "",
108-
"sample": None,
109-
}
110-
capture_post(
111-
base_url=str(environment.url.geturl()),
112-
router_name="workflow.router",
113-
function_name="register_dc_group",
114-
token=self._token,
115-
visit_name=environment.visit,
116-
session_id=environment.murfey_session,
117-
data=dcg_data,
105+
metadata_source = (
106+
self._basepath.parent / environment.visit / self._basepath.name
118107
)
108+
ensure_tomo_dcg_exists(metadata_source, environment, self._token)
119109

120110
for tilt_series in self._tilt_series.keys():
121111
if tilt_series not in self._tilt_series_with_pjids:

src/murfey/client/contexts/tomo_metadata.py

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,11 @@
1313
logger = logging.getLogger("murfey.client.contexts.tomo_metadata")
1414

1515

16-
def ensure_dcg_exists(
17-
transferred_file: Path, environment: MurfeyInstanceEnvironment, token: str
16+
def ensure_tomo_dcg_exists(
17+
metadata_source: Path, environment: MurfeyInstanceEnvironment, token: str
1818
):
19-
# Make sure we have a data collection group
20-
source = _get_source(transferred_file, environment=environment)
21-
if not source:
22-
return None
23-
source_visit_dir = source.parent
24-
25-
session_file = source / "Session.dm"
19+
"""Create a tomography data collection group"""
20+
session_file = metadata_source / "Session.dm"
2621
if not session_file.is_file():
2722
logger.warning(f"Cannot find session file {str(session_file)}")
2823
return
@@ -38,6 +33,7 @@ def ensure_dcg_exists(
3833
partial_path = "/".join(windows_path.split("\\")[visit_index + 1 :])
3934
logger.info("Partial Linux path successfully constructed from Windows path")
4035

36+
source_visit_dir = metadata_source.parent
4137
logger.info(
4238
f"Looking for atlas XML file in metadata directory {str((source_visit_dir / partial_path).parent)}"
4339
)
@@ -58,19 +54,21 @@ def ensure_dcg_exists(
5854
sample = int(p.replace("Sample", ""))
5955
break
6056
else:
61-
logger.warning(f"Sample could not be identified for {transferred_file}")
57+
logger.warning(f"Sample could not be identified for {metadata_source}")
6258
return
63-
environment.samples[source] = SampleInfo(atlas=Path(partial_path), sample=sample)
64-
dcg_tag = str(source).replace(f"/{environment.visit}", "")
59+
environment.samples[metadata_source] = SampleInfo(
60+
atlas=Path(partial_path), sample=sample
61+
)
62+
dcg_tag = str(metadata_source).replace(f"/{environment.visit}", "")
6563
dcg_data = {
6664
"experiment_type_id": 36, # Tomo
6765
"tag": dcg_tag,
6866
"atlas": str(
69-
_atlas_destination(environment, source, session_file, token)
70-
/ environment.samples[source].atlas.parent
67+
_atlas_destination(environment, metadata_source, session_file, token)
68+
/ environment.samples[metadata_source].atlas.parent
7169
/ atlas_xml_path.with_suffix(".jpg").name
7270
),
73-
"sample": environment.samples[source].sample,
71+
"sample": environment.samples[metadata_source].sample,
7472
"atlas_pixel_size": atlas_pixel_size,
7573
}
7674
capture_post(
@@ -102,13 +100,23 @@ def post_transfer(
102100
**kwargs,
103101
)
104102

105-
if transferred_file.name == "Session.dm" and environment:
103+
if environment is None:
104+
logger.warning("No environment set")
105+
return
106+
107+
metadata_source = _get_source(transferred_file, environment=environment)
108+
if not metadata_source:
109+
logger.warning(f"No source found for {str(transferred_file)}")
110+
return
111+
112+
if transferred_file.name == "Session.dm":
106113
logger.info("Tomography session metadata found")
107-
ensure_dcg_exists(transferred_file, environment, self._token)
114+
ensure_tomo_dcg_exists(metadata_source, environment, self._token)
108115

109-
elif transferred_file.name == "SearchMap.xml" and environment:
116+
elif transferred_file.name == "SearchMap.xml":
110117
logger.info("Tomography session search map xml found")
111-
dcg_tag = ensure_dcg_exists(transferred_file, environment, self._token)
118+
119+
dcg_tag = ensure_tomo_dcg_exists(metadata_source, environment, self._token)
112120
with open(transferred_file, "r") as sm_xml:
113121
sm_data = xmltodict.parse(sm_xml.read())
114122

@@ -208,9 +216,9 @@ def post_transfer(
208216
},
209217
)
210218

211-
elif transferred_file.name == "SearchMap.dm" and environment:
219+
elif transferred_file.name == "SearchMap.dm":
212220
logger.info("Tomography session search map dm found")
213-
dcg_tag = ensure_dcg_exists(transferred_file, environment, self._token)
221+
dcg_tag = ensure_tomo_dcg_exists(metadata_source, environment, self._token)
214222
with open(transferred_file, "r") as sm_xml:
215223
sm_data = xmltodict.parse(sm_xml.read())
216224

@@ -254,9 +262,9 @@ def post_transfer(
254262
},
255263
)
256264

257-
elif transferred_file.name == "BatchPositionsList.xml" and environment:
265+
elif transferred_file.name == "BatchPositionsList.xml":
258266
logger.info("Tomography session batch positions list found")
259-
dcg_tag = ensure_dcg_exists(transferred_file, environment, self._token)
267+
dcg_tag = ensure_tomo_dcg_exists(metadata_source, environment, self._token)
260268
with open(transferred_file) as xml:
261269
for_parsing = xml.read()
262270
batch_xml = xmltodict.parse(for_parsing)

0 commit comments

Comments
 (0)