コード例 #1
0
ファイル: pgn.py プロジェクト: sjsprecious/cime
    def _generate_baseline(self):
        super(PGN, self)._generate_baseline()

        basegen_dir = os.path.join(
            self._case.get_value("BASELINE_ROOT"), self._case.get_value("BASEGEN_CASE")
        )

        rundir = self._case.get_value("RUNDIR")
        casename = self._case.get_value("CASE")

        var_list = self.get_var_list()
        nvar = len(var_list)
        nprt = len(PERTURBATIONS)
        rmse_prototype = {}
        for icond in range(NUMBER_INITIAL_CONDITIONS):
            prt_rmse = {}
            for iprt, prt_name in enumerate(PERTURBATIONS):
                if prt_name == "woprt":
                    continue
                iinst_ctrl = pg._sub2instance(icond, 0, nprt)
                ifile_ctrl = os.path.join(
                    rundir,
                    INSTANCE_FILE_TEMPLATE.format(
                        casename + ".", self.atmmod, iinst_ctrl, "_woprt"
                    ),
                )

                iinst_test = pg._sub2instance(icond, iprt, nprt)
                ifile_test = os.path.join(
                    rundir,
                    INSTANCE_FILE_TEMPLATE.format(
                        casename + ".", self.atmmod, iinst_test, "_" + prt_name
                    ),
                )

                prt_rmse[prt_name] = pg.variables_rmse(
                    ifile_test, ifile_ctrl, var_list, "t_"
                )
            rmse_prototype[icond] = pd.concat(prt_rmse)
        rmse = pd.concat(rmse_prototype)
        cld_rmse = np.reshape(
            rmse.RMSE.values, (NUMBER_INITIAL_CONDITIONS, nprt - 1, nvar)
        )

        pg.rmse_writer(
            os.path.join(rundir, FCLD_NC),
            cld_rmse,
            list(PERTURBATIONS.keys()),
            var_list,
            INIT_COND_FILE_TEMPLATE,
            "cam",
        )

        logger.debug("PGN_INFO:copy:{} to {}".format(FCLD_NC, basegen_dir))
        shutil.copy(os.path.join(rundir, FCLD_NC), basegen_dir)
コード例 #2
0
ファイル: pgn.py プロジェクト: fmyuan/cime
    def run_phase(self):
        logger.debug("PGN_INFO: RUN PHASE")

        self.run_indv()

        # Here were are in case directory, we need to go to the run directory
        # and rename files
        rundir = self._case.get_value("RUNDIR")
        casename = self._case.get_value("CASE")
        logger.debug("PGN_INFO: Case name is:{}".format(casename))

        for icond in range(NUMBER_INITIAL_CONDITIONS):
            for iprt, (prt_name,
                       prt_value) in enumerate(PERTURBATIONS.items()):
                iinst = pg._sub2instance(icond, iprt, len(PERTURBATIONS))
                fname = os.path.join(
                    rundir,
                    INSTANCE_FILE_TEMPLATE.format(casename + '.', self.atmmod,
                                                  iinst, ''))
                renamed_fname = re.sub(r'\.nc$', '_{}.nc'.format(prt_name),
                                       fname)

                logger.debug("PGN_INFO: fname to rename:{}".format(fname))
                logger.debug("PGN_INFO: Renamed file:{}".format(renamed_fname))
                try:
                    shutil.move(fname, renamed_fname)
                except IOError:
                    CIME.utils.expect(
                        os.path.isfile(renamed_fname),
                        "ERROR: File {} does not exist".format(renamed_fname))
                    logger.debug("PGN_INFO: Renamed file already exists:"
                                 "{}".format(renamed_fname))

        logger.debug("PGN_INFO: RUN PHASE ENDS")