def test_masking(): install_path, data_path = get_config_paths() event_path = os.path.join(data_path, 'masking_test', 'current') set_files( event_path, { 'event.xml': 'event.xml', 'model.conf': 'model.conf', 'au_continental_shelf.geojson': 'au_continental_shelf.geojson', }) assemble = AssembleModule('masking_test', comment='Test comment.') assemble.execute() model = ModelModule('masking_test') model.execute() clear_files(event_path) hdf_file = os.path.join(event_path, 'products', 'shake_result.hdf') oc = ShakeMapOutputContainer.load(hdf_file) sa3 = oc.getIMTGrids('SA(3.0)', 'GREATER_OF_TWO_HORIZONTAL')['mean'] removed = np.isnan(sa3).astype(int) assert (removed[240, 240] == 1) assert (removed[260, 240] == 0) np.testing.assert_equal( removed[::100, ::100], [[1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 0, 1], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]) oc.close()
def test_model_2(): # # This is a small grid with station data and dyfi data (should succeed) # install_path, data_path = get_config_paths() event_path = os.path.join(data_path, 'nc72282711', 'current') set_files( event_path, { 'event.xml': 'event.xml', 'stationlist.xml.small': 'stationlist.xml', 'dyfi_dat.xml.small': 'dyfi_dat.xml', 'model.conf': 'model.conf', 'boat_fault.txt': 'boat_fault.txt' }) assemble = AssembleModule('nc72282711', comment='Test comment.') assemble.execute() model = ModelModule('nc72282711') model.execute() # # Since we've done this, we might as well run plotregr, too # plotregr = PlotRegr('nc72282711') plotregr.execute() plotregr.writeContents() clear_files(event_path)
def test_directivity(): # # Turned on directivity in model.conf # install_path, data_path = get_config_paths() event_path = os.path.join(data_path, 'directivity_test', 'current') set_files( event_path, { 'event.xml': 'event.xml', 'model.conf': 'model.conf', 'dir_fault.txt': 'dir_fault.txt' }) assemble = AssembleModule('directivity_test', comment='Test comment.') assemble.execute() model = ModelModule('directivity_test') model.execute() clear_files(event_path) hdf_file = os.path.join(event_path, 'products', 'shake_result.hdf') oc = ShakeMapOutputContainer.load(hdf_file) sa3 = np.exp( oc.getIMTGrids('SA(3.0)', 'GREATER_OF_TWO_HORIZONTAL')['mean']) # np.testing.assert_allclose(np.max(sa3), 1.15864273) np.testing.assert_allclose(np.max(sa3), 1.1567265149442174) # np.testing.assert_allclose(np.min(sa3), 0.9278920) np.testing.assert_allclose(np.min(sa3), 0.88508818541678) oc.close()
def test_model_7(): # # This event doesn't exist (should fail) # model = ModelModule('not_an_event') with pytest.raises(NotADirectoryError): model.execute()
def test_model_3(): # # This is a small grid with DYFI data only (should succeed) # assemble = AssembleModule('nc72282711_dyfi', comment='Test comment.') assemble.execute() model = ModelModule('nc72282711_dyfi') model.execute()
def test_model_3(): # # This is a small grid with DYFI data only (should succeed) # assemble = AssembleModule('nc72282711_dyfi') assemble.execute() model = ModelModule('nc72282711_dyfi') model.execute()
def test_model_4(): # # Run with no data and no fault, and use the default extent. # assemble = AssembleModule('nc72282711_nodata_nofault') assemble.execute() model = ModelModule('nc72282711_nodata_nofault') model.execute()
def test_model_1(): installpath, datapath = get_config_paths() # # This is Northridge for a set of output points (not a grid) # assemble = AssembleModule('northridge_points', comment='Test comment.') assemble.execute() model = ModelModule('northridge_points') model.execute()
def test_model_5(): # # Set the bias and outlier magnitude limits low to test additional # code branches # assemble = AssembleModule('nc72282711_nofault') assemble.execute() model = ModelModule('nc72282711_nofault') model.execute()
def test_model_4(): # # Run with no data and no fault, and use the default extent. # assemble = AssembleModule('nc72282711_nodata_nofault', comment='Test comment.') assemble.execute() model = ModelModule('nc72282711_nodata_nofault') model.execute()
def test_model_5(): # # Set the bias and outlier magnitude limits low to test additional # code branches # assemble = AssembleModule('nc72282711_nofault', comment='Test comment.') assemble.execute() model = ModelModule('nc72282711_nofault') model.execute()
def test_model_sim(): # # Run with no data and no fault, and use the default extent. # install_path, data_path = get_config_paths() # event_path = os.path.join(data_path, 'planet9', 'current') assemble = AssembleModule('planet9', comment='Test comment.') assemble.execute() model = ModelModule('planet9') model.execute()
def test_model_6(): installpath, datapath = get_config_paths() # # This event exists, but we hide the input hdf file (should fail) # hdf_file = os.path.join(datapath, 'nc72282711_dyfi', 'current', 'shake_data.hdf') if os.path.isfile(hdf_file): os.remove(hdf_file) model = ModelModule('nc72282711_dyfi') with pytest.raises(FileNotFoundError): model.execute()
def run_event(evid): installpath, datapath = get_config_paths() assemble = AssembleModule(evid, comment='Test comment.') assemble.execute() model = ModelModule(evid) model.execute() res_file = os.path.join(datapath, evid, 'current', 'products', 'shake_result.hdf') oc = ShakeMapOutputContainer.load(res_file) imts = oc.getIMTs() comps = oc.getComponents(imts[0]) imtdict = oc.getIMTArrays(imts[0], comps[0]) return imtdict
def test_model_4(): # # Run with no data and no fault, and use the default extent. # install_path, data_path = get_config_paths() event_path = os.path.join(data_path, 'nc72282711', 'current') set_files(event_path, {'event.xml': 'event.xml', 'model.conf': 'model.conf'}) assemble = AssembleModule('nc72282711', comment='Test comment.') assemble.execute() model = ModelModule('nc72282711') model.execute() clear_files(event_path)
def test_model_3(): # # This is a small grid with DYFI data only (should succeed) # install_path, data_path = get_config_paths() event_path = os.path.join(data_path, 'nc72282711', 'current') set_files(event_path, {'event.xml': 'event.xml', 'dyfi_dat.xml.small': 'dyfi_dat.xml', 'model.conf': 'model.conf', 'boat_fault.txt': 'boat_fault.txt'}) assemble = AssembleModule('nc72282711', comment='Test comment.') assemble.execute() model = ModelModule('nc72282711') model.execute() clear_files(event_path)
def test_model_2(): # # This is a small grid with station data and dyfi data (should succeed) # assemble = AssembleModule('nc72282711', comment='Test comment.') assemble.execute() model = ModelModule('nc72282711') model.execute() # # Since we've done this, we might as well run plotregr, too # plotregr = PlotRegr('nc72282711') plotregr.execute() plotregr.writeContents() pass
def test_model_1(): installpath, datapath = get_config_paths() # # This is Northridge for a set of output points (not a grid) # Remove the products directory to hit the code that makes it # (should succeed) # assemble = AssembleModule('northridge_points') assemble.execute() products_dir = os.path.join(datapath, 'northridge_points', 'current', 'products') if os.path.isdir(products_dir): shutil.rmtree(products_dir) model = ModelModule('northridge_points') model.execute()
def test_points(): installpath, datapath = get_config_paths() # An event with points rather than grid (should raise exception) evid = 'northridge_points' assemble = AssembleModule(evid, comment='Test comment.') assemble.execute() del assemble model = ModelModule(evid) model.execute() del model mapping = MappingModule(evid) # Mapping should raise exception with pytest.raises(NotImplementedError): mapping.execute() del mapping
def test_products(): installpath, datapath = get_config_paths() try: # # Make sure an output file exists # assemble = AssembleModule('nc72282711') assemble.execute() model = ModelModule('nc72282711') model.execute() # # Test the creation of products -- currently not checking results # for validity or consistency, but probably should # mod = ContourModule('nc72282711') mod.execute() mod = GridXMLModule('nc72282711') mod.execute() mod = InfoModule('nc72282711') mod.execute() mod = RasterModule('nc72282711') mod.execute() mod = RuptureModule('nc72282711') mod.execute() mod = StationModule('nc72282711') mod.execute() mod = MappingModule('nc72282711') mod.execute() finally: data_file = os.path.join(datapath, 'nc72282711', 'current', 'shake_data.hdf') if os.path.isfile(data_file): os.remove(data_file) res_file = os.path.join(datapath, 'nc72282711', 'current', 'products', 'shake_results.hdf') if os.path.isfile(res_file): os.remove(res_file)
def test_products(): installpath, datapath = get_config_paths() # # Use a real event for checks of products against the contents of # the output container # evid = 'integration_test_0001' try: # # Make sure an output file exists # assemble = AssembleModule(evid, comment='Test comment.') assemble.execute() del assemble model = ModelModule(evid) model.execute() del model res_file = os.path.join(datapath, evid, 'current', 'products', 'shake_result.hdf') oc = ShakeMapOutputContainer.load(res_file) # # Test the creation of products -- currently not checking results # for validity or consistency, but probably should # # # TODO: The stationlist.json should be validated, but we need a # function that will read it and convert it to something # we can test against. # check_failures(evid, datapath, StationModule) mod = StationModule(evid) mod.execute() mod.writeContents() check_failures(evid, datapath, MappingModule) mod = MappingModule(evid) mod.execute() mod.writeContents() check_failures(evid, datapath, PlotRegr) # # PlotRegr gets tested in the model tests for event 72282711 # # mod = PlotRegr(evid) # mod.execute() # mod.writeContents() check_failures(evid, datapath, KMLModule) mod = KMLModule(evid) mod.execute() mod.writeContents() del mod # # These check that the results are consistent with the output # container # do_rupture(evid, datapath, oc) do_info(evid, datapath, oc) do_raster(evid, datapath, oc) do_gridxml(evid, datapath, oc) oc.close() # # Checks contours against saved versions; if something # changes, will need to update the files in # data/integration_test_0001 # do_contour(evid, datapath) # do_contour_command_line(evid, datapath) check_failures(evid, datapath, TransferModule) mod = TransferModule(evid) mod.execute() bufiles = glob.glob(os.path.join(datapath, evid, 'backup*')) for bufile in bufiles: shutil.rmtree(bufile) finally: pass data_file = os.path.join(datapath, evid, 'current', 'shake_data.hdf') if os.path.isfile(data_file): os.remove(data_file)
def test_products(): installpath, datapath = get_config_paths() # # Use a real event for checks of products against the contents of # the output container # evid = 'integration_test_0001' try: # # Make sure an output file exists # assemble = AssembleModule(evid, comment='Test comment.') assemble.execute() del assemble model = ModelModule(evid) model.execute() del model res_file = os.path.join(datapath, evid, 'current', 'products', 'shake_result.hdf') oc = ShakeMapOutputContainer.load(res_file) # # The history module just outputs some info to the operator, so # here we just run it to make sure it doesn't crash anything. # Actual testing should be done via bug reports/feature requests # from users. # history = HistoryModule(evid) history.execute() del history # # Test the creation of products -- currently not checking results # for validity or consistency, but probably should # # # TODO: The stationlist.json should be validated, but we need a # function that will read it and convert it to something # we can test against. # check_failures(evid, datapath, StationModule) mod = StationModule(evid) mod.execute() mod.writeContents() check_failures(evid, datapath, MappingModule) mod = MappingModule(evid) mod.execute() mod.writeContents() check_failures(evid, datapath, PlotRegr) # # PlotRegr gets tested in the model tests for event 72282711 # # mod = PlotRegr(evid) # mod.execute() # mod.writeContents() check_failures(evid, datapath, KMLModule) mod = KMLModule(evid) mod.execute() mod.writeContents() del mod # This just exercises the ShapeModule code without actually # checking for valid results. mod = ShapeModule(evid) mod.execute() mod.writeContents() del mod # # These check that the results are consistent with the output # container # do_rupture(evid, datapath, oc) # do_info(evid, datapath, oc) do_raster(evid, datapath, oc) do_gridxml(evid, datapath, oc) oc.close() # # Checks contours against saved versions; if something # changes, will need to update the files in # data/integration_test_0001 # # TODO: (7/28/2021)I am disabling this test for a little while until # the float32 HDF version of the impactutils containers are in # wide distribution. At that point, I'll update the data files # and the test results. # do_contour(evid, datapath) # do_contour_command_line(evid, datapath) finally: pass data_file = os.path.join(datapath, evid, 'current', 'shake_data.hdf') if os.path.isfile(data_file): os.remove(data_file)
def test_verification(): installpath, datapath = get_config_paths() try: # # Test xtestplot on verification event 0006 # assemble = AssembleModule('verification_test_0006', comment='Test comment.') assemble.execute() model = ModelModule('verification_test_0006') model.execute() plot = XTestPlot('verification_test_0006') plot.execute() # # Test xtestplot_spectra on verification event 0007 # assemble = AssembleModule('verification_test_0007', comment='Test comment.') assemble.execute() model = ModelModule('verification_test_0007') model.execute() plot = XTestPlotSpectra('verification_test_0007') plot.execute() # # Test xtestimage on verification event 0011 # assemble = AssembleModule('verification_test_0011', comment='Test comment.') assemble.execute() model = ModelModule('verification_test_0011') model.execute() plot = XTestImage('verification_test_0011') plot.execute() regr = PlotRegr('verification_test_0011') regr.execute() # # Test xtestplot_multi on event 0008x # for vt in ('8a', '8b', '8c', '8d', '8e'): assemble = AssembleModule('verification_test_000%s' % vt, comment='Test comment.') assemble.execute() model = ModelModule('verification_test_000%s' % vt) model.execute() plot = XTestPlotMulti('verification_test_0008') plot.execute() finally: data_file = os.path.join(datapath, 'verification_test_0006', 'current', 'shake_data.hdf') if os.path.isfile(data_file): os.remove(data_file) data_file = os.path.join(datapath, 'verification_test_0007', 'current', 'shake_data.hdf') if os.path.isfile(data_file): os.remove(data_file) data_file = os.path.join(datapath, 'verification_test_0011', 'current', 'shake_data.hdf') if os.path.isfile(data_file): os.remove(data_file) for vt in ('8a', '8b', '8c', '8d', '8e'): evid = 'verification_test_000%s' % vt data_file = os.path.join(datapath, evid, 'current', 'shake_data.hdf') if os.path.isfile(data_file): os.remove(data_file)