예제 #1
0
파일: Map_Plot.py 프로젝트: mesowx/MesoPy
def main():

    # This is just useful for formatting returned dict
    # pp = pprint.PrettyPrinter(indent=2)

    # Create instance of Meso object, pass in YOUR token
    m = Meso(token='YOUR TOKEN')

    # Use to lookup stations, could specify counties or whatever here
    # findstationids = m.station_list(state='CO')
    # print(findstationids)

    # Grab most recent temp (F) ob in last 90 min at each of the below stations
    stations = ['kgxy, kccu, kcos, kden, kgjt, kbdu, kpub, klhx, kspd, kdro, ksbs, keeo, kguc, klic, '
                'kstk, kals, ktad']
    latest = m.latest(stid=stations, within='90', vars='air_temp', units='temp|F')

    # create a list to store everything, iterate over the number of objs returned in latest and append
    # lat, long, temp, and stid for use later
    data = []
    [data.append((float(ob['LATITUDE']), float(ob['LONGITUDE']), float(ob['OBSERVATIONS']['air_temp_value_1']['value']),
                  ob['STID'])) for ob in latest['STATION']]
    print(data)

    # Create a MapQuest open aerial instance.
    map_quest_aerial = cimgt.MapQuestOpenAerial()
    # Create a GeoAxes in the tile's projection.
    ax = plt.axes(projection=map_quest_aerial.crs)
    # Limit the extent of the map to Colorado's borders
    ax.set_extent([-102.03, -109.03, 37, 41])
    # Add the MapQuest data at zoom level 8.
    ax.add_image(map_quest_aerial, 8)

    # Plot lat/long pts with below params
    for lat, lon, temp, stid in data:
        plt.plot(lon, lat, marker='o', color='y', markersize=1,
                 alpha=0.7, transform=ccrs.Geodetic())

    # Transforms for the text func we're about to call
    geodetic_transform = ccrs.Geodetic()._as_mpl_transform(ax)
    text_transform = offset_copy(geodetic_transform, units='dots', x=0, y=0)

    # Plot temp and station id for each of the markers
    for lat, lon, temp, stid in data:
        plt.text(lon, lat, stid + '\n' + str(round(temp, 1)) + u' \N{DEGREE SIGN}' + 'F',
                 verticalalignment='center', horizontalalignment='center',
                 transform=text_transform, fontsize=9,
                 bbox=dict(facecolor='wheat', alpha=0.5, boxstyle='round'))
    plt.title('Current Weather Around Colorado')
    plt.show()
예제 #2
0
"""
@author: joshclark

This script just demonstrates some example usage for the workshop

"""
from MesoPy import Meso
import pprint

# I import Pretty Print to make the returned dictionary look, well, pretty.
pp = pprint.PrettyPrinter(indent=2)

# Instance a Meso object by passing in YOUR api_token
m = Meso(token='YOUR TOKEN')
# Fetches the latest obs for Boulder airport within 30 min of now
latest = m.latest(stid='kbdu', within='30', units='ENGLISH')
pp.pprint(latest)

# Let's format a pretty sentence that tells us the Boulder wx
x = latest['STATION'][0]
st_name = x['NAME']
temp = str(
    x['OBSERVATIONS']['air_temp_value_1']['value']) + u'\N{DEGREE SIGN}' + 'F'
wind = str(x['OBSERVATIONS']['wind_speed_value_1']['value']) + ' mph'

result = 'The current weather at ' + st_name + ' is ' + temp + ' with a sustained wind of ' + wind
print(result)

