def find_maps(job): """Find all hazard/result maps and store information about these in the db. Assumption: the default output path cannot be changed from the web GUI (openquake/default.gem:OUTPUT_DIR = computed_output) :param job: the :py:class:`geonode.mtapi.models.OqJob` instance in question :returns: a list of :py:class:`geonode.mtapi.models.Output` instances, one per map. """ logger.info("> find_maps") results = [] maps = list(sorted(glob.glob( "%s/*map*.xml" % os.path.join(job.path, "computed_output")))) maps = [(path, detect_output_type(path)) for path in maps] # Ignore anything that's not a hazard or loss map. maps = [(path, map_type) for path, map_type in maps if map_type in ("hazard", "loss")] for path, map_type in maps: output = Output(owner=job.owner, output_type="%s_map" % map_type, oq_job=job, path=path, size=os.path.getsize(path), display_name=os.path.basename(path)) output.save() results.append(output) logger.info("results = %s" % results) logger.info("< find_maps") return results
def find_maps(job): """Find all hazard/result maps and store information about these in the db. Assumption: the default output path cannot be changed from the web GUI (openquake/default.gem:OUTPUT_DIR = computed_output) :param job: the :py:class:`geonode.mtapi.models.OqJob` instance in question :returns: a list of :py:class:`geonode.mtapi.models.Output` instances, one per map. """ logger.info("> find_maps") results = [] maps = list(sorted(glob.glob( "%s/*map*.xml" % os.path.join(job.path, "computed_output")))) maps = [(path, detect_output_type(path)) for path in maps] # Ignore anything that's not a hazard or loss map. maps = [(path, map_type) for path, map_type in maps if map_type in ("hazard", "loss")] for path, map_type in maps: output = Output(owner=job.owner, output_type="%s_map" % map_type, oq_job=job, path=path, size=os.path.getsize(path)) output.save() results.append(output) logger.info("results = %s" % results) logger.info("< find_maps") return results
def setup_output(self, job_to_use=None, output_type="hazard_map"): """Create an output object of the given type. :param job_to_use: if set use the passed :py:class:`geonode.mtapi.models.OqJob` instance as opposed to creating a new one. :param str output_type: map type, one of "hazard_map", "loss_map" :returns: a :py:class:`geonode.mtapi.models.Output` instance """ job = job_to_use if job_to_use else self.setup_classic_job() output = Output(owner=job.owner, oq_job=job, output_type=output_type) output.path = self.touch( dir=os.path.join(job.path, "computed_output"), suffix=".xml", prefix="hzrd." if output_type == "hazard_map" else "loss.") output.display_name = os.path.basename(output.path) output.save() return output