コード例 #1
0
    def __init__(self, basis_dir, grid_dir, gap_data_list, flag=1,
                 file_name="fort.14", table_folder=None,
                 executable_dir=None):
        """ 
        Initalizes a gridInfo object and sets up a directory with links to the
        necessary input files to run :program:`Griddata_v1.1.32.F90` from
        within that directory.

        To run in parallel use :program:`mpirun` or :program:`ibrun`. If
        :program:`Griddata_v1.32.F90` has been compiled using the ``DGHIGHMEM``
        option make sure to correctly set ``OMP_NUM_THREADS`` to be the number
        of processors per node. Then the number of mpi tasks should be set to
        the number of nodes. 
        
        :param string basis_dir: the path to create the landuse_##
            directories in
        :param string grid_dir: the path where the ``fort.14`` formatted file
            is located, there also needs to be a ``fort.13`` formatted file
            here to use as a template
        :param gap_data_list: a list() of
            :class:`~polyadcirc.pyGriddata.table_management.gapInfo` objects
        :type gap_data_list: list
        :param int flag: flag to choose which averaging scheme to use ..see::
            :meth:`~polyadcirc.pyADCIRC.flag_fort14.flag_fort14`
        :param string file_name: the name of the ``fort.14`` formatted file in
            ``grid_dir``
        :param string table_folder: The folder containing the ``*.table`` file.
            This is ONLY necessary when running simutaneous copies of the
            :program:`Griddata`.
        :param string executable_dir: path to the directory containing the
            compiled ``Griddata_*.out`` executable 
        
        """
        self.file_name = file_name #: Name of grid file, ``*.14``
        self.grid_dir = grid_dir  #: path for the dir of the grid file
        self.gap_data_files = gap_data_list #: a list of gapInfo objects
        self.basis_dir = basis_dir #: path for the dir to create landuse_ in
        self.table_folder = table_folder #: path for the dir with ``*.table``
        """ list() of :class:`~polyadcirc.table_management.gapInfo` objects """
        self.__landclasses = [] 
        self.__unique_tables = {} 
        for gap in self.gap_data_files:
            #: dict of unique ``*.table`` files used
            self.__unique_tables[gap.table.file_name] = gap.table
        for k, v in self.__unique_tables.iteritems():
            for x in v.get_landclasses():
            #: list of landclasses used by this grid
                self.__landclasses.append((x, k))
        self.flag = flag #: averaging scheme flag

        if rank == 0:
            # Look for ``fort.14`` formatted file in grid_dir and place a link
            # to it in basis_dir
            fm.symlink(os.path.join(grid_dir, file_name),
                       os.path.join(basis_dir, file_name))
            flagged_file_name = f14.flag_go(self, flag)
            self.file_name = os.path.basename(flagged_file_name)

            # check to see if Griddata is here
            if executable_dir is None:
                executable_dir = sys.path
            else:
                executable_dir = [executable_dir]
            if len(glob.glob(os.path.join(self.basis_dir, 
                                          'Griddata_*.out'))) == 0:
                # check to see if Griddata is compiled and on the python path
                compiled_prog = None
                for p in executable_dir:
                    locations1 = glob.glob(os.path.join(p, "*Griddata_*.out"))
                    locations2 = glob.glob(os.path.join(p, "polyadcirc",
                                                        "pyGriddata", 
                                                        "Griddata_*.out"))
                    if locations1:
                        compiled_prog = locations1[0]
                    elif locations2:
                        compiled_prog = locations2[0]
                    else:
                        compiled_prog = None
                    break
                # put link to Griddata here
                if compiled_prog:
                    fm.symlink(compiled_prog,
                               os.path.join(basis_dir,
                                            os.path.basename(compiled_prog)))
                else:
                    print """Compile a copy of Griddata_v1.32.F90 and specify
                    it's location using executable_dir"""
            # Create links to gap files (*.asc) using gap_list of gapInfo
            # objects
            for gap in self.gap_data_files:
                local_file_name = os.path.basename(gap.file_name)
                fm.symlink(gap.file_name, os.path.join(basis_dir,
                                                       local_file_name))
                if os.path.exists(gap.file_name+'.binary'):
                    fm.symlink(gap.file_name+'.binary',
                               os.path.join(basis_dir, 
                                            local_file_name+'.binary'))
                gap.file_name = local_file_name
        self.file_name = comm.bcast(self.file_name, root=0)
        super(gridInfo, self).__init__()
