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


Python InputFileGenerator.add_stations方法代码示例

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


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

示例1: test_local_depth_will_be_set_to_zero

# 需要导入模块: from wfs_input_generator import InputFileGenerator [as 别名]
# 或者: from wfs_input_generator.InputFileGenerator import add_stations [as 别名]
def test_local_depth_will_be_set_to_zero():
    """
    Tests that the local depth will be set to zero if not given.
    """
    stations = [{
        "id": "BW.FURT",
        "latitude": 48.162899,
        "longitude": 11.2752,
        "elevation_in_m": 565.0},
        {"id": "BW.RJOB",
         "latitude": 47.737167,
         "longitude": 12.795714,
         "elevation_in_m": 860.0}]
    json_stations = json.dumps(stations)
    gen = InputFileGenerator()
    gen.add_stations(stations)
    # Now add the local depth again.
    stations[0]["local_depth_in_m"] = 0.0
    stations[1]["local_depth_in_m"] = 0.0
    assert sorted(stations) == sorted(gen._stations)

    # Repeat with the JSON variant.
    gen = InputFileGenerator()
    gen.add_stations(json_stations)
    assert sorted(stations) == sorted(gen._stations)
开发者ID:krischer,项目名称:wfs_input_generator,代码行数:27,代码来源:test_input_file_generator.py

示例2: test_id_lat_lon_ele_are_necessary

# 需要导入模块: from wfs_input_generator import InputFileGenerator [as 别名]
# 或者: from wfs_input_generator.InputFileGenerator import add_stations [as 别名]
    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,代码行数:36,代码来源:test_input_file_generator.py

示例3: test_adding_invalid_file_to_station_raises

# 需要导入模块: from wfs_input_generator import InputFileGenerator [as 别名]
# 或者: from wfs_input_generator.InputFileGenerator import add_stations [as 别名]
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,代码行数:9,代码来源:test_input_file_generator.py

示例4: test_adding_sac_file_without_coordinates

# 需要导入模块: from wfs_input_generator import InputFileGenerator [as 别名]
# 或者: from wfs_input_generator.InputFileGenerator import add_stations [as 别名]
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,代码行数:10,代码来源:test_input_file_generator.py

示例5: main

# 需要导入模块: from wfs_input_generator import InputFileGenerator [as 别名]
# 或者: from wfs_input_generator.InputFileGenerator import add_stations [as 别名]
def main():
    gen = InputFileGenerator()

    # SES3D 4.0 can only simulate one event at a time.
    gen.add_events("../tests/data/event1.xml")
    gen.add_stations(["../tests/data/dataless.seed.BW_FURT",
                      "../tests/data/dataless.seed.BW_RJOB"])

    # Just perform a standard forward simulation.
    gen.config.simulation_type = "normal simulation"

    gen.config.output_folder = "../OUTPUT"

    # Time configuration.
    gen.config.number_of_time_steps = 700
    gen.config.time_increment_in_s = 0.75

    # SES3D specific configuration
    gen.config.output_directory = "../DATA/OUTPUT/1.8s"
    # SES3D specific discretization
    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

    # Specify some source time function.
    gen.config.source_time_function = np.sin(np.linspace(0, 10, 700))

    # Configure the mesh.
    gen.config.mesh_min_latitude = -50.0
    gen.config.mesh_max_latitude = 50.0
    gen.config.mesh_min_longitude = -50.0
    gen.config.mesh_max_longitude = 50.0
    gen.config.mesh_min_depth_in_km = 0.0
    gen.config.mesh_max_depth_in_km = 200.0

    # Define the rotation. Take care this is defined as the rotation of the
    # mesh.  The data will be rotated in the opposite direction! The following
    # example will rotate the mesh 5 degrees southwards around the x-axis. For
    # a definition of the coordinate system refer to the rotations.py file. The
    # rotation is entirely optional.
    gen.config.rotation_angle_in_degree = 5.0
    gen.config.rotation_axis = [1.0, 0.0, 0.0]

    # Define Q
    gen.config.is_dissipative = True
    gen.config.Q_model_relaxation_times = [1.7308, 14.3961, 22.9973]
    gen.config.Q_model_weights_of_relaxation_mechanisms = \
        [2.5100, 2.4354, 0.0879]

    # Finally write the file to a folder. If not output directory is given, a
    # dictionary containing all the files will be returned.
    gen.write(format="ses3d_4_0", output_dir="output")
    print "Written files to 'output' folder."
