Exemple #1
0
    def __init__(self, hawc2_path, hawc2_cmd, htc_file, exe_dir, input_files, output_files, queue='workq', walltime='00:10:00'):
        self.hawc2_path = hawc2_path
        self.hawc2_cmd = hawc2_cmd
        self.htc_file = htc_file
        self.exe_dir = exe_dir
        self.queue = queue
        self.walltime = walltime

        if not os.path.isabs(htc_file):
            htc_file = pjoin(exe_dir, htc_file)
        else:
            htc_file = htc_file.replace("\\", "/")

        if htc_file not in input_files:
            input_files.append(htc_file)
        self.input_files = [abspath((pjoin(exe_dir, f), abspath(f))[os.path.isabs(f)])
                            for f in input_files]
        self.htc_file = relpath(htc_file, exe_dir)

        self.output_files = [abspath((pjoin(exe_dir, f), abspath(f))[os.path.isabs(f)])
                             for f in output_files]

        self.model_path = abspath(pjoin(exe_dir, relpath(os.path.commonprefix(
            self.input_files + self.output_files).rpartition("/")[0], exe_dir)))
        self.model_name = os.path.basename(abspath(self.model_path))
        self.jobname = os.path.splitext(os.path.basename(htc_file))[0]

        PBSFile.__init__(self, self.model_path, self.jobname, self.commands, queue, walltime=walltime)
    def __init__(self,
                 workdir,
                 jobname,
                 commands,
                 queue='workq',
                 walltime='00:10:00',
                 nodes=1,
                 ppn=1,
                 merge_std=True):
        """Description

        Parameters
        ----------
        walltime : int, str
            wall time as string ("hh:mm:ss") or second (integer)

        """
        self.workdir = workdir
        self.jobname = jobname
        self.commands = commands
        self.queue = queue
        self.walltime = walltime
        self.nodes = nodes
        self.ppn = ppn
        self.merge_std = merge_std
        self.stdout_filename = pjoin(workdir, './stdout/%s.out' % jobname)
        self.filename = "pbs_in/%s.in" % self.jobname
    def auto_detect_modelpath(self):
        if self.filename is None:
            return "../"

        #print (["../"*i for i in range(3)])
        import numpy as np
        input_files = HTCFile(self.filename, 'unknown').input_files()
        if len(input_files) == 1:  # only input file is the htc file
            return "../"
        rel_input_files = [f for f in input_files if not os.path.isabs(f)]

        def isfile_case_insensitive(f):
            try:
                f = fixcase(f)  # raises exception if not existing
                return os.path.isfile(f)
            except IOError:
                return False
        found = ([np.sum([isfile_case_insensitive(os.path.join(os.path.dirname(self.filename), "../" * i, f))
                          for f in rel_input_files]) for i in range(4)])

        if max(found) > 0:
            relpath = "../" * np.argmax(found)
            return abspath(pjoin(os.path.dirname(self.filename), relpath))
        else:
            raise ValueError(
                "Modelpath cannot be autodetected for '%s'.\nInput files not found near htc file" % self.filename)