Skip to content

Commit

Permalink
test: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Apr 21, 2024
1 parent 703d68b commit 83aaec1
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/nd2/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,22 @@
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime
from pathlib import Path
from typing import Any, Iterable, Iterator, Sequence, TypedDict, cast, no_type_check
from typing import (
TYPE_CHECKING,
Any,
Iterable,
Iterator,
Sequence,
TypedDict,
cast,
no_type_check,
)

import nd2

if TYPE_CHECKING:
from nd2.readers._modern.modern_reader import ModernReader

try:
import rich

Expand Down Expand Up @@ -47,26 +59,29 @@ def index_file(path: Path) -> Record:
with nd2.ND2File(path) as nd:
if nd.is_legacy:
software: dict = {}
acquired: str | None = ""
acquired: datetime | None = None
binary = False
else:
software = nd._rdr._app_info() # type: ignore
acquired = nd._rdr._acquisition_date() # type: ignore
rdr = cast("ModernReader", nd._rdr)
software = rdr._app_info()
acquired = rdr._acquisition_datetime()
binary = nd.binary_data is not None

stat = path.stat()
exp = [(x.type, x.count) for x in nd.experiment]
axes, shape = zip(*nd.sizes.items())
if isinstance(acquired, datetime):
acquired = acquired.strftime(TIME_FORMAT)
acq_str = acquired.strftime(TIME_FORMAT)
else:
acq_str = ""

return Record(
{
"path": str(path.resolve()),
"name": path.name,
"version": ".".join(map(str, nd.version)),
"kb": round(stat.st_size / 1000, 2),
"acquired": acquired or "",
"acquired": acq_str,
"experiment": ";".join([f"{t}:{c}" for t, c in exp]),
"dtype": str(nd.dtype),
"shape": list(shape),
Expand Down

0 comments on commit 83aaec1

Please sign in to comment.