Skip to content

Commit 3905bb8

Browse files
committed
Rescale pixel sizes and subimage sizes
1 parent f9ae1e7 commit 3905bb8

File tree

2 files changed

+58
-13
lines changed

2 files changed

+58
-13
lines changed

src/murfey/server/api/__init__.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -491,18 +491,6 @@ def register_grid_square(
491491
grid_square_params: GridSquareParameters,
492492
db=murfey_db,
493493
):
494-
if _transport_object:
495-
dcg = db.exec(
496-
select(DataCollectionGroup)
497-
.where(DataCollectionGroup.session_id == session_id)
498-
.where(DataCollectionGroup.tag == grid_square_params.tag)
499-
).one()
500-
gs_ispyb_response = _transport_object.do_insert_grid_square(
501-
dcg.atlas_id, gsid, grid_square_params
502-
)
503-
else:
504-
# mock up response so that below still works
505-
gs_ispyb_response = {"success": False, "return_value": None}
506494
try:
507495
grid_square = db.exec(
508496
select(GridSquare)
@@ -514,7 +502,20 @@ def register_grid_square(
514502
grid_square.y_location = grid_square_params.y_location
515503
grid_square.x_stage_position = grid_square_params.x_stage_position
516504
grid_square.y_stage_position = grid_square_params.y_stage_position
505+
# need to update ISPyB grid square here !!!!
517506
except Exception:
507+
if _transport_object:
508+
dcg = db.exec(
509+
select(DataCollectionGroup)
510+
.where(DataCollectionGroup.session_id == session_id)
511+
.where(DataCollectionGroup.tag == grid_square_params.tag)
512+
).one()
513+
gs_ispyb_response = _transport_object.do_insert_grid_square(
514+
dcg.atlas_id, gsid, grid_square_params
515+
)
516+
else:
517+
# mock up response so that below still works
518+
gs_ispyb_response = {"success": False, "return_value": None}
518519
secured_grid_square_image_path = secure_filename(grid_square_params.image)
519520
if (
520521
secured_grid_square_image_path

src/murfey/server/ispyb.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,34 @@ def do_insert_grid_square(
135135
grid_square_id: int,
136136
grid_square_parameters: GridSquareParameters,
137137
):
138-
# need to correct height and weight by pixel ratio !!!!!
138+
if (
139+
grid_square_parameters.height is not None
140+
and grid_square_parameters.width is not None
141+
and grid_square_parameters.pixel_size is not None
142+
and grid_square_parameters.thumbnail_size_x is not None
143+
and grid_square_parameters.thumbnail_size_y is not None
144+
and grid_square_parameters.readout_area_x is not None
145+
and grid_square_parameters.readout_area_y is not None
146+
and grid_square_parameters.angle is not None
147+
):
148+
grid_square_parameters.height = int(
149+
grid_square_parameters.height
150+
* (
151+
grid_square_parameters.thumbnail_size_y
152+
/ grid_square_parameters.readout_area_y
153+
)
154+
)
155+
grid_square_parameters.width = int(
156+
grid_square_parameters.width
157+
* (
158+
grid_square_parameters.thumbnail_size_x
159+
/ grid_square_parameters.readout_area_x
160+
)
161+
)
162+
grid_square_parameters.angle *= (
163+
grid_square_parameters.readout_area_x
164+
/ grid_square_parameters.thumbnail_size_x
165+
)
139166
record = GridSquare(
140167
atlasId=atlas_id,
141168
gridSquareLabel=grid_square_id,
@@ -168,6 +195,23 @@ def do_insert_foil_hole(
168195
grid_square_id: int,
169196
foil_hole_parameters: FoilHoleParameters,
170197
):
198+
if (
199+
foil_hole_parameters.diameter is not None
200+
and foil_hole_parameters.thumbnail_size_x is not None
201+
and foil_hole_parameters.readout_area_x is not None
202+
and foil_hole_parameters.pixel_size is not None
203+
):
204+
foil_hole_parameters.diameter = int(
205+
foil_hole_parameters.diameter
206+
* (
207+
foil_hole_parameters.thumbnail_size_x
208+
/ foil_hole_parameters.readout_area_x
209+
)
210+
)
211+
foil_hole_parameters.pixel_size *= (
212+
foil_hole_parameters.readout_area_x
213+
/ foil_hole_parameters.thumbnail_size_x
214+
)
171215
record = FoilHole(
172216
gridSquareId=grid_square_id,
173217
foilHoleLabel=foil_hole_parameters.name,

0 commit comments

Comments
 (0)