Make the list of input files for a particular energy bin X psf type
191701
def _make_input_file_list(binnedfile, num_files):
    
    outdir_base = os.path.abspath(os.path.dirname(binnedfile))
    outbasename = os.path.basename(binnedfile)
    filelist = ""
    for i in range(num_files):
        split_key = "%06i" % i
        output_dir = os.path.join(outdir_base, split_key)
        filepath = os.path.join(output_dir,
                                outbasename.replace('.fits', '_%s.fits' % split_key))
        filelist += ' %s' % filepath
    return filelist
881401
def matchingfiles(self, projectpath):
        """"""
        l = []
        for inputtemplate in self.input:
            l += inputtemplate.matchingfiles(projectpath)
        return l
585221
def GenerateDPKGFiles(self, template_path):
    """"""

    # Rename the generated binaries to the correct name.
    template_binary_dir = os.path.join(template_path, "dist/debian/grr-client")
    package_name = config.CONFIG.Get(
        "ClientBuilder.package_name", context=self.context)
    target_binary_dir = os.path.join(
        template_path, "dist/debian/%s%s" %
        (package_name,
         config.CONFIG.Get("ClientBuilder.target_dir", context=self.context)))
    if package_name == "grr-client":
      # Need to rename the template path or the move will fail.
      shutil.move(template_binary_dir, "%s-template" % template_binary_dir)
      template_binary_dir = "%s-template" % template_binary_dir

    utils.EnsureDirExists(os.path.dirname(target_binary_dir))
    shutil.move(template_binary_dir, target_binary_dir)

    shutil.move(
        os.path.join(target_binary_dir, "grr-client"),
        os.path.join(
            target_binary_dir,
            config.CONFIG.Get("Client.binary_name", context=self.context)))

    deb_in_dir = os.path.join(template_path, "dist/debian/debian.in/")

    self.GenerateDirectory(deb_in_dir, os.path.join(
        template_path, "dist/debian"), [("grr-client", package_name)])

    # Generate directories for the /usr/sbin link.
    utils.EnsureDirExists(
        os.path.join(template_path, "dist/debian/%s/usr/sbin" % package_name))

    if config.CONFIG.Get("Client.fleetspeak_enabled", context=self.context):
      self._GenerateFleetspeakConfig(template_path)
      shutil.rmtree(deb_in_dir)
      shutil.rmtree(os.path.join(template_path, "dist", "fleetspeak"))
      return

    # Generate the nanny template. This only exists from client version 3.1.2.5
    # onwards.
    if config.CONFIG["Template.version_numeric"] >= 3125:
      self.GenerateFile(
          os.path.join(target_binary_dir, "nanny.sh.in"),
          os.path.join(target_binary_dir, "nanny.sh"))

    # Generate the upstart template.
    self.GenerateFile(
        os.path.join(template_path, "dist/debian/upstart.in/grr-client.conf"),
        os.path.join(template_path, "dist/debian/%s.upstart" % package_name))

    # Generate the initd template. The init will not run if it detects upstart
    # is present.
    self.GenerateFile(
        os.path.join(template_path, "dist/debian/initd.in/grr-client"),
        os.path.join(template_path, "dist/debian/%s.init" % package_name))

    # Generate the systemd unit file.
    self.GenerateFile(
        os.path.join(template_path,
                     "dist/debian/systemd.in/grr-client.service"),
        os.path.join(template_path, "dist/debian/%s.service" % package_name))

    # Clean up the template dirs.
    shutil.rmtree(deb_in_dir)
    shutil.rmtree(os.path.join(template_path, "dist/debian/upstart.in"))
    shutil.rmtree(os.path.join(template_path, "dist/debian/initd.in"))
    shutil.rmtree(os.path.join(template_path, "dist/debian/systemd.in"))
