@@ -38,8 +38,13 @@ def parse_path(path, prefix=""):
3838 - `path` : The same as `full`, up to (including) the last separator.
3939 - `dname` : The segment between the last two separators (directory).
4040 - `fname` : The segment after the last separator (filename).
41- - `basename` : The filename without extension.
42- - `ext` : The filename extension, containing max 1 dot (included).
41+ - `basename` : The filename without extension. Note that *OME-TIFF*
42+ files (having a suffix like `.ome.tif` or `.ome.tiff`) are treated as
43+ special case in the sense that the `.ome` part is also stripped from
44+ the basename and added to the `ext` key (see below).
45+ - `ext` : The filename extension, containing max 1 dot (included) with
46+ the special case of `.ome.tif` / `.ome.tiff` where 2 dots are
47+ contained to represent the full suffix.
4348
4449 Examples
4550 --------
@@ -76,6 +81,17 @@ def parse_path(path, prefix=""):
7681 'basename': 'file',
7782 'orig': 'C:\\Temp\\foo\\file.ext',
7883 'path': 'C:/Temp/foo/'}
84+
85+ Special treatment for *OME-TIFF* suffixes:
86+
87+ >>> parse_path("/path/to/some/nice.OME.tIf")
88+ {'basename': 'nice',
89+ 'dname': 'some',
90+ 'ext': '.OME.tIf',
91+ 'fname': 'nice.OME.tIf',
92+ 'full': '/path/to/some/nice.OME.tIf',
93+ 'orig': '/path/to/some/nice.OME.tIf',
94+ 'path': '/path/to/some/'}
7995 """
8096 path = str (path )
8197 if prefix :
@@ -90,9 +106,12 @@ def parse_path(path, prefix=""):
90106 parsed ["path" ] = os .path .dirname (path ) + sep
91107 parsed ["fname" ] = os .path .basename (path )
92108 parsed ["dname" ] = os .path .basename (os .path .dirname (parsed ["path" ]))
93- split_ext = os .path .splitext (parsed ["fname" ])
94- parsed ["ext" ] = split_ext [1 ]
95- parsed ["basename" ] = split_ext [0 ]
109+ base , ext = os .path .splitext (parsed ["fname" ])
110+ parsed ["ext" ] = ext
111+ parsed ["basename" ] = base
112+ if base .lower ().endswith (".ome" ) and ext .lower ().startswith (".tif" ):
113+ parsed ["basename" ] = base [:- 4 ]
114+ parsed ["ext" ] = base [- 4 :] + ext
96115
97116 return parsed
98117
@@ -178,8 +197,8 @@ def image_basename(orig_name):
178197 ----------
179198 orig_name : str
180199
181- Example
182- -------
200+ Examples
201+ --------
183202 >>> image_basename('/path/to/some_funny_image_file_01.png')
184203 'some_funny_image_file_01'
185204
@@ -189,10 +208,7 @@ def image_basename(orig_name):
189208 >>> image_basename('/tmp/FoObAr.OMe.tIf')
190209 'FoObAr'
191210 """
192- base = os .path .splitext (os .path .basename (orig_name ))[0 ]
193- if base .lower ().endswith (".ome" ):
194- base = base [:- 4 ]
195- return base
211+ return parse_path (orig_name )["basename" ]
196212
197213
198214def gen_name_from_orig (path , orig_name , tag , suffix ):
0 commit comments