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

Python shake_event.ShakeEvent类代码示例

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

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



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

示例1: testSortedImpactedCities

 def testSortedImpactedCities(self):
     """Test getting impacted cities sorted by mmi then population."""
     myShakeId = '20120726022003'
     myShakeEvent = ShakeEvent(myShakeId)
     myTable = myShakeEvent.sortedImpactedCities()
     myExpectedResult = [
         {'dir_from': 13.119078636169434, 'dir_to': -166.88092041015625,
          'roman': 'II', 'dist_to': 3.036229133605957, 'mmi-int': 2.0,
          'name': 'Manado', 'mmi': 1.809999942779541, 'id': 207,
          'population': 451893},
         {'dir_from': -61.620426177978516, 'dir_to': 118.37957000732422,
          'roman': 'II', 'dist_to': 2.4977917671203613, 'mmi-int': 2.0,
          'name': 'Gorontalo', 'mmi': 2.25, 'id': 282,
          'population': 144195},
         {'dir_from': -114.04046630859375, 'dir_to': 65.95953369140625,
          'roman': 'II', 'dist_to': 3.3138768672943115, 'mmi-int': 2.0,
          'name': 'Luwuk', 'mmi': 1.5299999713897705, 'id': 215,
          'population': 47778},
         {'dir_from': 16.94407844543457, 'dir_to': -163.05592346191406,
          'roman': 'II', 'dist_to': 2.504295825958252, 'mmi-int': 2.0,
          'name': 'Tondano', 'mmi': 1.909999966621399, 'id': 57,
          'population': 33317},
         {'dir_from': 14.14267635345459, 'dir_to': -165.85733032226562,
          'roman': 'II', 'dist_to': 2.5372657775878906, 'mmi-int': 2.0,
          'name': 'Tomohon', 'mmi': 1.690000057220459, 'id': 58,
          'population': 27624}]
     myMessage = 'Got:\n%s\nExpected:\n%s\n' % (myTable, myExpectedResult)
     assert myTable == myExpectedResult, myMessage
开发者ID:maning,项目名称:inasafe,代码行数:28,代码来源:test_shake_event.py


示例2: testBearingToCardinal

    def testBearingToCardinal(self):
        """Test we can convert a bearing to a cardinal direction."""
        myShakeId = '20120726022003'
        myShakeEvent = ShakeEvent(myShakeId)

        # Ints should work
        myExpectedResult = 'SSE'
        myResult = myShakeEvent.bearingToCardinal(160)
        myMessage = ('Got:\n%s\nExpected:\n%s\n' %
                     (myResult, myExpectedResult))
        assert myResult == myExpectedResult, myMessage

        # Floats should work
        myExpectedResult = 'SW'
        myResult = myShakeEvent.bearingToCardinal(225.4)
        myMessage = ('Got:\n%s\nExpected:\n%s\n' %
                     (myResult, myExpectedResult))
        assert myResult == myExpectedResult, myMessage

        # non numeric data as input should return None
        myExpectedResult = None
        myResult = myShakeEvent.bearingToCardinal('foo')
        myMessage = ('Got:\n%s\nExpected:\n%s\n' %
                     (myResult, myExpectedResult))
        assert myResult == myExpectedResult, myMessage
开发者ID:maning,项目名称:inasafe,代码行数:25,代码来源:test_shake_event.py


示例3: test_eventParser

    def test_eventParser(self):
        """Test eventFilePath works (using cached data)"""
        myShakeId = '20120726022003'
        myShakeEvent = ShakeEvent(myShakeId)
        self.assertEquals(26, myShakeEvent.day)
        self.assertEquals(7, myShakeEvent.month)
        self.assertEquals(2012, myShakeEvent.year)
        self.assertEquals(2, myShakeEvent.hour)
        self.assertEquals(15, myShakeEvent.minute)
        self.assertEquals(35, myShakeEvent.second)
        self.assertEquals('WIB', myShakeEvent.timeZone)
        self.assertEquals(124.45, myShakeEvent.longitude)
        self.assertEquals(-0.21, myShakeEvent.latitude)
        self.assertEquals(11.0, myShakeEvent.depth)
        self.assertEquals('Southern Molucca Sea', myShakeEvent.location)
        self.assertEquals(122.45, myShakeEvent.xMinimum)
        self.assertEquals(126.45, myShakeEvent.xMaximum)
        self.assertEquals(-2.21, myShakeEvent.yMinimum)
        self.assertEquals(1.79, myShakeEvent.yMaximum)

        myGridXmlData = myShakeEvent.mmiData
        self.assertEquals(25921, len(myGridXmlData))

        myDelimitedString = myShakeEvent.mmiDataToDelimitedText()
        self.assertEqual(578234, len(myDelimitedString))