664256
def getbfs(coords, gbasis):
    """"""

    sym2powerlist = {
        'S' : [(0,0,0)],
        'P' : [(1,0,0),(0,1,0),(0,0,1)],
        'D' : [(2,0,0),(0,2,0),(0,0,2),(1,1,0),(0,1,1),(1,0,1)],
        'F' : [(3,0,0),(2,1,0),(2,0,1),(1,2,0),(1,1,1),(1,0,2),
               (0,3,0),(0,2,1),(0,1,2), (0,0,3)]
        }

    bfs = []
    for i, at_coords in enumerate(coords):
        bs = gbasis[i]
        for sym,prims in bs:
            for power in sym2powerlist[sym]:
                bf = cgbf(at_coords,power)
                for expnt,coef in prims:
                    bf.add_pgbf(expnt,coef)
                bf.normalize()
                bfs.append(bf)

    return bfs
1236842
def stisExt2PrimKw(stisfiles):
    

    kw_list = ['DATE-OBS', 'EXPEND', 'EXPSTART', 'EXPTIME']

    for sfile in stisfiles:
        toclose = False

        if isinstance(sfile, str):
            sfile = fits.open(sfile, mode='update')
            toclose = True

        #d = {}
        for k in kw_list:
            sfile[0].header[k] = sfile[1].header[k]
            sfile[0].header.comments[k] = "Copied from extension header"
        if toclose:
            sfile.close()
36610
def _show_psrs():
    
    sep = os.linesep

    types = "Supported types: " + ", ".join(API.list_types())
    cids = "IDs: " + ", ".join(c for c, _ps in API.list_by_cid())

    x_vs_ps = ["  %s: %s" % (x, ", ".join(p.cid() for p in ps))
               for x, ps in API.list_by_extension()]
    exts = "File extensions:" + sep + sep.join(x_vs_ps)

    _exit_with_output(sep.join([types, exts, cids]))
412752
def get_files(files, extnames=['.root']):
    """"""

    files_out = []
    for f in files:

        mime = mimetypes.guess_type(f)
        if os.path.splitext(f)[1] in extnames:
            files_out += [f]
        elif mime[0] == 'text/plain':
            files_out += list(np.loadtxt(f, unpack=True, dtype='str'))
        else:
            raise Exception('Unrecognized input type.')

    return files_out
456269
def _get_input_files(samples, base_dir, tx_out_dir):
    
    in_files = collections.defaultdict(list)
    for data in samples:
        sum_qc = tz.get_in(["summary", "qc"], data, {})
        if sum_qc in [None, "None"]:
            sum_qc = {}
        elif isinstance(sum_qc, six.string_types):
            sum_qc = {dd.get_algorithm_qc(data)[0]: sum_qc}
        elif not isinstance(sum_qc, dict):
            raise ValueError("Unexpected summary qc: %s" % sum_qc)
        for program, pfiles in sum_qc.items():
            if isinstance(pfiles, dict):
                pfiles = [pfiles["base"]] + pfiles.get("secondary", [])
            # CWL: presents output files as single file plus associated secondary files
            elif isinstance(pfiles, six.string_types):
                if os.path.exists(pfiles):
                    pfiles = [os.path.join(basedir, f) for basedir, subdir, filenames in os.walk(os.path.dirname(pfiles)) for f in filenames]
                else:
                    pfiles = []
            in_files[(dd.get_sample_name(data), program)].extend(pfiles)
    staged_files = []
    for (sample, program), files in in_files.items():
        cur_dir = utils.safe_makedir(os.path.join(base_dir, "inputs", sample, program))
        for f in files:
            if _check_multiqc_input(f) and _is_good_file_for_multiqc(f):
                if _in_temp_directory(f) or any([cwlutils.is_cwl_run(d) for d in samples]):
                    staged_f = os.path.join(cur_dir, os.path.basename(f))
                    shutil.copy(f, staged_f)
                    staged_files.append(staged_f)
                else:
                    staged_files.append(f)
    staged_files.extend(get_qsig_multiqc_files(samples))
    # Back compatible -- to migrate to explicit specifications in input YAML
    if not any([cwlutils.is_cwl_run(d) for d in samples]):
        staged_files += ["trimmed", "htseq-count/*summary"]
        # Add in created target_info file
        if os.path.isfile(os.path.join(base_dir, "report", "metrics", "target_info.yaml")):
            staged_files += [os.path.join(base_dir, "report", "metrics", "target_info.yaml")]
    return sorted(list(set(staged_files)))
