Ejemplo n.º 1
0
def configure_area_chart(area_chart, data_frame, data_source, through_key,
                         stacked):
    """Sets additional configuration details to the area chart, specific for flow visualization.

    Configures the legend location, click policy and ranges of the graph.

    Arguments:
        area_chart(charts.Area): area chart which will be further configured
        data_frame(pandas.DataFrame): original data frame
        data_source(pandas.DataFrame): transformed data frame with aggregated data
        through_key(str): key on the x axis
        stacked(bool): true if the values in the graph are stacked
    """
    # Get minimal and maximal values; note we will add some small bonus to the maximal value
    minimal_x_value = data_frame[through_key].min()
    maximal_x_value = data_frame[through_key].max()
    values_data_frame = pandas.DataFrame(data_source)
    minimal_y_value = values_data_frame.min().min()
    value_maxima = values_data_frame.max()
    maximal_y_value = 1.05 * (value_maxima.max()
                              if not stacked else value_maxima.sum())

    # Configure flow specific options
    area_chart.legend.location = 'top_left'
    area_chart.legend.click_policy = 'hide'
    area_chart.x_range = models.Range1d(minimal_x_value, maximal_x_value - 1)
    area_chart.y_range = models.Range1d(minimal_y_value, maximal_y_value)
Ejemplo n.º 2
0
    def _plot_bokeh(self, current_plot, show_legend=True):
        import bokeh.models as mdl
        import bokeh.plotting as bkh
        from bokeh.properties import value

        lst = []
        row_lst = []
        for plotter in self.plots:
            cur_plot = bkh.figure(title=plotter.title, plot_width=self.one_figsize[0] * self.BOKEH_RESIZE,
                                  plot_height=self.one_figsize[1] * self.BOKEH_RESIZE)
            if plotter.xlim is not None:
                cur_plot.x_range = mdl.Range1d(start=plotter.xlim[0], end=plotter.xlim[1])
            if plotter.ylim is not None:
                cur_plot.y_range = mdl.Range1d(start=plotter.ylim[0], end=plotter.ylim[1])
            cur_plot.title_text_font_size = value("{}pt".format(plotter.fontsize))
            cur_plot.xaxis.axis_label = plotter.xlabel
            cur_plot.yaxis.axis_label = plotter.ylabel
            cur_plot.legend.orientation = 'top_right'
            cur_plot = plotter._plot_bokeh(cur_plot, show_legend=show_legend)
            if len(row_lst) >= self.columns:
                lst.append(row_lst)
                row_lst = []
            row_lst.append(cur_plot)
        if len(row_lst) > 0:
            lst.append(row_lst)
        grid = mdl.GridPlot(children=lst)
        return grid
Ejemplo n.º 3
0
def create_village_name_map(survey, pie_column):

    means = survey.groupby('village_name')['_gps_point_latitude',
                                           '_gps_point_longitude',
                                           pie_column].mean()

    source = bkm.ColumnDataSource(
        data=dict(vn=means.index,
                  lat=means['_gps_point_latitude'],
                  lon=means['_gps_point_longitude'],
                  size=[10 for x in means[pie_column]],
                  angle=means[pie_column] * 6.28))

    wedges = bkg.Wedge(x='lon',
                       y='lat',
                       radius='size',
                       start_angle=0,
                       end_angle='angle',
                       fill_color='green',
                       fill_alpha=0.5,
                       radius_units='screen')
    wedges2 = bkg.Wedge(x='lon',
                        y='lat',
                        radius='size',
                        start_angle='angle',
                        end_angle=6.28,
                        fill_color='red',
                        fill_alpha=0.5,
                        radius_units='screen')
    text = bkg.Text(x='lon',
                    y='lat',
                    text='vn',
                    text_color='000',
                    text_font_size='12pt',
                    x_offset=10)

    map_options = bkm.GMapOptions(lat=-2.588,
                                  lng=140.5170,
                                  zoom=11,
                                  map_type='terrain')
    plot = bkm.GMapPlot(x_range=bkm.Range1d(),
                        y_range=bkm.Range1d(),
                        map_options=map_options,
                        title="Lake Sentani" + pie_column)
    plot.add_glyph(source, wedges)
    plot.add_glyph(source, wedges2)
    plot.add_glyph(source, text)

    #plot.add_tools(pan, wheel_zoom, box_zoom, resize, reset)
    plot.add_tools(bkm.BoxZoomTool(), bkm.PanTool(), bkm.ResetTool(),
                   bkm.WheelZoomTool())
    plot.add_layout(
        bkm.LinearAxis(axis_label='Longitude (deg)', major_tick_in=0), 'below')
    plot.add_layout(
        bkm.LinearAxis(axis_label='Latitude (deg)', major_tick_in=0), 'left')
    return plot
Ejemplo n.º 4
0
    def plot_daily_gas_bkh(self,
                           figsize=(650, 450),
                           plot_temperature=False,
                           colors=['black', 'darkturquoise']):
        p = bkh.figure(x_axis_type='datetime',
                       plot_width=figsize[0],
                       plot_height=figsize[1])

        p.line(x=self.energy_average['Date_'],
               y=32 * np.ones(len(self.energy_average)),
               line_dash='dashed',
               line_color=colors[0],
               legend_label='Typical domestic use (medium)')

        p.line(x=self.energy_average['Date_'],
               y=self.energy_average['gas_daily_total'],
               line_color=colors[0],
               legend_label='Mean of 115,000 UK households')

        p.xaxis.axis_label = 'Date'
        p.xaxis[0].formatter = bkm.DatetimeTickFormatter(days=['%d/%m'])

        p.y_range = bkm.Range1d(15, 70)
        p.yaxis.axis_label = 'Gas Consumption (Corrected) (kWh/ALP)'
        p.yaxis.axis_label_text_color = colors[0]

        if plot_temperature and self.weather_file:
            p.extra_y_ranges = {'temperature': bkm.Range1d(start=6, end=24)}

            p.line(x=self.energy_average['Date_'],
                   y=self.energy_average['temperature'],
                   line_color=colors[1],
                   legend_label='Temperature',
                   y_range_name='temperature')

            p.add_layout(
                bkm.LinearAxis(y_range_name='temperature',
                               axis_label='Mean Temperature (°C)',
                               axis_label_text_color=colors[1],
                               axis_line_color=colors[1],
                               major_label_text_color=colors[1],
                               major_tick_line_color=colors[1],
                               minor_tick_line_color=colors[1]), 'right')

            r = self.energy_average[['gas_daily_total', 'temperature'
                                     ]].corr(method='pearson').values[1, 0]
            p.legend.title = f'R = {r:.3f}'
            p.legend.location = 'top_left'
            p.legend.background_fill_alpha = 1.0

        #bkh.output_notebook()
        bkh.show(p)
Ejemplo n.º 5
0
    def init_plots(cls, phase_y_range, potential_y_range):
        x_range = models.Range1d(*cls.phis[[0, -1]])
        first_x = -1
        x_ticker = models.FixedTicker(
            ticks=np.arange(first_x, cls.phis_in_pi_units[-1], 0.5) * np.pi)
        x_tick_formatter = models.FuncTickFormatter.from_py_func(pi_format)

        phase_plot = cls.init_phase_plot(
            width=FIGURE_WIDTH,
            height=FIGURE_HEIGHT,
            x_range=x_range,
            y_range=phase_y_range,
            title='Phase portrait',
            toolbar_location=None,
        )
        phase_plot.xaxis.ticker = x_ticker
        phase_plot.xgrid.ticker = x_ticker
        phase_plot.xaxis[0].formatter = x_tick_formatter

        pot_plot = cls.init_potential_plot(
            width=FIGURE_WIDTH,
            height=FIGURE_HEIGHT,
            x_range=x_range,
            y_range=potential_y_range,
            x_axis_location='above',
            title='System potential',
            toolbar_location=None,
        )
        pot_plot.xaxis.ticker = x_ticker
        pot_plot.xgrid.ticker = x_ticker
        pot_plot.xaxis[0].formatter = x_tick_formatter

        return phase_plot, pot_plot
Ejemplo n.º 6
0
def _create_sorted_plt(comptable_cds,
                       n_comps,
                       x_var,
                       y_var,
                       title=None,
                       x_label=None,
                       y_label=None):
    """
    Create dynamic sorted plots

    Parameters
    ----------
    comptable_ds: bokeh.models.ColumnDataSource
        Data structure containing a limited set of columns from the comp_table

    x_var: str
        Name of variable for the x-axis

    y_var: str
        Name of variable for the y-axis

    title: str
        Plot title

    x_label: str
        X-axis label

    y_label: str
        Y-axis label

    Returns
    -------
    fig: bokeh.plotting.figure.Figure
        Bokeh plot of components ranked by a given feature
    """
    hovertool = models.HoverTool(
        tooltips=[('Component ID', '@component'), (
            'Kappa',
            '@kappa{0.00}'), ('Rho',
                              '@rho{0.00}'), ('Var. Expl.', '@varexp{0.00}%')])
    fig = plotting.figure(
        plot_width=400,
        plot_height=400,
        tools=["tap,wheel_zoom,reset,pan,crosshair,save", hovertool],
        title=title)
    fig.line(x=np.arange(1, n_comps + 1),
             y=comptable_cds.data[y_var].sort_values(ascending=False).values,
             color='black')
    fig.circle(x_var,
               y_var,
               source=comptable_cds,
               size=5,
               color='color',
               alpha=0.7)
    fig.xaxis.axis_label = x_label
    fig.yaxis.axis_label = y_label
    fig.x_range = models.Range1d(-1, n_comps + 1)
    fig.toolbar.logo = None

    return fig
Ejemplo n.º 7
0
    def hospital_plot(self):
        """
        Plot hospital locations.

        .. warning:: This method requires a Google API Key
        """
        map_options = {
            'lat': 40.70,
            'lng': -73.92,
            'map_type': 'roadmap',
            'zoom': 10,
        }
        plot = bkm.GMapPlot(
            api_key=keys.GOOGLE_API_KEY,
            x_range=bkm.Range1d(),
            y_range=bkm.Range1d(),
            map_options=bkm.GMapOptions(**map_options),
            plot_width=400,
            plot_height=600,
        )
        plot.title.text = 'New York City Hospitals'

        hospital = bkm.Circle(
            x='longitude',
            y='latitude',
            fill_alpha=0.8,
            fill_color='#cd5b1b',
            line_color=None,
            size=14,
        )

        hospitals = bkm.sources.ColumnDataSource(self.hospitals)
        plot.add_glyph(hospitals, hospital)

        hover = bkm.HoverTool()
        hover.tooltips = [
            ('Location', '@name'),
        ]
        plot.add_tools(
            hover,
            bkm.PanTool(),
            bkm.WheelZoomTool(),
        )

        bkio.output_file('hospitals.html')
        bkio.show(plot)
Ejemplo n.º 8
0
def plot_percents(data: list) -> plotting.Figure:
    """Return the bokeh of temperature data."""
    plot = make_timeseries_plot()
    plot.yaxis.formatter = models.NumeralTickFormatter(format="0%")
    plot.y_range = models.Range1d(0, 1)
    plot = make_fact_lines(plot, data)
    plot.legend.location = "top_left"  # because the legend requires glyphs
    return plot
Ejemplo n.º 9
0
def make_map():

    with open("./countries.geo.json", "r") as f:
        countries = bkm.GeoJSONDataSource(geojson=f.read())

    p = bkp.figure(width=1000, height=600, tools=tools, title='World Countries',
                   x_axis_label='Longitude', y_axis_label='Latitude')
    p.background_fill_color = "aqua"
    p.x_range = bkm.Range1d(start=-180, end=180)
    p.y_range = bkm.Range1d(start=-90, end=90)
    p.patches("xs", "ys", color="white", line_color="black", source=countries)

    layout = row(p)

    # Make a tab with the layout
    tab = Panel(child=layout, title='Word frequency')

    return tab
Ejemplo n.º 10
0
    def __init__(self,
                 max_points=100,
                 palette=None,
                 alpha=0.7,
                 size=8,
                 width=400,
                 height=400,
                 x_lim=None,
                 y_lim=None,
                 notebook=True):
        if not BOKEH_INSTALLED:
            raise RuntimeError('bokeh is not installed')

        if notebook:
            io.output_notebook()

        if palette is None:
            palette = palettes.Category10[10]

        self.max_points = max_points
        self.palette = itertools.cycle(palette)
        self.alpha = alpha
        self.size = size
        self.notebook = notebook

        # Add figure
        self.fig = plotting.figure(plot_width=width, plot_height=height)
        self.fig.xaxis.axis_label = 'x'
        self.fig.yaxis.axis_label = 'y'

        # Add limits
        if x_lim is not None:
            self.fig.x_range = models.Range1d(x_lim[0], x_lim[1])
        if y_lim is not None:
            self.fig.y_range = models.Range1d(y_lim[0], y_lim[1])

        self.source = models.ColumnDataSource(data={
            'x': [],
            'y': [],
            'label': []
        })

        self.views = {}
        self.scatters = {}
