示例#1
0
    def __init__(self, parameter_file, **kwargs):
        """
        Initializes a ModelSetup instance from a parameter file

        Parameters
        ----------
        parameter_file : str
            File which stores model parameters.  This is either an XML or INI
            file.  As of now, only the XML logic has been implemented.

        Returns
        -------
        None
        """
        self.parameter_parser = ppf.get_parameter_parser(parameter_file)

        # Ensure that the parameter parser has been fully fleshed out before
        # retrieving the modeling files.  If the parameter_parser references
        # a prototype file, a new instance of a parameter_parser is
        # returned that represents the fully fleshed out version
        self.parameter_parser = self.parameter_parser.get_parameters(**kwargs)
        p = self.parameter_parser

        # Write out the model file
        p.serialize()

        # Create a ModelDatabase instance
        if p.parameter_set == 'FULL':
            self.plot_db = \
                plot_database.PlotDatabase(p.model_type, p.model_region,
                    p.buffer, p.model_year, p.summary_level,
                    p.image_source, p.image_version, dsn=p.plot_dsn)
示例#2
0
    def __init__(self, parameter_file, **kwargs):
        """
        Initializes a ModelSetup instance from a parameter file

        Parameters
        ----------
        parameter_file : str
            File which stores model parameters.  This is either an XML or INI
            file.  As of now, only the XML logic has been implemented.

        Returns
        -------
        None
        """
        self.parameter_parser = ppf.get_parameter_parser(parameter_file)

        # Ensure that the parameter parser has been fully fleshed out before
        # retrieving the modeling files.  If the parameter_parser references
        # a prototype file, a new instance of a parameter_parser is
        # returned that represents the fully fleshed out version
        self.parameter_parser = self.parameter_parser.get_parameters(**kwargs)
        p = self.parameter_parser

        # Write out the model file
        p.serialize()

        # Create a ModelDatabase instance
        if p.parameter_set == 'FULL':
            self.plot_db = \
                plot_database.PlotDatabase(p.model_type, p.model_region,
                    p.buffer, p.model_year, p.summary_level,
                    p.image_source, p.image_version, dsn=p.plot_dsn)
示例#3
0
 def setUp(self):
     parameter_file = "D:/model_root/mr224/fc_kernel_mean_gb_5/model.xml"
     parameter_parser = ppf.get_parameter_parser(parameter_file)
     self.diagnostic_wrapper = dw.DiagnosticWrapper(parameter_parser)
示例#4
0
def main():
    #sppsz_proto_name = 'L:/orcawa/cmonster/models/v_1_0_tc_only_k1.xml'
    #model_region = 221

    # first argument is the parameter file and is required
    model_xml = sys.argv[1]

    parser = OptionParser()
    parser.add_option('-r', dest='model_regions',
        help='List or range of GNN model regions for which to setup models')
    parser.add_option('-d',dest='root_directory',
        help='Location of root directory for storing model results')
    parser.add_option('-y', dest='years',
        help='Range of model years to run, or comma-delimited list of ' + \
            'years to run')
    parser.add_option('-i', dest='image_version',
        help='Imagery version')
    parser.add_option('-s', dest='model_specs',
        help='Model specifications used for directory naming; eg. tc_only_k1')
    parser.add_option('-m', dest='run_mode',
        help='Run model: spatial (full spatial run) or point (plot' + \
            'locations only)')

#    mode_message = 'program mode: '
#    mode_message += '1 = create species & env matrices and run vegan CCA,'
#    mode_message += '2 = create species & env matrices only,'
#    mode_message += '3 = create species plot counts files only'
#    parser.add_option('-m',dest='run mode', default=1,
#        help=mode_message)

    options = (parser.parse_args())[0]

    # if optional arguments were supplied, loop through all years and
    # model regions specified
    if options.model_regions:
        #if regions are specified as a range, unpack into a list
        if options.model_regions.find('-') > 0:
            region_list = []
            regions_split = options.model_regions.split('-')
            start_region = int(regions_split[0])
            end_region = int(regions_split[1])
            for r in range(start_region, end_region + 1):
                region_list.append(r)
        else:
            #if regions are specified in a comma-delimited string,
            #add each region to a list
            region_list = options.model_regions.split(',')
            #convert to ints
            region_list = map(int, region_list)

        #loop through all model regions
        for region in region_list:
            if options.years:
                #if regions are specified as a range, unpack into a list
                if options.years.find('-') > 0:
                    year_list = []
                    years_split = options.years.split('-')
                    start_year = int(years_split[0])
                    end_year = int(years_split[1])
                    for y in range(start_year, end_year + 1):
                        year_list.append(y)

                else:
                    #if years are specified in a comma-delimited string,
                    #add each year to a list
                    year_list = options.years.split(',')
                    #convert to ints
                    year_list = map(int, year_list)

                # We need to parse the model_xml file here because we need
                # to know the project associated with this run
                p = ppf.get_parameter_parser(model_xml)

                root_dir = 'L:/orcawa/%s/models/mr%d/%s/%s' % (
                    p.model_project.lower(), region, options.image_version,
                        options.model_specs)

                # if run_mode option is not specified, default to spatial
                # mode and do not modify root directory
                if options.run_mode:
                    if options.run_mode == 'point':
                        # if run_mode is specified as 'point', add another
                        # subdirectory named point
                        root_dir = '/'.join([root_dir, 'point'])

                #loop through all model
                for year in year_list:

                    #create new folders, rename existing folder to _old
                    #and delete existing _old folders if necessary
                    model_dir = '/'.join([root_dir, str(year)])

                    if os.path.exists(model_dir):
                        #if the directory already exists see if there
                        #is already an _old directory
                        old_dir = model_dir + '_old'
                        if os.path.exists(old_dir):
                            #delete the existing old directory
                            shutil.rmtree(old_dir)
                        #rename existing model_dir to old_dir
                        os.rename(model_dir, old_dir)
                    #create new empty model directory
                    os.makedirs(model_dir)

                    #create modeling files
                    model = ModelSetup(
                        model_xml,
                        model_directory=model_dir,
                        model_region=region,
                        model_year=year
                    )
                    #model.create_species_plot_count_file()

                    model.create_modeling_files(
                        model_directory=model_dir,
                        model_region=region,
                        model_year=year,
                        create_ordination_matrices=True,
                        run_ordination=True,
                        create_attribute_data=True,
                        create_area_estimates=True,
                        create_report_metadata=True,
                        create_hex_attribute_file=True,
                        create_validation_attribute_file=False
                        )
