Example #1
0
    def test_write_uh_spectra(self):
        # Test the writing of the intial database records for UHS results.
        # The function under test (`write_uh_spectra`) should write:
        #   - 1 uiapi.output record
        #   - 1 hzrdr.uh_spectra record
        #   - 1 hzrdr.uh_spectrum record per PoE defined in the oq_job_profile

        # Call the function under test:
        write_uh_spectra(self.job_ctxt)

        # Now check that the expected records were indeed created.
        output = Output.objects.get(oq_job=self.job.id)
        self.assertEqual('uh_spectra', output.output_type)

        uh_spectra = UhSpectra.objects.get(output=output.id)
        self.assertEqual(
            self.job_profile.investigation_time, uh_spectra.timespan)
        self.assertEqual(
            self.job_profile.realizations, uh_spectra.realizations)
        self.assertEqual(self.job_profile.uhs_periods, uh_spectra.periods)

        uh_spectrums = UhSpectrum.objects.filter(uh_spectra=uh_spectra.id)
        # We just want to make sure there is one record in hzrdr.uh_spectrum
        # per PoE.
        self.assertEqual(
            set(self.job_profile.poes), set([x.poe for x in uh_spectrums]))
Example #2
0
    def test_write_uhs_spectrum_data(self):
        # Test `write_uhs_spectrum_data`.

        # To start with, we need to write the 'container' records for the UHS
        # results:
        write_uh_spectra(self.job_ctxt)

        uhs_results = []  # The results we want to write to HDF5
        uhs_result = java.jvm().JClass('org.gem.calc.UHSResult')

        # Build up a result list that we can pass to the function under test:
        for poe, uhs in self.UHS_RESULTS:
            uhs_results.append(uhs_result(poe, list_to_jdouble_array(uhs)))

        realization = 0
        test_site = Site(0.0, 0.0)

        # Call the function under test
        write_uhs_spectrum_data(
            self.job_ctxt, realization, test_site, uhs_results)

        uhs_data = UhSpectrumData.objects.filter(
            uh_spectrum__uh_spectra__output__oq_job=(
            self.job.id))

        self.assertEqual(len(self.UHS_RESULTS), len(uhs_data))
        self.assertTrue(all([x.realization == 0 for x in uhs_data]))

        uhs_results_dict = dict(self.UHS_RESULTS)  # keyed by PoE
        for uhs_datum in uhs_data:
            self.assertTrue(
                numpy.allclose(uhs_results_dict[uhs_datum.uh_spectrum.poe],
                               uhs_datum.sa_values))
            self.assertEqual(test_site.point.to_wkt(), uhs_datum.location.wkt)
Example #3
0
    def test_write_uhs_spectrum_data(self):
        # Test `write_uhs_spectrum_data`.

        # To start with, we need to write the 'container' records for the UHS
        # results:
        write_uh_spectra(self.job_ctxt)

        uhs_results = []  # The results we want to write to HDF5
        uhs_result = java.jvm().JClass('org.gem.calc.UHSResult')

        # Build up a result list that we can pass to the function under test:
        for poe, uhs in self.UHS_RESULTS:
            uhs_results.append(uhs_result(poe, list_to_jdouble_array(uhs)))

        realization = 0
        test_site = Site(0.0, 0.0)

        # Call the function under test
        write_uhs_spectrum_data(
            self.job_ctxt, realization, test_site, uhs_results)

        uhs_data = UhSpectrumData.objects.filter(
            uh_spectrum__uh_spectra__output__oq_job=(
            self.job.id))

        self.assertEqual(len(self.UHS_RESULTS), len(uhs_data))
        self.assertTrue(all([x.realization == 0 for x in uhs_data]))

        uhs_results_dict = dict(self.UHS_RESULTS)  # keyed by PoE
        for uhs_datum in uhs_data:
            self.assertTrue(
                numpy.allclose(uhs_results_dict[uhs_datum.uh_spectrum.poe],
                               uhs_datum.sa_values))
            self.assertEqual(test_site.point.to_wkt(), uhs_datum.location.wkt)
Example #4
0
    def test_write_uh_spectra(self):
        # Test the writing of the intial database records for UHS results.
        # The function under test (`write_uh_spectra`) should write:
        #   - 1 uiapi.output record
        #   - 1 hzrdr.uh_spectra record
        #   - 1 hzrdr.uh_spectrum record per PoE defined in the oq_job_profile

        # Call the function under test:
        write_uh_spectra(self.job_ctxt)

        # Now check that the expected records were indeed created.
        output = Output.objects.get(oq_job=self.job.id)
        self.assertEqual('uh_spectra', output.output_type)

        uh_spectra = UhSpectra.objects.get(output=output.id)
        self.assertEqual(
            self.job_profile.investigation_time, uh_spectra.timespan)
        self.assertEqual(
            self.job_profile.realizations, uh_spectra.realizations)
        self.assertEqual(self.job_profile.uhs_periods, uh_spectra.periods)

        uh_spectrums = UhSpectrum.objects.filter(uh_spectra=uh_spectra.id)
        # We just want to make sure there is one record in hzrdr.uh_spectrum
        # per PoE.
        self.assertEqual(
            set(self.job_profile.poes), set([x.poe for x in uh_spectrums]))