733165
def list(path='.'):
    """"""
    import os
    for f in os.listdir(path):
        if isfile(join(path, f)):
            yield join(path, f) if path != '.' else f
763273
def filesfile_string(self):
        """"""
        lines = []
        app = lines.append

        app(self.input_file.path)          # 1) Path of the input file
        app(self.output_file.path)         # 2) Path of the output file
        app(self.ddb_filepath)             # 3) Input derivative database e.g. t13.ddb.in
        app(self.md_filepath)              # 4) Output molecular dynamics e.g. t13.md
        app(self.gkk_filepath)             # 5) Input elphon matrix elements  (GKK file)
        app(self.outdir.path_join("out"))  # 6) Base name for elphon output files e.g. t13
        app(self.ddk_filepath)             # 7) File containing ddk filenames for elphon/transport.

        return "\n".join(lines)
660260
def get_input_files(self):
    
    input_files = list(self.__input_files)
    if isinstance(self.job(), CondorDAGJob):
      input_files = input_files + self.job().get_input_files()
    return input_files
345669
def detect_data_file(input, file_name=""):
    
    _, ext = os.path.splitext(file_name)

    if ext == ".m":
        line = input.readline() # first line
        if line.startswith("function"):
            type = "matpower"
            logger.info("Recognised MATPOWER data file.")
        elif line.startswith("Bus.con" or line.startswith("%")):
            type = "psat"
            logger.info("Recognised PSAT data file.")
        else:
            type = "unrecognised"
        input.seek(0) # reset buffer for parsing

    elif (ext == ".raw") or (ext == ".psse"):
        type = "psse"
        logger.info("Recognised PSS/E data file.")

    elif (ext == ".pkl") or (ext == ".pickle"):
        type = "pickle"
        logger.info("Recognised pickled case.")

    else:
        type = None

    return type
896427
def extract_input_filenames(drzfile):
    
    data_kws = fits.getval(drzfile, 'd*data', ext=0, memmap=False)
    if len(data_kws) == 0:
        return None
    fnames = []
    for kw in data_kws.cards:
        f = kw.value.split('[')[0]
        if f not in fnames:
            fnames.append(f)

    return fnames
470459
def _make_ltcube_file_list(ltsumfile, num_files):
    
    outbasename = os.path.basename(ltsumfile)
    lt_list_file = ltsumfile.replace('fits', 'lst')
    outfile = open(lt_list_file, 'w')
    for i in range(num_files):
        split_key = "%06i" % i
        output_dir = os.path.join(NAME_FACTORY.base_dict['basedir'], 'counts_cubes', split_key)
        filepath = os.path.join(output_dir, outbasename.replace('.fits', '_%s.fits' % split_key))
        outfile.write(filepath)
        outfile.write("\n")
    outfile.close()
    return '@' + lt_list_file
748426
def list_files(x, path=""):
    
    logger_directory.info("enter list_files")
    file_list = []
    if path:
        # list files from target directory
        files = os.listdir(path)
        for file in files:
            if file.endswith(x) and not file.startswith(("$", "~", ".")):
                # join the path and basename to create full path
                file_list.append(os.path.join(path, file))
    else:
        # list files from current working directory
        files = os.listdir()
        for file in files:
            if file.endswith(x) and not file.startswith(("$", "~", ".")):
                # append basename. not full path
                file_list.append(file)
    logger_directory.info("exit list_files")
    return file_list
1038346
def map_input_output(item, api):
    
    if isinstance(item, list):
        return [map_input_output(it, api) for it in item]

    elif isinstance(item, dict) and 'class' in item:
        if item['class'].lower() == 'file':
            return File(id=item['path'], api=api)

    else:
        return item
114580
async def List(self, arches, region, root_storage_type, series, stream, virt_type):
        '''
        
        '''
        # map input types to rpc msg
        _params = dict()
        msg = dict(type='ImageMetadata',
                   request='List',
                   version=2,
                   params=_params)
        _params['arches'] = arches
        _params['region'] = region
        _params['root-storage-type'] = root_storage_type
        _params['series'] = series
        _params['stream'] = stream
        _params['virt-type'] = virt_type
        reply = await self.rpc(msg)
        return reply