• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python wfs_input_generator.InputFileGenerator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中wfs_input_generator.InputFileGenerator的典型用法代码示例。如果您正苦于以下问题:Python InputFileGenerator类的具体用法?Python InputFileGenerator怎么用?Python InputFileGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了InputFileGenerator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_adding_multiple_events_JSON

def test_adding_multiple_events_JSON():
    """
    Tests adding multiple events as JSON.
    """
    events = [{
        "latitude": 45.0,
        "description": "Some description",
        "longitude": 12.1,
        "depth_in_km": 13.0,
        "origin_time": str(obspy.UTCDateTime(2012, 4, 12, 7, 15, 48, 500000)),
        "m_rr": -2.11e+18,
        "m_tt": -4.22e+19,
        "m_pp": 4.43e+19,
        "m_rt": -9.35e+18,
        "m_rp": -8.38e+18,
        "m_tp": -6.44e+18
    }, {
        "latitude": 13.93,
        "description": "Some other description",
        "longitude": -92.47,
        "depth_in_km": 28.7,
        "origin_time": str(obspy.UTCDateTime(2012, 11, 7, 16, 35, 55, 200000)),
        "m_rr": 1.02e+20,
        "m_tt": -7.96e+19,
        "m_pp": -2.19e+19,
        "m_rt": 6.94e+19,
        "m_rp": -4.08e+19,
        "m_tp": 4.09e+19}]
    gen = InputFileGenerator()
    gen.add_events(json.dumps(events))

    events[0]["origin_time"] = obspy.UTCDateTime(events[0]["origin_time"])
    events[1]["origin_time"] = obspy.UTCDateTime(events[1]["origin_time"])
    assert sorted(gen._events) == sorted(events)
开发者ID:krischer,项目名称:wfs_input_generator,代码行数:34,代码来源:test_input_file_generator.py


示例2: test_reading_events_from_dictionary

 def test_reading_events_from_dictionary(self):
     """
     Tests that events can also be passed as dictionaries.
     """
     events = [{
         "latitude": 45.0,
         "longitude": 12.1,
         "depth_in_km": 13.0,
         "origin_time": UTCDateTime(2012, 4, 12, 7, 15, 48, 500000),
         "m_rr": -2.11e+18,
         "m_tt": -4.22e+19,
         "m_pp": 4.43e+19,
         "m_rt": -9.35e+18,
         "m_rp": -8.38e+18,
         "m_tp": -6.44e+18
     }, {
         "latitude": 13.93,
         "longitude": -92.47,
         "depth_in_km": 28.7,
         "origin_time": UTCDateTime(2012, 11, 7, 16, 35, 55, 200000),
         "m_rr": 1.02e+20,
         "m_tt": -7.96e+19,
         "m_pp": -2.19e+19,
         "m_rt": 6.94e+19,
         "m_rp": -4.08e+19,
         "m_tp": 4.09e+19}]
     gen = InputFileGenerator()
     gen.add_events(events)
     self.assertEqual(sorted(gen._events), sorted(events))
开发者ID:msimon00,项目名称:wfs_input_generator,代码行数:29,代码来源:test_input_file_generator.py


示例3: test_adding_events_as_URL

def test_adding_events_as_URL():
    """
    QuakeMLs should be downloaded if necessary.

    Mock the actual downloading.
    """
    event = {"description": "FICTIONAL EVENT IN BAVARIA",
             "latitude": 45.0,
             "longitude": 12.1,
             "depth_in_km": 13.0,
             "origin_time": obspy.UTCDateTime(2012, 4, 12, 7, 15, 48, 500000),
             "m_rr": -2.11e+18,
             "m_tt": -4.22e+19,
             "m_pp": 4.43e+19,
             "m_rt": -9.35e+18,
             "m_rp": -8.38e+18,
             "m_tp": -6.44e+18,
             "_event_id": "smi:local/Event/2013-01-05T20:19:58.727909"}

    quake_ml_file = os.path.join(DATA, "event1.xml")
    with open(quake_ml_file, "rb") as fh:
        data = fh.read()

    gen = InputFileGenerator()

    # Mock the URL
    with mock.patch("urllib2.urlopen") as patch:
        class Dummy(object):
            def read(self):
                return data
        patch.return_value = Dummy()
        gen.add_events("http://some_url.com")

    patch.assert_called_once_with("http://some_url.com")
    assert [event] == gen._events
