def bond_turfs(form):

    folder_name = 'temp_folder_' + str(randint(1000, 10000))

    os.makedirs(folder_name)
    os.makedirs(folder_name + '/temp_folder')

    center_address = form['center_address']
    email = form['email']
    est_canvassers = int(form['est_canvassers'])
    percent_affordable = float(form['percent_affordable']) / 100.0
    coords = get_coordinates(center_address, False)
    skip_addresses = pd.read_csv("bond_skip_addresses.csv")
    print form
    print coords

    afford_units = read_afford_units(coords, skip_addresses)
    big_afford_units, small_afford_units = split_afford_units(afford_units)

    main_afford_units, backup_afford_units = main_backup_afford_units(
        big_afford_units, est_canvassers, percent_affordable)
    bonus_afford_units = get_bonus_afford_units(small_afford_units,
                                                main_afford_units)

    market_rate_units = get_market_rate_units(coords, afford_units,
                                              skip_addresses)
    market_rate_units = clean_market_rate_units(market_rate_units, coords)
    big_market_rate_units, small_market_rate_units = split_market_rate_units(
        market_rate_units)

    main_market_rate_units, backup_market_rate_units = main_backup_market_rate_units(
        big_market_rate_units, percent_affordable, est_canvassers)
    bonus_market_rate_units = get_bonus_market_rate_units(
        small_market_rate_units, main_market_rate_units)

    main_units = merge_units(main_afford_units, main_market_rate_units)
    main_units = main_units.sort_values("score",
                                        ascending=False).reset_index(drop=True)
    backup_units = merge_units(backup_afford_units, backup_market_rate_units)
    bonus_units = merge_units(bonus_afford_units, bonus_market_rate_units)

    backup_dict = match_frames(main_units, backup_units, colname="bigcount")
    main_unit_match, bonus_unit_match = bonus_match(main_units, bonus_units)
    bonus_dict = match_frames(main_unit_match, bonus_unit_match)

    make_pdf(main_units, backup_units, bonus_units, backup_dict,
             main_unit_match, bonus_unit_match, bonus_dict, folder_name)
    bond_assign_pdf(main_units, folder_name)

    #Email 3 pdfs to email address specified
    send_email(email, folder_name)
    print 'sent email'

    #Delete the temp folder
    shutil.rmtree(folder_name)

    return
def run(points=100, capacity=10, individuals=50, replace=25, generations=500):
    coordinates = get_coordinates(points, 0, 2000)
    environment = Environment(coordinates_to_distances(coordinates), capacity,
                              individuals, replace, generations)
    environment.individuals = sorted(
        environment.individuals, key=lambda individual: individual.evaluate())
    best = sorted(environment.individuals,
                  key=lambda individual: individual.evaluate())[0]

    return json.dumps({"coordinates": coordinates, "path": best.path})
def cli(points=100, capacity=10, individuals=50, replace=25, generations=500):
    coordinates = get_coordinates(points, 0, 2000)

    t1 = time.time_ns()

    environment = Environment(coordinates_to_distances(coordinates), capacity,
                              individuals, replace, generations)

    t2 = time.time_ns()

    print('Score: ' + str(round(environment.individuals[0].evaluate(), 3)))
    print('Path: ' + str(environment.individuals[0].path))
    print('Time: ' + str(round((t2 - t1) / 1000000000, 3)))
Exemple #4
0
    l = plt.legend(('Station Obs', 'Model', 'HF Radar'), loc='upper left')

# <markdowncell>

# Model data is not in the NGDC catalog

# <codecell>

#add map title
htmlContent = (
    '<p><h4>Location Map: Blue: Station Obs, Green: Model Data, Red: HF Radar</h4></p>'
)
station = st_list[st_list.keys()[0]]
map = folium.Map(location=[station["lat"], station["lon"]], zoom_start=10)
map.line(get_coordinates(bounding_box, bounding_box_type),
         line_color='#FF0000',
         line_weight=5)

