示例#1
0
 def init_default_param(self, dic_param):
     """Initialise the parameters as defined in the input dictionary
     Hardcoded in init_musepipe.py
     """
     for key in dic_param.keys():
         if self.verbose:
             mpipe.print_info(
                 "Default initialisation of attribute {0}".format(key))
         setattr(self, key, dic_param[key])
示例#2
0
 def _set_cpu(self, first_cpu=0, ncpu=24, list_cpu=None) :
     """Setting the cpu format for calling the esorex command
     """
     if (list_cpu is None) | (len(list_cpu) < 1):
         self.list_cpu = "{0}-{1}".format(first_cpu, first_cpu + ncpu - 1)
     else :
         self.list_cpu = "{0}".format(list_cpu[0])
         for i in range(1, len(list_cpu)) :
             self.list_cpu += ":{0}".format(list_cpu[i])
     if self.verbose:
         mpipe.print_info("LIST_CPU: {0}".format(self.list_cpu))
示例#3
0
    def __init__(self, galaxyname=None, pointing=1):
        if galaxyname not in MUSEPIPE_sample.keys():
            mpipe.print_error(
                "ERROR: no Galaxy named {gal} in the defined sample".format(
                    gal=galaxyname))
            return

        mpipe.print_info("Initialising Target {name}".format(name=galaxyname))
        self.targetname = galaxyname
        self.info_pointings = MUSEPIPE_sample[galaxyname]
        if pointing not in self.info_pointings.keys():
            mpipe.print_error(
                "ERROR: no pointing {pointing} for the Galaxy".format(
                    pointing))
            return
        self.pointing = pointing
        self.run = self.info_pointings[pointing]
示例#4
0
    def write_sof(self, sof_filename, sof_folder=None, new=False, verbose=None) :
        """Feeding an sof file with input filenames from a dictionary
        """
        # Setting the default SOF folder if not provided
        if sof_folder is None : sof_folder = self.paths.sof

        # Removing the extension of the file if already set
        if not sof_filename.lower().endswith(".sof") :
            sof_filename = sof_filename + ".sof"

        sof = joinpath(sof_folder, sof_filename)
        # If new file, start from scratch (overwrite)
        if new :
            sof_file = open(sof, "w+")
            if verbose :
                mpipe.print_info("Writing in file {0}".format(sof))
        # if not new, then append
        else :
            sof_file = open(sof, "a")
            if verbose :
                mpipe.print_info("Appending in file {0}".format(sof))
    
        # Use dictionary to write up the lines
        for key in self._sofdict.keys() :
            for item in self._sofdict[key] :
                text_to_write = "{0} {1}\n".format(item, key)
                sof_file.write(text_to_write)
                if verbose :
                    mpipe.print_info(text_to_write)

        sof_file.close()
        # Returning the current sof as relative path
        self.current_sof = mpipe.normpath(os.path.relpath(sof))
示例#5
0
    def read_param_file(self, filename, dic_param):
        """Reading an input parameter initialisation file 
        """
        # Testing existence of filename
        if not os.path.isfile(filename):
            mpipe.print_info(
                ("ERROR: input parameter {inputname} cannot be found. "
                 "We will use the default hardcoded in the "
                 "init_musepipe.py module").format(inputname=filename))
            return

        # If it exists, open and read it
        f_param = open(filename)
        lines = f_param.readlines()

        # Dummy dictionary to see which items are not initialised
        dummy_dic_param = copy.copy(dic_param)
        for line in lines:
            if line[0] in ["#", "%"]: continue

            sline = line.split()
            if sline[0] in dic_param.keys():
                if self.verbose:
                    mpipe.print_info("Initialisation of attribute {0}".format(
                        sline[0]))
                setattr(self, sline[0], sline[1])
                # Here we drop the item which was initialised
                val = dummy_dic_param.pop(sline[0])
            else:
                continue

        # Set of non initialised folders
        not_initialised_param = dummy_dic_param.keys()
        # Listing them as warning and using the hardcoded default
        for key in not_initialised_param:
            mpipe.print_info(("WARNING: parameter {param} not initialised "
                              "We will use the default hardcoded value from "
                              "init_musepipe.py").format(param=key))
            setattr(self, key, dic_param[key])