예제 #1
0
    def update_wps_namelist(self):
        # deferred import to resolve circular dependency on Project type
        from gis4wrf.core.transforms.project_to_wps_namelist import convert_project_to_wps_namelist

        self.fill_domains()
        wps = convert_project_to_wps_namelist(self)

        if not os.path.exists(self.wps_namelist_path):
            write_namelist(wps, self.wps_namelist_path)
        else:
            patch_namelist(self.wps_namelist_path, wps)
예제 #2
0
    def update_wrf_namelist(self):
        from gis4wrf.core.transforms.project_to_wrf_namelist import convert_project_to_wrf_namelist

        self.fill_domains()
        wrf = convert_project_to_wrf_namelist(self)

        # We use the end_* variables instead.
        delete_from_wrf_namelist = [
            'run_days', 'run_hours', 'run_minutes', 'run_seconds'
        ]

        patch_namelist(self.wrf_namelist_path, wrf, delete_from_wrf_namelist)
예제 #3
0
파일: project.py 프로젝트: GIS4WRF/gis4wrf
    def update_wrf_namelist(self):
        from gis4wrf.core.transforms.project_to_wrf_namelist import convert_project_to_wrf_namelist

        self.fill_domains()
        nml_patch = convert_project_to_wrf_namelist(self)

        # Allow the user to change the following max_dom sized variables, but patch if the size is wrong.
        # The size is typically wrong when the template namelist from the WRF distribution is initially
        # copied and the user has nested domains, since the template assumes no nesting.
        # If the variable exists already and the size is wrong, then the existing array is cut or extended,
        # where extension repeats the last value.
        skip_patch_if_size_matches = {
            'time_control':
            ['history_interval', 'frames_per_outfile', 'input_from_file'],
            'domains': ['e_vert']
        }
        nml_old = read_namelist(self.wrf_namelist_path, 'wrf')
        nml_path = self.wrf_namelist_path
        for group_name, var_names in skip_patch_if_size_matches.items():
            if group_name not in nml_old:
                continue
            for var_name in var_names:
                if var_name not in nml_old[group_name]:
                    continue
                old_size = len(nml_old[group_name][var_name])
                patch_size = len(nml_patch[group_name][var_name])
                if old_size == patch_size:
                    logger.debug(
                        f'{nml_path}: size of {group_name}/{var_name} as expected, skipping patch'
                    )
                    del nml_patch[group_name][var_name]
                    continue
                var_old = nml_old[group_name][var_name]
                if old_size < patch_size:
                    logger.debug(
                        f'{nml_path}: size of {group_name}/{var_name} smaller than expected,'
                        +
                        f' extending to correct size by repeating last array value {var_old[-1]}'
                    )
                    var_patch = var_old + [var_old[-1]
                                           ] * (patch_size - old_size)
                else:
                    logger.debug(
                        f'{nml_path}: size of {group_name}/{var_name} bigger than expected,'
                        + ' truncating to correct size')
                    var_patch = var_old[:patch_size]
                nml_patch[group_name][var_name] = var_patch

        patch_namelist(self.wrf_namelist_path, nml_patch)
예제 #4
0
파일: project.py 프로젝트: iwenfeng/gis4wrf
 def init_config_files_if_needed(self, geogrid_tbl_path: str, wrf_namelist_path: str) -> None:
     if not self.path:
         return
     files = [
         (geogrid_tbl_path, self.geogrid_tbl_path),
         (wrf_namelist_path, self.wrf_namelist_path)
     ]
     for src_path, dst_path in files:
         if not src_path or not os.path.exists(src_path):
             continue
         if not os.path.exists(dst_path):
             shutil.copyfile(src_path, dst_path)
             if src_path == wrf_namelist_path:
                 # We generate the end_* variables, so remove run_* otherwise we would
                 # have to fix them up. Users can add them manually again if they need to.
                 delete_from_wrf_namelist = ['run_days', 'run_hours', 'run_minutes', 'run_seconds']
                 patch_namelist(dst_path, {}, delete_from_wrf_namelist)