Ejemplo n.º 11
0
def plot_generic_ci(datafile):
   
   hdf = h5py.File(datafile, 'r') 
   
   
   figures = {}
   
   if not 'PARAMETERS' in hdf:
      return figures
   
   data = hdf['PARAMETERS']
   for i, (name, dataset) in enumerate(data.items()):
      
      if 'Chi2Val' in dataset:
         
         err = dataset.attrs.get('err', 0.0)
         emin = dataset.attrs.get('emin', err)
         emax = dataset.attrs.get('emax', err)
         value = dataset.attrs.get('value', 0.0)
         
         title = "{} = {:.2f} + {:.2f} - {:.2f}".format(name, value, emax, emin)
         
         fig = bpl.figure(plot_width=280, plot_height=280, tools=[], title=title)
         
         fig.ray(x=dataset['Chi2Val']['x'], y=dataset['Chi2Val']['y'], length=0, 
               angle=np.pi/2., line_width=3)
         
         fig.line(dataset['Chi2Fit']['x'], dataset['Chi2Fit']['y'], line_width=1,
                  color='red', alpha=0.7)
         
         min_chi2 = np.min(dataset['Chi2Val']['y'])
         fig.y_range = mpl.Range1d(0.85*min_chi2, 1.25*min_chi2)
         
         fig.min_border = 10
         fig.min_border_top = 1
         fig.min_border_bottom = 40
         fig.toolbar.logo = None
         fig.toolbar_location = None
         fig.title.align = 'center'
      
         figures[name] = fig
      
   return figures
    def mapGenerator(path, mapSelect, htmlString, title, scaleMin, scaleMax,
                     metric):
        '''
        HELPER FUNCTION
        
        mapGenerator()
        
        Generate a map from the processed level_1_dataframe and diplay as a 
            bokeh map of the earth for each weather station
        
        @param path        - String, of the current working directory                                  
        @param mapSelect   - String, string to select what map to generate
 
         'Annual Global Horizontal Irradiance (GJ/m^-2)',
         'Annual Direct Normal Irradiance (GJ/m^-2)',
         'Annual Diffuse Horizontal Irradiance (GJ/m^-2)',
         'Annual POA Global Irradiance (GJ/m^-2)',
         'Annual POA Direct Irradiance (GJ/m^-2)',
         'Annual POA Diffuse Irradiance (GJ/m^-2)',
         'Annual POA Sky Diffuse Irradiance (GJ/m^-2)',
         'Annual POA Ground Diffuse Irradiance (GJ/m^-2)',
         
         'Annual Global UV Dose (MJ/y^-1)',
         'Annual UV Dose at Latitude Tilt (MJ/y^-1)',
         
         'Annual Minimum Ambient Temperature (C)',
         'Annual Average Ambient Temperature (C)',
         'Annual Maximum Ambient Temperature (C)',
         'Annual Range Ambient Temperature (C)',
         'Average of Yearly Water Vapor Pressure(kPa)',
         'Sum of Yearly Water Vapor Pressure(kPa)',
         "Annual number of Hours Relative Humidity > to 85%",
         'Sum of Yearly Dew(mmd-1)'

        @param htmlString - String, what to name the html 
        @param title      - String, title of the map
        @param scaleMin   - Float,  minimum value of the scale
        @param scaleMax   - Float,  maximum value of the scale        
        @param metric     - String, metric of the value being measured        
        
        @return           -void, Bokeh map as a html
        '''
        colorSelector = "Viridis256"

        #Create the html to be exported
        output_file(htmlString + '.html')

        # Create the tools used for zooming and hovering on the map
        tools = "pan,wheel_zoom,box_zoom,reset,previewsave"

        #Access the .json file to create the map of countries and states
        # The json files will create layers to overlap the data with
        with open(path + "/Map/countries.geojson", "r") as f:
            countries = bkm.GeoJSONDataSource(geojson=f.read())
        with open(path + "/Map/us-states.json", "r") as f:
            states = bkm.GeoJSONDataSource(geojson=f.read())
        #Access the processed summary data pickle
        level_1_df = pd.read_pickle(
            path +
            "\\Pandas_Pickle_DataFrames\\Pickle_Level1_Summary\\Pickle_Level1_Summary.pickle"
        )

        #Radius is the size of the circle to be displayed on the map
        radiusList = []
        for i in range(0, len(level_1_df)):
            #Toggle size of circle
            radiusList.append(2)

        radius = radiusList
        selector = level_1_df[mapSelect]
        station = level_1_df['Station name']
        latitude = level_1_df['Site latitude']
        longitude = level_1_df['Site longitude']
        moduleTemp = level_1_df[mapSelect]
        uniqueID = level_1_df['Site Identifier Code']
        dataSource = level_1_df['Data Source']
        elevation = level_1_df['Site elevation (meters)'].astype(float)

        # The Boken map rendering package needs to store data in the ColumnDataFormat
        # Store the lat/lon from the Map_pickle.  Formatting for Lat/Lon has been
        # processed prior see "Map_Pickle_Processing.py" file for more details
        # Add other data to create hover labels
        source = ColumnDataSource(data=dict(Lat=latitude,
                                            Lon=longitude,
                                            radius=radius,
                                            selector=selector,
                                            Station=station,
                                            Latitude=latitude,
                                            Longitude=longitude,
                                            Module_Temp=moduleTemp,
                                            uniqueID=uniqueID,
                                            elevation=elevation,
                                            dataSource=dataSource))

        p = bkp.figure(width=1500,
                       height=900,
                       tools=tools,
                       title=title,
                       x_axis_type="mercator",
                       y_axis_type="mercator",
                       x_axis_label='Longitude',
                       y_axis_label='Latitude')

        p.x_range = bkm.Range1d(start=-180, end=180)
        p.y_range = bkm.Range1d(start=-90, end=90)

        #Create the datapoints as overlapping circles
        p.circle(
            "Lon",
            "Lat",
            source=source,
            radius="radius",
            #fill color will use linear_cmap() to scale the colors of the circles being displayed
            fill_color=linear_cmap('selector',
                                   colorSelector,
                                   low=scaleMin,
                                   high=scaleMax),
            line_color=None,
            # Alpha is the transparency of the circle
            alpha=0.3)
        #Stations will be the black dots displayed on the map
        stations = p.circle(
            "Lon",
            "Lat",
            source=source,
            radius=.1,
            #fill color will use linear_cmap() to scale the colors of the circles being displayed
            fill_color='black',
            line_color=None,
            # Alpha is the transparency of the circle
            alpha=.99)
        #Create the scale bar to the right of the map
        # Create color mapper to make the scale bar on the right of the map
        # palette = color scheme of the mapo
        # low/high sets the scale of the data, use the minimum value and maximum value of the data we are analyzing
        color_mapper = LinearColorMapper(palette=colorSelector,
                                         low=scaleMin,
                                         high=scaleMax)

        # color bar will be scale bar set to the right of the map
        color_bar = ColorBar(color_mapper=color_mapper,
                             ticker=LogTicker(),
                             label_standoff=12,
                             border_line_color=None,
                             location=(0, 0))
        # Assign the scale bar to " p " and put it to the right
        p.add_layout(color_bar, 'right')
        # These are the labels that are displayed when you hover over a spot on the map
        #( label , @data), data needs to be inside the ColumnDataSource()
        TOOLTIPS = [("Station", "@Station"), ("Site ID", "@uniqueID"),
                    ("Data Source", "@dataSource"), ("Lat", "@Latitude"),
                    ("Lon", "@Longitude"),
                    (htmlString, "@selector" + " " + metric),
                    ("Elevation", "@elevation" + " (m)")]
        #Create a hover tool that will rinder only the weather stations i.e stations are small black circles
        hover_labels = bkm.HoverTool(renderers=[stations], tooltips=TOOLTIPS)
        #Add the hover tool to the map
        p.add_tools(hover_labels)
        #Overlay the Country and States boarders
        p.patches("xs",
                  "ys",
                  color="white",
                  line_color="black",
                  source=countries,
                  fill_alpha=0,
                  line_alpha=1)
        p.patches("xs",
                  "ys",
                  color="white",
                  line_color="black",
                  source=states,
                  fill_alpha=0,
                  line_alpha=1)
        #Display the plot
        show(p)
Ejemplo n.º 13
0
def make_temp_graph(output_file: str, temp_data: typ.List, co2_data: typ.List,
                    bme280_data: typ.List) -> None:
    """グラフ作成.

    Args:
        output_file: 出力ファイル名
        temp_data: 温度データ
        co2_data: CO2データ
        bme280_data: BME280のデータ
    """
    tooltips: typ.List[typ.Tuple[str, str]] = [
        ("time", "@time{%F %T}"),
    ]
    df: pd.DataFrame
    deg_max: int = 0
    num_data: int = 0
    y_axis_label: str = "温度[℃]"
    if len(temp_data) > 0:
        num_data += 1
    if len(co2_data) > 0:
        num_data += 1
    if len(bme280_data) > 0:
        num_data += 1
    if len(temp_data) > 0:
        df1: pd.DataFrame = pd.DataFrame(temp_data,
                                         columns=list(temp_data[0].keys()))
        df1 = df1.rename(columns={"created_at": "time"})
        if num_data > 1:
            df1["time"] = df1["time"].apply(
                lambda x: x.replace(second=0, microsecond=0))
        df1["temp"] /= 1000
        df1 = df1[["time", "temp"]].drop_duplicates(subset="time")
        df = df1
        tooltips.append(("CPU温度", "@temp{0.0}"))
        deg_max = int(df["temp"].max()) + 10
    if len(co2_data) > 0:
        df2: pd.DataFrame = pd.DataFrame(co2_data,
                                         columns=list(co2_data[0].keys()))
        df2 = df2.rename(columns={"temp": "temp2", "created_at": "time"})
        if num_data > 1:
            df2["time"] = df2["time"].apply(
                lambda x: x.replace(second=0, microsecond=0))
        df2 = df2[["time", "co2", "temp2"]].drop_duplicates(subset="time")
        if len(temp_data) > 0:
            df = pd.merge(df1, df2, on="time", how="outer").sort_values("time")
        else:
            df = df2
        if len(bme280_data) == 0:
            tooltips.append(("気温", "@temp2"))
        tooltips.append(("CO₂", "@co2"))
        deg_max = max(deg_max, int(df["temp2"].max()) + 10)
    if len(bme280_data) > 0:
        df3: pd.DataFrame = pd.DataFrame(bme280_data,
                                         columns=list(bme280_data[0].keys()))
        df3 = df3.rename(columns={"temp": "temp3", "created_at": "time"})
        if num_data > 1:
            df3["time"] = df3["time"].apply(
                lambda x: x.replace(second=0, microsecond=0))
        df3 = df3[["time", "temp3", "pressure",
                   "humidity"]].drop_duplicates(subset="time")
        if num_data > 1:
            df = pd.merge(df, df3, on="time", how="outer").sort_values("time")
        else:
            df = df3
        tooltips.append(("気温", "@temp3{0.0}"))
        tooltips.append(("湿度", "@humidity{0.0}"))
        tooltips.append(("気圧", "@pressure{0,0.0}"))
        deg_max = max(deg_max,
                      int(df["temp3"].max()) + 10,
                      int(df["humidity"].max()) + 10)
        y_axis_label += "/湿度[%]"

    source: bp.ColumnDataSource = bp.ColumnDataSource(df)
    hover_tool: bm.HoverTool = bm.HoverTool(tooltips=tooltips,
                                            formatters={"@time": "datetime"})

    bp.output_file(output_file, title="Temperature")
    fig: bp.figure = bp.figure(
        title="Temperature",
        x_axis_type="datetime",
        x_axis_label="時刻",
        y_axis_label=y_axis_label,
        sizing_mode="stretch_both",
    )
    fig.add_tools(hover_tool)
    fmt: typ.List[str] = ["%H:%M"]
    fig.xaxis.formatter = bm.DatetimeTickFormatter(hours=fmt,
                                                   hourmin=fmt,
                                                   minutes=fmt)
    fig.y_range = bm.Range1d(0, deg_max)
    if len(temp_data) > 0:
        fig.line("time",
                 "temp",
                 legend_label="CPU温度",
                 line_color="red",
                 source=source)
    if len(co2_data) > 0:
        if len(bme280_data) == 0:
            fig.line("time",
                     "temp2",
                     legend_label="気温",
                     line_color="darkorange",
                     source=source)
        fig.extra_y_ranges["ppm"] = bm.Range1d(
            0, max(2000, df["co2"].max() * 1.05))
        fig.add_layout(bm.LinearAxis(y_range_name="ppm", axis_label="濃度[ppm]"),
                       "right")
        fig.line("time",
                 "co2",
                 legend_label="CO₂",
                 line_color="green",
                 y_range_name="ppm",
                 source=source)
    if len(bme280_data) > 0:
        fig.line("time",
                 "temp3",
                 legend_label="気温",
                 line_color="darkorange",
                 source=source)
        fig.line("time",
                 "humidity",
                 legend_label="湿度",
                 line_color="blue",
                 source=source)
        fig.extra_y_ranges["pressure"] = bm.Range1d(
            min(990, df["pressure"].min()), max(1020, df["pressure"].max()))
        fig.add_layout(
            bm.LinearAxis(y_range_name="pressure", axis_label="気圧[hPa]"),
            "right")
        fig.line("time",
                 "pressure",
                 legend_label="気圧",
                 line_color="deeppink",
                 y_range_name="pressure",
                 source=source)

    fig.legend.click_policy = "hide"
    fig.legend.location = "top_left"

    bp.save(fig)
