Skip to content
Merged
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
13 changes: 11 additions & 2 deletions src/murfey/client/contexts/spa.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,19 @@


def _get_source(file_path: Path, environment: MurfeyInstanceEnvironment) -> Path | None:
possible_sources = []

Check warning on line 82 in src/murfey/client/contexts/spa.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/spa.py#L82

Added line #L82 was not covered by tests
for s in environment.sources:
if file_path.is_relative_to(s):
return s
return None
possible_sources.append(s)

Check warning on line 85 in src/murfey/client/contexts/spa.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/spa.py#L85

Added line #L85 was not covered by tests
if not possible_sources:
return None

Check warning on line 87 in src/murfey/client/contexts/spa.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/spa.py#L87

Added line #L87 was not covered by tests
elif len(possible_sources) == 1:
return possible_sources[0]
source = possible_sources[0]

Check warning on line 90 in src/murfey/client/contexts/spa.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/spa.py#L89-L90

Added lines #L89 - L90 were not covered by tests
for extra_source in possible_sources[1:]:
if extra_source.is_relative_to(source):
source = extra_source
return source

Check warning on line 94 in src/murfey/client/contexts/spa.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/spa.py#L93-L94

Added lines #L93 - L94 were not covered by tests


def _get_xml_list_index(key: str, xml_list: list) -> int:
Expand Down
52 changes: 29 additions & 23 deletions src/murfey/client/contexts/spa_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@
instrument_name=environment.instrument_name,
demo=environment.demo,
)
if environment.visit in environment.default_destinations[source]:
return (
Path(machine_config.get("rsync_basepath", ""))
/ Path(environment.default_destinations[source]).parent
)
for i, destination_part in enumerate(
Path(environment.default_destinations[source]).parts
):
if destination_part == environment.visit:
return Path(machine_config.get("rsync_basepath", "")) / "/".join(

Check warning on line 73 in src/murfey/client/contexts/spa_metadata.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/spa_metadata.py#L73

Added line #L73 was not covered by tests
Path(environment.default_destinations[source]).parent.parts[: i + 1]
)
return (
Path(machine_config.get("rsync_basepath", ""))
/ Path(environment.default_destinations[source]).parent
Expand Down Expand Up @@ -117,12 +119,10 @@
source_visit_dir = source.parent

logger.info(
f"Looking for atlas XML file in metadata directory {str((source_visit_dir / environment.visit / partial_path).parent)}"
f"Looking for atlas XML file in metadata directory {str((source_visit_dir / partial_path).parent)}"
)
atlas_xml_path = list(
(source_visit_dir / environment.visit / partial_path).parent.glob(
"Atlas_*.xml"
)
(source_visit_dir / partial_path).parent.glob("Atlas_*.xml")
)[0]
logger.info(f"Atlas XML path {str(atlas_xml_path)} found")
with open(atlas_xml_path, "rb") as atlas_xml:
Expand All @@ -137,7 +137,6 @@
atlas_pixel_size = atlas_original_pixel_size * 7.8
logger.info(f"Atlas image pixel size determined to be {atlas_pixel_size}")

sample = None
for p in partial_path.split("/"):
if p.startswith("Sample"):
sample = int(p.replace("Sample", ""))
Expand All @@ -150,31 +149,34 @@
atlas=Path(partial_path), sample=sample
)
url = f"{str(environment.url.geturl())}/visits/{environment.visit}/{environment.murfey_session}/register_data_collection_group"
dcg_search_dir = "/".join(
dcg_search_dir = "/" + "/".join(

Check warning on line 152 in src/murfey/client/contexts/spa_metadata.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/spa_metadata.py#L152

Added line #L152 was not covered by tests
p
for p in transferred_file.parent.parts[1:]
if p != environment.visit
)
dcg_tag = str(
sorted(
Path(dcg_search_dir).glob("Images-Disc*"),
key=lambda x: x.stat().st_ctime,
)[-1]
dcg_images_dirs = sorted(

Check warning on line 157 in src/murfey/client/contexts/spa_metadata.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/spa_metadata.py#L157

Added line #L157 was not covered by tests
Path(dcg_search_dir).glob("Images-Disc*"),
key=lambda x: x.stat().st_ctime,
)
if not dcg_images_dirs:
logger.warning(f"Cannot find Images-Disc* in {dcg_search_dir}")
return
dcg_tag = str(dcg_images_dirs[-1])

Check warning on line 164 in src/murfey/client/contexts/spa_metadata.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/spa_metadata.py#L162-L164

Added lines #L162 - L164 were not covered by tests
dcg_data = {
"experiment_type": "single particle",
"experiment_type_id": 37,
"tag": dcg_tag,
"atlas": str(
_atlas_destination(environment, source, transferred_file)
/ environment.samples[source].atlas
/ environment.samples[source].atlas.parent
/ atlas_xml_path.with_suffix(".jpg").name
),
"sample": environment.samples[source].sample,
"atlas_pixel_size": atlas_pixel_size,
}
capture_post(url, json=dcg_data)
gs_pix_positions = get_grid_square_atlas_positions(
source_visit_dir / environment.visit / partial_path
source_visit_dir / partial_path
)
for gs, pos_data in gs_pix_positions.items():
if pos_data:
Expand Down Expand Up @@ -206,12 +208,16 @@
visitless_source_search_dir = str(source).replace(
f"/{environment.visit}", ""
)
visitless_source = str(
sorted(
Path(visitless_source_search_dir).glob("Images-Disc*"),
key=lambda x: x.stat().st_ctime,
)[-1]
visitless_source_images_dirs = sorted(

Check warning on line 211 in src/murfey/client/contexts/spa_metadata.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/spa_metadata.py#L211

Added line #L211 was not covered by tests
Path(visitless_source_search_dir).glob("Images-Disc*"),
key=lambda x: x.stat().st_ctime,
)
if not visitless_source_images_dirs:
logger.warning(

Check warning on line 216 in src/murfey/client/contexts/spa_metadata.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/spa_metadata.py#L216

Added line #L216 was not covered by tests
f"Cannot find Images-Disc* in {visitless_source_search_dir}"
)
return
visitless_source = str(visitless_source_images_dirs[-1])

Check warning on line 220 in src/murfey/client/contexts/spa_metadata.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/spa_metadata.py#L219-L220

Added lines #L219 - L220 were not covered by tests
for fh, fh_data in fh_positions.items():
capture_post(
f"{str(environment.url.geturl())}/sessions/{environment.murfey_session}/grid_square/{gs_name}/foil_hole",
Expand Down
1 change: 1 addition & 0 deletions src/murfey/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2569,6 +2569,7 @@
message["atlas_pixel_size"],
message["sample"],
)
_transport_object.transport.ack(header)

Check warning on line 2572 in src/murfey/server/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/__init__.py#L2572

Added line #L2572 was not covered by tests
return None
elif message["register"] == "data_collection":
murfey_session_id = message["session_id"]
Expand Down
84 changes: 39 additions & 45 deletions src/murfey/server/ispyb.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,32 +213,28 @@
grid_square_parameters.readout_area_x
/ grid_square_parameters.thumbnail_size_x
)
grid_square.gridSquareImage = grid_square_parameters.image
grid_square.pixelLocationX = (
int(grid_square_parameters.x_location / 7.8)
if grid_square_parameters.x_location
else None
)
grid_square.pixelLocationY = (
int(grid_square_parameters.y_location / 7.8)
if grid_square_parameters.y_location
else None
)
grid_square.pixelLocationY = grid_square_parameters.y_location
grid_square.height = (
int(grid_square_parameters.height / 7.8)
if grid_square_parameters.height is not None
else None
)
grid_square.width = (
int(grid_square_parameters.width / 7.8)
if grid_square_parameters.width is not None
else None
)
grid_square.angle = grid_square_parameters.angle
grid_square.stageLocationX = grid_square_parameters.x_stage_position
grid_square.stageLocationY = grid_square_parameters.y_stage_position
grid_square.pixelSize = grid_square_parameters.pixel_size
if grid_square_parameters.image:
grid_square.gridSquareImage = grid_square_parameters.image

Check warning on line 217 in src/murfey/server/ispyb.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/ispyb.py#L217

Added line #L217 was not covered by tests
if grid_square_parameters.x_location:
grid_square.pixelLocationX = int(

Check warning on line 219 in src/murfey/server/ispyb.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/ispyb.py#L219

Added line #L219 was not covered by tests
grid_square_parameters.x_location / 7.8
)
if grid_square_parameters.y_location:
grid_square.pixelLocationY = int(

Check warning on line 223 in src/murfey/server/ispyb.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/ispyb.py#L223

Added line #L223 was not covered by tests
grid_square_parameters.y_location / 7.8
)
if grid_square_parameters.height is not None:
grid_square.height = int(grid_square_parameters.height / 7.8)

Check warning on line 227 in src/murfey/server/ispyb.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/ispyb.py#L227

Added line #L227 was not covered by tests
if grid_square_parameters.width is not None:
grid_square.width = int(grid_square_parameters.width / 7.8)

Check warning on line 229 in src/murfey/server/ispyb.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/ispyb.py#L229

Added line #L229 was not covered by tests
if grid_square_parameters.angle:
grid_square.angle = grid_square_parameters.angle

Check warning on line 231 in src/murfey/server/ispyb.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/ispyb.py#L231

Added line #L231 was not covered by tests
if grid_square_parameters.x_stage_position:
grid_square.stageLocationX = grid_square_parameters.x_stage_position

Check warning on line 233 in src/murfey/server/ispyb.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/ispyb.py#L233

Added line #L233 was not covered by tests
if grid_square_parameters.y_stage_position:
grid_square.stageLocationY = grid_square_parameters.y_stage_position

Check warning on line 235 in src/murfey/server/ispyb.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/ispyb.py#L235

Added line #L235 was not covered by tests
if grid_square_parameters.pixel_size:
grid_square.pixelSize = grid_square_parameters.pixel_size

Check warning on line 237 in src/murfey/server/ispyb.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/ispyb.py#L237

Added line #L237 was not covered by tests
db.add(grid_square)
db.commit()
return {"success": True, "return_value": grid_square.gridSquareId}
Expand Down Expand Up @@ -296,7 +292,7 @@
with Session() as db:
db.add(record)
db.commit()
log.info(f"Created FoilHole {record.gridSquareId}")
log.info(f"Created FoilHole {record.foilHoleId}")

Check warning on line 295 in src/murfey/server/ispyb.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/ispyb.py#L295

Added line #L295 was not covered by tests
return {"success": True, "return_value": record.foilHoleId}
except ispyb.ISPyBException as e:
log.error(
Expand All @@ -317,24 +313,22 @@
foil_hole = (
db.query(FoilHole).filter(FoilHole.foilHoleId == foil_hole_id).one()
)
foil_hole.foilHoleImage = foil_hole_parameters.image
foil_hole.pixelLocationX = (
int(foil_hole_parameters.x_location * scale_factor)
if foil_hole_parameters.x_location
else None
)
foil_hole.pixelLocationY = (
int(foil_hole_parameters.y_location * scale_factor)
if foil_hole_parameters.y_location
else None
)
foil_hole.diameter = (
foil_hole_parameters.diameter * scale_factor
if foil_hole_parameters.diameter is not None
else None
)
foil_hole.stageLocationX = foil_hole_parameters.x_stage_position
foil_hole.stageLocationY = foil_hole_parameters.y_stage_position
if foil_hole_parameters.image:
foil_hole.foilHoleImage = foil_hole_parameters.image

Check warning on line 317 in src/murfey/server/ispyb.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/ispyb.py#L317

Added line #L317 was not covered by tests
if foil_hole_parameters.x_location:
foil_hole.pixelLocationX = int(

Check warning on line 319 in src/murfey/server/ispyb.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/ispyb.py#L319

Added line #L319 was not covered by tests
foil_hole_parameters.x_location * scale_factor
)
if foil_hole_parameters.y_location:
foil_hole.pixelLocationY = int(

Check warning on line 323 in src/murfey/server/ispyb.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/ispyb.py#L323

Added line #L323 was not covered by tests
foil_hole_parameters.y_location * scale_factor
)
if foil_hole_parameters.diameter is not None:
foil_hole.diameter = foil_hole_parameters.diameter * scale_factor

Check warning on line 327 in src/murfey/server/ispyb.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/ispyb.py#L327

Added line #L327 was not covered by tests
if foil_hole_parameters.x_stage_position:
foil_hole.stageLocationX = foil_hole_parameters.x_stage_position

Check warning on line 329 in src/murfey/server/ispyb.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/ispyb.py#L329

Added line #L329 was not covered by tests
if foil_hole_parameters.y_stage_position:
foil_hole.stageLocationY = foil_hole_parameters.y_stage_position

Check warning on line 331 in src/murfey/server/ispyb.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/ispyb.py#L331

Added line #L331 was not covered by tests
if (
foil_hole_parameters.readout_area_x is not None
and foil_hole_parameters.thumbnail_size_x is not None
Expand Down