开发者ID:maning,项目名称:inasafe,代码行数:25,代码来源:test_shake_event.py


示例4: testCalculateFatalities

    def testCalculateFatalities(self):
        """Test that we can calculate fatalities."""
        LOGGER.debug(QGISAPP.showSettings())
        myShakeId = '20120726022003'
        myShakeEvent = ShakeEvent(myShakeId)
        myResult, myFatalitiesHtml = myShakeEvent.calculateImpacts()

        myExpectedResult = (
            '/tmp/inasafe/realtime/shakemaps-extracted'
            '/20120726022003/impact-nearest.tif')
        myMessage = 'Got:\n%s\nExpected:\n%s\n' % (myResult, myExpectedResult)
        assert myResult == myExpectedResult, myMessage

        myExpectedResult = (
            '/tmp/inasafe/realtime/shakemaps-extracted'
            '/20120726022003/impacts.html')

        myMessage = 'Got:\n%s\nExpected:\n%s\n' % (
            myFatalitiesHtml,
            myExpectedResult)
        assert myFatalitiesHtml == myExpectedResult, myMessage

        myExpectedFatalities = {2: 0.0,  # rounded from 0.47386375223673427,
                                3: 0.0,  # rounded from 0.024892573693488258,
                                4: 0.0,
                                5: 0.0,
                                6: 0.0,
                                7: 0.0,
                                8: 0.0,
                                9: 0.0}

        myMessage = 'Got:\n%s\nExpected:\n%s\n' % (
            myShakeEvent.fatalityCounts, myExpectedFatalities)
        assert myShakeEvent.fatalityCounts == myExpectedFatalities, myMessage
开发者ID:maning,项目名称:inasafe,代码行数:34,代码来源:test_shake_event.py


示例5: testI18n

 def testI18n(self):
     """See if internationalisation is working."""
     myShakeId = '20120726022003'
     myShakeEvent = ShakeEvent(myShakeId, theLocale='id')
     myShaking = myShakeEvent.mmiShaking(5)
     myExpectedShaking = 'Sedang'
     self.assertEqual(myExpectedShaking, myShaking)
开发者ID:maning,项目名称:inasafe,代码行数:7,代码来源:test_shake_event.py


示例6: testSortedImpactedCities

    def testSortedImpactedCities(self):
        """Test getting impacted cities sorted by mmi then population."""
        myShakeId = '20120726022003'
        myShakeEvent = ShakeEvent(myShakeId)
        myTable = myShakeEvent.sortedImpactedCities()

        myFilePath = unique_filename(
            prefix='testSortedImpactedCities',
            suffix='.txt',
            dir=temp_dir('test'))
        myFile = file(myFilePath, 'wt')
        myFile.writelines(str(myTable))
        myFile.close()
        myTable = str(myTable).replace(', \'', ',\n\'')
        myTable += '\n'

        myFixturePath = os.path.join(
            dataDir(), 'tests', 'testSortedImpactedCities.txt')
        myFile = file(myFixturePath, 'rt')
        myExpectedString = myFile.read()
        myFile.close()
        myExpectedString = myExpectedString.replace(', \'', ',\n\'')

        self.maxDiff = None
        self.assertEqual(myExpectedString, myTable)
开发者ID:CharlesRethman,项目名称:inasafe,代码行数:25,代码来源:test_shake_event.py


示例7: testEventToShapefile

 def testEventToShapefile(self):
     """Check we can convert the shake event to a raster"""
     myShakeId = '20120726022003'
     myShakeEvent = ShakeEvent(myShakeId)
     myPath = myShakeEvent.mmiDataToShapefile(theForceFlag=True)
     assert os.path.exists(myPath)
     myExpectedQml = myPath.replace('shp', 'qml')
     myMessage = '%s not found' % myExpectedQml
     assert os.path.exists(myExpectedQml), myMessage
