def upload(self, from_path, to_path): """ :param Text from_path: :param Text to_path: """ # Emulate s3's flat storage by automatically creating directory path _make_local_path(_os.path.dirname(to_path)) # Write the object to a local file in the sandbox _copyfile(from_path, to_path)
def copyfile(old_fname, new_fname): """ Wrapper to copy a file """ if (RANK == 0): try: _copyfile(old_fname, new_fname) except: _copyfile(old_fname + '.npy', new_fname + '.npy')
def save(self, filename, latex='lualatex'): with open(self._wdirname / 'Figure_{}.tikz'.format(self.index), 'w') as f: self.write(f) rv = _run(['latexmk', "-{}".format(latex), "-silent", "-jobname=Figure_{}".format(self.index), self.viewdir / 'viewtemplate.tex'], cwd=self._wdir.name) if rv.returncode != 0: with open(self._wdirname / 'Figure_{}.log'.format(self.index)) as f: print(f.read()) else: _copyfile(self._wdirname / 'Figure_{}.pdf'.format(self.index), filename)
def copyfile(src, dst): """ Copy data from src to dst. Change OVERRIDE mode to specify the operation when dst existed. Examples -------- .. code-block :: python # to change the OVERRIDE operation from longling.Architecture import config config.OVERRIDE = False # skip existed dst config.OVERRIDE = None # use console input to determine config.OVERRIDE = False # override existed dst """ if override_check(dst): _copyfile(src, dst)
def make_pelican_starter_project(c, path): _make_sure_path_not_exists_but_parent_directory_does(path) _mkdir(path) _make_empty_content_tree(_join(path, 'content')) _mkdir(_join(path, 'output')) # skipping Makefile for now src = _build_starter_dir_path() # Copy over the config file (warnings without) this = 'pelicanconf.py' _copyfile(_join(src, this), _join(path, this)) # Copy the two pages over head = 'content', 'pages' for tail in 'my-one-page.md', 'my-other-page.md': this = (*head, tail) _copyfile(_join(src, *this), _join(path, *this))
def __init__(self, root, base_dir, use_nestcheck, transform=None, overwrite_transformed=False, **kwargs): filerootpath = _os.path.join(base_dir, root) _filerootpath = filerootpath if transform is not None: samples = _np.loadtxt(filerootpath + '.txt') ndims = samples.shape[1] - 2 temp = transform(samples[0, 2:], old_API=True) ntransform = len(temp) - ndims _exists = _os.path.isfile(filerootpath + '_transformed.txt') if not _exists or overwrite_transformed: transformed = _np.zeros( (samples.shape[0], samples.shape[1] + ntransform)) transformed[:, :2] = samples[:, :2] for i in range(samples.shape[0]): transformed[i, 2:] = transform(samples[i, 2:], old_API=True) _np.savetxt(filerootpath + '_transformed.txt', transformed) filerootpath += '_transformed' root += '_transformed' super(NestedBackend, self).__init__(filepath=filerootpath + '.txt', **kwargs) if getdist is not None: # getdist backend self._gd_bcknd = MCSamples( root=filerootpath, settings=self.kde_settings, sampler='nested', names=self.names, ranges=self.bounds, labels=[self.labels[name] for name in self.names]) self._gd_bcknd.readChains(getdist.chains.chainFiles(filerootpath)) self.use_nestcheck = use_nestcheck if self.use_nestcheck: # nestcheck backend if transform is not None: for ext in ['dead-birth.txt', 'phys_live-birth.txt']: _exists = _os.path.isfile(filerootpath + ext) if not _exists or overwrite_transformed: samples = _np.loadtxt(_filerootpath + ext) transformed = _np.zeros( (samples.shape[0], samples.shape[1] + ntransform)) transformed[:, ndims + ntransform:] = samples[:, ndims:] for i in range(samples.shape[0]): transformed[i,:ndims+ntransform] =\ transform(samples[i,:ndims], old_API=True) _np.savetxt(filerootpath + ext, transformed) # .stats file with same root needed, but do not need to modify # the .stats file contents if not _os.path.isfile(filerootpath + '.stats'): if _os.path.isfile(_filerootpath + '.stats'): try: from shutil import copyfile as _copyfile except ImportError: pass else: _copyfile(_filerootpath + '.stats', filerootpath + '.stats') try: kwargs['implementation'] except KeyError: print('Root %r sampling implementation not specified... ' 'assuming MultiNest for nestcheck...') self._nc_bcknd = process_multinest_run(root, base_dir=base_dir) else: if kwargs['implementation'] == 'multinest': self._nc_bcknd = process_multinest_run(root, base_dir=base_dir) elif kwargs['implementation'] == 'polychord': self._nc_bcknd = process_polychord_run(root, base_dir=base_dir) else: raise ValueError('Cannot process with nestcheck.')
def download(self, from_path, to_path): """ :param Text from_path: :param Text to_path: """ _copyfile(from_path, to_path)
def copyfile(src, dst): print " copying from %s to %s" % (src, dst) return _copyfile(src, dst)
def download(self, from_path, to_path): """ :param Text from_path: :param Text to_path: """ _copyfile(strip_file_header(from_path), strip_file_header(to_path))