开发者ID:aspinuso,项目名称:VERCE,代码行数:58,代码来源:ses_3d_4_0_simulation.py

示例6: test_wrong_stf_header_format

# 需要导入模块: from wfs_input_generator import InputFileGenerator [as 别名]
# 或者: from wfs_input_generator.InputFileGenerator import add_stations [as 别名]
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,代码行数:56,代码来源:test_ses3d_4_1_backend.py

示例7: test_adding_stations_as_URLs

# 需要导入模块: from wfs_input_generator import InputFileGenerator [as 别名]
# 或者: from wfs_input_generator.InputFileGenerator import add_stations [as 别名]
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,代码行数:56,代码来源:test_input_file_generator.py

示例8: test_station_filter

# 需要导入模块: from wfs_input_generator import InputFileGenerator [as 别名]
# 或者: from wfs_input_generator.InputFileGenerator import add_stations [as 别名]
def test_station_filter():
    """
    Tests the filtering of the stations.
    """
    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": "AA.THE",
         "latitude": 40.6319,
         "longitude": 22.9628,
         "elevation_in_m": 124.0,
         "local_depth_in_m": 0.0},
        {"id": "BL.XOR",
         "latitude": 39.366,
         "longitude": 23.192,
         "elevation_in_m": 500.0,
         "local_depth_in_m": 0.0}]

    gen = InputFileGenerator()
    gen.add_stations(stations)

    # No applied filter should just result in the same stations being available
    # everywhere.
    assert sorted(gen._filtered_stations) == sorted(gen._stations)

    # Wildcards are ok.
    gen.station_filter = ["HT.*", "AA.*"]
    # Only the last stations should not be available.
    assert sorted(gen._filtered_stations) == sorted(stations[:-1])

    # Removing the filter should make the missing stations reappear.
    gen.station_filter = None
    assert sorted(gen._filtered_stations) == sorted(gen._stations)
    gen.station_filter = []
    assert sorted(gen._filtered_stations) == sorted(gen._stations)
开发者ID:krischer,项目名称:wfs_input_generator,代码行数:55,代码来源:test_input_file_generator.py

示例9: test_real_world_example

# 需要导入模块: from wfs_input_generator import InputFileGenerator [as 别名]
# 或者: from wfs_input_generator.InputFileGenerator import add_stations [as 别名]
    def test_real_world_example(self):
        
        """
        Test that compares the created input files to those from a real world
        example.

        The only artificial thing is the source-time function but that is
        trivial to verify.

        This is a fairly comprehensive tests but should be used in comparision
        with other unit tests.
        """

        gen = InputFileGenerator()

        axisem_example_path = os.path.join(self.data_dir, "axisem_example")
        gen.add_stations([os.path.join(self.data_dir,"dataless.seed.BW_FURT"), os.path.join(self.data_dir,"dataless.seed.BW_RJOB")])
        gen.add_events(os.path.join(self.data_dir,"event1.xml"))

        # Configure it.
        gen.config.dominant_period= 10.0
        gen.config.seismogram_length=1000.0
        gen.config.number_of_processors=12
        gen.config.background_model = 'prem'
        # Write the input files to a dictionary.
        gen.write(format='axisem', output_dir = path)

        # The rest is only for asserting the produced files.
        for filename in glob.glob(os.path.join(path, "*_example")):
            with open(filename, "rt") as open_file:
                real_file = open_file.read()
            filename = os.path.basename(filename[:-8])

            if filename not in input_files:
                msg = "File '%s' has not been generated" % filename
                raise AssertionError(msg)

            lines = real_file.splitlines()
            new_lines = input_files[filename].splitlines()

            if len(lines) != len(new_lines):
                msg = ("File '%s' does not have the same number of lines "
                    "for the real (%i lines) and generated (%i lines) "
                    "input file") % (filename, len(lines), len(new_lines))
                raise AssertionError(msg)

            for line, new_line in zip(lines, new_lines):
                if line != new_line:
                    msg = "Line differs in file '%s'.\n" % filename
                    msg += "Expected: \"%s\"\n" % line
                    msg += "Got:      \"%s\"\n" % new_line
                    raise AssertionError(msg)