开发者ID:maning,项目名称:inasafe,代码行数:9,代码来源:test_shake_event.py


示例8: testBoundsToRect

 def testBoundsToRect(self):
     """Test that we can calculate the event bounds properly"""
     myShakeId = '20120726022003'
     myShakeEvent = ShakeEvent(myShakeId)
     myBounds = myShakeEvent.boundsToRectangle().toString()
     myExpectedResult = ('122.4500000000000028,-2.2100000000000000 : '
                        '126.4500000000000028,1.7900000000000000')
     myMessage = 'Got:\n%s\nExpected:\n%s\n' % (myBounds, myExpectedResult)
     assert myBounds == myExpectedResult, myMessage
开发者ID:gijs,项目名称:inasafe,代码行数:9,代码来源:test_shake_event.py


示例9: test_eventGridToCsv

 def test_eventGridToCsv(self):
     """Test grid data can be written to csv"""
     myShakeId = '20120726022003'
     myShakeEvent = ShakeEvent(myShakeId)
     myPath = myShakeEvent.mmiDataToDelimitedFile(theForceFlag=True)
     myFile = file(myPath, 'rt')
     myString = myFile.readlines()
     myFile.close()
     self.assertEqual(25922, len(myString))
开发者ID:maning,项目名称:inasafe,代码行数:9,代码来源:test_shake_event.py


示例10: test_gridXmlFilePath

 def test_gridXmlFilePath(self):
     """Test eventFilePath works(using cached data)"""
     myShakeId = '20120726022003'
     myExpectedPath = os.path.join(shakemapExtractDir(),
                                   myShakeId,
                                   'grid.xml')
     myShakeEvent = ShakeEvent(myShakeId)
     myPath = myShakeEvent.gridFilePath()
     self.assertEquals(myExpectedPath, myPath)
开发者ID:maning,项目名称:inasafe,代码行数:9,代码来源:test_shake_event.py


示例11: test_extractDateTime

 def test_extractDateTime(self):
     """Check that we extract date and time correctly."""
     myShakeId = '20120726022003'
     myShakeEvent = ShakeEvent(myShakeId, theLocale='en')
     myShakeEvent.extractDateTime('2012-08-07T01:55:12WIB')
     self.assertEqual(1, myShakeEvent.hour)
     self.assertEqual(55, myShakeEvent.minute)
     self.assertEqual(12, myShakeEvent.second)
     myShakeEvent.extractDateTime('2013-02-07T22:22:37WIB')
     self.assertEqual(22, myShakeEvent.hour)
     self.assertEqual(22, myShakeEvent.minute)
     self.assertEqual(37, myShakeEvent.second)
开发者ID:maning,项目名称:inasafe,代码行数:12,代码来源:test_shake_event.py


示例12: testRomanize

    def testRomanize(self):
        """Test we can convert MMI values to float."""
        myShakeId = '20120726022003'
        myShakeEvent = ShakeEvent(myShakeId)

        myValues = range(2, 10)
        myExpectedResult = ['II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX']
        myResult = []
        for myValue in myValues:
            myResult.append(myShakeEvent.romanize(myValue))
        myMessage = 'Got:\n%s\nExpected:\n%s\n' % (myResult, myExpectedResult)
        assert myResult == myExpectedResult, myMessage
开发者ID:maning,项目名称:inasafe,代码行数:12,代码来源:test_shake_event.py


示例13: testFatalitiesTable

 def testFatalitiesTable(self):
     """Test rendering a fatalities table."""
     myShakeId = '20120726022003'
     myShakeEvent = ShakeEvent(myShakeId)
     myShakeEvent.calculateImpacts()
     myResult = myShakeEvent.impactTable()
     # TODO compare actual content of impact table...
     myExpectedResult = ('/tmp/inasafe/realtime/shakemaps-extracted/'
                        '20120726022003/impacts.html')
     myMessage = ('Got:\n%s\nExpected:\n%s' %
                 (myResult, myExpectedResult))
     assert myResult == myExpectedResult, myMessage
开发者ID:gijs,项目名称:inasafe,代码行数:12,代码来源:test_shake_event.py


