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


Python InputFileGenerator.add_configuration方法代码示例

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


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

示例1: test_configuration_via_a_dictionary

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

示例2: test_configuration_via_JSON

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

示例3: test_config_raises_error_if_wrong_type

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

示例4: compute

# 需要导入模块: from wfs_input_generator import InputFileGenerator [as 别名]
# 或者: from wfs_input_generator.InputFileGenerator import add_configuration [as 别名]
    def compute(self):
        gen = InputFileGenerator()
        userconf = json.load(open(self.parameters["solver_conf_file"]))

        fields = userconf["fields"]

        for x in fields:
            gen.add_configuration({x["name"]:self.strToBool(x["value"])})    
    
        with open (self.parameters["quakeml"], "r") as events:
            quakeml=events.read()

        #unicode_qml=quakeml.decode('utf-8')
        #data = unicode_qml.encode('ascii','ignore')

##
        cat=readQuakeML(quakeml)
        events = []
        #cat = obspy.readEvents(data)
#Remove all events with no moment tensor.
        for event in cat:
            for fm in event.focal_mechanisms:
                if fm.moment_tensor and fm.moment_tensor.tensor:
                    events.append(event)
                    break
        cat.events = events

        gen.add_events(cat)

        evn=0
        outputdir=""
        for x in userconf["events"]:
            gen.event_filter=[x]
        
            if self.parameters["station_format"]=="stationXML":
                gen.add_stations(self.parameters["stations_file"])
                
        
            if self.parameters["station_format"]=="points":
                stlist = []
                with open(self.parameters["stations_file"]) as f:
                    k=False
                    for line in f:
                        
                        if (k==False):
                            k=True
                        else:
                            station={}
                            l=line.strip().split(" ")
                            station.update({"id":l[1]+"."+l[0]})           
                            station.update({"latitude":float(l[3])})
                            station.update({"longitude":float(l[2])})
                            station.update({"elevation_in_m":float(l[4])})
                            station.update({"local_depth_in_m":float(l[5])})
                            stlist.append(station)
                        
                        
                gen.add_stations(stlist)
                        
            gen.station_filter = userconf["stations"]
                        
            outputdir=self.outputdest+userconf["runId"]+"/"+userconf["runId"]+"_"+str(evn)+"/DATA"
            output_files = gen.write(format=userconf["solver"], output_dir=outputdir)
            
            
            locations = []
            for x in output_files.keys():
                locations.append("file://"+socket.gethostname()+outputdir+"/"+x)
                
            
            self.addOutput(gen._filtered_events,location=locations,metadata=self.extractEventMetadata(outputdir,gen._filtered_events),control={"con:immediateAccess":"true"})
        
            evn+=1
         
        self.addOutput(outputdir,location=locations,metadata={"to_xdecompose":str(outputdir)},control={"con:immediateAccess":"true"})
开发者ID:aspinuso,项目名称:VERCE,代码行数:77,代码来源:inputGenerator.py


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