def test_get_outputs_cpsha(self): self._create_job_profiles(self.user_name) self._set_up_complete_jobs() self._set_up_outputs() expected_cpsha = [self.cpsha_hc_output, self.cpsha_mean_hc_output, self.cpsha_lc_output] actual_cpsha = list(export.get_outputs(self.cpsha_job_fail.id)) self.assertEqual(expected_cpsha, actual_cpsha) expected_uhs = [self.uhs_output] actual_uhs = list(export.get_outputs(self.uhs_job.id)) self.assertEqual(expected_uhs, actual_uhs)
def test_get_outputs_cpsha(self): self._create_job_profiles(self.user_name) self._set_up_complete_jobs() self._set_up_outputs() expected_cpsha = [ self.cpsha_hc_output, self.cpsha_mean_hc_output, self.cpsha_lc_output ] actual_cpsha = list(export.get_outputs(self.cpsha_job_fail.id)) self.assertEqual(expected_cpsha, actual_cpsha) expected_uhs = [self.uhs_output] actual_uhs = list(export.get_outputs(self.uhs_job.id)) self.assertEqual(expected_uhs, actual_uhs)
def export(self, *args, **kwargs): """ If requested by the user, automatically export all result artifacts to the specified format. (NOTE: The only export format supported at the moment is NRML XML. :returns: A list of the export filenames, including the absolute path to each file. """ exported_files = [] logs.LOG.debug('> starting exports') if 'exports' in kwargs and 'xml' in kwargs['exports']: outputs = export_core.get_outputs(self.job.id) for output in outputs: exported_files.extend(hazard_export.export( output.id, self.job.hazard_calculation.export_dir)) for exp_file in exported_files: logs.LOG.debug('exported %s' % exp_file) logs.LOG.debug('< done with exports') return exported_files
def list_outputs(job_id): """Simple UI wrapper arround :function:`openquake.export.core.get_outputs`. It prints the results in a nice way.""" outputs = export.get_outputs(job_id) if len(outputs) > 0: print "ID\tOuput Type" for o in outputs: print "%s\t%s" % (o.id, o.output_type)
def list_outputs(job_id): """Simple UI wrapper arround :function:`openquake.export.core.get_outputs`. It prints the results in a nice way.""" outputs = export.get_outputs(job_id) if len(outputs) > 0: print 'ID\tOuput Type' for o in outputs: print '%s\t%s' % (o.id, o.output_type)
def test_classical_hazard_export(self): # Run a hazard calculation to compute some curves and maps # Call the exporter and verify that files were created # Since the hazard curve XML writer is concerned with correctly # generating XML, we won't test that here. target_dir = tempfile.mkdtemp() try: cfg = helpers.demo_file('simple_fault_demo_hazard/job.ini') # run the calculation to create something to export retcode = helpers.run_hazard_job_sp(cfg, silence=True) self.assertEqual(0, retcode) job = models.OqJob.objects.latest('id') outputs = export_core.get_outputs(job.id) expected_outputs = 18 # 6 hazard curves + 12 hazard maps self.assertEqual(expected_outputs, len(outputs)) # Export the hazard curves: curves = outputs.filter(output_type='hazard_curve') hc_files = [] for curve in curves: hc_files.extend(hazard.export(curve.id, target_dir)) self.assertEqual(6, len(hc_files)) for f in hc_files: self._test_exported_file(f) # Test hazard map export as well. maps = outputs.filter(output_type='hazard_map') hm_files = [] for haz_map in maps: hm_files.extend(hazard.export(haz_map.id, target_dir)) self.assertEqual(12, len(hm_files)) for f in hm_files: self._test_exported_file(f) finally: shutil.rmtree(target_dir)
def test_get_outputs_no_outputs(self): self._create_job_profiles(self.user_name) self._set_up_complete_jobs() self.assertTrue(len(export.get_outputs(self.uhs_job.id)) == 0) self.assertTrue(len(export.get_outputs(self.cpsha_job_fail.id)) == 0)
def test_export_for_event_based(self): # Run an event-based hazard calculation to compute SESs and GMFs # Call the exporters for both SES and GMF results and verify that # files were created # Since the XML writers (in `nrml.writers`) are concerned with # correctly generating the XML, we don't test that here... # but we should still have an end-to-end QA test. target_dir = tempfile.mkdtemp() try: cfg = helpers.demo_file('event_based_hazard/job.ini') # run the calculation to create something to export retcode = helpers.run_hazard_job_sp(cfg, silence=True) self.assertEqual(0, retcode) job = models.OqJob.objects.latest('id') outputs = export_core.get_outputs(job.id) # 2 GMFs, 2 SESs, 1 complete logic tree SES, 1 complete LT GMF, # and 4 hazard curve collections self.assertEqual(18, len(outputs)) ####### # SESs: ses_outputs = outputs.filter(output_type='ses') self.assertEqual(2, len(ses_outputs)) exported_files = [] for ses_output in ses_outputs: files = hazard.export(ses_output.id, target_dir) exported_files.extend(files) self.assertEqual(2, len(exported_files)) for f in exported_files: self._test_exported_file(f) ################## # Complete LT SES: [complete_lt_ses] = outputs.filter(output_type='complete_lt_ses') [exported_file] = hazard.export(complete_lt_ses.id, target_dir) self._test_exported_file(exported_file) ####### # GMFs: gmf_outputs = outputs.filter(output_type='gmf') self.assertEqual(2, len(gmf_outputs)) exported_files = [] for gmf_output in gmf_outputs: files = hazard.export(gmf_output.id, target_dir) exported_files.extend(files) self.assertEqual(2, len(exported_files)) # Check the file paths exist, are absolute, and the files aren't # empty. for f in exported_files: self._test_exported_file(f) ################## # Complete LT GMF: [complete_lt_gmf] = outputs.filter(output_type='complete_lt_gmf') [exported_file] = hazard.export(complete_lt_gmf.id, target_dir) self._test_exported_file(exported_file) # Check for the correct number of GMFs in the file: tree = etree.parse(exported_file) self.assertEqual(442, _number_of('nrml:gmf', tree)) ################ # Hazard curves: haz_curves = outputs.filter(output_type='hazard_curve') for curve in haz_curves: [exported_file] = hazard.export(curve.id, target_dir) self._test_exported_file(exported_file) finally: shutil.rmtree(target_dir)