コード例 #2
0
    def __init__(self, basis_dir, grid_dir, gap_data_list, flag=1,
                 file_name="fort.14", omp_num_threads=None):
        """ 
        Initalizes a gridInfo object and sets up a directory with links to the
        necessary input files to run :program:`Griddata_v1.1.32.F90` from
        within that directory.
        
        :param string basis_dir: the path to create the landuse_##
            directories in
        :param string grid_dir: the path where the ``fort.14`` formatted file
            is located, there also needs to be a ``fort.13`` formatted file
            here to use as a template
        :param gap_data_list: a list() of
            :class:`~polyadcirc.pyGriddata.table_management.gapInfo` objects
        :type gap_data_list: list()
        :param int flag: flag to choose which averaging scheme to use ..see::
            :meth:`~polyadcirc.pyADCIRC.flag_fort14.flag_fort14`
        :param string file_name: the name of the ``fort.14`` formatted file in
            ``grid_dir``
        
        """
        self.file_name = file_name #: Name of grid file, ``*.14``
        self.grid_dir = grid_dir  #: the path for the dir of the grid file
        self.gap_data_files = gap_data_list #: a list of gapInfo objects
        self.basis_dir = basis_dir #: the path for the dir to create landuse_ in
        self.omp_num_threads = omp_num_threads #: num threads per Griddata run
        """ list() of :class:`~polyadcirc.table_management.gapInfo` objects """
        self.__landclasses = [] 
        self.__unique_tables = {} 
        for gap in self.gap_data_files:
            #: dict() of unique ``*.table`` files used
            self.__unique_tables[gap.table.file_name] = gap.table
        for k, v in self.__unique_tables.iteritems():
            for x in v.get_landclasses():
            #: list of landclasses used by this grid
                self.__landclasses.append((x, k))
        self.flag = flag #: averaging scheme flag

        # Look for ``fort.14`` formatted file in grid_dir and place a link to
        # it in basis_dir
        fm.symlink(grid_dir+'/'+file_name, basis_dir+'/'+file_name)
        flagged_file_name = f14.flag_go(self, flag)
        self.file_name = os.path.basename(flagged_file_name)

        # check to see if Griddata is here
        if len(glob.glob(self.basis_dir+'/Griddata_*.out')) == 0:
            # check to see if Griddata is compiled and on the python path 
            for p in sys.path:
                if re.search("PolyADCIRC", p):
                    locations1 = glob.glob(p+"/*Griddata_*.out")
                    locations2 = glob.glob(p+"/polyadcirc/pyGriddata/Griddata_*.out")
                    if locations1:
                        compiled_prog = locations1[0]
                    elif locations2:
                        compiled_prog = locations2[0]
                    else:
                        compiled_prog = None
                    break
            # put link to Griddata here
            if compiled_prog:
                fm.symlink(compiled_prog,
                           os.path.join(basis_dir,
                                        os.path.basename(compiled_prog)))
            else:
                print "Compile a copy of Griddata_v1.32.F90 and put it in the"
                print "PolyADCIRC folder on your Python Path."
                print "Name it Griddata_parallel.out."
        
        # Create links to gap files (*.asc) using gap_list of gapInfo objects
        for gap in self.gap_data_files:
            local_file_name = os.path.basename(gap.file_name)
            fm.symlink(gap.file_name, basis_dir+'/'+local_file_name)
            gap.file_name = local_file_name

        super(gridInfo, self).__init__()