Ejemplo n.º 14
0
    def set_axes_ranges(self, ir, ic, ranges):
        """
        Set the axes ranges

        Args:
            ir (int): subplot row index
            ic (int): subplot col index
            limits (dict): min/max axes limits for each axis

        """

        if self.plot_func == 'plot_heatmap':
            return

        # X-axis
        if self.axes.share_x:
            xvals = ['xmin', 'xmax', 'x2min', 'x2max']
            for xval in xvals:
                xx = None
                for irow in range(0, self.nrow):
                    for icol in range(0, self.ncol):
                        if ranges[irow, icol][xval] is not None:
                            if irow == 0 and icol == 0:
                                xx = ranges[irow, icol][xval]
                            elif 'min' in xval:
                                xx = min(xx, ranges[irow, icol][xval])
                            else:
                                xx = max(xx, ranges[irow, icol][xval])

                if xx is not None and xval == 'xmin':
                    self.axes.obj[ir, ic].x_range = bm.Range1d(start=xx)
                elif xx is not None and xval == 'x2min':
                    self.axes2.obj[ir, ic].x_range = bm.Range1d(start=xx)
                elif xx is not None and xval == 'xmax':
                    self.axes.obj[ir, ic].x_range = bm.Range1d(end=xx)
                elif xx is not None and xval == 'x2max':
                    self.axes2.obj[ir, ic].x_range = bm.Range1d(end=xx)
        else:
            if ranges[ir, ic]['xmin'] is not None:
                self.axes.obj[ir, ic].x_range = bm.Range1d(
                    start=ranges[ir, ic]['xmin'])
            if ranges[ir, ic]['x2min'] is not None:
                self.axes2.obj[ir, ic].x_range = bm.Range1d(
                    start=ranges[ir, ic]['x2min'])
            if ranges[ir, ic]['xmax'] is not None:
                self.axes.obj[ir,
                              ic].x_range = bm.Range1d(end=ranges[ir,
                                                                  ic]['xmax'])
            if ranges[ir, ic]['x2max'] is not None:
                self.axes2.obj[ir, ic].x_range = bm.Range1d(
                    end=ranges[ir, ic]['x2max'])

        # Y-axis
        if self.axes.share_y:
            yvals = ['ymin', 'ymax', 'y2min', 'y2max']
            for yval in yvals:
                yy = None
                for irow in range(0, self.nrow):
                    for icol in range(0, self.ncol):
                        if ranges[irow, icol][yval] is not None:
                            if irow == 0 and icol == 0:
                                yy = ranges[irow, icol][yval]
                            elif 'min' in yval:
                                yy = min(yy, ranges[irow, icol][yval])
                            else:
                                yy = max(yy, ranges[irow, icol][yval])

                if yy is not None and yval == 'ymin':
                    self.axes.obj[ir, ic].y_range = bm.Range1d(start=yy)
                elif yy is not None and yval == 'y2min':
                    self.axes2.obj[ir, ic].y_range = bm.Range1d(start=yy)
                elif yy is not None and yval == 'ymax':
                    self.axes.obj[ir, ic].y_range = bm.Range1d(end=yy)
                elif yy is not None and yval == 'y2max':
                    self.axes2.obj[ir, ic].y_range = bm.Range1d(end=yy)
        else:
            if ranges[ir, ic]['ymin'] is not None:
                self.axes.obj[ir, ic].y_range = bm.Range1d(
                    start=ranges[ir, ic]['ymin'])
            if ranges[ir, ic]['y2min'] is not None:
                self.axes2.obj[ir, ic].y_range = bm.Range1d(
                    start=ranges[ir, ic]['y2min'])
            if ranges[ir, ic]['ymax'] is not None:
                self.axes.obj[ir,
                              ic].y_range = bm.Range1d(end=ranges[ir,
                                                                  ic]['ymax'])
            if ranges[ir, ic]['y2max'] is not None:
                self.axes2.obj[ir, ic].y_range = bm.Range1d(
                    end=ranges[ir, ic]['y2max'])
Ejemplo n.º 15
0
    def GENE(self):
        def gcw(*args, **kwargs):
            return self.ccwidget('geneview_' + args[0],
                                 *args[1:],
                                 **kwargs,
                                 setnamer='gene')

        #widgets
        w = dict(
            gene=gcw('gene_name', 'text'),
            warn=widgets.HTML(),
        )

        # data
        samples = self.counttable.columns
        nosamples = len(samples)

        #gene mapper
        gmapper = CMAPPER(self, name='gene')
        gmapper.method = 'gene'
        defgene = self.counttable.std(1).sort_values().tail(1).index[0]
        gmapper.value = defgene
        w['gene'].value = defgene

        #color mapper
        cmapper = CMAPPER(self, name='color')
        cmapper.method = 'metadata'
        cmapper.value = 'plate'

        #sort order
        smapper = CMAPPER(self, name='sort')
        smapper2 = CMAPPER(self, name='sort 2')

        def get_sort_order():
            sdf = pd.DataFrame({
                1: smapper.score.sort_values(),
                2: smapper2.score.sort_values()
            })
            sdf = sdf.sort_values(by=[1, 2])
            return sdf.index

        sort_order = get_sort_order()

        pdata = ColumnDataSource(
            dict(
                x=pd.Series(range(nosamples), index=sort_order),
                y=gmapper.score.loc[sort_order],
                score=cmapper.score.loc[sort_order],
            ))

        pdata2 = pd.DataFrame(
            dict(
                x=pd.Series(range(nosamples), index=sort_order),
                y=gmapper.score.loc[sort_order],
                score=cmapper.score.loc[sort_order],
            ))

        bfigure = bokeh_figure(
            plot_width=FIGSIZE[0],
            plot_height=int(FIGSIZE[1] * 0.8),
            # tools = bokeh_tools,
            y_range=bmodels.Range1d(gmapper.min(), gmapper.max()),
            toolbar_sticky=False,
            toolbar_location='left',
            title='geneplot')

        #bbar = bokeh_chart.Bar(pdata2, 'x', values='y', group='plate')
        bfigure.title.text_color = 'darkgrey'
        bfigure.title.text_font_style = 'normal'
        bfigure.title.text_font_size = "12px"
        bplot = bfigure.vbar(x='x',
                             width=0.5,
                             bottom=0,
                             top='y',
                             source=pdata,
                             legend='score',
                             color=dict(field='score',
                                        transform=cmapper.colormapper))

        blegend = bfigure.legend[0].items[0]
        bcolorbar = ColorBar(color_mapper=gmapper.colormapper,
                             ticker=BasicTicker(),
                             formatter=BasicTickFormatter(precision=1),
                             label_standoff=10,
                             border_line_color=None,
                             location=(0, 0))

        null_colorbar_mapper = LinearColorMapper(palette='Inferno256',
                                                 low=0,
                                                 high=0)

        if cmapper.discrete:
            #remove ColorBar
            bcolorbar.color_mapper = null_colorbar_mapper
        else:
            #remove legend
            bfigure.legend[0].items.pop(
            )  #remove legend - we can add this later again

        bfigure.add_layout(bcolorbar, 'right')

        # # display widgets
        display(ilabel('gene', w['gene']))
        cmapper.display()
        smapper.display()
        smapper2.display()
        display(w['warn'])
        #for k, v in bplot.data_source.data.items():
        #        print(k, v.shape, v.dropna().shape)
        bhandle = bokeh_io.show(bfigure, notebook_handle=True)

        #bhandle = bokeh_io.show(bbar, notebook_handle=True)

        def warn(message):
            w['warn'].value = '<b>{}</b>'.format(message)

        def on_gene_change(*args):
            gene = w['gene'].value
            if not gene in self.counttable.index:
                warn("gene {} is not in current counttable".format(gene))
                return

            sortorder = get_sort_order()
            gmapper.value = gene

            yval = gmapper.score.loc[sortorder]
            bplot.data_source.data['y'] = yval
            bokeh_io.push_notebook(handle=bhandle)

        def on_sort_change(*args):
            order = get_sort_order()
            d = bplot.data_source.data
            d['x'].index = order
            d['y'] = d['y'].loc[order]
            d['score'] = d['score'].loc[order]
            bokeh_io.push_notebook(handle=bhandle)

        def on_color_change(*args):
            order = get_sort_order()
            score = cmapper.score
            score = score.loc[order]
            bplot.data_source.data['score'] = score
            bplot.glyph.fill_color['transform'] = cmapper.colormapper
            cm = cmapper.colormapper
            self._cm = cm

            if cmapper.discrete:
                warn('discrete')
                bcolorbar.color_mapper = null_colorbar_mapper
                if not bfigure.legend[0].items:
                    bfigure.legend[0].items.append(blegend)
            else:
                warn('cont')
                bcolorbar.color_mapper = cmapper.colormapper
                if bfigure.legend[0].items:
                    bfigure.legend[0].items.pop()

            bokeh_io.push_notebook(handle=bhandle)

        smapper.on_change = on_sort_change
        smapper2.on_change = on_sort_change
        cmapper.on_change = on_color_change
        w['gene'].on_submit(on_gene_change)
        on_gene_change
        on_color_change
        on_sort_change
Ejemplo n.º 16
0
def set_range(fig, xx, yy, delta=.1):
    deltax = delta * (max(xx) - min(xx))
    deltay = delta * (max(yy) - min(yy))
    fig.x_range = models.Range1d(min(xx) - deltax, max(xx) + deltax)
    fig.y_range = models.Range1d(min(yy) - deltay, max(yy) + deltay)
Ejemplo n.º 17
0
def botscore_hist(botscore_dict, data, use_cap=False):
    bins = {
        'user_english': {},
        'tweet_english': {},
        'user_universal': {},
        'tweet_universal': {}
    }
    max_bin, score_type, score_mult = (101, 'cap',
                                       100) if use_cap else (51, 'scores', 10)
    for key in bins:
        bins[key] = {start: 0 for start in range(0, max_bin)}
    grouped_tweets = pd.concat(
        [datum.df
         for datum in data]).groupby('UserId').size().to_frame('tweet_count')
    for user_id, scores in botscore_dict.items():
        if user_id not in grouped_tweets.index:
            continue
        score_bin_english = int(scores[score_type]['english'] * score_mult)
        score_bin_universal = int(scores[score_type]['universal'] * score_mult)
        bins['user_english'][score_bin_english] += 1
        bins['user_universal'][score_bin_universal] += 1
        user_tweet_count = grouped_tweets.loc[user_id].tweet_count
        bins['tweet_english'][score_bin_english] -= user_tweet_count
        bins['tweet_universal'][score_bin_universal] -= user_tweet_count

    # Plot bins
    extra_y_start = min(
        it.chain(bins['tweet_english'].values(),
                 bins['tweet_universal'].values())) - 1000
    extra_y_end = max(
        it.chain(bins['user_english'].values(),
                 bins['user_universal'].values())) + 5000
    fig_english = bplt.figure(plot_width=500,
                              plot_height=500,
                              title='English Score Distr')
    fig_english.extra_y_ranges = {
        'tweets': bmodels.Range1d(start=extra_y_start, end=extra_y_end)
    }
    fig_english.add_layout(bmodels.LinearAxis(y_range_name='tweets'), 'right')
    fig_english.vbar(x=list(bins['user_english'].keys()),
                     width=0.95,
                     bottom=0,
                     top=list(bins['user_english'].values()),
                     legend='Users')
    fig_english.vbar(x=list(bins['tweet_english'].keys()),
                     width=0.95,
                     bottom=0,
                     top=list(bins['tweet_english'].values()),
                     y_range_name='tweets',
                     color='red',
                     legend='Tweets')

    fig_universal = bplt.figure(plot_width=500,
                                plot_height=500,
                                title='Universal Score Distr')
    fig_universal.extra_y_ranges = {
        'tweets': bmodels.Range1d(start=extra_y_start, end=extra_y_end)
    }
    fig_universal.add_layout(bmodels.LinearAxis(y_range_name='tweets'),
                             'right')
    fig_universal.vbar(x=list(bins['user_universal'].keys()),
                       width=0.95,
                       bottom=0,
                       top=list(bins['user_universal'].values()),
                       legend='Users')
    fig_universal.vbar(x=list(bins['tweet_universal'].keys()),
                       width=0.95,
                       bottom=0,
                       top=list(bins['tweet_universal'].values()),
                       y_range_name='tweets',
                       color='red',
                       legend='Tweets')
    bplt.show(blayouts.row(fig_english, fig_universal))
