本文整理汇总了Python中shake_event.ShakeEvent类的典型用法代码示例。如果您正苦于以下问题:Python ShakeEvent类的具体用法?Python ShakeEvent怎么用?Python ShakeEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ShakeEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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
示例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))
示例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
示例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)
示例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)
示例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
示例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
示例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))
示例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)
示例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)
示例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
示例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
示例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
示例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