def run_diseaseStations (disease): from disease_vars_dict import disease_vars # var majors for disease variables majors = {'temp': [23,126], 'prcp': [5], 'lwet': [118], 'rhum': [24], 'wspd': [28,128], 'srad': [119,132] } # variables recorded at all airports airport_vars = ['prcp','temp','rhum','wspd','wdir'] # airports in and around NY airports = [("kalb", "Albany Airport"), ("kbgm", "Binghamton Airport"), ("kbfd", "Bradford, PA Airport"), ("khwv", "Brookhaven Airport"), ("kbuf", "Buffalo Airport"), ("kbtv", "Burlington, VT Airport"), ("kdsv", "Dansville Airport"), ("kdkk", "Dunkirk Airport"), ("kelm", "Elmira Airport"), ("keri", "Erie, PA Airport"), ("kfrg", "Farmingdale Airport"), ("kfzy", "Fulton Airport"), ("kgfl", "Glens Falls Airport"), ("krme", "Griffiss Airport"), ("kisp", "Islip Airport"), ("kith", "Ithaca Airport"), ("kjhw", "Jamestown Airport"), ("kmss", "Massena Airport"), ("kmgj", "Montgomery Airport"), ("kmtp", "Montauk Airport"), ("kmsv", "Monticello Airport"), ("knyc", "New York - Central Park"), ("kjfk", "New York - JFK Airport"), ("klga", "New York - LGA Airport"), ("kiag", "Niagara Falls Airport"), ("kpeo", "Penn Yan Airport"), ("kpou", "Poughkeepsie Airport"), ("kroc", "Rochester Airport"), ("kslk", "Saranac Lake Airport"), ("kswf", "Newburgh Stewart Field"), ("ksyr", "Syracuse Airport"), ("kfok", "Suffolk County Airport"), ("kart", "Watertown Airport"), ("kgtb", "Wheeler Sack Field"), ("khpn", "White Plains Airport"), ("kelz", "Wellsville Airport"), ("krut", "Rutland, VT Airport"), ("kddh", "Bennington, VT Airport"), ("kaqw", "North Adams, MA Airport"), ("kpsf", "Pittsfield, MA Airport"), ("kdxr", "Danbury, CT Airport"), ("kbdr", "Bridgeport, CT Airport"), ("kfwn", "Sussex, NJ Airport"), ("kcdw", "Fairfield, NJ Airport"), ("kteb", "Teterboro, NJ Airport"), ("kewr", "Newark, NJ Airport"), ("kovs", "Boscobel, WI Airport"), ("kcid", "Cedar Rapids, IA Airport"), ("kiow", "Iowa City, IA Airport"), ("koma", "Omaha, NE Airport"), ("klnk", "Lincoln, NE Airport")] # network codes station_type = {57: 'newa', 58: 'cu_log', 7: 'icao', 28: 'njwx'} good_stations = [] try: # check for valid disease if disease_vars.has_key(disease): # build list of desired variables vmaj = [] for v in disease_vars[disease]: vmaj = vmaj + majors[v] # obtain stations that report any of these variables results_dict = get_stations_with_var ('NY',vmaj,(2008,1,1),(9999,12,31)) # remove stations that don't report a variable for k in results_dict.keys(): for v in disease_vars[disease]: for m in majors[v]: if m in results_dict[k]['var_major_id']: break else: ##del results_dict[k] break #don't use station else: rdk = results_dict[k] for i in range(len(rdk['ids'])): net = rdk['ids'][i].network id = rdk['ids'][i].id if station_type.has_key(net): stanet = station_type[net] staid = id break else: stanet = '' staid = id good_stations.append(staid) # add airports if they have necessary variables for v in disease_vars[disease]: if v not in airport_vars: break #can't use airports else: for ap in airports: good_stations.append(ap[0]) station_dict = {"stations": good_stations} json_return = json.dumps(station_dict) except: print_exception() return json_return
def run_diseaseStations (disease): from disease_vars_dict import disease_vars # var majors for disease variables majors = {'temp': [23,126], 'prcp': [5], 'lwet': [118], 'rhum': [24], 'wspd': [28,128], 'srad': [119,132] } # variables recorded at all airports airport_vars = ['prcp','temp','rhum','wspd','wdir'] # airports in and around NY airports = [("kalb", "Albany Airport"), ("kbgm", "Binghamton Airport"), ("kbfd", "Bradford, PA Airport"), ("khwv", "Brookhaven Airport"), ("kbuf", "Buffalo Airport"), ("kbtv", "Burlington, VT Airport"), ("kdsv", "Dansville Airport"), ("kdkk", "Dunkirk Airport"), ("kelm", "Elmira Airport"), ("keri", "Erie, PA Airport"), ("kfrg", "Farmingdale Airport"), ("kfzy", "Fulton Airport"), ("kgfl", "Glens Falls Airport"), ("krme", "Griffiss Airport"), ("kisp", "Islip Airport"), ("kith", "Ithaca Airport"), ("kjhw", "Jamestown Airport"), ("kmss", "Massena Airport"), ("kmgj", "Montgomery Airport"), ("kmtp", "Montauk Airport"), ("kmsv", "Monticello Airport"), ("knyc", "New York - Central Park"), ("kjfk", "New York - JFK Airport"), ("klga", "New York - LGA Airport"), ("kiag", "Niagara Falls Airport"), ("kpeo", "Penn Yan Airport"), ("kpou", "Poughkeepsie Airport"), ("kroc", "Rochester Airport"), ("kslk", "Saranac Lake Airport"), ("kswf", "Newburgh Stewart Field"), ("ksyr", "Syracuse Airport"), ("kfok", "Westhampton Beach Airport"), ("kart", "Watertown Airport"), ("kgtb", "Wheeler Sack Field"), ("khpn", "White Plains Airport"), ("kelz", "Wellsville Airport"), ("krut", "Rutland, VT Airport"), ("kddh", "Bennington, VT Airport"), ("kaqw", "North Adams, MA Airport"), ("kpsf", "Pittsfield, MA Airport"), ("kdxr", "Danbury, CT Airport"), ("kbdr", "Bridgeport, CT Airport"), ("kfwn", "Sussex, NJ Airport"), ("kcdw", "Fairfield, NJ Airport"), ("kteb", "Teterboro, NJ Airport"), ("kmpv", "Montpelier, VT Airport"), ("kmvl", "Morrisville, VT Airport"), ("kvsf", "Springfield, VT Airport"), ("k12n", "Andover, NJ Airport"), ("kacy", "Atlantic City, NJ Airport"), ("kblm", "Farmingdale, NJ Airport"), ("kmiv", "Millville, NJ Airport"), ("kmmu", "Morristown, NJ Airport"), ("knel", "Lakehurst NAS, NJ"), ("ksmq", "Somerville, NJ Airport"), ("kttn", "Trenton, NJ Airport"), ("kvay", "Mount Holly, NJ Airport"), ("kwri", "McGuire AFB, NJ Airport"), ("kwwd", "Wildwood, NJ Airport"), ("kphl", "Philadelphia, PA Airport"), ("kpne", "NE Philadelphia, PA Airport"), ("kpit", "Pittsburgh, PA Airport"), ("kmdt", "Middletown Harrisburg, PA Airport"), ("kipt", "Williamsport, PA Airport"), ("kavp", "Wilkes-Barre, PA Airport"), ("kabe", "Allentown, PA Airport"), ("kaoo", "Altoona, PA Airport"), ("krdg", "Reading, PA Airport"), ("kjst", "Johnstown, PA Airport"), ("kduj", "DuBois, PA Airport"), ("kilg", "Wilmington, DE Airport"), ("korh", "Worcester, MA Airport"), ("kore", "Orange, MA Airport"), ("kpym", "Plymouth, MA Airport"), ("kbvy", "Beverly, MA Airport"), ("khya", "Hyannis, MA Airport"), ("kbos", "Boston Logan, MA Airport"), ("kack", "Nantucket, MA Airport"), ("kcef", "Chicopee Falls, MA Airport"), ("klwm", "Lawrence, MA Airport"), ("kbaf", "Westfield, MA Airport"), ("kmqe", "E Milton Blue Hill, MA"), ("kbed", "Bedford, MA Airport"), ("kpvc", "Provincetown, MA Airport"), ("ktan", "Taunton, MA Airport"), ("kowd", "Norwood, MA Airport"), ("kfmh", "Falmouth Otis AFB, MA"), ("kfit", "Fitchburg, MA Airport"), ("kmvy", "Vineyard Haven, MA Airport"), ("kewb", "New Bedford, MA Airport"), ("kcqx", "Chatham, MA Airport"), ("kuuu", "Newport, RI Airport"), ("kpvd", "Providence, RI Airport"), ("kbdl", "Hartford (Bradley AP), CT"), ("kstl", "St. Louis, MO Airport"), ("kgpz", "Grand Rapids, MN Airport"), ("kewr", "Newark, NJ Airport"), ("kovs", "Boscobel, WI Airport"), ("kcid", "Cedar Rapids, IA Airport"), ("kiow", "Iowa City, IA Airport"), ("koma", "Omaha, NE Airport"), ("klnk", "Lincoln, NE Airport"), ("kcon", "Concord, NH Airport"), ("kash", "Nashua, NH Airport"), ("kmht", "Manchester, NH Airport"), ("kdlh", "Diluth, MN Airport"), ("kmsp", "Minneapolis, MN Airport"), ("krst", "Rochester, MN Airport"), ("kstc", "St Cloud, MN Airport"), ("kdca", "Washington, DC Airport"), ("kged", "Georgetown, DE Airport"), ("kbwi", "Baltimore, MD Airport"), ("ksby", "Salisbury, MD Airport"), ("kavl", "Asheville, NC Airport"), ("kclt", "Charlotte, NC Airport"), ("kfsd", "Sioux Falls, SD Airport"), ("klse", "La Crosse, WI Airport"), ("krfd", "Rockford, IL Airport"), ("karr", "Aurora, IL Airport")] # network codes station_type = {57: 'newa', 58: 'cu_log', 7: 'icao', 28: 'njwx'} good_stations = [] try: # check for valid disease if disease_vars.has_key(disease): # build list of desired variables vmaj = [] for v in disease_vars[disease]: vmaj = vmaj + majors[v] # obtain stations that report any of these variables results_dict = get_stations_with_var ('NY',vmaj,(2008,1,1),(9999,12,31)) # remove stations that don't report a variable for k in results_dict.keys(): for v in disease_vars[disease]: for m in majors[v]: if m in results_dict[k]['var_major_id']: break else: ##del results_dict[k] break #don't use station else: rdk = results_dict[k] for i in range(len(rdk['ids'])): net = rdk['ids'][i].network id = rdk['ids'][i].id if station_type.has_key(net): stanet = station_type[net] staid = id break else: stanet = '' staid = id good_stations.append(staid) # add airports if they have necessary variables for v in disease_vars[disease]: if v not in airport_vars: break #can't use airports else: for ap in airports: good_stations.append(ap[0]) station_dict = {"stations": good_stations} json_return = json.dumps(station_dict) except: print_exception() return json_return