def write(filename, source, header=None, **kwargs): """Write data into to raw/mhd file pair Arguments --------- filename : str The file name of the raw/mhd file. source : source specification The source to write as mhd/raw file. Returns ------- filename : str The filename of the mhd file. """ import ClearMap.IO.IO as io fext = io.file_extension(filename) if fext == "raw": header_name = filename[:-3] + 'mhd' raw_name = filename elif fext == 'mhd': header_name = filename raw_name = filename[:-3] + 'raw' else: header_name = filename + '.mhd' raw_name = filename + '.raw' hdm_header = header_from_source(source, header=header) write_header(header_name, hdm_header) write_raw(raw_name, source) return header_name
def write_color_palette(filename=None): """Creates a pal or lut file for imaris or imagej based on label colors of atlas. Arguments --------- filename : str The name of the color palette file. Returns ------- filename : str The name of the file to which the color palette was written. """ cm = color_map(alpha=False, as_int=True) fext = io.file_extension(filename) if fext == 'pal': col.write_PAL(filename, cm) elif fext == 'lut': col.write_LUT(filename, cm) else: raise RuntimeError('color pallete format: %s not lut or pal' % fext) return filename
def info(self, tile_axes = None, check_extensions = True): s = self.__str__() + '\n'; l = np.max([len(k) for k in self.file_type_to_name]); l = '%' + '%d' % l + 's'; for k,v in self.file_type_to_name.items(): if len(te.Expression(v).tags) > 0: if check_extensions: files = self.file_list(k, extension='*'); extensions = [io.file_extension(f) for f in files]; extensions = np.unique(extensions); #print(extensions) else: extensions = [self.extension(k)]; if len(extensions) == 0: s += l % k + ': no file\n'; else: kk = k; for extension in extensions: expression = te.Expression(self.filename(k, extension=extension)); tag_names = expression.tag_names(); if tile_axes is None: tile_axes_ = tag_names; else: tile_axes_ = tile_axes; for n in tile_axes_: if not n in tag_names: raise ValueError('The expression does not have the named pattern %s' % n); for n in tag_names: if not n in tile_axes_: raise ValueError('The expression has the named pattern %s that is not in tile_axes=%r' % (n, tile_axes_)); #construct tiling files = io.file_list(expression); if len(files) > 0: tile_positions = [expression.values(f) for f in files]; tile_positions = [tuple(tv[n] for n in tile_axes_) for tv in tile_positions]; tile_lower = tuple(np.min(tile_positions, axis = 0)); tile_upper = tuple(np.max(tile_positions, axis = 0)); tag_names = tuple(tag_names); if kk is not None: s += (l % kk) + ': ' kk = None; else: s += (l % '') + ' ' s+= ('%s {%d files, %r: %r -> %r}' % (expression.string()[len(self.directory)+1:], len(files), tag_names, tile_lower, tile_upper)) + '\n'; else: fname = self.filename(k); files = []; if io.is_file(fname): files += [fname]; fname = self.filename(k, postfix = '*'); files += io.file_list(fname); if len(files) > 0: files = [f[len(self.directory)+1:] for f in files] s += l % k + ': ' + files[0] + '\n' for f in files[1:]: s += l % '' + ' ' + f + '\n' else: s += l % k + ': no file\n'; print(s);