Skip to content

Commit 0410384

Browse files
committed
Data parsing code refactoring & improvement
1 parent ff84658 commit 0410384

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

python/main.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,13 @@ async def get_files(files: list[UploadFile]) -> UploadFilesResponse:
468468
if len(dcm.pixel_array.shape) == 2: # noqa: PLR2004
469469
proper_dicom_paths.append(fp)
470470
total_uploaded_file_bytes += len(contents)
471+
total_uploaded_file_megabytes = "%.1f" % (
472+
total_uploaded_file_bytes / (10**3) ** 2
473+
)
474+
else:
475+
Path.unlink(fp)
471476
except InvalidDicomError:
472-
pass
473-
total_uploaded_file_megabytes = "%.1f" % (total_uploaded_file_bytes / (10**3) ** 2)
477+
Path.unlink(fp)
474478
return UploadFilesResponse(
475479
n_uploaded_files=len(proper_dicom_paths),
476480
total_size=total_uploaded_file_megabytes,
@@ -686,7 +690,6 @@ def prepare_medsam() -> None:
686690
medsam_model = load_model()
687691
raw_fp = Path("./tmp/session-data/raw")
688692
dcm_fps = sorted(raw_fp.glob("*"))
689-
time.time()
690693
temp_dir = Path("./tmp/session-data/embed")
691694
hs, ws = [], []
692695
for idx, dcm_fp in enumerate(dcm_fps):
@@ -699,7 +702,6 @@ def prepare_medsam() -> None:
699702
hs.append(h)
700703
ws.append(w)
701704
img_256 = cv2.resize(src=img_3c, dsize=(256, 256)).astype(np.float32)
702-
newh, neww = img_256.shape[:2]
703705
img_256 = (img_256 - img_256.min()) / np.clip(
704706
img_256.max() - img_256.min(),
705707
a_min=1e-8,
@@ -1047,13 +1049,7 @@ def get_dicom_paths(
10471049
self, # noqa: ANN101
10481050
data_dp: str,
10491051
) -> list[Path]:
1050-
dicom_paths = list(Path(data_dp).rglob("*"))
1051-
proper_dicom_paths = []
1052-
for dicom_path in dicom_paths:
1053-
ds = pydicom.dcmread(dicom_path, stop_before_pixels=True)
1054-
if ds:
1055-
proper_dicom_paths.append(dicom_path)
1056-
return proper_dicom_paths
1052+
return list(Path(data_dp).rglob("*"))
10571053

10581054
def parse_file(
10591055
self, # noqa: ANN101

0 commit comments

Comments
 (0)