开发者ID:krischer,项目名称:wfs_input_generator,代码行数:35,代码来源:test_input_file_generator.py


示例4: test_adding_invalid_file_to_event_raises

def test_adding_invalid_file_to_event_raises():
    """
    Adding some invalid things should of course raise.
    """
    gen = InputFileGenerator()
    with pytest.raises(ValueError):
        gen.add_events("some_nonesense")
开发者ID:krischer,项目名称:wfs_input_generator,代码行数:7,代码来源:test_input_file_generator.py


示例5: test_configuration_via_a_dictionary

def test_configuration_via_a_dictionary():
    """
    Tests that a dictionary can be used to update the configuration.
    """
    gen = InputFileGenerator()
    gen.config.test = "1"
    assert gen.config == {"test": "1"}

    gen.add_configuration({
        "something_else": 2,
        "and_more": 3.0})

    assert gen.config == {
        "test": "1",
        "something_else": 2,
        "and_more": 3.0}

    # Adding the something that already exists overwrites.
    gen.add_configuration({
        "test": "4"})

    assert gen.config == {
        "test": "4",
        "something_else": 2,
        "and_more": 3.0}
开发者ID:krischer,项目名称:wfs_input_generator,代码行数:25,代码来源:test_input_file_generator.py


示例6: test_adding_invalid_file_to_station_raises

def test_adding_invalid_file_to_station_raises():
    """
    Adding some invalid things should of course raise.
    """
    gen = InputFileGenerator()
    with pytest.raises(IOError):
        gen.add_stations("some_nonesense")
开发者ID:krischer,项目名称:wfs_input_generator,代码行数:7,代码来源:test_input_file_generator.py


示例7: test_id_lat_lon_ele_are_necessary

    def test_id_lat_lon_ele_are_necessary(self):
        """
        Tests that some station fields need to be set.
        """
        # Station with missing id.
        station_1 = {"latitude": 47.737167,
             "longitude": 11.2752,
             "elevation_in_m": 565.0}
        # Station with missing latitude.
        station_2 = {"id": "BW.FURT",
             "longitude": 11.2752,
             "elevation_in_m": 565.0}
        # Station with missing longitude.
        station_3 = {"id": "BW.FURT",
             "latitude": 47.737167,
             "elevation_in_m": 565.0}
        # Station with missing elevation.
        station_4 = {"id": "BW.FURT",
             "latitude": 47.737167,
             "longitude": 11.2752}
        # Station with everything necessary
        station_5 = {"id": "BW.FURT",
             "latitude": 47.737167,
             "longitude": 11.2752,
             "elevation_in_m": 565.0}

        gen = InputFileGenerator()
        # The first 4 should raise a ValueError
        self.assertRaises(ValueError, gen.add_stations, station_1)
        self.assertRaises(ValueError, gen.add_stations, station_2)
        self.assertRaises(ValueError, gen.add_stations, station_3)
        self.assertRaises(ValueError, gen.add_stations, station_4)
        # The last one not.
        gen.add_stations(station_5)
开发者ID:msimon00,项目名称:wfs_input_generator,代码行数:34,代码来源:test_input_file_generator.py


示例8: test_configuration_via_JSON

