tlambert03 / nd2

Full-featured nd2 (Nikon NIS Elements) file reader for python. Outputs to numpy, dask, and xarray. Exhaustive metadata extraction
https://tlambert03.github.io/nd2
BSD 3-Clause "New" or "Revised" License
54 stars 15 forks source link

Issue with saving nd2 to ome-tiff #225

Closed BornKrefeld closed 6 months ago

BornKrefeld commented 6 months ago

Description

Describe what you were trying to get done. Tell us what happened, what went wrong, and what you expected to happen.

Intention was to save a nd2 file to ome-tiff with interpreter nd2 and ome-tiff

What I Did

read nd2 and save as ome_types

import nd2 import ome_types

or open a file with nd2.ND2File

f = nd2.ND2File('Test2202_ecoliatcc25922_growthonchip_4chips_xy001.nd2')

with nd2.ND2File ( 'Test2202_ecoliatcc25922_growthonchip_4chips_xy001.nd2' ) as myfile: myfile.write_tiff ( 'myfile.ome.tiff', progress = True )

f.close() # don't forget to close when not using a context manager! f.closed # boolean, whether the file is closed

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

C:\Users\Born\venv\Scripts\python.exe "C:\Users\Born\PycharmProjects\python bio process Pims_DA_NA\DS_ND2 Data save to OME_Tiff.py" 
Traceback (most recent call last):
  File "C:\Users\Born\PycharmProjects\python bio process Pims_DA_NA\DS_ND2 Data save to OME_Tiff.py", line 9, in <module>
    myfile.write_tiff ( 'myfile.ome.tiff', progress = True )
  File "C:\Users\Born\venv\Lib\site-packages\nd2\nd2file.py", line 874, in write_tiff
    return nd2_to_tiff(
           ^^^^^^^^^^^^
  File "C:\Users\Born\venv\Lib\site-packages\nd2\tiff.py", line 138, in nd2_to_tiff
    ome = nd2_ome_metadata(
          ^^^^^^^^^^^^^^^^^
  File "C:\Users\Born\venv\Lib\site-packages\nd2\_ome.py", line 181, in nd2_ome_metadata
    m.Image(
  File "C:\Users\Born\venv\Lib\site-packages\ome_types\_mixins\_base_type.py", line 104, in __init__
    super().__init__(**data)
  File "C:\Users\Born\venv\Lib\site-packages\pydantic\main.py", line 171, in __init__
    self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 1 validation error for Image
acquisition_date
  Input should be a valid datetime or date, invalid character in year [type=datetime_from_date_parsing, input_value='22.02.2024  15:29:04', input_type=str]
    For further information visit https://errors.pydantic.dev/2.6/v/datetime_from_date_parsing
sys:1: UserWarning: ND2File file not closed before garbage collection. Please use `with ND2File(...):` context or call `.close()`.

Process finished with exit code 1
tlambert03 commented 6 months ago

thanks @BornKrefeld ... this is the same issue as #221 , but it looks like you have another different date format than @rysk-t did. Let me contact the folks at LIM who wrote the nd2sdk to get some input on how best to parse date information from an nd2 file