示例14: testEventInfoString

 def testEventInfoString(self):
     """Test we can get a location info string nicely."""
     myShakeId = '20120726022003'
     myShakeEvent = ShakeEvent(myShakeId)
     myDegreeSymbol = unichr(176)
     myExpectedResult = (
         'M 5.0 26-7-2012 2:15:35 Latitude: 0%s12\'36.00"S Longitude: '
         '124%s27\'0.00"E Depth: 11.0km Located 0.00km n/a of n/a'
         % (myDegreeSymbol, myDegreeSymbol))
     myResult = myShakeEvent.eventInfo()
     myMessage = ('Got:\n%s\nExpected:\n%s\n' %
                  (myResult, myExpectedResult))
     assert myResult == myExpectedResult, myMessage
开发者ID:maning,项目名称:inasafe,代码行数:13,代码来源:test_shake_event.py


示例15: testMmiColour

    def testMmiColour(self):
        """Test that we can get a colour given an mmi number."""
        myShakeId = '20120726022003'
        myShakeEvent = ShakeEvent(myShakeId)

        myValues = range(0, 12)
        myExpectedResult = ['#FFFFFF', '#FFFFFF', '#209fff', '#00cfff',
                            '#55ffff', '#aaffff', '#fff000', '#ffa800',
                            '#ff7000', '#ff0000', '#D00', '#800']
        myResult = []
        for myValue in myValues:
            myResult.append(myShakeEvent.mmiColour(myValue))
        myMessage = 'Got:\n%s\nExpected:\n%s\n' % (myResult, myExpectedResult)
        assert myResult == myExpectedResult, myMessage
开发者ID:maning,项目名称:inasafe,代码行数:14,代码来源:test_shake_event.py


示例16: testImpactedCitiesTable

    def testImpactedCitiesTable(self):
        """Test getting impacted cities table."""
        myShakeId = '20120726022003'
        myShakeEvent = ShakeEvent(myShakeId)
        myTable, myPath = myShakeEvent.impactedCitiesTable()
        myExpectedResult = 906
        myTable = myTable.toNewlineFreeString()
        myResult = len(myTable)
        myMessage = ('Got:\n%s\nExpected:\n%s\nFor rendered table:\n%s' %
                    (myResult, myExpectedResult, myTable))
        assert myResult == myExpectedResult, myMessage

        myExpectedPath = ('/tmp/inasafe/realtime/shakemaps-extracted/'
                         '20120726022003/affected-cities.html')
        myMessage = 'Got:\n%s\nExpected:\n%s\n' % (myPath, myExpectedPath)
        assert myPath == myExpectedPath, myMessage
开发者ID:gijs,项目名称:inasafe,代码行数:16,代码来源:test_shake_event.py


示例17: testLocalCities

    def testLocalCities(self):
        """Test that we can retrieve the cities local to the event"""
        myShakeId = '20120726022003'
        myShakeEvent = ShakeEvent(myShakeId)
        # Get teh mem layer
        myCitiesLayer = myShakeEvent.localCitiesMemoryLayer()
        myProvider = myCitiesLayer.dataProvider()

        myFeature = QgsFeature()
        myAttributes = myProvider.attributeIndexes()
        myProvider.select(myAttributes)
        myExpectedFeatureCount = 6
        self.assertEquals(myProvider.featureCount(), myExpectedFeatureCount)
        myStrings = []
        while myProvider.nextFeature(myFeature):
            # fetch map of attributes
            myAttributes = myFeature.attributeMap()
            for (myKey, myValue) in myAttributes.iteritems():
                myStrings.append("%d: %s\n" % (myKey, myValue.toString()))
            myStrings.append('------------------\n')
        LOGGER.debug('Mem table:\n %s' % myStrings)
        myFilePath = unique_filename(prefix='testLocalCities',
                                     suffix='.txt',
                                     dir=temp_dir('test'))
        myFile = file(myFilePath, 'wt')
        myFile.writelines(myStrings)
        myFile.close()

        myFixturePath = os.path.join(dataDir(), 'tests', 'testLocalCities.txt')
        myFile = file(myFixturePath, 'rt')
        myExpectedString = myFile.readlines()
        myFile.close()

        myDiff = difflib.unified_diff(myStrings, myExpectedString)
        myDiffList = list(myDiff)
        myDiffString = ''
        for _, myLine in enumerate(myDiffList):
            myDiffString += myLine

        myMessage = ('Diff is not zero length:\n'
                     'Control file: %s\n'
                     'Test file: %s\n'
                     'Diff:\n%s'
                     % (myFixturePath,
                        myFilePath,
                        myDiffString))
        self.assertEqual(myDiffString, '', myMessage)