# I import Pretty Print to make the returned dictionary look, well, pretty.
pp = pprint.PrettyPrinter(indent=2)
예제 #3
0
파일: Map_Plot.py 프로젝트: joejoezz/AWNPy
def main():

    # This is just useful for formatting returned dict
    # pp = pprint.PrettyPrinter(indent=2)

    # Create instance of Meso object, pass in YOUR token
    m = Meso(token='YOUR TOKEN')

    # Use to lookup stations, could specify counties or whatever here
    # findstationids = m.station_list(state='CO')
    # print(findstationids)

    # Grab most recent temp (F) ob in last 90 min at each of the below stations
    stations = [
        'kgxy, kccu, kcos, kden, kgjt, kbdu, kpub, klhx, kspd, kdro, ksbs, keeo, kguc, klic, '
        'kstk, kals, ktad'
    ]
    latest = m.latest(stid=stations,
                      within='90',
                      vars='air_temp',
                      units='temp|F')

    # create a list to store everything, iterate over the number of objs returned in latest and append
    # lat, long, temp, and stid for use later
    data = []
    [
        data.append((float(ob['LATITUDE']), float(ob['LONGITUDE']),
                     float(ob['OBSERVATIONS']['air_temp_value_1']['value']),
                     ob['STID'])) for ob in latest['STATION']
    ]
    print(data)

    # Create a MapQuest open aerial instance.
    map_quest_aerial = cimgt.MapQuestOpenAerial()
    # Create a GeoAxes in the tile's projection.
    ax = plt.axes(projection=map_quest_aerial.crs)
    # Limit the extent of the map to Colorado's borders
    ax.set_extent([-102.03, -109.03, 37, 41])
    # Add the MapQuest data at zoom level 8.
    ax.add_image(map_quest_aerial, 8)

    # Plot lat/long pts with below params
    for lat, lon, temp, stid in data:
        plt.plot(lon,
                 lat,
                 marker='o',
                 color='y',
                 markersize=1,
                 alpha=0.7,
                 transform=ccrs.Geodetic())

    # Transforms for the text func we're about to call
    geodetic_transform = ccrs.Geodetic()._as_mpl_transform(ax)
    text_transform = offset_copy(geodetic_transform, units='dots', x=0, y=0)

    # Plot temp and station id for each of the markers
    for lat, lon, temp, stid in data:
        plt.text(lon,
                 lat,
                 stid + '\n' + str(round(temp, 1)) + u' \N{DEGREE SIGN}' + 'F',
                 verticalalignment='center',
                 horizontalalignment='center',
                 transform=text_transform,
                 fontsize=9,
                 bbox=dict(facecolor='wheat', alpha=0.5, boxstyle='round'))
    plt.title('Current Weather Around Colorado')
    plt.show()
예제 #4
0
"""
@author: joshclark

This script just demonstrates some example usage for the workshop

"""
from MesoPy import Meso
import pprint

# I import Pretty Print to make the returned dictionary look, well, pretty.
pp = pprint.PrettyPrinter(indent=2)

# Instance a Meso object by passing in YOUR api_token
m = Meso(token='YOUR TOKEN')
# Fetches the latest obs for Boulder airport within 30 min of now
latest = m.latest(stid='kbdu', within='30', units='ENGLISH')
pp.pprint(latest)

# Let's format a pretty sentence that tells us the Boulder wx
x = latest['STATION'][0]
st_name = x['NAME']
temp = str(x['OBSERVATIONS']['air_temp_value_1']['value']) + u'\N{DEGREE SIGN}' + 'F'
wind = str(x['OBSERVATIONS']['wind_speed_value_1']['value']) + ' mph'

result = 'The current weather at ' + st_name + ' is ' + temp + ' with a sustained wind of ' + wind
print(result)

# I import Pretty Print to make the returned dictionary look, well, pretty.
pp = pprint.PrettyPrinter(indent=2)