def test_configuration_via_JSON():
    """
    A JSON document can also be used.
    """
    gen = InputFileGenerator()
    gen.config.test = "1"
    assert gen.config == {"test": "1"}

    gen.add_configuration(json.dumps({
        "something_else": 2,
        "and_more": 3.0}))

    assert gen.config == {
        "test": "1",
        "something_else": 2,
        "and_more": 3.0}

    # Adding the something that already exists overwrites.
    gen.add_configuration(json.dumps({
        "test": "4"}))

    assert gen.config == {
        "test": "4",
        "something_else": 2,
        "and_more": 3.0}
开发者ID:krischer,项目名称:wfs_input_generator,代码行数:25,代码来源:test_input_file_generator.py


示例9: test_reading_QuakeML_files

    def test_reading_QuakeML_files(self):
        """
        Tests the reading of QuakeML Files.
        """
        event_file_1 = os.path.join(self.data_dir, "event1.xml")
        event_file_2 = os.path.join(self.data_dir, "event2.xml")

        gen = InputFileGenerator()
        gen.add_events([event_file_1, event_file_2])

        # Sort to be able to compare.
        events = sorted(gen._events)
        self.assertEqual([{
            "latitude": 45.0,
            "longitude": 12.1,
            "depth_in_km": 13.0,
            "origin_time": UTCDateTime(2012, 4, 12, 7, 15, 48, 500000),
            "m_rr": -2.11e+18,
            "m_tt": -4.22e+19,
            "m_pp": 4.43e+19,
            "m_rt": -9.35e+18,
            "m_rp": -8.38e+18,
            "m_tp": -6.44e+18
        }, {
            "latitude": 13.93,
            "longitude": -92.47,
            "depth_in_km": 28.7,
            "origin_time": UTCDateTime(2012, 11, 7, 16, 35, 55, 200000),
            "m_rr": 1.02e+20,
            "m_tt": -7.96e+19,
            "m_pp": -2.19e+19,
            "m_rt": 6.94e+19,
            "m_rp": -4.08e+19,
            "m_tp": 4.09e+19}],
            events)
开发者ID:msimon00,项目名称:wfs_input_generator,代码行数:35,代码来源:test_input_file_generator.py


示例10: test_event_filter_JSON

def test_event_filter_JSON():
    """
    Event filters can be set as JSON.
    """
    filters = ["smi:some/url", "smi:some/other/url"]
    gen = InputFileGenerator()
    gen.event_filter = json.dumps(filters)
    assert gen.event_filter == filters
开发者ID:krischer,项目名称:wfs_input_generator,代码行数:8,代码来源:test_input_file_generator.py


示例11: test_station_filter_JSON

def test_station_filter_JSON():
    """
    station filters can be set as JSON.
    """
    filters = ["BW.HH*", "NE.*"]
    gen = InputFileGenerator()
    gen.station_filter = json.dumps(filters)
    assert gen.station_filter == filters
开发者ID:krischer,项目名称:wfs_input_generator,代码行数:8,代码来源:test_input_file_generator.py


示例12: test_adding_sac_file_without_coordinates

def test_adding_sac_file_without_coordinates():
    """
    This sac file has no coordinates, thus no station should actually be added.
    """
    sac_file = os.path.join(DATA, "example_without_coordinates.sac")
    gen = InputFileGenerator()
    gen.add_stations(sac_file)
    assert gen._stations == []
开发者ID:krischer,项目名称:wfs_input_generator,代码行数:8,代码来源:test_input_file_generator.py


示例13: test_adding_stations_as_URLs

