Skip to content

Commit

Permalink
Merge pull request #23 from leorrose/develop
Browse files Browse the repository at this point in the history
Lenient extraction of corrupted imaging data TXT files
  • Loading branch information
Milad4849 authored Nov 23, 2023
2 parents c253939 + 4345543 commit 8e091da
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions readimc/txt_file.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re
from os import PathLike
from typing import List, Optional, Sequence, TextIO, Tuple, Union
from warnings import warn

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -93,11 +94,14 @@ def close(self) -> None:
self._fh.close()
self._fh = None

def read_acquisition(self, acquisition: Optional[Acquisition] = None) -> np.ndarray:
def read_acquisition(
self, acquisition: Optional[Acquisition] = None, strict: bool = True
) -> np.ndarray:
"""Reads IMC acquisition data as numpy array.
:param acquisition: the acquisition to read (for compatibility with ``IMCFile``
and ``MCDFile``; unused)
:param strict: set this parameter to False to try to recover corrupted data
:return: the acquisition data as 32-bit floating point array,
shape: (c, y, x)
"""
Expand All @@ -121,7 +125,12 @@ def read_acquisition(self, acquisition: Optional[Acquisition] = None) -> np.ndar
)
width, height = df[["X", "Y"]].add(1).max(axis=0).astype(int)
if width * height != len(df.index):
raise IOError(
if strict:
raise IOError(

Check warning on line 129 in readimc/txt_file.py

View check run for this annotation

Codecov / codecov/patch

readimc/txt_file.py#L128-L129

Added lines #L128 - L129 were not covered by tests
f"TXT file '{self.path.name}' corrupted: "
"inconsistent acquisition image data size"
)
warn(

Check warning on line 133 in readimc/txt_file.py

View check run for this annotation

Codecov / codecov/patch

readimc/txt_file.py#L133

Added line #L133 was not covered by tests
f"TXT file '{self.path.name}' corrupted: "
"inconsistent acquisition image data size"
)
Expand Down

0 comments on commit 8e091da

Please sign in to comment.