def validate_model_name(mname): # Get existing models in repository models = mdig.repository.get_models() if mname not in models.keys(): abort(404, "No such model") try: dm = DispersalModel(models[mname]) except mdig.model.ValidationError: abort(500, "Model %s is badly formed" % mname) # Hack to get instances to initialise mapsets if they need to # and then save them dm.get_instances() dm.save_model() return dm
def create_occupancy_gif(self, m_name, instance_idx=None, ls=None): action = "OCCUPANCY_GIF" model_file = mdig.repository.get_models()[m_name] dm = DispersalModel(model_file) instance = dm.get_instances()[instance_idx] # Tell web interface we've started msg = { 'model': m_name, 'action': action, 'status': { 'started': datetime.datetime.now() } } self.results_q.put(msg) self.log.debug("Checking/creating envelopes") # Tell web interface what we're doing msg = { 'model': m_name, 'action': action, 'status': { 'active_instance': instance_idx, 'description': "Creating occupancy envelopes" } } self.results_q.put(msg) # Add listener so that we have progress updates instance.listeners.append(self.listener) # ...now actually create the envelopes if necessary instance.update_occupancy_envelope(ls_list=[ls]) # ...now convert occupancy envelopes into images via ExportAction from actions import ExportAction ea = ExportAction() ea.parse_options([]) ea.options.output_gif = True ea.options.output_image = True ea.options.output_lifestage = ls ea.options.overwrite_flag = True ea.listeners.append(self.listener) self.log.debug("Generating images") msg = { 'model': m_name, 'action': action, 'status': { 'active_instance': instance_idx, 'description': "Generating images" } } self.results_q.put(msg) ea.do_instance(instance) dm.save_model() msg = { 'model': m_name, 'action': action, 'status': { 'complete': datetime.datetime.now() } } self.results_q.put(msg)