def test_adding_stations_as_URLs():
    """
    StationXML should be downloaded if necessary.

    Mock the actual downloading.
    """
    stations = [
        {"id": "HT.HORT",
         "latitude": 40.5978,
         "longitude": 23.0995,
         "elevation_in_m": 925.0,
         "local_depth_in_m": 0.0},
        {"id": "HT.LIT",
         "latitude": 40.1003,
         "longitude": 22.489,
         "elevation_in_m": 568.0,
         "local_depth_in_m": 0.0},
        {"id": "HT.PAIG",
         "latitude": 39.9363,
         "longitude": 23.6768,
         "elevation_in_m": 213.0,
         "local_depth_in_m": 0.0},
        {"id": "HT.SOH",
         "latitude": 40.8206,
         "longitude": 23.3556,
         "elevation_in_m": 728.0,
         "local_depth_in_m": 0.0},
        {"id": "HT.THE",
         "latitude": 40.6319,
         "longitude": 22.9628,
         "elevation_in_m": 124.0,
         "local_depth_in_m": 0.0},
        {"id": "HT.XOR",
         "latitude": 39.366,
         "longitude": 23.192,
         "elevation_in_m": 500.0,
         "local_depth_in_m": 0.0}]

    station_xml_file = os.path.join(DATA, "station.xml")
    with open(station_xml_file, "rb") as fh:
        data = fh.read()

    gen = InputFileGenerator()

    # Mock the URL
    with mock.patch("urllib2.urlopen") as patch:
        class Dummy(object):
            def read(self):
                return data
        patch.return_value = Dummy()
        gen.add_stations("http://some_url.com")

    patch.assert_called_once_with("http://some_url.com")
    assert sorted(stations) == sorted(gen._stations)
开发者ID:krischer,项目名称:wfs_input_generator,代码行数:54,代码来源:test_input_file_generator.py


示例14: test_config_raises_error_if_wrong_type

def test_config_raises_error_if_wrong_type():
    """
    The configuration method should raise in case a wrong type is added.
    """
    gen = InputFileGenerator()

    with pytest.raises(ValueError):
        gen.add_configuration("something")

    # Same with JSON if it is not a JSON object but a list.
    with pytest.raises(ValueError):
        gen.add_configuration(json.dumps([{"something": "new"}]))
开发者ID:krischer,项目名称:wfs_input_generator,代码行数:12,代码来源:test_input_file_generator.py


示例15: test_adding_stations_as_SAC_files

def test_adding_stations_as_SAC_files():
    """
    Tests adding stations as SAC files.
    """
    sac_file = os.path.join(DATA, "example.sac")
    gen = InputFileGenerator()
    gen.add_stations(sac_file)

    assert gen._stations[0]["id"] == "IU.ANMO"
    assert round(gen._stations[0]["latitude"] - 34.94598, 5) == 0
    assert round(gen._stations[0]["longitude"] - -106.45713, 5) == 0
    assert round(gen._stations[0]["elevation_in_m"] - 1671.0, 5) == 0
    assert round(gen._stations[0]["local_depth_in_m"] - 145.0, 5) == 0
开发者ID:krischer,项目名称:wfs_input_generator,代码行数:13,代码来源:test_input_file_generator.py


示例16: test_adding_a_single_station_dictionary

def test_adding_a_single_station_dictionary():
    """
    Tests adding a single station dictionary.
    """
    station = {
        "id": "BW.FURT",
        "latitude": 48.162899,
        "longitude": 11.2752,
        "elevation_in_m": 565.0,
        "local_depth_in_m": 10.0}
    gen = InputFileGenerator()
    gen.add_stations(station)
    assert [station] == gen._stations
开发者ID:krischer,项目名称:wfs_input_generator,代码行数:13,代码来源:test_input_file_generator.py


示例17: test_station_dicts_with_invalid_information_raise

def test_station_dicts_with_invalid_information_raise():
    """
    Station dicts that have invalid types that cannot be converted should
    raise!
    """
    # All the coordinate values should be converted to floats.
    station = {"id": "BW.FURT",
               "latitude": "A",
               "longitude": 2,
               "elevation_in_m": 3,
               "local_depth_in_m": 4}
    gen = InputFileGenerator()
    with pytest.raises(ValueError):
        gen.add_stations(station)
开发者ID:krischer,项目名称:wfs_input_generator,代码行数:14,代码来源:test_input_file_generator.py