Ejemplo n.º 18
0
def make_power_graph(output_file: str, data: typ.List, window: int) -> None:
    """グラフ作成.

    Args:
        output_file: 出力ファイル名
        data: データ
        window: 移動平均のサンプル数
    """
    cols: typ.Tuple = ("time", "電力量", "電力", "電流R", "電流T", "MA電力", "MA電流R",
                       "MA電流T")
    datadict: typ.Dict = {}
    for col in cols:
        datadict[col] = []
    has_data: bool = len(data) > 0
    for row in data:
        datadict["time"].append(row["created_at"])
        datadict["電力量"].append(calc_電力量(row))
        datadict["電力"].append(row["瞬時電力"])
        datadict["電流R"].append(row["瞬時電流_r"] / 10.0)
        datadict["電流T"].append(row["瞬時電流_t"] / 10.0)
        datadict["MA電力"].append(statistics.mean(datadict["電力"][-window:]))
        datadict["MA電流T"].append(statistics.mean(datadict["電流T"][-window:]))
        datadict["MA電流R"].append(statistics.mean(datadict["電流R"][-window:]))

    source: bp.ColumnDataSource = bp.ColumnDataSource(datadict)
    tooltips: typ.List[typ.Tuple[str, str]] = [
        ("time", "@time{%F %T}"),
        ("積算電力量", "@{電力量}{0,0.0}"),
        ("瞬時電力", "@{電力}{0,0}"),
        ("瞬時電流(R相)", "@{電流R}{0,0.0}"),
        ("瞬時電流(T相)", "@{電流T}{0,0.0}"),
    ]
    hover_tool: bm.HoverTool = bm.HoverTool(tooltips=tooltips,
                                            formatters={"@time": "datetime"})

    bp.output_file(output_file, title="Power consumption")
    fig: bp.figure = bp.figure(
        title="Power consumption",
        x_axis_type="datetime",
        x_axis_label="時刻",
        y_axis_label="電力量[kWh]",
        sizing_mode="stretch_both",
    )
    fig.add_tools(hover_tool)
    fmt: typ.List[str] = ["%H:%M"]
    fig.xaxis.formatter = bm.DatetimeTickFormatter(hours=fmt,
                                                   hourmin=fmt,
                                                   minutes=fmt)
    if has_data:
        電力量_min: float = min(datadict["電力量"])
        電力量_max: float = max(datadict["電力量"])
        電力量_5p: float = (電力量_max - 電力量_min) * 0.05
        fig.y_range = bm.Range1d(電力量_min - 電力量_5p, 電力量_max + 電力量_5p)
    fig.extra_y_ranges["W"] = bm.Range1d(
        0,
        max(datadict["電力"]) * 1.05 if has_data else 0)
    fig.add_layout(bm.LinearAxis(y_range_name="W", axis_label="電力[W]"), "left")
    fig.extra_y_ranges["A"] = bm.Range1d(
        0,
        max(*datadict["電流R"], *datadict["電流T"]) * 1.05 if has_data else 0)
    fig.add_layout(bm.LinearAxis(y_range_name="A", axis_label="電流[A]"),
                   "right")

    fig.line("time",
             "電力量",
             legend_label="積算電力量",
             line_color="red",
             source=source)

    raw_data: typ.List = [
        ("電力", "W", "瞬時電力", "orange"),
        ("電流R", "A", "瞬時電流(R相)", "blue"),
        ("電流T", "A", "瞬時電流(T相)", "green"),
    ]
    for col, range_name, legend_label, color in raw_data:
        fig.line(
            "time",
            col,
            y_range_name=range_name,
            legend_label=legend_label,
            line_color=color,
            line_alpha=0.8,
            source=source,
        ).visible = False

    ma_data: typ.List = [
        ("MA電力", "W", "瞬時電力(移動平均)", "orange"),
        ("MA電流R", "A", "瞬時電流(R相)(移動平均)", "blue"),
        ("MA電流T", "A", "瞬時電流(T相)(移動平均)", "green"),
    ]
    for col, range_name, legend_label, color in ma_data:
        fig.line(
            "time",
            col,
            y_range_name=range_name,
            legend_label=legend_label,
            line_color=color,
            line_width=2,
            line_alpha=0.8,
            line_dash="dotted",
            source=source,
        )

    fig.legend.click_policy = "hide"
    fig.legend.location = "top_left"

    bp.save(fig)
Ejemplo n.º 19
0
def outputMapDew(path, mapSelect):

    if mapSelect == 'dew_yield':
        moduleType = 'Sum of Yearly Dew(mmd-1)'
        htmlString = '_yearly_dew'
        colorSelector = "Viridis256"
        #Assign the upper and lower bounds of the map

    #Create the html to be exported
    output_file('Yearly_Dew_Yield_Map(mmd-1)' + htmlString + '.html')

    # Create the tools used for zooming and hovering on the map
    tools = "pan,wheel_zoom,box_zoom,reset,previewsave"

    #Access the .json file to create the map of countries and states
    # THe json files will create layers to overlap the data with
    with open(path + "/Map/countries.geojson", "r") as f:
        countries = bkm.GeoJSONDataSource(geojson=f.read())
    with open(path + "/Map/us-states.json", "r") as f:
        states = bkm.GeoJSONDataSource(geojson=f.read())

    #Access the processed summary data pickle
    level_1_df = pd.read_pickle(
        path + "\\Pandas_Pickle_DataFrames\\Pickle_Map\\Pickle_Map.pickle")

    # Bring in all the data to display on map

    #Radius is the size of the circle to be displayed on the map
    radiusList = []
    for i in range(0, len(level_1_df)):
        #Toggle size of circle
        radiusList.append(2)
    lat = level_1_df['N'].astype(float)  #Northing and easting if Needed
    lon = level_1_df['E'].astype(float)
    radius = radiusList
    dew = level_1_df[moduleType]
    station = level_1_df['Station name']
    latitude = level_1_df['Site latitude']
    longitude = level_1_df['Site longitude']
    moduleTemp = level_1_df[moduleType]
    uniqueID = level_1_df['Site Identifier Code']

    # The Boken map rendering package needs to store data in the ColumnDataFormat
    # Store the lat/lon from the Map_pickle.  Formatting for Lat/Lon has been
    # processed prior see "Map_Pickle_Processing.py" file for more details
    # Add other data to create hover labels
    source = ColumnDataSource(data=dict(Lat=latitude,
                                        Lon=longitude,
                                        radius=radius,
                                        dew=dew,
                                        Station=station,
                                        Latitude=latitude,
                                        Longitude=longitude,
                                        Module_Temp=moduleTemp,
                                        uniqueID=uniqueID))

    p = bkp.figure(width=1500,
                   height=900,
                   tools=tools,
                   title='IWEC, CWEC, and Average Dew Yield(mmd-1)',
                   x_axis_type="mercator",
                   y_axis_type="mercator",
                   x_axis_label='Longitude',
                   y_axis_label='Latitude')

    p.x_range = bkm.Range1d(start=-180, end=180)
    p.y_range = bkm.Range1d(start=-90, end=90)

    #Create the datapoints as overlapping circles
    p.circle(
        "Lon",
        "Lat",
        source=source,
        radius="radius",
        #fill color will use linear_cmap() to scale the colors of the circles being displayed
        fill_color=linear_cmap('dew', colorSelector, low=20, high=300),
        line_color=None,
        # Alpha is the transparency of the circle
        alpha=0.3)
    #Stations will be the black dots displayed on the map
    stations = p.circle(
        "Lon",
        "Lat",
        source=source,
        radius=.1,
        #fill color will use linear_cmap() to scale the colors of the circles being displayed
        fill_color='black',
        line_color=None,
        # Alpha is the transparency of the circle
        alpha=.99)

    #Create the scale bar to the right of the map

    # Create color mapper to make the scale bar on the right of the map
    # palette = color scheme of the mapo
    # low/high sets the scale of the data, use the minimum value and maximum value of the data we are analyzing
    color_mapper = LogColorMapper(palette=colorSelector, low=20, high=300)

    # color bar will be scale bar set to the right of the map
    color_bar = ColorBar(color_mapper=color_mapper,
                         ticker=LogTicker(),
                         label_standoff=12,
                         border_line_color=None,
                         location=(0, 0))
    # Assign the scale bar to " p " and put it to the right
    p.add_layout(color_bar, 'right')

    # These are the labels that are displayed when you hover over a spot on the map
    #( label , @data), data needs to be inside the ColumnDataSource()
    TOOLTIPS = [
        ("Station", "@Station"),
        ("Site ID", "@uniqueID"),
        ("Lat", "@Latitude"),
        ("Lon", "@Longitude"),
        ("Yearly_Dew_Yield", "@dew"),
    ]

    #Create a hover tool that will rinder only the weather stations i.e stations are small black circles
    hover_labels = bkm.HoverTool(renderers=[stations], tooltips=TOOLTIPS)
    #Add the hover tool to the map
    p.add_tools(hover_labels)
    #Overlay the Country and States boarders
    p.patches("xs",
              "ys",
              color="white",
              line_color="black",
              source=countries,
              fill_alpha=0,
              line_alpha=1)
    p.patches("xs",
              "ys",
              color="white",
              line_color="black",
              source=states,
              fill_alpha=0,
              line_alpha=1)
    #Display the plot
    show(p)
Ejemplo n.º 20
0
 def _initialize_limits(self, p):
     if self.xlim is not None:
         p.x_range = models.Range1d(self.xlim[0], self.xlim[-1])
     if self.ylim is not None:
         p.y_range = models.Range1d(self.ylim[0], self.ylim[-1])
