Пример #1
0
    def prep_all(self, parallel=False, removeBinaries=False):
        """
        Assumes that all the necessary input files are in ``self.basis_dir``.
        This function generates a ``landuse_##`` folder in ``self.basis_dir``
        for every land classification number containing a ``fort.13`` file
        specific to that land classification number.

        .. todo:: Update so that landuse folders can be prepped n at a time and
                  so that this could be run on a HPC system
        
        """

        first_script = self.setup_landuse_folder(0)
        # run grid_all_data in this folder 
        subprocess.call(['./'+first_script], cwd=self.basis_dir)
        # set up remaining land-use classifications
        script_list = self.setup_landuse_folders(False)
        # run remaining bash scripts
        if not parallel:
            for s in script_list:
                subprocess.call(['./'+s], cwd=self.basis_dir)
        else:
            print "This needs to be implemented so that we can simultaneously \
                    run griddata on all of the remaining landuse folders. I \
                    would sugguest using gnu parallel."
        # remove unnecessary files
        if removeBinaries:
            binaries = glob.glob(self.basis_dir+'/*.asc.binary')
            for f in binaries:
                os.remove(f)
        self.cleanup_landuse_folders()
        fm.rename13(basis_dir=self.basis_dir)
Пример #2
0
    def prep_test(self, removeBinaries=False):
        """
        Assumes :meth:`~polyadcirc.pyGriddata.prep_mesh.prep_all` has been run
        first. Prepares a fort.13 file for testing purposes.
        
        :param binary removeBinaries: flag wheter or not to remove
            ``*.asc.binary`` files

        """
        subprocess.call(['./'+self.setup_folder('test')], cwd=
                        self.basis_dir)
        self.convert(os.path.join(self.basis_dir, 'test'))
        # remove unnecessary files
        if removeBinaries:
            binaries = glob.glob(os.path.join(self.basis_dir, '*.asc.binary'))
            for f in binaries:
                os.remove(f)
        self.cleanup_landuse_folder(os.path.join(self.basis_dir, 'test'))
        fm.rename13(['test'], self.basis_dir)  
Пример #3
0
    def prep_test(self, removeBinaries=False):
        """
        Assumes :meth:`~polyadcirc.pyGriddata.prep_mesh.prep_all` has been run
        first. Prepares a fort.13 file for testing purposes.

        :param grid: :class:`~polyim.pyGriddata.gridInfo`
        :param string path: THIS MUST BE CWD (``'.'``) or ``None``

        """
        subprocess.call(['./'+self.setup_folder('test')], cwd=
                        self.basis_dir)
        self.convert(self.basis_dir+'/'+'test')
        # remove unnecessary files
        if removeBinaries:
            binaries = glob.glob(self.basis_dir+'/*.asc.binary')
            for f in binaries:
                os.remove(f)
        self.cleanup_landuse_folder(self.basis_dir+'/test')
        fm.rename13(['test'], self.basis_dir)  
Пример #4
0
    def prep_all(self, removeBinaries=False, class_nums=None, condense=True,
                 TOL=None):
        """
        Assumes that all the necessary input files are in ``self.basis_dir``.
        This function generates a ``landuse_##`` folder in ``self.basis_dir``
        for every land classification number containing a ``fort.13`` file
        specific to that land classification number.

        .. todo:: Update so that landuse folders can be prepped n at a time and
                  so that this could be run on a HPC system

        Currently, the parallel option preps the first folder and then all the
        remaining folders at once.

        :param binary parallel: Flag whether or not to simultaneously prep
            landuse folders.
        :param binary removeBinarues: Flag whether or not to remove
            ``*.asc.binary`` files when completed.
        :param list class_nums: List of integers indicating which classes to
            prep. This assumes all the ``*.asc.binary`` files are already in
            existence.
        :param bool condense: Flag whether or not to condense ``fort.13`` to
            only non-zero values within a tolerance.
        :param double TOL: Tolerance below which to consider a Manning's n
            value to be zero if ``condense == True``
        
        """
        if class_nums is None:
            class_nums = range(len(self.__landclasses))
        if rank > class_nums:
            print "There are more MPI TASKS than land classes."
            print "This code only scales to MPI_TASKS = len(land_classes)."
            print "Extra MPI TASKS will not be used."
            return

        # Are there any binary files?
        binaries = glob.glob(os.path.join(self.basis_dir, '*.asc.binary'))
        # If not create them
        if not(binaries) and rank == 0:
            # set up first landuse folder
            first_script = self.setup_landuse_folder(class_nums[0])
            # set up remaining land-use classifications
            script_list = self.setup_landuse_folders(False)
            # run grid_all_data in this folder 
            subprocess.call(['./'+first_script], cwd=self.basis_dir)
            class_nums.remove(0)
            landuse_folder = 'landuse_00'
            self.cleanup_landuse_folder(os.path.join(self.basis_dir,
                                                     landuse_folder))
            fm.rename13([landuse_folder], self.basis_dir)
            if condense:
                print "Removing values below TOL"
                landuse_folder_path = os.path.join(self.basis_dir,
                                                   landuse_folder)
                # read fort.13 file
                mann_dict = f13.read_nodal_attr_dict(landuse_folder_path)
                # condense fort.13 file
                condensed_bv = tmm.condense_bv_dict(mann_dict, TOL)
                # write new file
                f13.update_mann(condensed_bv, landuse_folder_path)
        elif rank == 0:
            script_list = self.setup_landuse_folders()
        else:
            script_list = None
            class_nums = None
        class_nums = comm.bcast(class_nums, root=0)
        script_list = comm.bcast(script_list, root=0)
        
        if len(class_nums) != len(script_list):
            temp = [script_list[i] for i in class_nums]
            script_list = temp

        # run remaining bash scripts
        for i in range(0+rank, len(script_list), size):
            # run griddata
            subprocess.call(['./'+script_list[i]], cwd=self.basis_dir)
            # clean up folder
            match_string = r"grid_all_(.*)_"+self.file_name[:-3]+r"\.sh"
            landuse_folder = re.match(match_string, script_list[i]).groups()[0]
            self.cleanup_landuse_folder(os.path.join(self.basis_dir,
                                                     landuse_folder))
            # rename fort.13 file
            fm.rename13([landuse_folder], self.basis_dir) 
            if condense:
                print "Removing values below TOL"
                landuse_folder_path = os.path.join(self.basis_dir,
                                                   landuse_folder)
                # read fort.13 file
                mann_dict = f13.read_nodal_attr_dict(landuse_folder_path)
                # condense fort.13 file
                condensed_bv = tmm.condense_bv_dict(mann_dict, TOL)
                # write new file
                f13.update_mann(condensed_bv, landuse_folder_path) 
        print "Done"
        # remove unnecessary files
        if removeBinaries and rank == 0:
            binaries = glob.glob(os.path.join(self.basis_dir, '*.asc.binary'))
            for f in binaries:
                os.remove(f)