示例#5
0
def main():
    #sppsz_proto_name = 'L:/orcawa/cmonster/models/v_1_0_tc_only_k1.xml'
    #model_region = 221

    # first argument is the parameter file and is required
    model_xml = sys.argv[1]

    parser = OptionParser()
    parser.add_option(
        '-r',
        dest='model_regions',
        help='List or range of GNN model regions for which to setup models')
    parser.add_option(
        '-d',
        dest='root_directory',
        help='Location of root directory for storing model results')
    parser.add_option('-y', dest='years',
        help='Range of model years to run, or comma-delimited list of ' + \
            'years to run')
    parser.add_option('-i', dest='image_version', help='Imagery version')
    parser.add_option(
        '-s',
        dest='model_specs',
        help='Model specifications used for directory naming; eg. tc_only_k1')
    parser.add_option('-m', dest='run_mode',
        help='Run model: spatial (full spatial run) or point (plot' + \
            'locations only)')

    #    mode_message = 'program mode: '
    #    mode_message += '1 = create species & env matrices and run vegan CCA,'
    #    mode_message += '2 = create species & env matrices only,'
    #    mode_message += '3 = create species plot counts files only'
    #    parser.add_option('-m',dest='run mode', default=1,
    #        help=mode_message)

    options = (parser.parse_args())[0]

    # if optional arguments were supplied, loop through all years and
    # model regions specified
    if options.model_regions:
        #if regions are specified as a range, unpack into a list
        if options.model_regions.find('-') > 0:
            region_list = []
            regions_split = options.model_regions.split('-')
            start_region = int(regions_split[0])
            end_region = int(regions_split[1])
            for r in range(start_region, end_region + 1):
                region_list.append(r)
        else:
            #if regions are specified in a comma-delimited string,
            #add each region to a list
            region_list = options.model_regions.split(',')
            #convert to ints
            region_list = map(int, region_list)

        #loop through all model regions
        for region in region_list:
            if options.years:
                #if regions are specified as a range, unpack into a list
                if options.years.find('-') > 0:
                    year_list = []
                    years_split = options.years.split('-')
                    start_year = int(years_split[0])
                    end_year = int(years_split[1])
                    for y in range(start_year, end_year + 1):
                        year_list.append(y)

                else:
                    #if years are specified in a comma-delimited string,
                    #add each year to a list
                    year_list = options.years.split(',')
                    #convert to ints
                    year_list = map(int, year_list)

                # We need to parse the model_xml file here because we need
                # to know the project associated with this run
                p = ppf.get_parameter_parser(model_xml)

                root_dir = 'L:/orcawa/%s/models/mr%d/%s/%s' % (
                    p.model_project.lower(), region, options.image_version,
                    options.model_specs)

                # if run_mode option is not specified, default to spatial
                # mode and do not modify root directory
                if options.run_mode:
                    if options.run_mode == 'point':
                        # if run_mode is specified as 'point', add another
                        # subdirectory named point
                        root_dir = '/'.join([root_dir, 'point'])

                #loop through all model
                for year in year_list:

                    #create new folders, rename existing folder to _old
                    #and delete existing _old folders if necessary
                    model_dir = '/'.join([root_dir, str(year)])

                    if os.path.exists(model_dir):
                        #if the directory already exists see if there
                        #is already an _old directory
                        old_dir = model_dir + '_old'
                        if os.path.exists(old_dir):
                            #delete the existing old directory
                            shutil.rmtree(old_dir)
                        #rename existing model_dir to old_dir
                        os.rename(model_dir, old_dir)
                    #create new empty model directory
                    os.makedirs(model_dir)

                    #create modeling files
                    model = ModelSetup(model_xml,
                                       model_directory=model_dir,
                                       model_region=region,
                                       model_year=year)
                    #model.create_species_plot_count_file()

                    model.create_modeling_files(
                        model_directory=model_dir,
                        model_region=region,
                        model_year=year,
                        create_ordination_matrices=True,
                        run_ordination=True,
                        create_attribute_data=True,
                        create_area_estimates=True,
                        create_report_metadata=True,
                        create_hex_attribute_file=True,
                        create_validation_attribute_file=False)
示例#6
0
 def __init__(self, parameter_file):
     self.parser = ppf.get_parameter_parser(parameter_file)
     self.parameter_file = parameter_file
示例#7
0
 def __init__(self, parameter_file):
     self.parser = ppf.get_parameter_parser(parameter_file)
     self.parameter_file = parameter_file
 def setUp(self):
     parameter_file = 'D:/model_root/mr224/fc_kernel_mean_gb_5/model.xml'
     parameter_parser = ppf.get_parameter_parser(parameter_file)
     self.diagnostic_wrapper = dw.DiagnosticWrapper(parameter_parser)