Ejemplo n.º 21
0
def generate_plot(data, df_all_prediction):
    COLORS = d3["Category10"][10]

    tooltips = f"""
            <div>
                <p>
                    <span style="font-size: 12px; color: black;font-family:century gothic;">Nombre de cas : </span>
                    <span style="font-size: 12px; color: {COLORS[0]}; font-weight: bold;font-family:century gothic;">@total_cases</span>
                <br> 
                    <span style="font-size: 12px; color: black;font-family:century gothic;">Nombre de nouveaux cas : </span>
                    <span style="font-size: 12px; color: {COLORS[1]}; font-weight: bold;font-family:century gothic;">@new_cases</span>
                <br> 
                    <span style="font-size: 12px; color: black;font-family:century gothic;">Nombre de deces : </span>
                    <span style="font-size: 12px; color: {COLORS[3]}; font-weight: bold;font-family:century gothic;">@total_deaths</span>
                <br> 
                    <span style="font-size: 12px; color: black;font-family:century gothic;">Nombre nouveaux deces : </span>
                    <span style="font-size: 12px; color: {COLORS[5]}; font-weight: bold;font-family:century gothic;">@new_deaths</span>
                <br> 
                    <span style="font-size: 12px; color: black;font-family:century gothic;">Date : </span>
                    <span style="font-size: 12px; color: black; font-weight: bold;font-family:century gothic;">@date_str</span>
                </p>
            </div>
        """

    tooltips_predictions = (f"""
            <div>
                <p>
                    <span style="font-size: 12px; color: black;font-family:century gothic;">Prédiction nombre de cas : </span>
                    <span style="font-size: 12px; color: {COLORS[0]}; font-weight: bold;font-family:century gothic;">@median_display</span>
                <br> 
                    <span style="font-size: 12px; color: black;font-family:century gothic;">Date : </span>
                    <span style="font-size: 12px; color: black; font-weight: bold;font-family:century gothic;">"""
                            + """@date_str</span>
                </p>
            </div>
        """)

    hover = bkm.tools.HoverTool(names=["line_total"],
                                tooltips=tooltips,
                                mode="vline")

    hover_prediction = bkm.tools.HoverTool(
        names=["prediction"],
        tooltips=tooltips_predictions,
    )

    # --- define all DataSource needed --- #

    source_all = bkm.ColumnDataSource(data)
    country = "World"
    source = bkm.ColumnDataSource(get_country(data, country))

    source_all_prediction = bkm.ColumnDataSource(df_all_prediction)
    source_prediction = bkm.ColumnDataSource(
        get_country(df_all_prediction, country))

    date_end_training = np.unique(
        get_country(df_all_prediction, country)["date_end_train"])[-1]
    source_prediction_end_date = bkm.ColumnDataSource(
        get_country(df_all_prediction, country)[get_country(
            df_all_prediction, country).date_end_train == date_end_training])

    slider = bkm.Slider(
        start=0,
        end=len(
            np.unique(
                get_country(df_all_prediction, country)["date_end_train"])) -
        1,
        value=0,
        step=1,
        title="Days dropped for prediction",
    )

    # ----------- #

    p = bkp.figure(
        y_axis_type="linear",
        x_axis_type="datetime",
        sizing_mode="stretch_both",
        title=f"Covid 19 evolution: {country}",
        x_axis_label="date",
        y_axis_label="Total number of Covid 19 cases",
        tools=[hover, "pan", "wheel_zoom", "reset"],
        x_range=[
            get_country(data, country).date.min(),
            get_country(data, country).date.max() + datetime.timedelta(days=1),
        ],
        y_range=[
            -get_country(data, country).total_cases.max() * 0.05,
            get_country(data, country).total_cases.max() * 1.1,
        ],
    )
    p.yaxis.formatter = bkm.formatters.NumeralTickFormatter(format="0,0")
    p.xaxis.formatter = bkm.formatters.DatetimeTickFormatter(
        days=["%d/%m", "%d%a"], months=["%m/%Y", "%b %Y"])
    p.add_tools(hover_prediction)
    p.toolbar.active_drag = None

    # p.toolbar.active_scroll = p.select_one(bkm.WheelZoomTool)

    y_extra_range_max = np.max([
        np.max(get_country(data, country).new_cases.values),
        np.max(get_country(data, country).total_deaths.values),
    ])

    p.extra_y_ranges = {
        "Number of deaths":
        bkm.Range1d(start=-0.05 * y_extra_range_max,
                    end=1.1 * y_extra_range_max)
    }
    p.add_layout(
        bkm.LinearAxis(
            y_range_name="Number of deaths",
            axis_label="New Covid 19 cases",
            formatter=bkm.formatters.NumeralTickFormatter(format="0,0"),
        ),
        "right",
    )

    # --- plot total cases --- #

    p.line(
        source=source,
        x="date",
        y="total_cases",
        name="line_total",
        color=COLORS[0],
        legend_label="total cases",
        muted_alpha=0.1,
    )
    p.circle(source=source,
             x="date",
             y="total_cases",
             color=COLORS[0],
             muted_alpha=0.1)

    # --- plot new cases --- #

    p.vbar(
        source=source,
        x="date",
        top="new_cases",
        color=COLORS[1],
        width=50e6,
        alpha=0.5,
        name="bar",
        y_range_name="Number of deaths",
        legend_label="new cases",
        muted_alpha=0.1,
    )

    # --- plot total death --- #

    p.line(
        source=source,
        x="date",
        y="total_deaths",
        color=COLORS[3],
        y_range_name="Number of deaths",
        name="line_death",
        legend_label="total deaths",
        muted_alpha=0.1,
    )
    p.circle(
        source=source,
        x="date",
        y="total_deaths",
        color=COLORS[3],
        y_range_name="Number of deaths",
        muted_alpha=0.1,
    )

    # --- plot new death --- #

    p.vbar(
        source=source,
        x="date",
        top="new_deaths",
        color=COLORS[5],
        width=50e6,
        alpha=0.5,
        y_range_name="Number of deaths",
        legend_label="new deaths",
        muted_alpha=0.1,
    )

    button_click_count = bkm.ColumnDataSource({"clicks": [0]})

    select = bkm.Select(title="Country: ",
                        value=country,
                        options=list(data.location.unique()))
    button_log = bkm.Button(label="Log Scale", button_type="primary")

    # --- Predictions --- #

    median_prediction = p.line(
        source=source_prediction_end_date,
        x="date",
        y="median",
        line_color=COLORS[0],
        name="prediction",
    )
    prediction_cases_line = p.line(
        source=source_prediction_end_date,
        x="date",
        y="derivative",
        color=COLORS[1],
        y_range_name="Number of deaths",
    )

    band_low = bkm.Band(
        source=source_prediction_end_date,
        base="date",
        lower="25%",
        upper="median",
        fill_color=COLORS[0],
        level="underlay",
        fill_alpha=0.1,
        line_width=0.5,
        line_color="black",
    )

    band_high = bkm.Band(
        source=source_prediction_end_date,
        base="date",
        lower="median",
        upper="75%",
        fill_color=COLORS[0],
        level="underlay",
        fill_alpha=0.1,
        line_width=0.5,
        line_color="black",
    )

    median_prediction.visible = False
    prediction_cases_line.visible = False
    band_low.visible = False
    band_high.visible = False

    p.add_layout(band_low)
    p.add_layout(band_high)

    button_prediction = bkm.Button(label="Show predictions",
                                   button_type="primary")

    # -- Callback -- #

    callback = bkm.CustomJS(
        args=dict(
            source=source,
            source_all=source_all,
            select=select,
            x_range=p.x_range,
            y_range_left=p.y_range,
            y_range_right=p.extra_y_ranges["Number of deaths"],
            title=p.title,
            button_click_count=button_click_count,
            slider=slider,
            source_all_prediction=source_all_prediction,
            source_prediction=source_prediction,
            source_prediction_end_date=source_prediction_end_date,
            median_prediction=median_prediction,
            band_low=band_low,
            prediction_cases_line=prediction_cases_line,
            band_high=band_high,
        ),
        code="""
        var country = select.value
    
        var date = source_all.data['date']
        var date_str = source_all.data['date_str']
        var location = source_all.data['location']
        var total_cases = source_all.data['total_cases']
        var new_cases = source_all.data['new_cases']
        var total_deaths = source_all.data['total_deaths']
        var new_deaths = source_all.data['new_deaths']
    
    
        var new_date = []
        var new_date_str = []
        var new_total_cases = []
        var new_new_cases = []
        var new_total_deaths = []
        var new_new_deaths = []
    
    
        for(var i=0; i < date.length; i++){
            if(location[i]==country){
                new_date.push(date[i]);
                new_date_str.push(date_str[i])
                new_total_cases.push(total_cases[i]);
                new_new_cases.push(new_cases[i]);
                new_total_deaths.push(total_deaths[i]);
                new_new_deaths.push(new_deaths[i]);
            }
        }
    
        source.data['date']=new_date;
        source.data['date_str']=new_date_str;
        source.data['total_cases']=new_total_cases;
        source.data['new_cases']=new_new_cases;
        source.data['total_deaths']=new_total_deaths;
        source.data['new_deaths']=new_new_deaths;
    
        const new_cases_no_Nan = new_new_cases.filter(function (value) {
            return !Number.isNaN(value);
        });
        const cases_no_Nan = new_total_cases.filter(function (value) {
            return !Number.isNaN(value);
        });
    
        y_range_right.setv({"start": -0.05*Math.max.apply(Math, new_cases_no_Nan.concat(new_total_deaths)), 
                            "end": 1.1*Math.max.apply(Math, new_cases_no_Nan.concat(new_total_deaths))})
    
        y_range_left.setv({"start": -0.05*Math.max.apply(Math, cases_no_Nan), 
                           "end": 1.1*Math.max.apply(Math, cases_no_Nan)})
    
        x_range.setv({"start": Math.min.apply(Math, new_date), "end": 1.0001*Math.max.apply(Math, new_date)})
    
        title.text = "Evolution du nombre de cas en " + country
    
        source.change.emit();
    
    
        // change value of predictions
    
        button_click_count.data.clicks = 0
    
        median_prediction.visible = false
        band_low.visible = false
        band_high.visible = false
        prediction_cases_line.visble = false
    
        var date_end_prediction = source_all_prediction.data['date_end_train']
    
        var location = source_all_prediction.data['location']
        var date = source_all_prediction.data['date']
        var date_str = source_all_prediction.data['date_str']
        var quantile_1 = source_all_prediction.data['25%']
        var quantile_2 = source_all_prediction.data['median']
        var quantile_3 = source_all_prediction.data['75%']
        var new_cases = source_all_prediction.data['derivative']
        var median_prediction = source_all_prediction.data['median_display']
    
        var new_date = []
        var new_date_str = []
        var new_date_end_prediction = []
        var new_quantile_1 = []
        var new_quantile_2 = []
        var new_quantile_3 = []
        var new_new_cases = []
        var new_median_prediction = []
    
        for(var i=0; i < quantile_1.length; i++){
            if(location[i]==country){
                new_date.push(date[i])
                new_date_str.push(date_str[i])
                new_date_end_prediction.push(date_end_prediction[i])
                new_quantile_1.push(quantile_1[i]);
                new_quantile_2.push(quantile_2[i]);
                new_quantile_3.push(quantile_3[i]);
                new_new_cases.push(new_cases[i]);
                new_median_prediction.push(median_prediction[i]);
            }
        }   
        source_prediction.data['date']=new_date
        source_prediction.data['date_str']=new_date_str
        source_prediction.data['date_end_train']=new_date_end_prediction
        source_prediction.data['25%']=new_quantile_1;
        source_prediction.data['median']=new_quantile_2;
        source_prediction.data['75%']=new_quantile_3;
        source_prediction.data['derivative']=new_new_cases;
        source_prediction.data['median_display']=new_median_prediction;
    
    
        var n = new_date.length
        var max_date = Math.max.apply(Math, new_date_end_prediction)
    
        var new_date_bis = []
        var new_date_str_bis = []
        var new_date_end_prediction_bis = []
        var new_quantile_1_bis = []
        var new_quantile_2_bis = []
        var new_quantile_3_bis = []
        var new_new_cases_bis = []
        var new_median_prediction_bis = []
    
        for(var i=0; i < n; i++){
            if(new_date_end_prediction[i]==max_date){
                new_date_bis.push(new_date[i])
                new_date_str_bis.push(new_date_str[i])
                new_date_end_prediction_bis.push(new_date_end_prediction[i])
                new_quantile_1_bis.push(new_quantile_1[i]);
                new_quantile_2_bis.push(new_quantile_2[i]);
                new_quantile_3_bis.push(new_quantile_3[i]);
                new_new_cases_bis.push(new_new_cases[i]);
                new_median_prediction_bis.push(new_median_prediction[i]);
            }
        }
    
        var n = new_date_bis.length
        var max_date = Math.max.apply(Math, new_date_end_prediction_bis)
    
        source_prediction_end_date.data['date']=new_date_bis
        source_prediction_end_date.data['date_str']=new_date_str_bis
        source_prediction_end_date.data['date_end_train']=new_date_end_prediction_bis
        source_prediction_end_date.data['25%']=new_quantile_1_bis;
        source_prediction_end_date.data['median']=new_quantile_2_bis;
        source_prediction_end_date.data['75%']=new_quantile_3_bis;
        source_prediction_end_date.data['derivative']=new_new_cases_bis;
        source_prediction_end_date.data['median_display']=new_median_prediction_bis;
    
        source_prediction.change.emit();
        source_prediction_end_date.change.emit()
    
    
    
        const unique = (value, index, self) => {
                   return self.indexOf(value) === index
               }
    
        // change slider value
    
        slider.setv({"end": new_date_end_prediction.filter(unique).length - 1, "value": 0})
    
        """,
    )

    callback_button = bkm.CustomJS(
        args=dict(y_axis=p.left, title=p.title),
        code="""
        console.log(y_axis)
        y_axis = LogAxis()
    """,
    )

    select.js_on_change("value", callback)
    button_log.js_on_click(callback_button)

    callback_button = bkm.CustomJS(
        args=dict(
            source=source,
            source_prediction=source_prediction,
            source_all_prediction=source_all_prediction,
            source_prediction_end_date=source_prediction_end_date,
            select=select,
            button_prediction=button_prediction,
            median_prediction=median_prediction,
            band_low=band_low,
            prediction_cases_line=prediction_cases_line,
            band_high=band_high,
            button_click_count=button_click_count,
            x_range=p.x_range,
            y_range_left=p.y_range,
            y_range_right=p.extra_y_ranges["Number of deaths"],
        ),
        code="""
           // function to get unique value of an array
           const unique = (value, index, self) => {
               return self.indexOf(value) === index
           }

           var date = source.data['date'];
           var total_cases = source.data['total_cases'];
           var new_cases = source.data['new_cases'];
           var total_deaths = source.data['total_deaths'];

           var date_prediction = source_prediction.data['date'];
           var total_cases_prediction = source_prediction.data['75%'];

           const new_cases_no_Nan = new_cases.filter(function (value) {
               return !Number.isNaN(value);
           });
           const cases_no_Nan = total_cases.filter(function (value) {
               return !Number.isNaN(value);
           });

           var country = select.value
           button_click_count.data.clicks ++
           var show_prediction = (button_click_count.data.clicks % 2) == 1

           var locations_predicted = source_all_prediction.data['location'].filter(unique)

           if (locations_predicted.includes(country) == false){
               window.alert("This country doesn't have prediction: Available countries are: " + locations_predicted);
           }
           else{
               if (show_prediction == true){
                   median_prediction.visible = true
                   band_low.visible = true
                   band_high.visible = true
                   prediction_cases_line.visble = true
                   const y_range_right_values = [].concat([].slice.call(new_cases_no_Nan), [].slice.call(total_deaths))

                   y_range_left.setv({"start": -0.05*Math.max.apply(Math, total_cases_prediction), "end": 1.1 * Math.max.apply(Math, total_cases_prediction)})
                   y_range_right.setv({"start": -0.05*Math.max.apply(Math, y_range_right_values) * Math.max.apply(Math, total_cases_prediction) / Math.max.apply(Math, cases_no_Nan),
                                       "end": 1.1*Math.max.apply(Math, y_range_right_values) * Math.max.apply(Math, total_cases_prediction) / Math.max.apply(Math, cases_no_Nan)})

                   x_range.setv({"start": Math.min.apply(Math, date_prediction), "end": 1.0001*Math.max.apply(Math, date_prediction)})
               }
               else{
                   median_prediction.visible = false
                   band_low.visible = false
                   band_high.visible = false
                   prediction_cases_line.visble = false
                   const y_range_right_values = [].concat([].slice.call(new_cases_no_Nan), [].slice.call(total_deaths))

                   y_range_left.setv({"start": -0.05*Math.max.apply(Math, cases_no_Nan), "end": 1.1*Math.max.apply(Math, cases_no_Nan)})
                   y_range_right.setv({"start": -0.05*Math.max.apply(Math, y_range_right_values), "end": 1.1*Math.max.apply(Math, y_range_right_values)})
                   x_range.setv({"start": Math.min.apply(Math, date), "end": 1.0001*Math.max.apply(Math, date)})

               }
           }


           """,
    )

    button_prediction.js_on_click(callback_button)

    callback_slider = bkm.CustomJS(
        args=dict(
            source=source,
            source_prediction=source_prediction,
            source_all_prediction=source_all_prediction,
            source_prediction_end_date=source_prediction_end_date,
            select=select,
            prediction_cases_line=prediction_cases_line,
            slider=slider,
            button_click_count=button_click_count,
            x_range=p.x_range,
            y_range_left=p.y_range,
            y_range_right=p.extra_y_ranges["Number of deaths"],
        ),
        code="""

                           // function to get unique value of an array
                           const unique = (value, index, self) => {
                               return self.indexOf(value) === index
                           }

                           var slider_value = slider.value
                           var country = select.value

                           var date_prediction = source_prediction.data['date']
                           var date_str = source_prediction.data['date_str']
                           var date_end_prediction = source_prediction.data['date_end_train']
                           var quantile_1 = source_prediction.data['25%'];
                           var quantile_2 = source_prediction.data['median']
                           var quantile_3 = source_prediction.data['75%']
                           var new_cases = source_prediction.data['derivative'];
                           var median_prediction = source_prediction.data['median_display']

                           var unique_end_prediction = date_end_prediction.filter(unique)

                           var show_prediction = (button_click_count.data.clicks % 2) == 1
                           var locations_predicted = source_all_prediction.data['location'].filter(unique)

                           if (show_prediction == true && locations_predicted.includes(country)){
                                var new_date_prediction = []
                                var new_date_str = []
                                var new_date_end_prediction = []
                                var new_quantile_1 = []
                                var new_quantile_2 = []
                                var new_quantile_3 = []
                                var new_new_cases = []
                                var new_median_prediction = []

                                for(var i=0; i < quantile_1.length; i++){
                                    if(date_end_prediction[i]==unique_end_prediction[slider.end - slider_value]){
                                        new_date_prediction.push(date_prediction[i])
                                        new_date_str.push(date_str[i])
                                        new_date_end_prediction.push(date_end_prediction[i])
                                        new_quantile_1.push(quantile_1[i]);
                                        new_quantile_2.push(quantile_2[i]);
                                        new_quantile_3.push(quantile_3[i]);
                                        new_new_cases.push(new_cases[i]);
                                        new_median_prediction.push(median_prediction[i]);
                                    }
                                }   


                                source_prediction_end_date.data['date']=new_date_prediction
                                source_prediction_end_date.data['date_str']=new_date_str
                                source_prediction_end_date.data['date_end_train']=new_date_end_prediction
                                source_prediction_end_date.data['25%']=new_quantile_1;
                                source_prediction_end_date.data['median']=new_quantile_2;
                                source_prediction_end_date.data['75%']=new_quantile_3;
                                source_prediction_end_date.data['derivative']=new_new_cases;
                                source_prediction_end_date.data['median_display']=new_median_prediction;

                                source_prediction_end_date.change.emit();

                                var date_prediction = source_prediction_end_date.data['date'];
                                var total_cases_prediction = source_prediction_end_date.data['75%'];

                                const new_cases_no_Nan = new_cases.filter(function (value) {
                                    return !Number.isNaN(value);
                                 });
                                const cases_no_Nan = quantile_2.filter(function (value) {
                                   return !Number.isNaN(value);
                                 });


                                // y_range_left.setv({"start": -0.05*Math.max.apply(Math, total_cases_prediction), "end": 1.1*Math.max.apply(Math, total_cases_prediction)})
                                // x_range.setv({"start": Math.min.apply(Math, date_prediction), "end": 1.0001*Math.max.apply(Math, date_prediction)})

                           }

                                   """,
    )

    slider.js_on_change("value", callback_slider)

    p.legend.location = "top_left"
    p.legend.click_policy = "mute"

    return select, button_prediction, slider, p