开发者ID:gijs,项目名称:inasafe,代码行数:47,代码来源:test_shake_event.py


示例18: testEventToContours

    def testEventToContours(self):
        """Check we can extract contours from the event"""
        myShakeId = '20120726022003'
        myShakeEvent = ShakeEvent(myShakeId)
        myPath = myShakeEvent.mmiDataToContours(theForceFlag=True,
                                                theAlgorithm='invdist')
        assert self.checkFeatureCount(myPath, 16)
        assert os.path.exists(myPath)
        myExpectedQml = myPath.replace('shp', 'qml')
        myMessage = '%s not found' % myExpectedQml
        assert os.path.exists(myExpectedQml), myMessage

        myPath = myShakeEvent.mmiDataToContours(theForceFlag=True,
                                                theAlgorithm='nearest')
        assert self.checkFeatureCount(myPath, 132)
        myPath = myShakeEvent.mmiDataToContours(theForceFlag=True,
                                                theAlgorithm='average')
        assert self.checkFeatureCount(myPath, 132)
开发者ID:maning,项目名称:inasafe,代码行数:18,代码来源:test_shake_event.py


示例19: testEventToRaster

    def testEventToRaster(self):
        """Check we can convert the shake event to a raster"""
        myShakeId = '20120726022003'
        myShakeEvent = ShakeEvent(myShakeId)
        myExpectedState = """latitude: -0.21
longitude: 124.45
eventId: 20120726022003
magnitude: 5.0
depth: 11.0
description: None
location: Southern Molucca Sea
day: 26
month: 7
year: 2012
time: None
timeZone: WIB
xMinimum: 122.45
xMaximum: 126.45
yMinimum: -2.21
yMaximum: 1.79
rows: 161.0
columns: 161.0
mmiData: Populated
populationRasterPath: None
impactFile: None
impactKeywordsFile: None
fatalityCounts: None
displacedCounts: None
affectedCounts: None
extentWithCities: Not set
zoomFactor: 1.25
searchBoxes: None
"""
        myState = str(myShakeEvent)
        myMessage = (('Expected:\n----------------\n%s'
                     '\n\nGot\n------------------\n%s\n') %
                     (myExpectedState, myState))
        assert myState == myExpectedState, myMessage
        myPath = myShakeEvent.mmiDataToRaster(theForceFlag=True)
        assert os.path.exists(myPath)
        myExpectedQml = myPath.replace('tif', 'qml')
        assert os.path.exists(myExpectedQml)
        myExpectedKeywords = myPath.replace('tif', 'keywords')
        assert os.path.exists(myExpectedKeywords)
开发者ID:maning,项目名称:inasafe,代码行数:44,代码来源:test_shake_event.py


示例20: testImpactedCitiesTable

    def testImpactedCitiesTable(self):
        """Test getting impacted cities table."""
        myShakeId = '20120726022003'
        myShakeEvent = ShakeEvent(myShakeId)
        myTable, myPath = myShakeEvent.impactedCitiesTable()
        myExpectedStrings = [
            '<td>Tondano</td><td>33</td><td>I</td>',
            '<td>Luwuk</td><td>47</td><td>I</td>',
            '<td>Bitung</td><td>137</td><td>I</td>',
            '<td>Manado</td><td>451</td><td>I</td>',
            '<td>Gorontalo</td><td>144</td><td>II</td>']
        myTable = myTable.toNewlineFreeString().replace('   ', '')
        for myString in myExpectedStrings:
            self.assertIn(myString, myTable)

        self.maxDiff = None
        myExpectedPath = (
            '/tmp/inasafe/realtime/shakemaps-extracted/'
            '20120726022003/affected-cities.html')
        myMessage = 'Got:\n%s\nExpected:\n%s\n' % (myPath, myExpectedPath)
        assert myPath == myExpectedPath, myMessage
开发者ID:CharlesRethman,项目名称:inasafe,代码行数:21,代码来源:test_shake_event.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python shakedown.deployment_wait函数代码示例发布时间:2022-05-27
下一篇:
Python shake.Shake类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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