当前位置: 首页>>代码示例>>Python>>正文


Python wfs_input_generator.InputFileGenerator类代码示例

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


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


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