Ejemplo n.º 22
0
    def __init__(self):
        try:
            self.api_key = keys.GOOGLE_API_KEY
        except NameError:
            self.api_key = None
        self.data = None
        self.data_url = ('https://timothyhelton.github.io/assets/data/'
                         'nyc_subway_locations.csv')
        self.data_types = {
            'division': str,
            'line': str,
            'name': str,
            'latitude': np.float64,
            'longitude': np.float64,
            'route_1': str,
            'route_2': str,
            'route_3': str,
            'route_4': str,
            'route_5': str,
            'route_6': str,
            'route_7': str,
            'route_8': str,
            'route_9': str,
            'route_10': str,
            'route_11': str,
            'entrance_type': str,
            'entry': str,
            'exit_only': str,
            'vending': str,
            'staffing': str,
            'staff_hours': str,
            'ada': str,
            'ada_notes': str,
            'free_crossover': str,
            'north_south_street': str,
            'east_west_street': str,
            'corner': str,
            'entrance_latitude': np.float64,
            'entrance_longitude': np.float64,
            'station_location': str,
            'entrance_location': str,
        }
        self.hosp = locations.Hospitals()
        self.hosp_dist = None
        self.hosp_prox = None
        self.hosp_stations = None

        self.map_glyph_hospital = bkm.Circle(
            x='longitude',
            y='latitude',
            fill_alpha=0.8,
            fill_color='#cd5b1b',
            line_color=None,
            size=14,
        )
        self.map_glyph_subway = bkm.Diamond(
            x='longitude',
            y='latitude',
            fill_color='#3062C8',
            line_color=None,
            size=10,
        )
        self.map_options = {
            'lat': 40.70,
            'lng': -73.92,
            'map_type': 'roadmap',
            'zoom': 10,
        }
        self.map_plot = bkm.GMapPlot(
            api_key=self.api_key,
            x_range=bkm.Range1d(),
            y_range=bkm.Range1d(),
            map_options=bkm.GMapOptions(**self.map_options),
            plot_width=400,
            plot_height=600,
        )
        self.trains = None
        self.load_data()
Ejemplo n.º 23
0
def print_html():
    conso_elec, weather_stat = run()

    conso_elec['date_c'] = pd.to_datetime(conso_elec.date)
    conso_elec = conso_elec.sort_values(by='date_c')
    conso_elec = conso_elec.reset_index(drop=True)
    weather_stat['Dato'] = pd.to_datetime(weather_stat.Dato, format='%Y-%m-%d')

    if any(conso_elec.conso.diff() < 0):
        l = (conso_elec.conso.diff() < 0)
        ind = [i for i, l in enumerate(l)
               if l]  # Give the index of the error line
        d = conso_elec.date[ind]
        print(
            "Your database contains an error, please check the values arround {d}"
            .format(d=d))

    #Group by all conso in the same month, and take the last value to substract with previous month
    grp = conso_elec.groupby(
        [conso_elec.date_c.dt.year, conso_elec.date_c.dt.month])
    res = grp.last()
    res.conso = res.conso.diff()

    #Group all the initial values
    #Conso
    x = res.date_c
    y = res.conso
    #Weather from Yr.no
    x_data = weather_stat.Dato
    y_min = weather_stat.Min_T
    y_max = weather_stat.Maks_T
    y_mean = weather_stat.Middel_T
    y_normal = weather_stat.Normal_T

    p = figure(plot_width=800,
               plot_height=500,
               y_axis_label="Energy consumed in kWh/month",
               x_axis_type="datetime",
               tools="resize,save",
               toolbar_location="above",
               title="Electrical consumption at Inkognito, Oslo")

    #Add second axis
    p.extra_y_ranges = {
        "Temp": bkm.Range1d(start=min(y_min - 5), end=max(y_max + 5))
    }
    p.add_layout(bkm.LinearAxis(y_range_name="Temp"), 'right')

    #Source1 gets the conso values and print it with its hover method
    source1 = bkm.ColumnDataSource(
        data={
            "x": x,
            "y": y,
            "bill": y * elec_price,
            "CO2": y * m_CO2,
            "time_tooltip": res.date
        })
    g1 = bkm.VBar(x='x', top='y', width=1e9, bottom=0, fill_color='green')
    g1_r = p.add_glyph(source_or_glyph=source1, glyph=g1)
    g1_hover = bkm.HoverTool(renderers=[g1_r],
                             tooltips={
                                 "Conso": "@y kWh",
                                 "Bill": "±@bill{int} NOK",
                                 "CO2 prod.": "@CO2{int} Kg",
                                 "Date": "@time_tooltip"
                             })
    p.add_tools(g1_hover)

    #Creates a dictionnary with the weather data and ads a tooltip column for the date hover
    data = {
        "x_data": x_data,
        "y_min": y_min,
        "y_max": y_max,
        "y_mean": y_mean,
        "DJU": confort_T - y_mean
    }
    #Convert the date into a string to be read in the hover
    df = pd.DataFrame(data)
    df['tooltip'] = [x.strftime("%Y-%m-%d") for x in df['x_data']]
    #Source2 does the same as source1 with the temperatures
    source2 = bkm.ColumnDataSource(df)
    g2 = bkm.Line(x='x_data',
                  y='y_mean',
                  line_color='orange',
                  name="Avg_temp",
                  line_alpha=0.9)
    g2_r = p.add_glyph(source_or_glyph=source2, glyph=g2, y_range_name="Temp")
    g2_hover = bkm.HoverTool(renderers=[g2_r],
                             tooltips={
                                 "Avg. Temp.": "$y ˚C",
                                 "DJU": "@DJU{int}",
                                 "Date": "@tooltip"
                             })
    p.add_tools(g2_hover)

    p.line(x_data,
           y_max,
           y_range_name="Temp",
           legend="max_temp",
           color='red',
           line_alpha=0.5,
           line_dash='dashdot')
    p.line(x_data,
           y_min,
           y_range_name="Temp",
           legend="min_temp",
           color='blue',
           line_alpha=0.5,
           line_dash='dashdot')
    p.line(x_data,
           y_normal,
           y_range_name="Temp",
           legend="normal_temp",
           color='black',
           line_alpha=1,
           line_dash='dashed')

    output_file("conso_elec.html", title="Inkognito_conso")
    show(p)
Ejemplo n.º 24
0
    def __init__(self,
                 start_position,
                 goal_position,
                 obstacles,
                 speed=1,
                 param_values=None):
        self.position = start_position
        self.goal_position = goal_position
        self.obstacles = obstacles
        self.obstacle_symbols = [
            sp.symbols(f'o{i}x, o{i}y') for i, _ in enumerate(obstacles)
        ]
        self.speed = speed
        self.params = self.default_params
        self.params.update(param_values or {})

        xs = [start_position[0], goal_position[0], *(o[0] for o in obstacles)]
        ys = [start_position[1], goal_position[1], *(o[1] for o in obstacles)]
        self.birdseye_plot = figure(
            width=FIGURE_WIDTH,
            match_aspect=True,
            x_range=models.Range1d(min(xs) - PADDING,
                                   max(xs) + PADDING),
            y_range=models.Range1d(min(ys) - PADDING,
                                   max(ys) + PADDING),
            title='Top-down view',
        )
        super().__init__()
        self.t_slider.value = 20  # Simulation length.

        self.numeric_eqn = None
        self.numeric_nullcline_eqn = None
        self.compiled_eqn = None
        self.compile()

        self.objects_source = models.ColumnDataSource(
            data=dict(x=[], y=[], color=[], name=[]))
        self.objects_source.on_change('data', self.positions_changed)
        self.trajectory_source = models.ColumnDataSource(data=dict(x=[], y=[]))

        self.angle_indicator_source = models.ColumnDataSource(
            data=dict(x=[], y=[], color=[]))
        self.nullcline_source = models.ColumnDataSource(data=dict(x=[], y=[]))

        self.plot.width = FIGURE_WIDTH
        self.plot.width = FIGURE_WIDTH
        self.plot.xaxis.axis_label = 'φ'
        self.plot.yaxis.axis_label = 'dφ/dt'

        self.plot.line(
            x='x',
            y='y',
            source=self.nullcline_source,
            color='black',
            line_width=NULLCLINE_WIDTH,
        )
        self.plot.cross(
            x='x',
            y='y',
            color='color',
            source=self.angle_indicator_source,
            size=INDICATOR_SIZE,
            line_width=INDICATOR_LINE_WIDTH,
            alpha=0.7,
        )

        for dim in ['width', 'height']:
            self.plot.add_layout(
                models.Span(
                    location=0,
                    dimension=dim,
                    line_color='black',
                    line_width=1,
                    line_dash='dashed',
                ))

        self.birdseye_plot.axis.visible = False
        self.birdseye_plot.grid.visible = False
        self.birdseye_plot.on_event(events.DoubleTap, self.on_doubleclick)

        objects = self.birdseye_plot.circle(
            x='x',
            y='y',
            color='color',
            source=self.objects_source,
            size=CIRCLE_SIZE,
        )
        self.birdseye_plot.line(
            x='x',
            y='y',
            source=self.trajectory_source,
            color=AGENT_COLOR,
        )

        drag_tool = models.PointDrawTool(renderers=[objects])
        hover_tool = models.HoverTool(
            renderers=[objects],
            tooltips=[('Object', '@name')],
        )
        self.birdseye_plot.tools = [drag_tool, hover_tool]
        self.birdseye_plot.toolbar.active_drag = drag_tool

        self.sim_button = models.Button(label='Sim')
        self.sim_button.on_click(self.sim_button_clicked)
        self.clear_button = models.Button(label='Clear')
        self.clear_button.on_click(self.clear_button_clicked)

        self.update_birdseye_plot()
Ejemplo n.º 25
0
def freqz(b,
          a=1,
          fs=2.0,
          worN=None,
          whole=False,
          degrees=True,
          style='solid',
          thickness=1,
          title=None,
          xlabel='Frequency (Hz)',
          xlim=None,
          ylim=None,
          width=None,
          height=None,
          hold=False,
          interactive=None):
    """Plot frequency response of a filter.

    This is a convenience function to plot frequency response, and internally uses
    :func:`scipy.signal.freqz` to estimate the response. For further details, see the
    documentation for :func:`scipy.signal.freqz`.

    :param b: numerator of a linear filter
    :param a: denominator of a linear filter
    :param fs: sampling rate in Hz (optional, normalized frequency if not specified)
    :param worN: see :func:`scipy.signal.freqz`
    :param whole: see :func:`scipy.signal.freqz`
    :param degrees: True to display phase in degrees, False for radians
    :param style: line style ('solid', 'dashed', 'dotted', 'dotdash', 'dashdot')
    :param thickness: line width in pixels
    :param title: figure title
    :param xlabel: x-axis label
    :param ylabel1: y-axis label for magnitude
    :param ylabel2: y-axis label for phase
    :param xlim: x-axis limits (min, max)
    :param ylim: y-axis limits (min, max)
    :param width: figure width in pixels
    :param height: figure height in pixels
    :param interactive: enable interactive tools (pan, zoom, etc) for plot
    :param hold: if set to True, output is not plotted immediately, but combined with the next plot

    >>> import arlpy
    >>> arlpy.plot.freqz([1,1,1,1,1], fs=120000);
    """
    w, h = _sig.freqz(b, a, worN, whole)
    Hxx = 20 * _np.log10(abs(h) + _np.finfo(float).eps)
    f = w * fs / (2 * _np.pi)
    if xlim is None:
        xlim = (0, fs / 2)
    if ylim is None:
        ylim = (_np.max(Hxx) - 50, _np.max(Hxx) + 10)
    figure(title=title,
           xlabel=xlabel,
           ylabel='Amplitude (dB)',
           xlim=xlim,
           ylim=ylim,
           width=width,
           height=height,
           interactive=interactive)
    _hold_enable(True)
    plot(f,
         Hxx,
         color=color(0),
         style=style,
         thickness=thickness,
         legend='Magnitude')
    fig = gcf()
    units = 180 / _np.pi if degrees else 1
    fig.extra_y_ranges = {
        'phase': _bmodels.Range1d(start=-_np.pi * units, end=_np.pi * units)
    }
    fig.add_layout(
        _bmodels.LinearAxis(
            y_range_name='phase',
            axis_label='Phase (degrees)' if degrees else 'Phase (radians)'),
        'right')
    phase = _np.angle(h) * units
    fig.line(f,
             phase,
             line_color=color(1),
             line_dash=style,
             line_width=thickness,
             legend='Phase',
             y_range_name='phase')
    _hold_enable(hold)