示例18: test_adding_a_single_station_as_JSON

def test_adding_a_single_station_as_JSON():
    """
    Asserts that a single station can be added as JSON.
    """
    station = {
        "id": "BW.FURT",
        "latitude": 48.162899,
        "longitude": 11.2752,
        "elevation_in_m": 565.0,
        "local_depth_in_m": 10.0}
    json_station = json.dumps(station)
    gen = InputFileGenerator()
    gen.add_stations(json_station)
    assert [station] == gen._stations
开发者ID:krischer,项目名称:wfs_input_generator,代码行数:14,代码来源:test_input_file_generator.py


示例19: test_adding_sac_file_without_local_depth

def test_adding_sac_file_without_local_depth():
    """
    This file has no local depth. This should be ok.
    """
    sac_file = os.path.join(DATA, "example_without_local_depth.sac")
    gen = InputFileGenerator()
    gen.add_stations(sac_file)

    assert gen._stations[0]["id"] == "IU.ANMO"
    assert round(gen._stations[0]["latitude"] - 34.94598, 5) == 0
    assert round(gen._stations[0]["longitude"] - -106.45713, 5) == 0
    assert round(gen._stations[0]["elevation_in_m"] - 1671.0, 5) == 0
    # Local depth will be set to 0 in case it is not available.
    assert gen._stations[0]["local_depth_in_m"] == 0
开发者ID:krischer,项目名称:wfs_input_generator,代码行数:14,代码来源:test_input_file_generator.py


示例20: test_wrong_stf_header_format

def test_wrong_stf_header_format():
    """
    Simple test asserting that the correct exceptions get raised when
    attempting to write invalid STF headers.
    """
    station = {
        "id": "KO.ADVT",
        "latitude": 41.0,
        "longitude": 33.1234,
        "elevation_in_m": 10}
    event = {
        "latitude": 39.260,
        "longitude": 41.040,
        "depth_in_km": 5.0,
        "origin_time": UTCDateTime(2012, 4, 12, 7, 15, 48, 500000),
        "m_rr": 1.0e16,
        "m_tt": 1.0e16,
        "m_pp": 1.0e16,
        "m_rt": 0.0,
        "m_rp": 0.0,
        "m_tp": 0.0}

    gen = InputFileGenerator()
    gen.add_stations(station)
    gen.add_events(event)

    # Configure it.
    gen.config.number_of_time_steps = 4000
    gen.config.time_increment_in_s = 0.13
    gen.config.output_folder = "../DATA/OUTPUT/1.8s/"
    gen.config.mesh_min_latitude = 34.1
    gen.config.mesh_max_latitude = 42.9
    gen.config.mesh_min_longitude = 23.1
    gen.config.mesh_max_longitude = 42.9
    gen.config.mesh_min_depth_in_km = 0.0
    gen.config.mesh_max_depth_in_km = 471.0
    gen.config.nx_global = 66
    gen.config.ny_global = 108
    gen.config.nz_global = 28
    gen.config.px = 3
    gen.config.py = 4
    gen.config.pz = 4
    gen.config.source_time_function = np.linspace(1.0, 0.0, 4000)
    gen.config.is_dissipative = False

    gen.config.stf_header = "simple string"
    # Write the input files to a dictionary.
    with pytest.raises(ValueError):
        gen.write(format="ses3d_4_1")

    gen.config.stf_header = ["1", "2", "3", "4", "5", "6"]
    # Write the input files to a dictionary.
    with pytest.raises(ValueError):
        gen.write(format="ses3d_4_1")
开发者ID:krischer,项目名称:wfs_input_generator,代码行数:54,代码来源:test_ses3d_4_1_backend.py



注:本文中的wfs_input_generator.InputFileGenerator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python cache.delete_template_fragment_cache函数代码示例发布时间:2022-05-26
下一篇:
Python wfm.wave函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap