Skip to content
Merged
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
38 changes: 22 additions & 16 deletions src/murfey/workflows/spa/flush_spa_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
gs_name: int,
foil_hole_params: FoilHoleParameters,
murfey_db: Session,
):
) -> Optional[int]:
try:
gs = murfey_db.exec(
select(GridSquare)
Expand All @@ -120,10 +120,10 @@
).one()
gsid = gs.id
except NoResultFound:
logger.debug(
logger.warning(

Check warning on line 123 in src/murfey/workflows/spa/flush_spa_preprocess.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/workflows/spa/flush_spa_preprocess.py#L123

Added line #L123 was not covered by tests
f"Foil hole {sanitise(str(foil_hole_params.name))} could not be registered as grid square {sanitise(str(gs_name))} was not found"
)
return
return None

Check warning on line 126 in src/murfey/workflows/spa/flush_spa_preprocess.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/workflows/spa/flush_spa_preprocess.py#L126

Added line #L126 was not covered by tests
secured_foil_hole_image_path = secure_filename(foil_hole_params.image)
if foil_hole_params.image and Path(secured_foil_hole_image_path).is_file():
jpeg_size = Image.open(secured_foil_hole_image_path).size
Expand Down Expand Up @@ -193,6 +193,7 @@
murfey_db.add(foil_hole)
murfey_db.commit()
murfey_db.close()
return foil_hole.id

Check warning on line 196 in src/murfey/workflows/spa/flush_spa_preprocess.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/workflows/spa/flush_spa_preprocess.py#L196

Added line #L196 was not covered by tests


def _grid_square_metadata_file(f: Path, grid_square: int) -> Optional[Path]:
Expand Down Expand Up @@ -287,8 +288,7 @@
name=foil_hole,
)
# Insert or update this foil hole in the database
register_foil_hole(session_id, gs.id, foil_hole_parameters, murfey_db)
return foil_hole
return register_foil_hole(session_id, gs.id, foil_hole_parameters, murfey_db)

Check warning on line 291 in src/murfey/workflows/spa/flush_spa_preprocess.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/workflows/spa/flush_spa_preprocess.py#L291

Added line #L291 was not covered by tests


def flush_spa_preprocess(message: dict, murfey_db: Session, demo: bool = False) -> bool:
Expand Down Expand Up @@ -349,23 +349,29 @@
murfey_db.add(feedback_params)

for i, f in enumerate(stashed_files):
if f.foil_hole_id:
foil_hole_id = f.foil_hole_id
else:
# Register grid square and foil hole if not present
try:
try:
foil_hole_id = None

Check warning on line 353 in src/murfey/workflows/spa/flush_spa_preprocess.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/workflows/spa/flush_spa_preprocess.py#L352-L353

Added lines #L352 - L353 were not covered by tests
if f.foil_hole_id:
# Check if the foil hole id has been registered in the database
db_foil_hole = murfey_db.exec(

Check warning on line 356 in src/murfey/workflows/spa/flush_spa_preprocess.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/workflows/spa/flush_spa_preprocess.py#L356

Added line #L356 was not covered by tests
select(FoilHole).where(FoilHole.id == f.foil_hole_id)
).all()
if db_foil_hole:
foil_hole_id = f.foil_hole_id

Check warning on line 360 in src/murfey/workflows/spa/flush_spa_preprocess.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/workflows/spa/flush_spa_preprocess.py#L360

Added line #L360 was not covered by tests
if not foil_hole_id:
# Register grid square and foil hole if not present
foil_hole_id = _flush_position_analysis(
movie_path=Path(f.file_path),
dcg_id=collected_ids[0].id,
session_id=session_id,
murfey_db=murfey_db,
)
except Exception as e:
logger.error(
f"Flushing position analysis for {f.file_path} caused exception {e}",
exc_info=True,
)
foil_hole_id = None
except Exception as e:
logger.error(

Check warning on line 370 in src/murfey/workflows/spa/flush_spa_preprocess.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/workflows/spa/flush_spa_preprocess.py#L369-L370

Added lines #L369 - L370 were not covered by tests
f"Flushing position analysis for {f.file_path} caused exception {e}",
exc_info=True,
)
foil_hole_id = None

Check warning on line 374 in src/murfey/workflows/spa/flush_spa_preprocess.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/workflows/spa/flush_spa_preprocess.py#L374

Added line #L374 was not covered by tests

mrcp = Path(f.mrc_out)
ppath = Path(f.file_path)
Expand Down
Loading