# Instance a Meso object by passing in YOUR api_token
예제 #5
0
def surfacePlot(api):
    m = Meso(token=MesoPy_token)
    stids = [
        'KAIG', 'KATW', 'KASX', 'KDLL', 'KOVS', 'KBUU', 'KCLI', 'KEGV', 'KEAU',
        'KFLD', 'KCMY', 'KGRB', 'KHYR', 'KJVL', 'KUNU', 'KENW', 'KLSE', 'KRCX',
        'KLNL', 'KLNR', 'KMSN', 'KMTW', 'KMFI', 'KMDZ', 'KLUM', 'KRRL', 'KMKE',
        'KMRJ', 'K82C', 'TT278', 'KEFT', 'KRNH', 'KOSH', 'KPBH', 'KPVB',
        'KPDC', 'KRHI', 'KBCK', 'LAAW3', 'WUEW3', 'KRPD', 'KEZS', 'KSBM',
        'KRZN', 'KSTE', 'KSUE', 'KSUW', 'KY51', 'KRYV', 'KUES', 'KPCZ', 'KAUW',
        'KY50', 'KETB', 'KISW', 'KARV', 'GDNW3', 'KRGK', 'AFWW3'
    ]  #stations
    latest = m.latest(
        stid=stids, within='30', vars='air_temp',
        units='temp|F')  #gets the latest temps (measured over past 30 minutes)
    data = []  #a list with 4 columns: lat, long, temps, stid
    for ob in latest['STATION']:
        data.append((float(ob['LATITUDE']), float(ob['LONGITUDE']),
                     float(ob['OBSERVATIONS']['air_temp_value_1']['value']),
                     ob['STID']))
    # Now that we have all the data, we can make the figure
    fig = plt.figure(figsize=(10, 10))
    plt.style.use('ggplot')
    ax = plt.axes(projection=ccrs.Mercator())
    ax.set_extent([-86.5, -93.2, 41.75, 47.25])
    ax.add_feature(
        ShapelyFeature(
            Reader("ne_50m_admin_1_states_provinces_lakes.shp").geometries(),
            ccrs.PlateCarree(),
            facecolor='w',
            edgecolor='gray',
            linewidth=1.5))
    county_shpfile = 'c_05ap16.shp'  #wi county shapefile
    WI = Reader(county_shpfile).records()
    for i in WI:
        if i.attributes['STATE'] == 'WI':
            ax.add_geometries(i.geometry,
                              ccrs.PlateCarree(),
                              facecolor='white',
                              edgecolor='gray')

    roads = cfeature.NaturalEarthFeature(category='cultural',
                                         name='roads',
                                         scale='10m',
                                         facecolor='none')
    ax.add_feature(roads, edgecolor='red')
    ax.add_feature(
        ShapelyFeature(Reader("ne_50m_lakes.shp").geometries(),
                       ccrs.PlateCarree(),
                       facecolor='lightblue',
                       edgecolor='gray',
                       linewidth=1.5))

    for lat, lon, temp, stid in data:  #plots a marker for each station
        plt.plot(lon,
                 lat,
                 marker='o',
                 color='blue',
                 markersize=10,
                 alpha=0.7,
                 transform=ccrs.PlateCarree())

    # Transforms for the text function
    transform = ccrs.PlateCarree()._as_mpl_transform(ax)
    text_transform = offset_copy(transform, units='dots', x=0, y=0)

    # Plot temp for each of the markers
    for lat, lon, temp, stid in data:
        plt.text(lon,
                 lat,
                 str(round(temp, 1)) + u'\N{DEGREE SIGN}' + 'F\n\n',
                 verticalalignment='center',
                 horizontalalignment='center',
                 transform=text_transform,
                 fontsize=11)

    uppertext = """Surface Observations 
over Wisconsin, taken
in the last 30 minutes.
Data accessed from
MesoWest and 
SynopticLabs.\n"""

    lowertext = """See more current surface observations here: 
http://mesowest.utah.edu/
http://aos.wisc.edu/weather/wx_obs/Surface.html
Learn how to interpret surface observation symbols here: 
http://ww2010.atmos.uiuc.edu/%28Gh%29/guides/maps/sfcobs/home.rxml"""
    ax.text(0.015,
            0.01,
            lowertext,
            verticalalignment='bottom',
            horizontalalignment='left',
            transform=ax.transAxes,
            fontsize='10.5',
            bbox=dict(facecolor='white', alpha=0.5))
    ax.text(0.015,
            0.13,
            uppertext,
            verticalalignment='bottom',
            horizontalalignment='left',
            transform=ax.transAxes,
            fontsize='10.5',
            bbox=dict(facecolor='white', alpha=0.5))
    plt.title('Current Weather Around Wisconsin', fontsize=14)
    plt.savefig('WI_Obs.png', bbox_inches='tight')
    #plt.show()

    tweet = "What's the weather like around WI? Find out more here: http://aos.wisc.edu/weather/wx_obs/Surface.html"
    try:
        #print 'WI_Obs.png'
        api.update_with_media("WI_Obs.png", status=tweet)
    except tweepy.error.TweepError:
        print("Twitter error raised")
    plt.close('all')
