def create_panels(self): """ Generate the panels from self's current config. This is called from within the render_wrapper function. """ # Create and save the panels. panels = [] domains = {} # id: ([items], colour) for index, config in enumerate(self.panel_list): gis = config['GIS files'].get() csv = config['CSV directory'].get() field = config['Field'].get() graph = config["Graph statistics"].get() per_field = config["Per-field"].get() map_domain_id = config["Same scales (map)"].get() if map_domain_id == "": map_domain_id = len(domains) graph_domain_id = config["Same scales (graph)"].get() if graph_domain_id == "": graph_domain_id = len(domains) + 1 name = config["Name"].get() # Find the value transformations and names. value_trans, value_tran_names = \ get_transform_tuple(config['Transforms'].get(), \ self.models[(gis, csv)]) value = self.values[((gis, csv), field, value_trans)] graph_trans, graph_tran_names = \ get_transform_tuple(config['Graph transforms'].get(), \ self.models[(gis, csv)]) panel = {'values': value} if graph != 'None': graphs = [] # Generate a list of statistics. stats = [] for stat in graph.split("+"): stats.append(stat.strip().lower()) stat_name = " (" + ", ".join(stats) + ") (" + \ " + ".join(graph_tran_names) + ")" if per_field == 'False': # Just one graph. graph_value = self.values[((gis, csv), field, \ graph_trans)] graphs.append(Graphable(graph_value, field + stat_name, \ statistics = stats)) graph_label = 'Key' else: # Multiple, per-field graphs. # Figure out the available fields. fields = value.model.get_patch_fields().items() # Generate a graph for each field. for field_no, patch_set in fields: graph_value = self.values[((gis, csv), field, \ tuple(list(graph_trans) + \ [lambda v: patch_filter(v, patch_set)]))] graphs.append(Graphable(graph_value, str(field_no), \ statistics = stats)) # Set the graph label. graph_label = "Fields" + stat_name # Add the graph to the panel. graph = Graph(graphs, label = graph_label) panel['graphs'] = graph # Add the graph to the domain list. if graph_domain_id in domains: domains[graph_domain_id][0].append(graph) else: domains[graph_domain_id] = ([graph], False) # Add the description. panel['desc'] = config["Description string"].get().format(\ name = name, field = field, csv = csv, gis = gis, \ transform = " + ".join(value_tran_names)) # Add the map to the domains. domains[map_domain_id] = (domains.get(map_domain_id, \ ([], True))[0] + [value], True) panels.append(panel) # Initialise the domains. i = 0 for items, coloured in domains.values(): if coloured: Domain(items, MAP_COLOUR_LIST[i]) i += 1 else: Domain(items) return panels
if __name__ == "__main__": import os.path localpath = os.path.dirname(__file__) # Create a Models. small = Model(os.path.join(localpath, "gis/SmallPatches"), \ os.path.join(localpath, "csv/small")) # Create the values. We also include the transformation, for later use. values = [(Values(small, "SWTotal"), "None"), (Values(small, "NO3Total"), "None")] # Create the graphs. graphs = [Graph([Graphable(Values(small, "SWTotal"), \ "SWTotal (min, mean, max)", \ statistics = ['min', 'mean', 'max'])]), \ Graph([Graphable(Values(small, "NO3Total", \ transforms = [lambda v: patch_filter(v, patch_set)]), \ "Field #{}".format(i), statistics = ['mean']) \ for i, patch_set in small.get_patch_fields().items()]) ] # Create the description strings... descriptions = [] for value, transform in values: descriptions.append("""Field of interest: {field} CSV: {csv} GIS: {gis} Transform: {transform}""".format(field = value.field, \ csv = value.model.csv, gis = value.model.gis, \ transform = transform)) # Create and save the panels. panels = [] for value, graph, desc in zip(values, graphs, descriptions):