コード例 #1
0
ファイル: station_test.py プロジェクト: g-weatherill/shakemap
def test(stationfile,xmlfile,eventdict):
    tmp,dbfile = tempfile.mkstemp()
    os.close(tmp)
    os.remove(dbfile)
    try:
        print('Testing load from XML format...')
        t1 = time.time()
        stations1 = StationList.loadFromXML([xmlfile],dbfile)
        t2 = time.time()
        print('Passed load from XML format %i stations in %.2f seconds.' % (len(stations1),t2-t1))

        print('Testing filling in distance and derived MMI/PGM values...')
        source = Source(eventdict)
        stations1.fillTables(source)
        print('Passed filling in distance and derived MMI/PGM values...')
        
        print('Testing retrieval of MMI data from StationList object...')
        t1 = time.time()
        mmidf1 = stations1.getMMIStations()
        t2 = time.time()
        print('Passed retrieval of %i MMI data in %.2f seconds from StationList object.' % (len(mmidf1),t2-t1))

        print('Testing retrieval of instrumented data from StationList object...')
        t1 = time.time()
        imtdf1 = stations1.getInstrumentedStations()
        t2 = time.time()
        print('Passed retrieval of %i instrumented data in %.2f seconds from StationList object.' % (len(imtdf1),t2-t1))


        print('Testing load from sqlite format...')
        t1 = time.time()
        stations2 = StationList(stationfile)
        t2 = time.time()
        print('Passed load from sqlite format %i stations in %.2f seconds.' % (len(stations1),t2-t1))

        print('Testing retrieval of MMI data from StationList object...')
        t1 = time.time()
        mmidf2 = stations2.getMMIStations()
        t2 = time.time()
        print('Passed retrieval of %i MMI data in %.2f seconds from StationList object.' % (len(mmidf2),t2-t1))

        print('Testing retrieval of instrumented data from StationList object...')
        t1 = time.time()
        imtdf2 = stations2.getInstrumentedStations()
        t2 = time.time()
        print('Passed retrieval of %i instrumented data in %.2f seconds from StationList object.' % (len(imtdf1),t2-t1))

        assert(len(stations1) == len(stations2))

        
               
    except Exception as msg:
        print('Error caught: %s' % str(msg))
    if os.path.isfile(dbfile):
        os.remove(dbfile)
コード例 #2
0
def _test_intensity():

    datadir = os.path.abspath(
        os.path.join(homedir, '..', 'data', 'eventdata', 'northridge'))
    shakefile = os.path.join(datadir, 'northridge_grid.xml')
    topofile = os.path.join(datadir, 'northridge_topo.grd')
    faultfile = os.path.join(datadir, 'northridge_fault.txt')
    cityfile = os.path.join(datadir, 'northridge_cities.txt')
    coastfile = os.path.join(datadir, 'northridge_coastline.json')
    countryfile = os.path.join(datadir, 'northridge_countries.json')
    statefile = os.path.join(datadir, 'northridge_states.json')
    lakefile = os.path.join(datadir, 'northridge_lakes.json')
    oceanfile = os.path.join(datadir, 'northridge_ocean.json')
    stationfile = os.path.join(datadir, 'northridge_stations.db')
    roadfile = os.path.join(datadir, 'northridge_roads.json')
    tancptfile = os.path.join(shakedir, 'shakemap', 'mapping', 'tan.cpt')
    shakecptfile = os.path.join(shakedir, 'shakemap', 'mapping',
                                'shakecpt.cpt')

    layerdict = {
        'coast': coastfile,
        'ocean': oceanfile,
        'lake': lakefile,
        'country': countryfile,
        'roads': roadfile,
        'state': statefile
    }

    tancolormap = GMTColorMap.loadFromCPT(tancptfile)
    shakecolormap = GMTColorMap.loadFromCPT(shakecptfile)
    cities = BasemapCities.loadFromCSV(cityfile)
    shakemap = ShakeGrid.load(shakefile, adjust='res')
    stations = StationList(stationfile)
    fault = Fault.readFaultFile(faultfile)
    edict = shakemap.getEventDict()
    eventdict = {
        'lat': edict['lat'],
        'lon': edict['lon'],
        'depth': edict['depth'],
        'mag': edict['magnitude'],
        'time': edict['event_timestamp']
    }
    source = Source(eventdict, fault)
    maker = MapMaker(shakemap, topofile, stations, fault, layerdict, source,
                     cities)

    # draw intensity map
    outfolder = os.path.expanduser('~')
    maker.setIntensityLayer('mmi')
    maker.setIntensityGMTColorMap(shakecolormap)
    intensity_map = maker.drawIntensityMap(outfolder)
    print('Intensity map saved as: %s' % intensity_map)

    # draw contour maps
    maker.setContourGMTColorMap(tancolormap)

    # Draw pgv contours
    maker.setContourLayer('pgv')
    contour_pgv_map = maker.drawContourMap(outfolder)
    print('PGV contour map saved as: %s' % contour_pgv_map)

    # Draw pga contours
    maker.setContourLayer('pga')
    contour_pga_map = maker.drawContourMap(outfolder)
    print('PGA contour map saved as: %s' % contour_pga_map)

    # Draw psa0.3 contours
    maker.setContourLayer('psa03')
    contour_psa03_map = maker.drawContourMap(outfolder)
    print('PSA0.3 contour map saved as: %s' % contour_psa03_map)

    # Draw psa1.0 contours
    maker.setContourLayer('psa10')
    contour_psa10_map = maker.drawContourMap(outfolder)
    print('PSA1.0 contour map saved as: %s' % contour_psa10_map)

    # Draw psa3.0 contours
    maker.setContourLayer('psa30')
    contour_psa30_map = maker.drawContourMap(outfolder)
    print('PSA3.0 contour map saved as: %s' % contour_psa30_map)