开发者ID:msimon00,项目名称:wfs_input_generator,代码行数:54,代码来源:test_axisem_writer.py

示例10: test_adding_stations_as_SAC_files

# 需要导入模块: from wfs_input_generator import InputFileGenerator [as 别名]
# 或者: from wfs_input_generator.InputFileGenerator import add_stations [as 别名]
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,代码行数:15,代码来源:test_input_file_generator.py

示例11: test_adding_a_single_station_dictionary

# 需要导入模块: from wfs_input_generator import InputFileGenerator [as 别名]
# 或者: from wfs_input_generator.InputFileGenerator import add_stations [as 别名]
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,代码行数:15,代码来源:test_input_file_generator.py

示例12: test_adding_sac_file_without_local_depth

# 需要导入模块: from wfs_input_generator import InputFileGenerator [as 别名]
# 或者: from wfs_input_generator.InputFileGenerator import add_stations [as 别名]
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,代码行数:16,代码来源:test_input_file_generator.py

示例13: test_adding_a_single_station_as_JSON

# 需要导入模块: from wfs_input_generator import InputFileGenerator [as 别名]
# 或者: from wfs_input_generator.InputFileGenerator import add_stations [as 别名]
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,代码行数:16,代码来源:test_input_file_generator.py

示例14: test_station_dicts_with_invalid_information_raise

# 需要导入模块: from wfs_input_generator import InputFileGenerator [as 别名]
# 或者: from wfs_input_generator.InputFileGenerator import add_stations [as 别名]
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,代码行数:16,代码来源:test_input_file_generator.py

示例15: test_adding_single_and_multiple_items

# 需要导入模块: from wfs_input_generator import InputFileGenerator [as 别名]
# 或者: from wfs_input_generator.InputFileGenerator import add_stations [as 别名]
    def test_adding_single_and_multiple_items(self):
        """
        Reading all files at once or seperate should make not difference.
        """
        seed_file_1 = os.path.join(self.data_dir, "dataless.seed.BW_FURT")
        seed_file_2 = os.path.join(self.data_dir, "dataless.seed.BW_RJOB")
        station_1 = {"id": "BW.FURT",
             "latitude": 48.162899,
             "longitude": 11.2752,
             "elevation_in_m": 565.0,
             "local_depth_in_m": 0.0}
        station_2 = {"id": "BW.RJOB",
             "latitude": 47.737167,
             "longitude": 12.795714,
             "elevation_in_m": 860.0,
             "local_depth_in_m": 0.0}

        # Try with SEED files first.
        gen1 = InputFileGenerator()
        gen2 = InputFileGenerator()
        gen1.add_stations([seed_file_1, seed_file_2])
        gen2.add_stations(seed_file_1)
        gen2.add_stations(seed_file_2)
        self.assertEqual(sorted(gen1._stations), sorted(gen2._stations))

        # Now try with the dictionaries.
        gen1 = InputFileGenerator()
        gen2 = InputFileGenerator()
        gen1.add_stations([station_1, station_2])
        gen2.add_stations(station_1)
        gen2.add_stations(station_2)
        self.assertEqual(sorted(gen1._stations), sorted(gen2._stations))
开发者ID:msimon00,项目名称:wfs_input_generator,代码行数:34,代码来源:test_input_file_generator.py


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