#!/usr/bin/env python3
'''
Copyright © 2018 nick3499@github
Title ⟹ 'Current Weather Conditions: MesoPy (MesoWest API Wrapper)'
Hosted ⟹ https://github.com/nick3499/mesowest_latest_ob
ISC License (ISC) ⟹ https://opensource.org/licenses/ISC
MesoWest Python wrapper ⟹ https://github.com/mesowx/MesoPy
API token required ⟹ https://synopticlabs.org/api/guides/?getstarted
Note: noticed data coming from more than one station, e.g. KILROMEO4, AR794.
'''

from MesoPy import Meso  # import `Meso()`
m = Meso(token='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')  # pass API `token`
lat = m.latest(stid='AR794')  # pass station ID, get `latest()` ob JSON data
s = lat['STATION'][0]['STID']  # station ID
s1 = lat['STATION'][0]['NAME']  # station name
ob = lat['STATION'][0]['OBSERVATIONS']  # JSON path prefix for current ob
s2 = ob['precip_accum_24_hour_value_1']['value']  # precip
s2 = "{0:.1f}".format(s2 * .0393700787)  # mm to in
s3 = ob['solar_radiation_value_1']['value']  # solar rad
s4 = ob['wind_gust_value_1']['value']  # wind gust
s4 = "{0:.1f}".format(s4 * 1.1507794)  # knots to mph
s5 = ob['dew_point_temperature_value_1d']['value']  # dew point
s5 = "{0:.1f}".format((1.8 * s5) + 32.0)  # C to F
s6 = ob['wind_cardinal_direction_value_1d']['value']  # wind cardinal dir
s7 = ob['pressure_value_1d']['value']  # baro psi (KILROMEO4)
s7 = "{0:.1f}".format((s7 * 0.029529987507120267) * .01)  # inHg to Mb
s8 = ob['wind_direction_value_1']['value']  # wind dir degrees
s9 = ob['sea_level_pressure_value_1d']['value']  # sea level psi (KILROMEO4)
s9 = "{0:.1f}".format((s9 * 0.029529987507120267) * .01)  # inHg to Mb
s10 = ob['precip_accum_since_local_midnight_value_1']['value']
예제 #7
0
파일: test_main.py 프로젝트: slk5033/MesoPy
def testauth():
    badtoken = Meso(token='3030')
    badtoken.latest(stid=['kfnl', 'kden', 'ksdf'], within='30')