#plot the obs station,
for st in st_list:
    lat = st_list[st]['lat']
    lon = st_list[st]['lon']

    popupString = '<b>Obs Location:</b><br>' + st + '<br><b>Source:</b><br>' + st_list[
        st]['source']

    if 'hasObsData' in st_list[st] and st_list[st]['hasObsData'] == False:
        map.circle_marker([lat, lon],
                          popup=popupString,
                          radius=1000,
    if ent['ws_pts'] >4:      
        df = ent['data']   
        fig = plt.figure(figsize=(18, 3))
        plt.plot(df.index, df['sea_water_speed (cm/s)'])
        fig.suptitle('HF Radar:'+ " lat:"+str(ent["lat"])+" lon:"+str(ent["lon"]), fontsize=14)
        plt.xlabel('Date', fontsize=18)
        plt.ylabel('sea_water_speed (cm/s)', fontsize=16)  
        ent['valid'] = True     

# <codecell>

#add map title
htmlContent = ('<p><h4>Station Map: Red circles have no obs data, Green is coops, Dark Blue is ndbc, Purple is HR Radar locations</h4></p>') 
station =  st_list[st_list.keys()[0]]
map = folium.Map(location=[station["lat"], station["lon"]], zoom_start=4)
map.line(get_coordinates(bounding_box, bounding_box_type), line_color='#FF0000', line_weight=5)

#plot the obs station, 
for st in st_list:  
    lat = st_list[st]['lat']
    lon = st_list[st]['lon']
    
    popupString = '<b>Obs Location:</b><br>'+st+'<br><b>Source:</b><br>'+st_list[st]['source']
    
    if st_list[st]['hasObsData'] == False:
        map.circle_marker([lat,lon], popup=popupString, 
                          radius=1000,
                          line_color='#FF0000',
                          fill_color='#FF0000', 
                          fill_opacity=0.2)
        
for n in range(len(stations)):
    # get the station data from the sos end point
    name = stations[n]
    longname = obs_df[n].name
    lat = obs_lat[n]
    lon = obs_lon[n]
    popup_string = "<b>Station:</b><br>" + longname
    m.simple_marker([lat, lon], popup=popup_string)

    popup_string = "<b>Model Grid Point</b>"
    m.circle_marker(
        [model_lat[n], model_lon[n]], popup=popup_string, fill_color="#ff0000", radius=5000, line_color="#ff0000"
    )

m.line(get_coordinates(bounding_box, bounding_box_type), line_color="#FF0000", line_weight=5)

inline_map(m)

# <markdowncell>

# #### Plot Modeled vs Obs Currents

# <codecell>

# for df in model_df:
for n in range(len(obs_df)):
    ax = model_df[n].plot(figsize=(14, 6), title=model_df[n].name, legend=False)
    plt.setp(ax.lines[0], linewidth=3, color="0.7", zorder=1)
    ax.legend()
    #     ax.set_ylabel('Current speed m/s')
groups = df.groupby(df.index)


# In[ ]:

import folium
import vincent
from utilities import get_coordinates, inline_map

lon_center, lat_center = np.array(bbox).reshape(2, 2).mean(axis=0)
ssh = folium.Map(width=750, height=500,
                 location=[lat_center, lon_center], zoom_start=5)

# Create the map and add the bounding box line.
kw = dict(line_color='#FF0000', line_weight=2)
ssh.line(get_coordinates(bbox), **kw)

# Clusters.
for station, info in groups:
    station = get_coops_longname(station)
    for lat, lon, name in zip(info.lat, info.lon, info.name):
        location = lat, lon
        popup = '<b>{}</b>\n{}'.format(station, name)
        ssh.simple_marker(location=location, popup=popup,
                          clustered_marker=True)

# Model and observations.
for station in dfs:
    sta_name = get_coops_longname(station)
    df = dfs[station].dropna(axis=1, how='all')
    # FIXME: This is bad!  But I cannot represent NaN with Vega!
Exemple #8
0
n = 0
for df in obs_df:
    #get the station data from the sos end point
    longname = df.name
    lat = obs_loc_df['latitude (degree)'][n]
    lon = obs_loc_df['longitude (degree)'][n]
    popup_string = ('<b>Station:</b><br>'+ longname)
    if len(df) > min_data_pts:
        m.simple_marker([lat, lon], popup=popup_string)
    else:
        #popup_string += '<br>No Data Available'
        popup_string += '<br>Not enough data available<br>requested pts: ' + str(min_data_pts ) + '<br>Available pts: ' + str(len(Hs_obs_df[n]))
        m.circle_marker([lat, lon], popup=popup_string, fill_color='#ff0000', radius=10000, line_color='#ff0000')
    n += 1
m.line(get_coordinates(bounding_box,bounding_box_type), line_color='#FF0000', line_weight=5)

inline_map(m)

# <markdowncell>

# ### Plot water temperature for each station

# <codecell>

for df in obs_df:
    if len(df) > min_data_pts:
        fig, axes = plt.subplots(figsize=(20,5))
        df['Observed Data'].plot()
        axes.set_title(df.name)
        axes.set_ylabel('Temperature (C)')
def apt_turfs(form):
    folder_name = 'temp_folder_' + str(randint(1000, 10000))

    os.makedirs(folder_name)
    os.makedirs(folder_name + '/temp_folder')

    center_address = form['center_address']
    email = form['email']
    est_canvas_teams = int(form['est_canvas_teams'])
    center_coords = get_coordinates(center_address, False)
    team_max = 45
    skip_addresses = pd.read_csv("bond_skip_addresses.csv")
    print 'Set coords'

    #Filter by region
    #Filter by skip addresses

    data = upload_apartment_list()
    print 'Got apartment list'

    data = data.loc[:, ["address", "units", "cost", "year", "LAT", "LON"]]

    #Fill in the missing year and cost with the averages
    avgyear = np.mean(data.loc[pd.notnull(data["year"]), "year"].map(float))
    avgcost = np.mean(data.loc[pd.notnull(data["cost"]), "cost"].map(float))
    #print avgyear
    data.loc[pd.isnull(data["cost"]), "cost"] = avgcost
    #print data["year"]
    data.loc[pd.isnull(data["year"]), "year"] = avgyear
    print data["units"]
    print 'updated data'

    min_len = 99999999999999999999
    for j in range(20):
        [temp_data, team_table,
         temp_routes] = iterate_apts(data, center_coords, random_function,
                                     avgyear, avgcost, est_canvas_teams,
                                     team_max)
        total_len = sum([i[-1] for i in temp_routes]) / len(team_table)
        if total_len < min_len:
            min_len = total_len
            min_data = temp_data.copy()
            min_team = team_table.copy()
            min_routes = temp_routes[:]

    pdf = FPDF()

    #Scroll through each team, label apartment type, write PDFs
    for ind, row in min_team.iterrows():
        teams = row.teams
        temp_table = min_data[min_data["team"] == ind]
        temp_table["order"] = get_order(min_routes[ind][0][1:])
        temp_table["apt_type"] = "bonus"
        temp_table["apt_sort"] = 2
        big_apts = temp_table[temp_table["units"] >= team_max]
        start = True
        for ind1, row1 in big_apts.iterrows():
            if start:
                temp_table.at[ind1, "apt_type"] = "main"
                temp_table.at[ind1, "apt_sort"] = 0
                start = False
            else:
                temp_table.at[ind1, "apt_type"] = "backup"
                temp_table.at[ind1, "apt_sort"] = 1
        temp_table = temp_table.sort_values(by=["apt_sort", "order"])
        add_pages(temp_table, int(teams), pdf, ind)
    pdf.output(folder_name + "/temp_folder/pdf.pdf")

    #Email 3 pdfs to email address specified
    send_email(email, folder_name)
    print 'sent email'

    #Delete the temp folder
    shutil.rmtree(folder_name)

    return
        ax.set_xlim([2000, 2015])
        ax.set_title("Yearly Max Speed Per Station, Marker Scaled Per "
                     "Annual Pts (bigger = more pts per year)")
        ax.set_ylabel("speed (knots)")
        ax.set_xlabel("Year")
        ax.legend(loc='upper left')

# <markdowncell>

# #### Produce Interactive Map

# <codecell>

station = st_list[st_list.keys()[0]]
m = folium.Map(location=[station["lat"], station["lon"]], zoom_start=4)
m.line(get_coordinates(bounding_box, bounding_box_type),
       line_color='#FF0000', line_weight=5)

# Plot the obs station.
for st in st_list:
    hasObs = st_list[st]['hasObsData']
    if hasObs:
        fname = './images/%s.png' % st.split(":")[-1]
        if os.path.isfile(fname):
            popup = ('Obs Location:<br>%s<br><img border=120 src="'
                     './images/%s.png" width="242" height="242">' %
                     (st, st.split(":")[-1]))
            m.simple_marker([st_list[st]["lat"], st_list[st]["lon"]],
                            popup=popup,
                            marker_color="green",
                            marker_icon="ok")
# In[ ]:

import folium
import vincent
from utilities import get_coordinates, inline_map

lon_center, lat_center = np.array(bbox).reshape(2, 2).mean(axis=0)
ssh = folium.Map(width=750,
                 height=500,
                 location=[lat_center, lon_center],
                 zoom_start=5)

# Create the map and add the bounding box line.
kw = dict(line_color='#FF0000', line_weight=2)
ssh.line(get_coordinates(bbox), **kw)

# Clusters.
for station, info in groups:
    station = get_coops_longname(station)
    for lat, lon, name in zip(info.lat, info.lon, info.name):
        location = lat, lon
        popup = '<b>{}</b>\n{}'.format(station, name)
        ssh.simple_marker(location=location,
                          popup=popup,
                          clustered_marker=True)

# Model and observations.
for station in dfs:
    sta_name = get_coops_longname(station)
    df = dfs[station].dropna(axis=1, how='all')