示例#1
0
 def create_metadata_file(self, table_name):
     #assign dummy values to required PlotDatabase parameters since we
     #don't need these parameters to generate metadata
     model_type = 'sppsz'
     model_region = 221
     buffer = 0
     model_year = 2000
     summary_level = 'FC'
     image_source = 'N/A'
     image_version = 0.0
     dsn = 'rocky2lemma'
     
     plot_db = db.PlotDatabase(model_type, model_region, buffer,
                               model_year, summary_level, 
                               image_source, image_version, dsn)
     
     metadata = plot_db.get_metadata_field_dictionary(table_name)
     
     ordinal_dict = {}
     for key in metadata.keys():
         ordinal_dict[metadata[key]['ORDINAL']] = key
     
     for ordinal in sorted(ordinal_dict.keys()):
         key = ordinal_dict[ordinal]
         yield metadata[key]
示例#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 __init__(self, parameter_parser):
        self.parameter_parser = parameter_parser
        p = self.parameter_parser

        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)
示例#4
0
 def setUp(self):
     self.plot_database = pd.PlotDatabase('sppsz', dsn='rocky2test_lemma')
示例#5
0
    def create_model_xml(self, model_directory, model_region, model_year):
        """
        Create an XML string from prototype XML specialized for the
        model directory, model region, and model year

        Parameters
        ----------
        model_directory : str
            Model directory for this model

        model_region : int
            Modeling region with which to specialize this XML

        model_year : int
            Year (4-digit) with which to specialize this XML

        Returns
        -------
        out_xml : StringIO
            XML string to be serialized
        """

        # Make a deep copy of this instance
        obj = deepcopy(self)

        # Switch the parameter_set tag to now be 'FULL'
        obj.parameter_set = 'FULL'

        # Replace the necessary elements with the model directory,
        # model region and year
        obj.model_directory = model_directory
        obj.model_region = model_region
        obj.model_year = model_year

        # Create a PlotDatabase instance for filling in many elements
        # Note that we pass obj.model_region and obj.model_year as
        # specified rather than the prototype's values; everything else
        # can come from the prototype
        plot_db = \
            plot_database.PlotDatabase(self.model_type, obj.model_region,
                self.buffer, obj.model_year, self.summary_level,
                self.image_source, self.image_version, dsn=self.plot_dsn)

        # Model boundary_raster and region extent
        rec = (plot_db.get_model_region_window())[0]
        obj.boundary_raster = rec.BOUNDARY_RASTER
        obj.envelope = [rec.X_MIN, rec.Y_MIN, rec.X_MAX, rec.Y_MAX]

        # Plot image crosswalk
        #
        # For model types that use imagery, we need to match plot assessment
        # years to available image years.  First look for the presence of a
        # keyword tag in the <plot_image_crosswalk> block and if it exists,
        # query the database for the plot assessment years and available
        # image years and return the formatted XML.  Otherwise, skip this
        # section as the crosswalk has already been defined.
        value = self.plot_image_crosswalk
        if value and isinstance(value, str):
            pi_data = plot_db.get_plot_image_pairs(value)
            obj.plot_image_crosswalk = pi_data

        # If the plot_image_crosswalk tag is missing, we need to populate
        # the plot_years tag in non-imagery models
        else:
            obj.plot_years = plot_db.get_plot_years()

        # Ordination variables
        #
        # First look for the presence of the keyword tag in the
        # 'ordination_variables' block and if it exists, query the database
        # for the allowed spatial variables.  Otherwise, skip over this section
        # as the spatial variables have already been specified
        value = self.get_ordination_variables()
        if value and isinstance(value, str):
            ord_vars = plot_db.get_ordination_variable_list(
                value, self.variable_filter)
            obj.set_ordination_variables(ord_vars)

        # Accuracy assessment report name
        if self.accuracy_assessment_report:
            mr_str = 'mr' + str(obj.model_region)
            prefix = '_'.join(
                (mr_str, self.model_type, str(obj.model_year), 'aa'))
            obj.accuracy_assessment_report = prefix + '.pdf'

        # Deannotate the tree
        objectify.deannotate(obj.tree)
        etree.cleanup_namespaces(obj.tree)

        # Ensure the newly created XML validates against the schema
        utilities.validate_xml(obj.tree, self.xml_schema_file)

        # Return the tree for serializing
        return obj