def get_plot_data_source_summary(self, ids): """ Get plot counts grouped by data sources and assessment years Parameters ---------- ids : str comma-delimited list of IDs for plots to include (should be PNTID, CCID, FCID or PLTID depending on self.summary_level) Returns ------- plot_data_sources : numpy.recarray ID, DATA_SOURCE, ASSESSMENT_YEAR """ sql = """ EXEC lemma.GET_PLOT_DATA_SOURCE_SUMMARY @ids = '%s', @summary_level = '%s' """ sql = sql % (ids, self.summary_level) (records, descr) = self.get_data(sql) plot_data_sources = utilities.pyodbc2rec(records, descr) return plot_data_sources
def get_metadata_codes(self, table_names): """ Get metadata for just the codes in the tables passed in Parameters ---------- table_names: str comma-delimited list of table names to get metadata for Returns ------- metadata_codes: numpy.recarray code names and descriptions """ sql = """ EXEC lemma.GET_METADATA_TABLE_CODES @table_names = '%s' """ sql = sql % (table_names) try: (records, desc) = self.get_data(sql) except IndexError: # If the query returned no records, return None # this means there were no coded fields in the table(s) metadata_codes = None else: metadata_codes = utilities.pyodbc2rec(records, desc) return metadata_codes
def get_metadata_code_dictionary(self, field_name): """ Build a dictionary of codes for a given field Parameters ---------- table_name : str The database object name field_name : str The field name within the table_name Returns ------- code_dict : dict A dictionary of all codes associated with this field """ sql = "EXEC lemma.GET_METADATA_CODES '" sql += field_name + "'" code_dict = {} (records, desc) = self.get_data(sql) code_table = utilities.pyodbc2rec(records, desc) for row in code_table: code_value = row.CODE_VALUE inner_dict = {} for key in row.dtype.names: # if key <> 'CODE_VALUE': inner_dict[key] = row[key] code_dict[code_value] = inner_dict return code_dict
def get_plot_image_pairs(self, keyword): """ Query the database to get all plot assessment years and available imagery years and crosswalk the returned information using the logic associated with each keyword Parameters ---------- keyword : str Keyword to determine the logic of how to match plot assessment years to imagery years. The only keyword implemented now is 'DEFAULT', which matches plots to the closest year of imagery available. Returns ------- plot_image_years : numpy.recarray PLOT_YEAR, IMAGE_YEAR """ sql = """ EXEC lemma.GET_PLOT_IMAGE_PAIRS @model_region = %d, @buffer = %d, @image_source = '%s', @image_version = %f, @keyword = '%s' """ sql = sql % (self.model_region, self.buffer, self.image_source, self.image_version, keyword) (records, descr) = self.get_data(sql) plot_image_years = utilities.pyodbc2rec(records, descr) return plot_image_years
def get_species_names(self, id_str, lump_table): """ Get common names and scientific names for species codes Parameters ---------- id_str: str comma-delimited list of IDs to include Returns ------- species_names : numpy.recarray SPP_SYMBOL, SCIENTIFIC_NAME, COMMON_NAME """ sql = """ EXEC lemma.GET_SPECIES_NAMES @ids = '%s', @summary_level = '%s', @model_type = '%s', @lump_table = %d """ sql = sql % (id_str, self.summary_level, self.model_type, lump_table) (records, descr) = self.get_data(sql) species_info = utilities.pyodbc2rec(records, descr) return species_info
def get_structure_metadata(self, project_id): """ Get metadata for all of the structure attributes Parameters ---------- None Returns ------- fields: numpy.recarray field names and definitions codes: numpy.recarray code names and definitions """ sql = """ EXEC lemma.GET_STRUCTURE_METADATA_FIELDS @model_type = '%s', @summary_level = '%s', @model_region = %d, @project_id = '%s' """ sql = sql % (self.model_type, self.summary_level, \ self.model_region, project_id) records, descr = self.get_data(sql) metadata_fields = utilities.pyodbc2rec(records, descr) structure_table = self.get_structure_table_name() metadata_codes = self.get_metadata_codes(structure_table) return metadata_fields, metadata_codes
def get_attribute_data(self, id_str): """ Get an attribute table which includes both continuous stand variables and species by abundance measure (basal area, percent cover, etc.) for use in accuracy assessment for NN models. Parameters ---------- id_str: str Comma-delimited list of IDs to include Returns ------- attibute_data: numpy.recarray Structure and species attribute data summarized at the requested summary level """ sql = """ EXEC lemma.GET_MODEL_ATTRIBUTES @ids = '%s', @summary_level = '%s', @model_region = %d, @model_type = '%s' """ sql = sql % ( id_str, self.summary_level, self.model_region, self.model_type) (records, descr) = self.get_data(sql) stand_attribute_data = utilities.pyodbc2rec(records, descr) return stand_attribute_data
def get_ordination_variable_descriptions(self, ordination_vars): """ """ sql = """ EXEC lemma.GET_ORDINATION_VARIABLE_DESCRIPTIONS @ordination_vars = '%s' """ sql = sql % (ordination_vars) (records, descr) = self.get_data(sql) ordination_vars = utilities.pyodbc2rec(records, descr) return ordination_vars
def get_area_estimates(self, comparison_year): """ Get estimates of acres separated into forest, nonforest and nonsampled areas Parameters ---------- comparison_year : int Year for which plot assessment years will be compared. If more than one plot exists at a location, the plot that is temporally closer to this parameter will be chosen Returns ------- observed_data: numpy.recarray structure and species data and # forest hectares nf_hectares: float # nonforest hectares ns_hectares: float # nonsampled hectares """ sql_base = """ EXEC lemma.GET_AREA_EXPANSIONS @model_region = %d, @model_type = '%s', @glc_group = '%s', @model_year = %d """ # Forested area sql = sql_base % (self.model_region, self.model_type, 'F', comparison_year) (records, descr) = self.get_data(sql) observed_data = utilities.pyodbc2rec(records, descr) # Nonforest area sql = sql_base % (self.model_region, self.model_type, 'NF', comparison_year) (records, descr) = self.get_data(sql) nf_hectares = records[0][0] # Non-sampled area sql = sql_base % (self.model_region, self.model_type, 'NS', comparison_year) (records, descr) = self.get_data(sql) ns_hectares = records[0][0] return observed_data, nf_hectares, ns_hectares
def get_species_plot_counts(self, id_str): sql = """ EXEC lemma.GET_SPECIES_PLOT_COUNTS @ids = '%s', @summary_level = '%s', @model_region = %d, @model_type = '%s' """ sql = sql % (id_str, self.summary_level, self.model_region, self.model_type) records, descr = self.get_data(sql) species_plot_counts = utilities.pyodbc2rec(records, descr) return species_plot_counts
def get_validation_attributes(self): """ Get structure and species attributes for validation plots Returns ------- validation_attributes: numpy.recarray """ sql = """ EXEC lemma.GET_VALIDATION_ATTRIBUTES @summary_level = '%s', @model_region = %d, @model_type = '%s' """ sql = sql % (self.summary_level, self.model_region, self.model_type) records, descr = self.get_data(sql) validation_attributes = utilities.pyodbc2rec(records, descr) return validation_attributes
def get_environmental_matrix(self, id_str, plot_years, image_years, spatial_vars): """ Get a matrix of plots by environmental variables for use as input to NN models Parameters ---------- id_str: str comma-delimited list of IDs to include plot_years: str comma-delimited list of plot assessment years image_years: str comma-delimited list of image years spatial_vars: str comma-delimited list of spatial variables to return Returns ------- env_matrix: numpy.recarray **ID: unique plot identifier as specified by summary_level ordination variables (names correspond to spatial_vars list) """ sql = """ EXEC lemma.GET_ENVIRONMENTAL_MATRIX @ids = '%s', @summary_level = '%s', @model_region = %d, @model_type = '%s', @plot_years = '%s', @image_years = '%s', @image_source = '%s', @image_version = %f, @spatial_vars = '%s' """ sql = sql % (id_str, self.summary_level, self.model_region, self.model_type, plot_years, image_years, self.image_source, self.image_version, spatial_vars) records, descr = self.get_data(sql) env_matrix = utilities.pyodbc2rec(records, descr) return env_matrix
def get_species_metadata(self): """ Get metadata for all of the species attributes Returns ------- fields: numpy.recarray field names and definitions codes: numpy.recarray code names and definitions """ sql = """ EXEC lemma.GET_SPECIES_METADATA @model_region = %d, @model_type = '%s' """ sql = sql % (self.model_region, self.model_type) records, descr = self.get_data(sql) species_metadata = utilities.pyodbc2rec(records, descr) return species_metadata
def get_species_matrix(self, id_str, purpose, lump_table): """ Get a species data in the format of a crosstab table of species by abundance measure (basal area, percent cover, etc.) for use as input to NN models or for attaching to model output or for using in model accuracy assessment Parameters ---------- id_str: str comma-delimited list of IDs to include purpose: str ORDINATION: for use as input to model ordination ATTRIBUTE: for joining attributes to model output ACCURACY: for use in accuracy assessment lump_table: bool indicates whether to lump species using this model region's lump table in the model database Returns ------- species_matrix: numpy.recarray **ID: unique plot identifier as specified by summary_level species abundance (names differ by which species occur in model region) """ sql = """ EXEC lemma.GET_SPECIES_MATRIX @ids = '%s', @summary_level = '%s', @model_region = %d, @model_type = '%s', @purpose = '%s', @lump_table = %d """ sql = sql % (id_str, self.summary_level, self.model_region, self.model_type, purpose, lump_table) (records, descr) = self.get_data(sql) species_matrix = utilities.pyodbc2rec(records, descr) return species_matrix
def get_model_region_window(self): """ Get the bounding coordinates for this model region Parameters ---------- None Returns ------- mr_bounds : numpy.recarray X_MIN, Y_MIN, X_MAX, Y_MAX, BOUNDARY_RASTER (file location) """ sql = """ EXEC lemma.GET_MODEL_REGION_WINDOW @model_region = %d """ sql = sql % (self.model_region) (records, descr) = self.get_data(sql) bounds = utilities.pyodbc2rec(records, descr) return bounds
def get_people_info(self): """ Get information about people associated with this project for the accuracy assessment report Parameters ---------- None Returns ------- model_region_info: numpy.recarray """ sql = """ EXEC lemma.get_people_info @project_id = '%s' """ sql = sql % (self.project_id) (records, descr) = self.get_data(sql) people_info = utilities.pyodbc2rec(records, descr) return people_info
def get_hex_attributes(self, comparison_year, plot_years, image_years): """ Get hexagon IDs and continuous stand attributes for forested Annual plots to be used in Riemann accuracy diagnostics Parameters ---------- comparison_year: int Year for which plot assessment years will be compared. If more than one plot exists at a location, the plot that is temporally closer to this parameter will be chosen plot_years: str comma-delimited list of plot assessment years image_years: str comma-delimited list of image years Returns ------- hex_attributes: numpy.recarray """ sql = """ EXEC lemma.GET_HEX_ATTRIBUTES @model_region = %d, @model_type = '%s', @model_year = %d, @summary_level = '%s', @plot_years = '%s', @image_years = '%s', @image_source = '%s', @image_version = %f """ sql = sql % (self.model_region, self.model_type, comparison_year, self.summary_level, plot_years, image_years, self.image_source, self.image_version) records, descr = self.get_data(sql) hex_attributes = utilities.pyodbc2rec(records, descr) return hex_attributes
def get_metadata_fields(self, table_names): """ Get metadata for just the fields in the tables passed in Parameters ---------- table_names: str comma-delimited list of table names to get metadata for Returns ------- metadata_fields: numpy.recarray field names and descriptions """ sql = """ EXEC lemma.GET_METADATA_TABLE_FIELDS @table_names = '%s' """ sql = sql % (table_names) (records, desc) = self.get_data(sql) metadata_fields = utilities.pyodbc2rec(records, desc) return metadata_fields
def get_ordination_variable_list(self, var_types, variable_filter): """ Query the database to get a list of ordination variables and their file locations for this model region Parameters ---------- var_types: str keyword to specify which variables to return Values: ALL = all variables that have complete coverage for this MR DEFAULT = subset of variables chosen for this MR variable_filter: str method of filtering ordination variables: RAW or FOCAL Returns ------- ordination_table : numpy.recarray VARIABLE_NAME, VARIABLE_PATH """ # Create the parameter signature and get the possible ordination # variables sql = """ EXEC lemma.GET_ORDINATION_VARIABLE_LIST @model_region = %d, @model_type = '%s', @model_year = %d, @buffer = %d, @var_types = '%s', @image_source = '%s', @image_version = %f, @variable_filter = '%s' """ sql = sql % (self.model_region, self.model_type, self.model_year, self.buffer, var_types, self.image_source, self.image_version, variable_filter) (records, descr) = self.get_data(sql) ordination_table = utilities.pyodbc2rec(records, descr) return ordination_table
def get_model_region_info(self): """ Get information about this model region for the accuracy assessment report Parameters ---------- None Returns ------- model_region_info: numpy.recarray """ sql = """ EXEC lemma.get_model_region_info @model_region = %d, @project_id = '%s' """ sql = sql % (self.model_region, self.project_id) (records, descr) = self.get_data(sql) model_region_info = utilities.pyodbc2rec(records, descr) return model_region_info