コード例 #3
0
def _test():

    tmp, dbfile = tempfile.mkstemp()
    os.close(tmp)
    os.remove(dbfile)

    homedir = os.path.dirname(os.path.abspath(__file__))
    xmlfile = os.path.abspath(
        os.path.join(homedir, '..', 'data', 'eventdata', 'northridge',
                     'northridge_stations.xml'))
    stationfile = os.path.abspath(
        os.path.join(homedir, '..', 'data', 'eventdata', 'northridge',
                     'northridge_stations.db'))
    eventdict = {
        'lat': 34.213,
        'lon': -118.537,
        'depth': 18.2,
        'mag': 6.7,
        'time': datetime(1994, 1, 17, 12, 30, 55),
        'mech': 'ALL',
        'dip': 45,
        'rake': 90
    }

    try:
        print('Testing load from XML format...')
        t1 = time.time()
        stations1 = StationList.loadFromXML([xmlfile], dbfile)
        t2 = time.time()
        print('Passed load from XML format %i stations in %.2f seconds.' %
              (len(stations1), t2 - t1))

        print('Testing filling in distance and derived MMI/PGM values...')
        source = Source(eventdict)
        stations1.fillTables(source)
        print('Passed filling in distance and derived MMI/PGM values...')

        print('Testing retrieval of MMI data from StationList object...')
        t1 = time.time()
        mmidf1 = stations1.getMMIStations()
        t2 = time.time()
        print(
            'Passed retrieval of %i MMI data in %.2f seconds from StationList object.'
            % (len(mmidf1), t2 - t1))

        print(
            'Testing retrieval of instrumented data from StationList object...'
        )
        t1 = time.time()
        imtdf1 = stations1.getInstrumentedStations()
        t2 = time.time()
        print(
            'Passed retrieval of %i instrumented data in %.2f seconds from StationList object.'
            % (len(imtdf1), t2 - t1))

        print('Testing load from sqlite format...')
        t1 = time.time()
        stations2 = StationList(stationfile)
        t2 = time.time()
        print('Passed load from sqlite format %i stations in %.2f seconds.' %
              (len(stations1), t2 - t1))

        print('Testing retrieval of MMI data from StationList object...')
        t1 = time.time()
        mmidf2 = stations2.getMMIStations()
        t2 = time.time()
        print(
            'Passed retrieval of %i MMI data in %.2f seconds from StationList object.'
            % (len(mmidf2), t2 - t1))

        print(
            'Testing retrieval of instrumented data from StationList object...'
        )
        t1 = time.time()
        imtdf2 = stations2.getInstrumentedStations()
        t2 = time.time()
        print(
            'Passed retrieval of %i instrumented data in %.2f seconds from StationList object.'
            % (len(imtdf1), t2 - t1))

        assert (len(stations1) == len(stations2))

    except Exception as msg:
        print('Error caught: %s' % str(msg))
    if os.path.isfile(dbfile):
        os.remove(dbfile)