Ejemplo n.º 26
0
def outputMapTemp(path, mapSelect):

    #Select which solar module temperature calculation the user would like to see

    if mapSelect == 'open_rack_cell_glassback':
        moduleType = 'Average (98th Percentile) Module Temperature__open_rack_cell_glassback (C)'
        chartHeader = 'Open Rack Cell Glass Back'
        htmlString = '_open_rack_cell_glassback'
        colorSelector = 'Spectral6'
        #Assign the upper and lower bounds of the map
        mapScaleUpper = 100
        mapScaleLower = 20

    elif mapSelect == 'roof_mount_cell_glassback':
        moduleType = 'Average (98th Percentile) Module Temperature__roof_mount_cell_glassback (C)'
        chartHeader = 'Roof Mount Cell Glass Back'
        htmlString = '_roof_mount_cell_glassback'
        colorSelector = 'Spectral6'
        #Assign the upper and lower bounds of the map
        mapScaleUpper = 100
        mapScaleLower = 20

    elif mapSelect == 'open_rack_cell_polymerback':
        moduleType = 'Average (98th Percentile) Module Temperature__open_rack_cell_polymerback (C)'
        chartHeader = 'Open Rack Cell Polymer Back'
        htmlString = '_open_rack_cell_polymerback'
        colorSelector = 'Spectral6'
        #Assign the upper and lower bounds of the map
        mapScaleUpper = 100
        mapScaleLower = 20

    elif mapSelect == 'insulated_back_polymerback':
        moduleType = 'Average (98th Percentile) Module Temperature__insulated_back_polymerback (C)'
        chartHeader = 'Insulated Back Polymer Back'
        htmlString = '_insulated_back_polymerback'
        colorSelector = 'Spectral6'
        #Assign the upper and lower bounds of the map
        mapScaleUpper = 100
        mapScaleLower = 20

    elif mapSelect == 'open_rack_polymer_thinfilm_steel':
        moduleType = 'Average (98th Percentile) Module Temperature__open_rack_polymer_thinfilm_steel (C)'
        chartHeader = 'Open Rack Polymer Thin Film Steel'
        htmlString = '_open_rack_polymer_thinfilm_steel'
        colorSelector = 'Spectral6'
        #Assign the upper and lower bounds of the map
        mapScaleUpper = 100
        mapScaleLower = 20

    elif mapSelect == '22x_concentrator_tracker':
        moduleType = 'Average (98th Percentile) Module Temperature__22x_concentrator_tracker (C)'
        chartHeader = '22x Concentrator Tracker'
        htmlString = '_22x_concentrator_tracker'
        colorSelector = 'Spectral6'
        #Assign the upper and lower bounds of the map
        mapScaleUpper = 100
        mapScaleLower = 20

    #Create the html to be exported
    output_file('Module_Temperature_Map' + htmlString + '.html')

    # Create the tools used for zooming and hovering on the map
    tools = "pan,wheel_zoom,box_zoom,reset,previewsave"

    #Access the .json file to create the map of countries and states
    # THe json files will create layers to overlap the data with
    with open(path + "/Map/countries.geojson", "r") as f:
        countries = bkm.GeoJSONDataSource(geojson=f.read())
    with open(path + "/Map/us-states.json", "r") as f:
        states = bkm.GeoJSONDataSource(geojson=f.read())

    #Access the processed summary data pickle
    level_1_df = pd.read_pickle(
        path + "\\Pandas_Pickle_DataFrames\\Pickle_Map\\Pickle_Map.pickle")

    # Bring in all the data to display on map

    #Radius is the size of the circle to be displayed on the map
    radiusList = []
    for i in range(0, len(level_1_df)):
        #Toggle size of circle
        radiusList.append(2)
    lat = level_1_df['N'].astype(float)  #Northing and easting if Needed
    lon = level_1_df['E'].astype(float)
    radius = radiusList
    temperature = level_1_df[moduleType]
    station = level_1_df['Station name']
    latitude = level_1_df['Site latitude']
    longitude = level_1_df['Site longitude']
    moduleTemp = level_1_df[moduleType]
    uniqueID = level_1_df['Site Identifier Code']

    # The Boken map rendering package needs to store data in the ColumnDataFormat
    # Store the lat/lon from the Map_pickle.  Formatting for Lat/Lon has been
    # processed prior see "Map_Pickle_Processing.py" file for more details
    # Add other data to create hover labels
    source = ColumnDataSource(data=dict(Lat=latitude,
                                        Lon=longitude,
                                        radius=radius,
                                        temperature=temperature,
                                        Station=station,
                                        Latitude=latitude,
                                        Longitude=longitude,
                                        Module_Temp=moduleTemp,
                                        uniqueID=uniqueID))

    # Create the figure with the map parameters.  This controls the window
    p = bkp.figure(
        width=1500,
        height=900,
        tools=tools,
        title=
        'IWEC, CWEC, and TMY-3 98th Precentile of Module Temperature Celsius (King Model) '
        + chartHeader,
        x_axis_type="mercator",
        y_axis_type="mercator",
        x_axis_label='Longitude',
        y_axis_label='Latitude')

    p.x_range = bkm.Range1d(start=-180, end=180)
    p.y_range = bkm.Range1d(start=-90, end=90)

    #Create the datapoints as overlapping circles
    p.circle(
        "Lon",
        "Lat",
        source=source,
        radius="radius",
        #fill color will use linear_cmap() to scale the colors of the circles being displayed
        fill_color=linear_cmap('temperature',
                               colorSelector,
                               low=mapScaleLower,
                               high=mapScaleUpper),
        line_color=None,
        # Alpha is the transparency of the circle
        alpha=0.3)
    #Stations will be the black dots displayed on the map
    stations = p.circle(
        "Lon",
        "Lat",
        source=source,
        radius=.1,
        #fill color will use linear_cmap() to scale the colors of the circles being displayed
        fill_color='black',
        line_color=None,
        # Alpha is the transparency of the circle
        alpha=.99)

    #Create the scale bar to the right of the map

    # Create color mapper to make the scale bar on the right of the map
    # palette = color scheme of the mapo
    # low/high sets the scale of the data, use the minimum value and maximum value of the data we are analyzing
    color_mapper = LogColorMapper(palette=colorSelector,
                                  low=mapScaleLower,
                                  high=mapScaleUpper)

    # color bar will be scale bar set to the right of the map
    color_bar = ColorBar(color_mapper=color_mapper,
                         ticker=LogTicker(),
                         label_standoff=12,
                         border_line_color=None,
                         location=(0, 0))
    # Assign the scale bar to " p " and put it to the right
    p.add_layout(color_bar, 'right')

    # These are the labels that are displayed when you hover over a spot on the map
    #( label , @data), data needs to be inside the ColumnDataSource()
    TOOLTIPS = [
        ("Station", "@Station"),
        ("Site ID", "@uniqueID"),
        ("Lat", "@Latitude"),
        ("Lon", "@Longitude"),
        ("Module_Temp", "@Module_Temp"),
    ]

    #Create a hover tool that will rinder only the weather stations i.e stations are small black circles
    hover_labels = bkm.HoverTool(renderers=[stations], tooltips=TOOLTIPS)
    #Add the hover tool to the map
    p.add_tools(hover_labels)
    #Overlay the Country and States boarders
    p.patches("xs",
              "ys",
              color="white",
              line_color="black",
              source=countries,
              fill_alpha=0,
              line_alpha=1)
    p.patches("xs",
              "ys",
              color="white",
              line_color="black",
              source=states,
              fill_alpha=0,
              line_alpha=1)
    #Display the plot
    show(p)
