bluesky / suitcase-tiff

http://nsls-ii.github.io/suitcase
Other
2 stars 5 forks source link

tiff-series exporter does not support empty directory kwarg on Windows #20

Open EliotGann opened 5 years ago

EliotGann commented 5 years ago

Created by @mrakitin while trying suitcase-tiff exported at SST-2/RSOXS.

It is also true for all suitcases.

Current behavior:

In [14]: tiff_series.export(db[-1].documents(fill=True), file_prefix='test', directory='')
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-14-c77817249410> in <module>
----> 1 tiff_series.export(db[-1].documents(fill=True), file_prefix='test', directory='')

c:\users\greateyes\appdata\local\conda\conda\envs\collection-2019-1.2-rsoxs\lib\site-packages\suitcase\tiff_series\__init__.py in export(gen, directory, file_prefix, bigtiff, byteorder, imagej, **kwargs)
     99                     **kwargs) as serializer:
    100         for item in gen:
--> 101             serializer(*item)
    102
    103     return serializer.artifacts

c:\users\greateyes\appdata\local\conda\conda\envs\collection-2019-1.2-rsoxs\lib\site-packages\event_model\__init__.py in __call__(self, name, doc, validate)
     69             instance as doc, a copy of doc, or a different dict altogether.
     70         """
---> 71         output_doc = getattr(self, name)(doc)
     72         if validate:
     73             jsonschema.validate(output_doc,

c:\users\greateyes\appdata\local\conda\conda\envs\collection-2019-1.2-rsoxs\lib\site-packages\suitcase\tiff_series\__init__.py in event(self, doc)
    223                 filename = (f'{self._templated_file_prefix}'
    224                             f'{streamname}-{field}-{num}.tiff')
--> 225                 file = self._manager.open('stream_data', filename, 'xb')
    226                 tw = TiffWriter(file, **self._init_kwargs)
    227                 self._tiff_writers[streamname][field+f'-{num}'] = tw

c:\users\greateyes\appdata\local\conda\conda\envs\collection-2019-1.2-rsoxs\lib\site-packages\suitcase\utils\__init__.py in open(self, label, postfix, mode, encoding, errors)
    121                 f'to be one of {self._allowed_modes}')
    122         filepath = self.reserve_name(label, postfix)
--> 123         os.makedirs(os.path.dirname(filepath), exist_ok=True)
    124         f = open(filepath, mode=mode, encoding=encoding, errors=errors)
    125         self._files.append(f)

c:\users\greateyes\appdata\local\conda\conda\envs\collection-2019-1.2-rsoxs\lib\os.py in makedirs(name, mode, exist_ok)
    218             return
    219     try:
--> 220         mkdir(name, mode)
    221     except OSError:
    222         # Cannot rely on checking for EEXIST, since the operating system

FileNotFoundError: [WinError 3] The system cannot find the path specified: ''

In [15]: tiff_series.export(db[-1].documents(fill=True), file_prefix='test', directory='')

Expected behavior:

If the directory kwarg is '' or '.', it should properly recognize it and convert to current directory, as it does it on Linux (with e.g. os.getcwd()).

danielballan commented 5 years ago

Thanks for the report. I think the simplest fix here would be to change the default value of directory to '.', if that works. I was actually surprised that '' works on Linux; it seems improper or at least unusual. Can you confirm that directory='.' works on Windows --- i.e. that it resolves to the current working directory?

mrakitin commented 5 years ago

No, it does not work on Windows. We tested multiple scenarios, and the only thing which worked was os.getcwd().

danielballan commented 5 years ago

Interesting. On Windows, CPython sets os.path.curdir to '.' so I would expect '.' to work. Maybe it doesn't join properly with the rest of the path. Can we see the traceback when you try to use '.', @EliotGann? (The example above just shows ''.)