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_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_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_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_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_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_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_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_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 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_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_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_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_cancel(): installpath, datapath = get_config_paths() shutil.copytree(os.path.join(datapath, 'integration_test_0001'), os.path.join(datapath, 'dummy_event')) # Process a non-existent event (should fail) try: mod = AssembleModule('dummy_event', comment='') mod.execute() mod = ModelModule('dummy_event') mod.execute() mod = CancelModule('dummy_event') mod.execute() finally: shutil.rmtree(os.path.join(datapath, 'dummy_event')) amp_file = os.path.join(installpath, 'data', 'amps.db') if os.path.isfile(amp_file): os.remove(amp_file)
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_assemble(): installpath, datapath = get_config_paths() # Process a non-existent event (should fail) amod = AssembleModule('not_an_event') with pytest.raises(NotADirectoryError): amod.execute() # Would succeed but we remove event.xml (should fail) event_file = os.path.join(datapath, 'wenchuan', 'current', 'event.xml') os.rename(event_file, event_file + '_safe') try: amod = AssembleModule('wenchuan') with pytest.raises(FileNotFoundError): amod.execute() finally: os.rename(event_file + '_safe', event_file) # Normal event (should succeed) data_file = os.path.join(datapath, 'wenchuan', 'current', 'shake_data.hdf') if os.path.isfile(data_file): os.remove(data_file) try: amod = AssembleModule('wenchuan') amod.execute() # # Run a second time to exercise a different branch of the code # amod.execute() finally: if os.path.isfile(data_file): os.remove(data_file) # Do an event with model.conf (not model_zc.conf) and no zoneinfo # (should succeed) data_file = os.path.join(datapath, 'nc72282711', 'current', 'shake_data.hdf') if os.path.isfile(data_file): os.remove(data_file) try: amod = AssembleModule('nc72282711') amod.execute() finally: if os.path.isfile(data_file): os.remove(data_file) # Try not having an event-specific config (should succeed) model_file = os.path.join(datapath, 'nc72282711', 'current', 'model.conf') os.rename(model_file, model_file + '_safe') data_file = os.path.join(datapath, 'nc72282711', 'current', 'shake_data.hdf') if os.path.isfile(data_file): os.remove(data_file) try: amod = AssembleModule('nc72282711') amod.execute() finally: os.rename(model_file + '_safe', model_file) if os.path.isfile(data_file): os.remove(data_file) # Do an event with DYFI data (should succeed) hdf_file = os.path.join(datapath, 'nc72282711_dyfi', 'current', 'shake_data.hdf') if os.path.isfile(hdf_file): os.rename(hdf_file, hdf_file + '_safe') try: amod = AssembleModule('nc72282711_dyfi') amod.execute() finally: if os.path.isfile(hdf_file + '_safe'): os.rename(hdf_file + '_safe', hdf_file) # # Try some bad config files # # Should fail validation model_file = os.path.join(datapath, 'nc72282711_nodata_nofault', 'current', 'model_zc.conf') os.rename(model_file, model_file + '_safe') shutil.copyfile(model_file + '.bad0', model_file) try: amod = AssembleModule('nc72282711_nodata_nofault') with pytest.raises(RuntimeError): amod.execute() finally: os.rename(model_file + '_safe', model_file) # Should fail vs30 filename check model_file = os.path.join(datapath, 'nc72282711_nodata_nofault', 'current', 'model_zc.conf') os.rename(model_file, model_file + '_safe') shutil.copyfile(model_file + '.bad1', model_file) try: amod = AssembleModule('nc72282711_nodata_nofault') with pytest.raises(FileNotFoundError): amod.execute() finally: os.rename(model_file + '_safe', model_file) # Should fail prediction locations filename check model_file = os.path.join(datapath, 'nc72282711_nodata_nofault', 'current', 'model_zc.conf') os.rename(model_file, model_file + '_safe') shutil.copyfile(model_file + '.bad2', model_file) try: amod = AssembleModule('nc72282711_nodata_nofault') with pytest.raises(FileNotFoundError): amod.execute() finally: os.rename(model_file + '_safe', model_file) # # Make sure the location file substitutions work (should succeed) # data_file = os.path.join( datapath, 'northridge_points', 'current', 'shake_data.hdf') if os.path.isfile(data_file): os.remove(data_file) try: amod = AssembleModule('northridge_points') amod.execute() finally: if os.path.isfile(data_file): os.remove(data_file)
def test_augment(): installpath, datapath = get_config_paths() # Process a non-existent event (should fail) augment = AugmentModule('not_an_event', comment='Test comment.') with pytest.raises(NotADirectoryError): augment.execute() # This would succeed, but we remove shake_data.hdf (should fail) hdf_file = os.path.join(datapath, 'wenchuan', 'current', 'shake_data.hdf') if os.path.isfile(hdf_file): os.rename(hdf_file, hdf_file + '_safe') try: augment = AugmentModule('wenchuan', comment='Test comment.') with pytest.raises(FileNotFoundError): augment.execute() finally: if os.path.isfile(hdf_file + '_safe'): os.rename(hdf_file + '_safe', hdf_file) # Normal event (should succeed) data_file = os.path.join(datapath, 'wenchuan', 'current', 'shake_data.hdf') if os.path.isfile(data_file): os.remove(data_file) try: assemble = AssembleModule('wenchuan', comment='Test comment.') assemble.execute() augment = AugmentModule('wenchuan', comment='Test comment.') augment.execute() finally: if os.path.isfile(data_file): os.remove(data_file) # Do an event with model.conf (not model_zc.conf) and no zoneinfo # (should succeed) data_file = os.path.join(datapath, 'nc72282711', 'current', 'shake_data.hdf') if os.path.isfile(data_file): os.remove(data_file) try: assemble = AssembleModule('nc72282711', comment='Test comment.') assemble.execute() augment = AugmentModule('nc72282711', comment='Test comment.') augment.execute() finally: if os.path.isfile(data_file): os.remove(data_file) # # Make sure the location file substitutions work (should succeed) # data_file = os.path.join(datapath, 'northridge_points', 'current', 'shake_data.hdf') if os.path.isfile(data_file): os.remove(data_file) try: assemble = AssembleModule('northridge_points', comment='Test comment.') assemble.execute() augment = AugmentModule('northridge_points', comment='Test comment.') augment.execute() finally: if os.path.isfile(data_file): os.remove(data_file) # # Try some bad config files # data_file = os.path.join(datapath, 'nc72282711_nodata_nofault', 'current', 'shake_data.hdf') if os.path.isfile(data_file): os.remove(data_file) try: assemble = AssembleModule('nc72282711_nodata_nofault', comment='Test comment.') assemble.execute() # Should fail validation model_file = os.path.join(datapath, 'nc72282711_nodata_nofault', 'current', 'model_zc.conf') os.rename(model_file, model_file + '_safe') shutil.copyfile(model_file + '.bad0', model_file) try: augment = AugmentModule('nc72282711_nodata_nofault', comment='Test comment.') with pytest.raises(RuntimeError): augment.execute() finally: os.rename(model_file + '_safe', model_file) # Should fail vs30 filename check model_file = os.path.join(datapath, 'nc72282711_nodata_nofault', 'current', 'model_zc.conf') os.rename(model_file, model_file + '_safe') shutil.copyfile(model_file + '.bad1', model_file) try: augment = AugmentModule('nc72282711_nodata_nofault', comment='Test comment.') with pytest.raises(FileNotFoundError): augment.execute() finally: os.rename(model_file + '_safe', model_file) # Should fail prediction locations filename check model_file = os.path.join(datapath, 'nc72282711_nodata_nofault', 'current', 'model_zc.conf') os.rename(model_file, model_file + '_safe') shutil.copyfile(model_file + '.bad2', model_file) try: augment = AugmentModule('nc72282711_nodata_nofault', comment='Test comment.') with pytest.raises(FileNotFoundError): augment.execute() finally: os.rename(model_file + '_safe', model_file) finally: if os.path.isfile(data_file): os.remove(data_file) # # Switch originators (should succeed) # model_file = os.path.join(datapath, 'nc72282711', 'current', 'model.conf') os.rename(model_file, model_file + '_safe') shutil.copyfile(model_file + '.cz', model_file) data_file = os.path.join(datapath, 'nc72282711', 'current', 'shake_data.hdf') if os.path.isfile(data_file): os.remove(data_file) try: assemble = AssembleModule('nc72282711', comment='Test comment.') assemble.execute() augment = AugmentModule('nc72282711', comment='Test comment.') augment.execute() finally: os.rename(model_file + '_safe', model_file) if os.path.isfile(data_file): os.remove(data_file)
def test_assemble(): installpath, datapath = get_config_paths() # Process a non-existent event (should fail) amod = AssembleModule('not_an_event', comment='Test comment.') with pytest.raises(NotADirectoryError): amod.execute() # Would succeed but we remove event.xml (should fail) event_file = os.path.join(datapath, 'wenchuan', 'current', 'event.xml') os.rename(event_file, event_file + '_safe') try: amod = AssembleModule('wenchuan', comment='Test comment.') with pytest.raises(FileNotFoundError): amod.execute() finally: os.rename(event_file + '_safe', event_file) # Normal event (should succeed) data_file = os.path.join(datapath, 'wenchuan', 'current', 'shake_data.hdf') if os.path.isfile(data_file): os.remove(data_file) try: amod = AssembleModule('wenchuan', comment='Test comment.') amod.execute() # # Run a second time to exercise a different branch of the code # amod.execute() finally: if os.path.isfile(data_file): os.remove(data_file) # Do an event with model.conf (not model_zc.conf) and no zoneinfo # (should succeed) data_file = os.path.join(datapath, 'nc72282711', 'current', 'shake_data.hdf') if os.path.isfile(data_file): os.remove(data_file) try: amod = AssembleModule('nc72282711', comment='Test comment.') amod.execute() finally: if os.path.isfile(data_file): os.remove(data_file) # Try not having an event-specific config (should succeed) model_file = os.path.join(datapath, 'nc72282711', 'current', 'model.conf') os.rename(model_file, model_file + '_safe') data_file = os.path.join(datapath, 'nc72282711', 'current', 'shake_data.hdf') if os.path.isfile(data_file): os.remove(data_file) try: amod = AssembleModule('nc72282711', comment='Test comment.') amod.execute() finally: os.rename(model_file + '_safe', model_file) if os.path.isfile(data_file): os.remove(data_file) # Do an event with DYFI data (should succeed) hdf_file = os.path.join(datapath, 'nc72282711_dyfi', 'current', 'shake_data.hdf') if os.path.isfile(hdf_file): os.rename(hdf_file, hdf_file + '_safe') try: amod = AssembleModule('nc72282711_dyfi', comment='Test comment.') amod.execute() finally: if os.path.isfile(hdf_file + '_safe'): os.rename(hdf_file + '_safe', hdf_file) # # Try some bad config files # # Should fail validation model_file = os.path.join(datapath, 'nc72282711_nodata_nofault', 'current', 'model_zc.conf') os.rename(model_file, model_file + '_safe') shutil.copyfile(model_file + '.bad0', model_file) try: amod = AssembleModule('nc72282711_nodata_nofault', comment='Test comment.') with pytest.raises(RuntimeError): amod.execute() finally: os.rename(model_file + '_safe', model_file) # Should fail vs30 filename check model_file = os.path.join(datapath, 'nc72282711_nodata_nofault', 'current', 'model_zc.conf') os.rename(model_file, model_file + '_safe') shutil.copyfile(model_file + '.bad1', model_file) try: amod = AssembleModule('nc72282711_nodata_nofault', comment='Test comment.') with pytest.raises(FileNotFoundError): amod.execute() finally: os.rename(model_file + '_safe', model_file) # Should fail prediction locations filename check model_file = os.path.join(datapath, 'nc72282711_nodata_nofault', 'current', 'model_zc.conf') os.rename(model_file, model_file + '_safe') shutil.copyfile(model_file + '.bad2', model_file) try: amod = AssembleModule('nc72282711_nodata_nofault', comment='Test comment.') with pytest.raises(FileNotFoundError): amod.execute() finally: os.rename(model_file + '_safe', model_file) # # Make sure the location file substitutions work (should succeed) # data_file = os.path.join( datapath, 'northridge_points', 'current', 'shake_data.hdf') if os.path.isfile(data_file): os.remove(data_file) try: amod = AssembleModule('northridge_points', comment='Test comment.') amod.execute() finally: if os.path.isfile(data_file): os.remove(data_file)
def test_assemble_augment(): installpath, datapath = get_config_paths() # Process a non-existent event (should fail) amod = AssembleModule('not_an_event', comment='Test comment.') with pytest.raises(NotADirectoryError): amod.execute() # Process a non-existent event (should fail) augment = AugmentModule('not_an_event', comment='Test comment.') with pytest.raises(NotADirectoryError): augment.execute() # Would succeed but we remove event.xml (should fail) event_file = os.path.join(datapath, 'wenchuan', 'current', 'event.xml') os.rename(event_file, event_file + '_safe') try: amod = AssembleModule('wenchuan', comment='Test comment.') with pytest.raises(FileNotFoundError): amod.execute() finally: os.rename(event_file + '_safe', event_file) # Normal event (should succeed) data_file = os.path.join(datapath, 'wenchuan', 'current', 'shake_data.hdf') if os.path.isfile(data_file): os.remove(data_file) try: amod = AssembleModule('wenchuan', comment='Test comment.') amod.execute() # # Run a second time to exercise a different branch of the code # amod.execute() finally: pass # This would succeed, but we remove shake_data.hdf (should fail) hdf_file = os.path.join(datapath, 'wenchuan', 'current', 'shake_data.hdf') if os.path.isfile(hdf_file): os.rename(hdf_file, hdf_file + '_safe') try: augment = AugmentModule('wenchuan', comment='Test comment.') with pytest.raises(FileNotFoundError): augment.execute() finally: # Put shake_data.hdf back for the next test if os.path.isfile(hdf_file + '_safe'): os.rename(hdf_file + '_safe', hdf_file) # Normal event (should succeed) try: augment = AugmentModule('wenchuan', comment='Test comment.') augment.execute() finally: if os.path.isfile(data_file): os.remove(data_file) # Do an event with model.conf (not model_select.conf) and no zoneinfo # (should succeed) event_path = os.path.join(datapath, 'nc72282711', 'current') set_files( event_path, { 'event.xml': 'event.xml', 'stationlist.xml': 'stationlist.xml', 'boat_fault.txt': 'boat_fault.txt', 'model.conf': 'model.conf' }) data_file = os.path.join(datapath, 'nc72282711', 'current', 'shake_data.hdf') if os.path.isfile(data_file): os.remove(data_file) try: assemble = AssembleModule('nc72282711', comment='Test comment.') assemble.execute() augment = AugmentModule('nc72282711', comment='Test comment.') augment.execute() finally: if os.path.isfile(data_file): os.remove(data_file) clear_files(event_path) # Try not having an event-specific config (should succeed) set_files( event_path, { 'event.xml': 'event.xml', 'stationlist.xml': 'stationlist.xml', 'boat_fault.txt': 'boat_fault.txt' }) try: amod = AssembleModule('nc72282711', comment='Test comment.') amod.execute() augment = AugmentModule('nc72282711', comment='Test comment.') augment.execute() finally: if os.path.isfile(data_file): os.remove(data_file) clear_files(event_path) # Do an event with DYFI data (should succeed) set_files( event_path, { 'event.xml': 'event.xml', 'stationlist.xml': 'stationlist.xml', 'boat_fault.txt': 'boat_fault.txt', 'dyfi_dat.xml': 'dyfi_dat.xml' }) try: amod = AssembleModule('nc72282711', comment='Test comment.') amod.execute() augment = AugmentModule('nc72282711', comment='Test comment.') augment.execute() finally: if os.path.isfile(data_file): os.remove(data_file) clear_files(event_path) # # Try some bad config files # # Should fail validation set_files(event_path, { 'event.xml': 'event.xml', 'model_select.conf.bad0': 'model_select.conf' }) try: amod = AssembleModule('nc72282711', comment='Test comment.') with pytest.raises(RuntimeError): amod.execute() finally: clear_files(event_path) # Should fail vs30 filename check set_files(event_path, { 'event.xml': 'event.xml', 'model_select.conf.bad1': 'model_select.conf' }) try: amod = AssembleModule('nc72282711', comment='Test comment.') with pytest.raises(RuntimeError): amod.execute() finally: clear_files(event_path) # Should fail prediction locations filename check set_files(event_path, { 'event.xml': 'event.xml', 'model_select.conf.bad2': 'model_select.conf' }) try: amod = AssembleModule('nc72282711', comment='Test comment.') with pytest.raises(FileNotFoundError): amod.execute() finally: clear_files(event_path) # # Make sure the location file substitutions work (should succeed) # data_file = os.path.join(datapath, 'northridge_points', 'current', 'shake_data.hdf') if os.path.isfile(data_file): os.remove(data_file) try: assemble = AssembleModule('northridge_points', comment='Test comment.') assemble.execute() augment = AugmentModule('northridge_points', comment='Test comment.') augment.execute() finally: if os.path.isfile(data_file): os.remove(data_file) # # Try some bad config files # try: set_files(event_path, {'event.xml': 'event.xml'}) assemble = AssembleModule('nc72282711', comment='Test comment.') assemble.execute() # Should fail validation set_files(event_path, {'model_select.conf.bad0': 'model_select.conf'}) augment = AugmentModule('nc72282711', comment='Test comment.') with pytest.raises(RuntimeError): augment.execute() clear_files(event_path) # Should fail vs30 filename check set_files(event_path, {'event.xml': 'event.xml'}) assemble = AssembleModule('nc72282711', comment='Test comment.') assemble.execute() set_files( event_path, { 'event.xml': 'event.xml', 'model_select.conf.bad1': 'model_select.conf' }) augment = AugmentModule('nc72282711', comment='Test comment.') with pytest.raises(RuntimeError): augment.execute() clear_files(event_path) # Should fail prediction locations filename check set_files(event_path, {'event.xml': 'event.xml'}) assemble = AssembleModule('nc72282711', comment='Test comment.') assemble.execute() set_files( event_path, { 'event.xml': 'event.xml', 'model_select.conf.bad2': 'model_select.conf' }) augment = AugmentModule('nc72282711', comment='Test comment.') with pytest.raises(FileNotFoundError): augment.execute() finally: clear_files(event_path) # # Switch originators (should succeed) # set_files(event_path, { 'event.xml': 'event.xml', 'model.conf.cz': 'model.conf' }) try: assemble = AssembleModule('nc72282711', comment='Test comment.') assemble.execute() augment = AugmentModule('nc72282711', comment='Test comment.') augment.execute() finally: if os.path.isfile(data_file): os.remove(data_file) clear_files(event_path)
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)