예제 #8
0
def surfacePlot(api):
    m = Meso(token=MesoPy_token)
    stids = ['KAIG', 'KATW', 'KASX', 'KDLL', 'KOVS', 'KBUU', 'KCLI', 'KEGV', 'KEAU', 'KFLD',
            'KCMY', 'KGRB', 'KHYR', 'KJVL', 'KUNU', 'KENW', 'KLSE', 'KRCX', 'KLNL', 'KLNR',
            'KMSN', 'KMTW', 'KMFI', 'KMDZ', 'KLUM', 'KRRL', 'KMKE', 'KMRJ', 'K82C', 'TT278',
            'KEFT', 'KRNH', 'KOSH', 'KPBH', 'KPVB', 'KPDC', 'KRHI', 'KBCK', 'LAAW3', 'WUEW3',
            'KRPD', 'KEZS', 'KSBM', 'KRZN', 'KSTE', 'KSUE', 'KSUW', 'KY51', 'KRYV', 'KUES',
            'KPCZ', 'KAUW', 'KY50', 'KETB', 'KISW', 'KARV', 'GDNW3', 'KRGK', 'AFWW3'] #stations
    latest = m.latest(stid=stids, within='30', vars='air_temp', units='temp|F') #gets the latest temps (measured over past 30 minutes)
    data = [] #a list with 4 columns: lat, long, temps, stid
    for ob in latest['STATION']:
        data.append((float(ob['LATITUDE']), float(ob['LONGITUDE']),
                     float(ob['OBSERVATIONS']['air_temp_value_1']['value']),ob['STID'])) 
    # Now that we have all the data, we can make the figure
    fig = plt.figure(figsize=(10,10))
    plt.style.use('ggplot')
    ax = plt.axes(projection=ccrs.Mercator())
    ax.set_extent([-86.5, -93.2, 41.75, 47.25])
    ax.add_feature(ShapelyFeature(Reader("ne_50m_admin_1_states_provinces_lakes.shp").geometries(), 
                                  ccrs.PlateCarree(), facecolor = 'w', edgecolor = 'gray', linewidth=1.5))
    county_shpfile = 'c_05ap16.shp' #wi county shapefile
    WI = Reader(county_shpfile).records()
    for i in WI:
        if i.attributes['STATE'] == 'WI':
            ax.add_geometries(i.geometry, ccrs.PlateCarree(), facecolor='white',edgecolor = 'gray')
    
    roads = cfeature.NaturalEarthFeature(
        category='cultural',
        name='roads',
        scale='10m',
        facecolor = 'none')
    ax.add_feature(roads, edgecolor='red')
    ax.add_feature(ShapelyFeature(Reader("ne_50m_lakes.shp").geometries(),
                                  ccrs.PlateCarree(), facecolor = 'lightblue', edgecolor = 'gray', linewidth=1.5))
    
    for lat, lon, temp, stid in data: #plots a marker for each station
        plt.plot(lon, lat, marker='o', color='blue', markersize=10,
                 alpha=0.7, transform = ccrs.PlateCarree()) 

    # Transforms for the text function
    transform = ccrs.PlateCarree()._as_mpl_transform(ax)
    text_transform = offset_copy(transform, units='dots', x=0, y=0)

    # Plot temp for each of the markers
    for lat, lon, temp, stid in data:
        plt.text(lon, lat, str(round(temp, 1)) + u'\N{DEGREE SIGN}' + 'F\n\n',
                 verticalalignment='center', horizontalalignment='center',
                 transform=text_transform, fontsize=11)
    
    uppertext = """Surface Observations 
over Wisconsin, taken
in the last 30 minutes.
Data accessed from
MesoWest and 
SynopticLabs.\n"""

    lowertext = """See more current surface observations here: 
http://mesowest.utah.edu/
http://aos.wisc.edu/weather/wx_obs/Surface.html
Learn how to interpret surface observation symbols here: 
http://ww2010.atmos.uiuc.edu/%28Gh%29/guides/maps/sfcobs/home.rxml"""
    ax.text(0.015, 0.01, lowertext, verticalalignment = 'bottom', horizontalalignment = 'left', 
            transform=ax.transAxes, fontsize = '10.5', bbox=dict(facecolor='white', alpha = 0.5))
    ax.text(0.015, 0.13, uppertext, verticalalignment = 'bottom', horizontalalignment = 'left', 
            transform=ax.transAxes, fontsize = '10.5', bbox=dict(facecolor='white', alpha = 0.5))
    plt.title('Current Weather Around Wisconsin', fontsize=14)
    plt.savefig('WI_Obs.png', bbox_inches = 'tight')
    #plt.show()
    
    tweet = "What's the weather like around WI? Find out more here: http://aos.wisc.edu/weather/wx_obs/Surface.html"
    try:
        #print 'WI_Obs.png'
        api.update_with_media("WI_Obs.png", status = tweet)
    except tweepy.error.TweepError:
        print ("Twitter error raised")
    plt.close('all')
예제 #9
0
파일: test_main.py 프로젝트: scollis/MesoPy
def testauth():
    badtoken = Meso(token='3030')
    badtoken.latest(stid=['kfnl', 'kden', 'ksdf'], within='30')