def test(): homedir = os.path.dirname( os.path.abspath(__file__)) #where is this script? expocat = ExpoCat.fromDefault() clat = 0.37 clon = -79.94 radius = 400 minicat = expocat.selectByRadius(clat, clon, radius) print('Testing that historical events returned are correct...') maxmmi = 8 nmaxmmi = 103000 events = minicat.getHistoricalEvents(maxmmi, nmaxmmi, clat, clon) assert events[0]['EventID'] == '197610060912' assert events[1]['EventID'] == '199603282303' assert events[2]['EventID'] == '198703060410' print('Passed.') print('Testing that events selected by hazard are correct...') fire = expocat.selectByHazard('fire') tsunami = expocat.selectByHazard('tsunami') liquefaction = expocat.selectByHazard('liquefaction') landslide = expocat.selectByHazard('landslide') assert fire._dataframe['Fire'].sum() == len(fire) assert tsunami._dataframe['Tsunami'].sum() == len(tsunami) assert liquefaction._dataframe['Liquefaction'].sum() == len(liquefaction) assert landslide._dataframe['Landslide'].sum() == len(landslide) print('Passed.')
def _getHistoricalEarthquakes(self): expocat = ExpoCat.fromDefault() clat, clon = self._event_dict['lat'], self._event_dict['lon'] inbounds = expocat.selectByRadius(clat, clon, EVENT_RADIUS) maxmmi = self._pagerdict['pager']['maxmmi'] nmmi = self._nmmi deaths = self._fatmodel_results['TotalFatalities'] etime = self._event_dict['event_timestamp'] eventlist = inbounds.getHistoricalEvents(maxmmi, nmmi, clat, clon) return eventlist
def test_hazards(): clat = 0.37 clon = -79.94 mag = 7.8 expocat = ExpoCat.fromDefault() minicat = expocat.selectByRadius(clat, clon, SEARCH_RADIUS) hazards = get_secondary_hazards(minicat, mag) comment = get_secondary_comment(clat, clon, mag) for hazard in hazards: print('Looking for %s in comment string...' % hazard) assert comment.find(hazard) > -1
def test_historical(): clat = 0.37 clon = -79.94 expodict = {'EC': [0, 0, 115000, 5238000, 5971000, 2085000, 1760000, 103000, 0, 0], 'TotalExposure': [0, 0, 115000, 5238000, 5971000, 2085000, 1760000, 103000, 0, 0]} fatdict = {'EC': 98, 'TotalDeaths': 98} ccode = 'EC' histcomment = get_historical_comment(clat, clon, 7.8, expodict, fatdict) expocat = ExpoCat.fromDefault() minicat = expocat.selectByRadius(clat, clon, SEARCH_RADIUS) df = minicat.getDataFrame() df = df.sort_values( ['TotalDeaths', 'MaxMMI', 'NumMaxMMI'], ascending=False) assert histcomment.find(commify(int(df.iloc[0]['TotalDeaths']))) > -1
def _getHistoricalEarthquakes(self): expocat = ExpoCat.fromDefault() clat, clon = self._event_dict['lat'], self._event_dict['lon'] print('Select events by radius.') inbounds = expocat.selectByRadius(clat, clon, EVENT_RADIUS) maxmmi = self._pagerdict['pager']['maxmmi'] nmmi = self._nmmi deaths = self._fatmodel_results['TotalFatalities'] etime = self._event_dict['event_timestamp'] print('Select historical earthquakes.') eventlist = inbounds.getHistoricalEvents(maxmmi, nmmi, deaths, clat, clon) for event in eventlist: if event is not None: event['Time'] = event['Time'].strftime(DATETIMEFMT) return eventlist
def get_historical_comment(lat,lon,mag,expodict,fatdict,ccode): default = """There were no earthquakes with significant population exposure to shaking within a 400 km radius of this event.""" expocat = ExpoCat.fromDefault() expocat = expocat.selectByRadius(lat,lon,SEARCH_RADIUS) df = expocat.getDataFrame() #sort df by totaldeaths (inverse), then by maxmmmi, then by nmaxmmi. df = df.sort_values(['TotalDeaths','MaxMMI','NumMaxMMI'],ascending=False) if len(df) == 0: return default if len(df) >= 1: worst_event = df.iloc[0] desc = get_quake_desc(worst_event,lat,lon,True) return desc
def get_secondary_comment(lat, lon, mag): expocat = ExpoCat.fromDefault() expocat = expocat.selectByRadius(lat, lon, SEARCH_RADIUS) hazards = get_secondary_hazards(expocat, mag) if len(hazards) == 0: return '' nhazards = len(hazards) allhazardstrings = ['tsunamis', 'landslides', 'fires', 'liquefaction'] sfmt = 'Recent earthquakes in this area have caused secondary hazards such as %s that might have contributed to losses.' if nhazards == 1: fstr = hazards[0] elif nhazards == 2: fstr = ' and '.join(hazards) elif nhazards == 3: fstr = ', '.join(hazards[0:2]) + ' and %s' % hazards[2] else: fstr = ', '.join(hazards[0:3]) + ' and %s' % hazards[3] hazcomm = sfmt % fstr return hazcomm