def commands(self): rel_exe_dir = relpath(abspath(self.exe_dir), abspath(self.modelpath)) copy_input_to_scratch, copy_input_to_exe_dir = self.copy_input() return template(copy_hawc2=self.copy_hawc2(), exe_dir=cluster_path(self.exe_dir), copy_input_to_scratch=copy_input_to_scratch, copy_input_to_exe_dir=copy_input_to_exe_dir, rel_exe_dir=rel_exe_dir, hawc2_cmd=self.hawc2_cmd, htc_file=self.htc_file, jobname=self.jobname, copy_output=self.copy_output(), modelpath=cluster_path(self.modelpath), modelname=self.modelname)
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)
def __init__(self, filename=None, modelpath=None, jinja_tags={}): """ Parameters --------- filename : str Absolute filename of htc file modelpath : str Model path relative to htc file """ if filename is not None: try: filename = fixcase(abspath(filename)) with self.open(str(filename)): pass except Exception: pass self.filename = filename self.jinja_tags = jinja_tags self.modelpath = modelpath or self.auto_detect_modelpath() if filename and self.modelpath != "unknown" and not os.path.isabs(self.modelpath): drive, p = os.path.splitdrive(os.path.join(os.path.dirname(str(self.filename)), self.modelpath)) self.modelpath = os.path.join(drive, os.path.splitdrive(os.path.realpath(p))[1]).replace("\\", "/") if self.modelpath != 'unknown' and self.modelpath[-1] != '/': self.modelpath += "/"
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)