def query_result_fname(qaid, qauuid, cfgstr, ext='.npz', hack27=False): """ Builds a filename for a queryresult Args: qaid (int): query annotation rowid qauuid (uuid.UUID): query annotation unique universal id cfgstr (str): query parameter configuration string ext (str): filetype extension """ import warnings warnings.warn('Should be using new chip_match structure') #fname_fmt = 'res_{cfgstr}_qaid={qaid}_qauuid={quuid}{ext}' fname_fmt = 'qaid={qaid}_res_{cfgstr}_quuid={quuid}{ext}' quuid_str = str(qauuid)[0:8] if TRUNCATE_UUIDS else str(qauuid) fmt_dict = dict(cfgstr=cfgstr, qaid=qaid, quuid=quuid_str, ext=ext) #fname = fname_fmt.format(**fmt_dict) fname = ut.long_fname_format(fname_fmt, fmt_dict, ['cfgstr'], max_len=MAX_FNAME_LEN, hack27=hack27) # condence the filename if it is too long (grumble grumble windows) #if (not FORCE_LONGNAME) and len(fname) > 64: #if len(fname) > MAX_FNAME_LEN: # hash_id = ut.hashstr(cfgstr) # fname = fname_fmt.format( # cfgstr=hash_id, qaid=qaid, quuid=quuid_str, ext=ext) return fname
def get_word_dname(wx, metrics): stats_ = metrics.wx2_wdist_stats[wx] wname_clean = 'wx=%06d' % wx stats1 = 'max={max},min={min},mean={mean},'.format(**stats_) stats2 = 'std={std},nMaxMin=({nMax},{nMin}),shape={shape}'.format(**stats_) fname_fmt = wname_clean + '_{stats1}{stats2}' fmt_dict = dict(stats1=stats1, stats2=stats2) word_dname = ut.long_fname_format(fname_fmt, fmt_dict, ['stats2', 'stats1'], max_len=250, hashlen=4) return word_dname
def prepare_figure_fpath(fig, fpath, fnum, usetitle, defaultext, verbose, dpath=None): if fpath is None or usetitle: if fig._suptitle is not None: # safer than using the canvas window title # that only works in qt title = 'fig(%r) ' % (fig.number, ) + fig._suptitle.get_text() else: title = fig.canvas.get_window_title() if fpath is None: fpath = sanitize_img_fname(title) elif usetitle: title = sanitize_img_fname(title) fpath = join(fpath, title) # Split into dpath, fname, and extension dpath_, fname_ = split(fpath) if dpath is None: dpath = dpath_ fname, ext = splitext(fname_) # Add the extension back if it wasnt a real extension if ext not in ut.IMG_EXTENSIONS and ext != '.pdf': fname += ext ext = '' # Add in DPI information # size_suffix = 'DPI=%r_WH=%d,%d' % (custom_constants.DPI, custom_constants.FIGSIZE[0], custom_constants.FIGSIZE[1]) add_render_suffix = False if add_render_suffix: size_suffix = 'DPI=%r_WH=%d,%d' % ( fig.dpi, int(fig.get_figwidth()), int(fig.get_figheight()), ) else: size_suffix = '' # Sanatize fname = sanitize_img_fname(fname) ext = sanitize_img_ext(ext, defaultext) # Format safely fname_fmt = '{fname}_{size_suffix}{ext}' fmt_dict = dict(fname=fname, ext=ext, size_suffix=size_suffix) if verbose > 1: print('[custom_figure] Formating long name') fname_clean = ut.long_fname_format(fname_fmt, fmt_dict, ['size_suffix', 'fname'], max_len=155, hashlen=8) # Normalize extension fpath_clean = join(dpath, fname_clean) return fpath_clean
def append_copy_task(self, fpath_orig, dstdir=None): """ helper which copies a summary figure to root dir """ fname_orig, ext = splitext(basename(fpath_orig)) outdir = dirname(fpath_orig) fdir_clean, cfgdir = split(outdir) if dstdir is None: dstdir = fdir_clean #aug = cfgdir[0:min(len(cfgdir), 10)] aug = cfgdir fname_fmt = '{aug}_{fname_orig}{ext}' fmt_dict = {'aug': aug, 'fname_orig': fname_orig, 'ext': ext} fname_clean = ut.long_fname_format(fname_fmt, fmt_dict, ['fname_orig'], max_len=128) fdst_clean = join(dstdir, fname_clean) self.cp_task_list.append((fpath_orig, fdst_clean))
def prepare_figure_fpath(fig, fpath, fnum, usetitle, defaultext, verbose, dpath=None): if fpath is None or usetitle: if fig._suptitle is not None: # safer than using the canvas window title # that only works in qt title = 'fig(%r) ' % (fig.number,) + fig._suptitle.get_text() else: title = fig.canvas.get_window_title() if fpath is None: fpath = sanitize_img_fname(title) elif usetitle: title = sanitize_img_fname(title) fpath = join(fpath, title) # Split into dpath, fname, and extension dpath_, fname_ = split(fpath) if dpath is None: dpath = dpath_ fname, ext = splitext(fname_) # Add the extension back if it wasnt a real extension if ext not in ut.IMG_EXTENSIONS and ext != '.pdf': fname += ext ext = '' # Add in DPI information #size_suffix = 'DPI=%r_WH=%d,%d' % (custom_constants.DPI, custom_constants.FIGSIZE[0], custom_constants.FIGSIZE[1]) add_render_suffix = False if add_render_suffix: size_suffix = 'DPI=%r_WH=%d,%d' % (fig.dpi, int(fig.get_figwidth()), int(fig.get_figheight())) else: size_suffix = '' # Sanatize fname = sanitize_img_fname(fname) ext = sanitize_img_ext(ext, defaultext) # Format safely fname_fmt = '{fname}_{size_suffix}{ext}' fmt_dict = dict(fname=fname, ext=ext, size_suffix=size_suffix) if verbose > 1: print('[custom_figure] Formating long name') fname_clean = ut.long_fname_format(fname_fmt, fmt_dict, ['size_suffix', 'fname'], max_len=155, hashlen=8) # Normalize extension fpath_clean = join(dpath, fname_clean) return fpath_clean