Ejemplo n.º 27
0
    def outputMapTemp(path , mapSelect):
        '''
        EXECUTION METHOD
        
        outputMapTemp()
        
        Method to create a map of the Dew Yield around the world.
        This method will use a package called Bokeh that generates a html file 
        containing the map.  User will have thier defualt browser open and display the map
        
        @param path         - String, of the current working directory                                  
        @param mapSelect    - String, string to select what map to generate
                                    ACCEPTABLE STRINGS AS PARAMETERS
                                       - 'open_rack_cell_glassback'
                                       - 'roof_mount_cell_glassback'
                                       - 'open_rack_cell_polymerback'
                                       - 'insulated_back_polymerback'
                                       - 'open_rack_polymer_thinfilm_steel'
                                       - '22x_concentrator_tracker'                               
        
        @return void        - Generates a html Bokeh map
        '''        
        #Select which solar module temperature calculation the user would like to see
        
        ### 98th percentile maps
        if mapSelect == 'open_rack_cell_glassback98th':
            moduleType = 'Annual Average (98th Percentile) Module Temperature__open_rack_cell_glassback (C)'            
            minTemp = 'Annual Minimum Module Temperature__open_rack_cell_glassback (C)'
            maxTemp = 'Annual Maximum Module Temperature__open_rack_cell_glassback (C)'
            avgTemp = 'Annual Average Module Temperature__open_rack_cell_glassback (C)'
            module98 = 'Annual Average (98th Percentile) Module Temperature__open_rack_cell_glassback (C)'                        
            chartHeader = '98th Percentile Module Temperature Open Rack Cell Glass Back (C)'
            htmlString = '_open_rack_cell_glassback'
            colorSelector = 'Spectral6'
            #Assign the upper and lower bounds of the map 
            mapScaleUpper = 100
            mapScaleLower = 20
            
        elif mapSelect == 'roof_mount_cell_glassback98th':
            moduleType = 'Annual Average (98th Percentile) Module Temperature__roof_mount_cell_glassback (C)'            
            minTemp = 'Annual Minimum Module Temperature__roof_mount_cell_glassback (C)'
            maxTemp = 'Annual Maximum Module Temperature__roof_mount_cell_glassback (C)'
            avgTemp = 'Annual Average Module Temperature__roof_mount_cell_glassback (C)'
            module98 = 'Annual Average (98th Percentile) Module Temperature__roof_mount_cell_glassback (C)'                        
            chartHeader = '98th Percentile Module Temperature Roof Mount Cell Glass Back (C)'
            htmlString = '_roof_mount_cell_glassback'
            colorSelector = 'Spectral6'
            #Assign the upper and lower bounds of the map 
            mapScaleUpper = 100
            mapScaleLower = 20
            
        elif mapSelect == 'open_rack_cell_polymerback98th':
            moduleType = 'Annual Average (98th Percentile) Module Temperature__open_rack_cell_polymerback (C)'            
            minTemp = 'Annual Minimum Module Temperature__open_rack_cell_polymerback (C)'
            maxTemp = 'Annual Maximum Module Temperature__open_rack_cell_polymerback (C)'
            avgTemp = 'Annual Average Module Temperature__open_rack_cell_polymerback (C)'
            module98 = 'Annual Average (98th Percentile) Module Temperature__open_rack_cell_polymerback (C)'                        
            chartHeader = '98th Percentile Module Temperature Open Rack Cell Polymer Back (C)'
            htmlString = '_open_rack_cell_polymerback'
            colorSelector = 'Spectral6'
            #Assign the upper and lower bounds of the map 
            mapScaleUpper = 100
            mapScaleLower = 20
            
        elif mapSelect == 'insulated_back_polymerback98th':
            moduleType = 'Annual Average (98th Percentile) Module Temperature__insulated_back_polymerback (C)'            
            minTemp = 'Annual Minimum Module Temperature__insulated_back_polymerback (C)'
            maxTemp = 'Annual Maximum Module Temperature__insulated_back_polymerback (C)'
            avgTemp = 'Annual Average Module Temperature__insulated_back_polymerback (C)'
            module98 = 'Annual Average (98th Percentile) Module Temperature__insulated_back_polymerback (C)'                        
            chartHeader = '98th Percentile Module Temperature Insulated Back Polymer Back (C)'
            htmlString = '_insulated_back_polymerback'
            colorSelector = 'Spectral6'
            #Assign the upper and lower bounds of the map 
            mapScaleUpper = 100
            mapScaleLower = 20
            
        elif mapSelect == 'open_rack_polymer_thinfilm_steel98th':
            moduleType = 'Annual Average (98th Percentile) Module Temperature__open_rack_polymer_thinfilm_steel (C)'            
            minTemp = 'Annual Minimum Module Temperature__open_rack_polymer_thinfilm_steel (C)'
            maxTemp = 'Annual Maximum Module Temperature__open_rack_polymer_thinfilm_steel (C)'
            avgTemp = 'Annual Average Module Temperature__open_rack_polymer_thinfilm_steel (C)'
            module98 = 'Annual Average (98th Percentile) Module Temperature__open_rack_polymer_thinfilm_steel (C)'        
            chartHeader = '98th Percentile Module Temperature Open Rack Polymer Thin Film Steel (C)'
            htmlString = '_open_rack_polymer_thinfilm_steel'
            colorSelector = 'Spectral6' 
            #Assign the upper and lower bounds of the map 
            mapScaleUpper = 100
            mapScaleLower = 20
            
        elif mapSelect == '22x_concentrator_tracker98th':
            moduleType = 'Annual Average (98th Percentile) Module Temperature__22x_concentrator_tracker (C)'            
            minTemp = 'Annual Minimum Module Temperature__22x_concentrator_tracker (C)'
            maxTemp = 'Annual Maximum Module Temperature__22x_concentrator_tracker (C)'
            avgTemp = 'Annual Average Module Temperature__22x_concentrator_tracker (C)'
            module98 = 'Annual Average (98th Percentile) Module Temperature__22x_concentrator_tracker (C)'            
            chartHeader = '98th Percentile Module Temperature 22x Concentrator Tracker (C)'
            htmlString = '_22x_concentrator_tracker'
            colorSelector = 'Spectral6'
            #Assign the upper and lower bounds of the map 
            mapScaleUpper = 100
            mapScaleLower = 20
            
            
        ### Average Temp Maps  
        elif mapSelect == 'AverageModuleTemperature__open_rack_cell_glassback':
            moduleType = 'Annual Average Module Temperature__open_rack_cell_glassback (C)'
            minTemp = 'Annual Minimum Module Temperature__open_rack_cell_glassback (C)'
            maxTemp = 'Annual Maximum Module Temperature__open_rack_cell_glassback (C)'
            avgTemp = 'Annual Average Module Temperature__open_rack_cell_glassback (C)'
            module98 = 'Annual Average (98th Percentile) Module Temperature__open_rack_cell_glassback (C)'
            chartHeader = 'Annual Average Module Temperature Open Rack Cell Glassback (C)'
            htmlString = 'Average_Temp_open_rack_cell_glassback'
            colorSelector = 'Spectral6'
            #Assign the upper and lower bounds of the map 
            mapScaleUpper = 35
            mapScaleLower = 1
            
        elif mapSelect == 'AverageModuleTemperature__roof_mount_cell_glassback':
            moduleType = 'Annual Average Module Temperature__roof_mount_cell_glassback (C)'
            minTemp = 'Annual Minimum Module Temperature__roof_mount_cell_glassback (C)'
            maxTemp = 'Annual Maximum Module Temperature__roof_mount_cell_glassback (C)'
            avgTemp = 'Annual Average Module Temperature__roof_mount_cell_glassback (C)'
            module98 = 'Annual Average (98th Percentile) Module Temperature__roof_mount_cell_glassback (C)'
            chartHeader = 'Annual Average Module Temperature Roof Mount Cell Glassback (C)'
            htmlString = 'Average_Temp_roof_mount_cell_glassback'
            colorSelector = 'Spectral6'
            #Assign the upper and lower bounds of the map 
            mapScaleUpper = 35
            mapScaleLower = 1 
            
        elif mapSelect == 'AverageModuleTemperature__open_rack_cell_polymerback':
            moduleType = 'Annual Average Module Temperature__open_rack_cell_polymerback (C)'
            minTemp = 'Annual Minimum Module Temperature__open_rack_cell_polymerback (C)'
            maxTemp = 'Annual Maximum Module Temperature__open_rack_cell_polymerback (C)'
            avgTemp = 'Annual Average Module Temperature__open_rack_cell_polymerback (C)'
            module98 = 'Annual Average (98th Percentile) Module Temperature__open_rack_cell_polymerback (C)'
            chartHeader = 'Annual Average Module Temperature Open Rack Cell Polymerback (C)'
            htmlString = 'Average_Temp_open_rack_cell_polymerback'
            colorSelector = 'Spectral6'
            #Assign the upper and lower bounds of the map 
            mapScaleUpper = 35
            mapScaleLower = 1    
            
        elif mapSelect == 'AverageModuleTemperature__insulated_back_polymerback':
            moduleType = 'Annual Average Module Temperature__insulated_back_polymerback (C)'
            minTemp = 'Annual Minimum Module Temperature__insulated_back_polymerback (C)'
            maxTemp = 'Annual Maximum Module Temperature__insulated_back_polymerback (C)'
            avgTemp = 'Annual Average Module Temperature__insulated_back_polymerback (C)'
            module98 = 'Annual Average (98th Percentile) Module Temperature__insulated_back_polymerback (C)'
            chartHeader = 'Annual Average Module Temperature Insulated Back Polymerback (C)'
            htmlString = 'Average_Temp_insulated_back_polymerback'
            colorSelector = 'Spectral6'
            #Assign the upper and lower bounds of the map 
            mapScaleUpper = 35
            mapScaleLower = 1   
            
        elif mapSelect == 'AverageModuleTemperature__open_rack_polymer_thinfilm_steel':
            moduleType = 'Annual Average Module Temperature__open_rack_polymer_thinfilm_steel (C)'
            minTemp = 'Annual Minimum Module Temperature__open_rack_polymer_thinfilm_steel (C)'
            maxTemp = 'Annual Maximum Module Temperature__open_rack_polymer_thinfilm_steel (C)'
            avgTemp = 'Annual Average Module Temperature__open_rack_polymer_thinfilm_steel (C)'
            module98 = 'Annual Average (98th Percentile) Module Temperature__open_rack_polymer_thinfilm_steel (C)'
            chartHeader = 'Annual Average Module Temperature Open Rack Polymer Thinfilm Steel (C)'
            htmlString = 'Average_Temp_open_rack_polymer_thinfilm_steel'
            colorSelector = 'Spectral6'
            #Assign the upper and lower bounds of the map 
            mapScaleUpper = 35
            mapScaleLower = 1   
            
        elif mapSelect == 'AverageModuleTemperature__22x_concentrator_tracker':
            moduleType = 'Annual Average Module Temperature__22x_concentrator_tracker (C)'
            minTemp = 'Annual Minimum Module Temperature__22x_concentrator_tracker (C)'
            maxTemp = 'Annual Maximum Module Temperature__22x_concentrator_tracker (C)'
            avgTemp = 'Annual Average Module Temperature__22x_concentrator_tracker (C)'
            module98 = 'Annual Average (98th Percentile) Module Temperature__22x_concentrator_tracker (C)'
            chartHeader = 'Annual Average Module Temperature 22x Concentrator Tracker (C)'
            htmlString = 'Average_Temp_22x_concentrator_tracker'
            colorSelector = 'Spectral6'
            #Assign the upper and lower bounds of the map 
            mapScaleUpper = 35
            mapScaleLower = 1        
        

        
        
        



        #Create the html to be exported
        output_file('Module_Temperature_Map' + htmlString + '.html') 
        
        # Create the tools used for zooming and hovering on the map
        tools = "pan,wheel_zoom,box_zoom,reset,previewsave"
        
        #Access the .json file to create the map of countries and states
        # THe json files will create layers to overlap the data with
        with open(path + "/Map/countries.geojson", "r") as f:
            countries = bkm.GeoJSONDataSource(geojson=f.read())  
        with open(path + "/Map/us-states.json", "r") as f:
            states = bkm.GeoJSONDataSource(geojson=f.read())      
        
        #Access the processed summary data pickle
        level_1_df = pd.read_pickle(path + "\\Pandas_Pickle_DataFrames\\Pickle_Level1_Summary\\Pickle_Level1_Summary.pickle")
    
        # Bring in all the data to display on map
        
        #Radius is the size of the circle to be displayed on the map
        radiusList = []
        for i in range(0, len(level_1_df)):
            #Toggle size of circle
            radiusList.append(2)
        radius = radiusList
        selector = level_1_df[moduleType]
        station = level_1_df['Station name']
        latitude = level_1_df['Site latitude']
        longitude = level_1_df['Site longitude']
        
        uniqueID = level_1_df['Site Identifier Code']
        dataSource = level_1_df['Data Source']
        
        moduleTemp98 = level_1_df[module98]
        moduleMinTemp = level_1_df[minTemp]            
        moduleMaxTemp = level_1_df[maxTemp]
        moduleAvgTemp = level_1_df[avgTemp]
    
    
    
        # The Boken map rendering package needs to store data in the ColumnDataFormat
        # Store the lat/lon from the Map_pickle.  Formatting for Lat/Lon has been 
        # processed prior see "Map_Pickle_Processing.py" file for more details 
        # Add other data to create hover labels
        source = ColumnDataSource(
            data = dict(
                Lat = latitude,
                Lon = longitude,
                radius = radius,
                selector = selector,
                Station = station,
                Latitude = latitude,
                Longitude = longitude,
                Module_Temp98 = moduleTemp98,
                Module_Min_Temp = moduleMinTemp,
                Module_Avg_Temp = moduleAvgTemp,
                Module_Max_Temp = moduleMaxTemp,
                uniqueID = uniqueID,
                dataSource = dataSource
                ) )
        
        # Create the figure with the map parameters.  This controls the window
        p = bkp.figure(width=1500, 
                   height=900, 
                   tools=tools, 
                   title= chartHeader ,
                   
                   x_axis_type="mercator",
                   y_axis_type="mercator",
    
                   x_axis_label='Longitude', 
                   y_axis_label='Latitude')
    
        p.x_range = bkm.Range1d(start=-180, end=180)
        p.y_range = bkm.Range1d(start=-90, end=90)
    
    
        #Create the datapoints as overlapping circles
        p.circle("Lon",
                 "Lat", 
                 source= source , 
                 radius="radius" , 
                 #fill color will use linear_cmap() to scale the colors of the circles being displayed
                 fill_color = linear_cmap('selector', colorSelector, low= mapScaleLower, high= mapScaleUpper),
                 line_color =None,  
                 # Alpha is the transparency of the circle
                 alpha=0.3)
        #Stations will be the black dots displayed on the map
        stations = p.circle("Lon",
                 "Lat", 
                 source=source , 
                 radius= .1 , 
                 #fill color will use linear_cmap() to scale the colors of the circles being displayed
                 fill_color = 'black',
                 line_color = None,
                 # Alpha is the transparency of the circle
                  alpha=.99)   
    
    
        #Create the scale bar to the right of the map
        
        # Create color mapper to make the scale bar on the right of the map
        # palette = color scheme of the mapo
        # low/high sets the scale of the data, use the minimum value and maximum value of the data we are analyzing
        color_mapper = LinearColorMapper(palette= colorSelector,  low= mapScaleLower, high=mapScaleUpper)
        
        # color bar will be scale bar set to the right of the map
        color_bar = ColorBar(color_mapper=color_mapper, ticker=LogTicker(),
                         label_standoff=12, border_line_color=None, location=(0,0))
        # Assign the scale bar to " p " and put it to the right
        p.add_layout(color_bar, 'right')
        
    
        # These are the labels that are displayed when you hover over a spot on the map
        #( label , @data), data needs to be inside the ColumnDataSource()
        TOOLTIPS = [
        ("Station","@Station") ,
        ("Site ID","@uniqueID"),
        ("Data Source", "@dataSource"),
        ("Lat","@Latitude"),
        ("Lon","@Longitude"),
        
        ("Module Minimum Temp","@Module_Min_Temp" + " (C)"),
        ("Module Average Temp","@Module_Avg_Temp" + " (C)"),
        ("Module Maximum Temp","@Module_Max_Temp" + " (C)"),
        ("98 Percentile Module Temp","@Module_Temp98" + " (C)")
        ]
        
        #Create a hover tool that will rinder only the weather stations i.e stations are small black circles
        hover_labels = bkm.HoverTool(renderers=[stations],
                             tooltips= TOOLTIPS )
        #Add the hover tool to the map
        p.add_tools(hover_labels)
        #Overlay the Country and States boarders
        p.patches("xs", "ys", color="white", line_color="black", source=countries , fill_alpha = 0 , line_alpha = 1)
        p.patches("xs", "ys", color="white", line_color="black", source=states , fill_alpha = 0 , line_alpha = 1)
        #Display the plot
        show(p)
Ejemplo n.º 28
0
               "@micrograph_number"), ("phase shift", "@phase_shift"),
              ("astigmatism",
               "@astigmatism"), ("defocus U",
                                 "@defocusU"), ("defocus V", "@defocusV")])

phase_shift_fig.add_tools(phase_shift_hover)

phase_shift_fig.xaxis.axis_label = "Micrograph number"
phase_shift_fig.yaxis.axis_label = "Phase shift, degrees"

ctf_fig = bplt.figure(plot_width=1200,
                      title="CTF",
                      tools="ywheel_zoom",
                      y_range=(0, 1))

ctf_fig.extra_y_ranges = {"epa": bmodels.Range1d(start=10, end=20)}
ctf_fig.add_layout(bmodels.LinearAxis(y_range_name="epa"), 'right')

# print('Reading {}'.format(sys.argv[1]))

# micrograph = mrcfile.open(sys.argv[1], 'r', permissive=True)

# micrograph_ps = estimate_power_spectrum(micrograph.data, 512, 0.5)

pixel_size = 0.66

# wys, wxs = np.meshgrid(np.linspace(-1/(2*pixel_size), 1/(2*pixel_size), 512, endpoint=False),
#                        np.linspace(-1/(2*pixel_size), 1/(2*pixel_size), 512, endpoint=False),
#                        indexing='ij')

# mean = micrograph_ps[ np.sqrt(wys**2 + wxs**2) > 1/50 ].mean()