def create_replicate_map_pack(self, m_name, instance_idx, replicate, ls): action = "REPLICATE_MAP_PACK" 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(), 'active_instance': instance_idx, 'description': "Generating images", 'active_replicate': replicate}} self.results_q.put(msg) # Add listener so that we have progress updates instance.listeners.append(self.listener) # also convert replicate maps into images # via ExportAction from actions import ExportAction ea = ExportAction() ea.parse_options([]) ea.options.output_map_pack = True ea.options.output_lifestage = ls ea.options.overwrite_flag = True ea.options.reps = [replicate] try: ea.do_instance(instance) except: raise msg = {'model': m_name, 'action': action, 'status': { 'active_instance': instance_idx, 'description': "Generating images", 'active_replicate': replicate, 'complete': datetime.datetime.now()}} self.results_q.put(msg)
def create_occupancy_map_pack(self, m_name, instance_idx=None, ls=None): action = "OCCUPANCY_MAP_PACK" 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]) # also convert occupancy envelopes into images # via ExportAction from actions import ExportAction ea = ExportAction() ea.parse_options([]) ea.options.output_map_pack = True ea.options.output_lifestage = ls ea.options.overwrite_flag = True ea.listeners.append(self.listener) self.log.debug("Exporting maps") msg = { 'model': m_name, 'action': action, 'status': { 'active_instance': instance_idx, 'description': "Exporting maps" } } self.results_q.put(msg) try: ea.do_instance(instance) except: raise msg = { 'model': m_name, 'action': action, 'status': { 'complete': datetime.datetime.now() } } self.results_q.put(msg)
def run_model(self, m_name, instances, rerun=False): model_file = mdig.repository.get_models()[m_name] dm = DispersalModel(model_file) if rerun: dm.reset_instances() msg = { 'model': m_name, 'action': "RUN", 'status': { 'started': datetime.datetime.now() } } self.results_q.put(msg) i_objs = dm.get_instances() for instance in instances: i = i_objs[instance] i.listeners.append(self.listener) msg = { 'model': m_name, 'action': "RUN", 'status': { 'active_instance': instance } } i.run() msg = {'model': m_name, 'action': "RUN", 'status': {'complete': datetime.datetime.now()}} self.results_q.put(msg)
def run_model(self, m_name, instances, rerun=False): model_file = mdig.repository.get_models()[m_name] dm = DispersalModel(model_file) if rerun: dm.reset_instances() msg = { 'model': m_name, 'action': "RUN", 'status': { 'started': datetime.datetime.now() } } self.results_q.put(msg) i_objs = dm.get_instances() for instance in instances: i = i_objs[instance] i.listeners.append(self.listener) msg = { 'model': m_name, 'action': "RUN", 'status': { 'active_instance': instance } } i.run() msg = { 'model': m_name, 'action': "RUN", 'status': { 'complete': datetime.datetime.now() } } self.results_q.put(msg)
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 index(): # Get existing models in repository models = mdig.repository.get_models() ms = models.keys()[:] ms.sort() m_list = [] for m in ms: try: dm = DispersalModel(models[m], setup=False) desc = dm.get_description() desc = re.sub("[\\s\\t]+", " ", desc) m_list.append((m, desc, dm.infer_location())) except mdig.model.ValidationError, e: log.error(str(e))
def create_replicate_gif(self, m_name, instance_idx, replicate, ls): action = "REPLICATE_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(), 'active_instance': instance_idx, 'description': "Generating images", 'active_replicate': replicate } } self.results_q.put(msg) # Add listener so that we have progress updates instance.listeners.append(self.listener) # also convert replicate maps 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.options.reps = [replicate] try: ea.do_instance(instance) except: raise msg = { 'model': m_name, 'action': action, 'status': { 'active_instance': instance_idx, 'description': "Generating images", 'active_replicate': replicate, 'complete': datetime.datetime.now() } } self.results_q.put(msg)
def create_occupancy_map_pack(self, m_name, instance_idx=None, ls=None): action = "OCCUPANCY_MAP_PACK" 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]) # also convert occupancy envelopes into images # via ExportAction from actions import ExportAction ea = ExportAction() ea.parse_options([]) ea.options.output_map_pack = True ea.options.output_lifestage = ls ea.options.overwrite_flag = True ea.listeners.append(self.listener) self.log.debug("Exporting maps") msg = {'model': m_name, 'action': action, 'status': {'active_instance': instance_idx, 'description': "Exporting maps"}} self.results_q.put(msg) try: ea.do_instance(instance) except: raise msg = {'model': m_name, 'action': action, 'status': { 'complete': datetime.datetime.now()}} self.results_q.put(msg)