# File naming conventions for MagellanMapperimportosfromtypingimportOptional,Tuplefrommagmap.ioimportlibmag
[docs]defmake_subimage_name(base:str,offset:Optional[Tuple[int,int,int]]=None,shape:Optional[Tuple[int,int,int]]=None,suffix:Optional[str]=None)->str:"""Make name of subimage for a given offset and shape. The order of ``offset`` and ``shape`` are assumed to be in ``z, y, x`` but will be reversed for the output name since the user-oriented ordering is ``x, y, z``. Args: base: Start of name, which can include full parent path. offset: Offset as a tuple; defaults to None to ignore sub-image. shape: Shape as a tuple; defaults to None to ignore sub-image. suffix: Suffix to append, replacing any existing extension in ``base``; defaults to None. Returns: Name (or path) to subimage. """name=baseifoffsetisnotNoneandshapeisnotNone:# sub-image offset/shape stored as z,y,x, but file named as x,y,zroi_site="{}x{}".format(offset[::-1],shape[::-1]).replace(" ","")name=libmag.insert_before_ext(base,roi_site,"_")ifsuffix:name=libmag.combine_paths(name,suffix)print("subimage name: {}".format(name))returnname
[docs]defget_roi_path(path,offset,roi_size=None):"""Get a string describing an ROI for an image at a given path. Args: path (str): Path to include in string, without extension. offset (List[int]): Offset of ROI. roi_size (List[int]): Shape of ROI; defaults to None to ignore. Returns: str: String with ``path`` without extension followed immediately by ``offset`` and ``roi_size`` as tuples, with all spaces removed. """size=""ifroi_sizeisnotNone:size="x{}".format(tuple(roi_size))return"{}_offset{}{}".format(os.path.splitext(path)[0],tuple(offset),size).replace(" ","")