Exemplo n.º 1
0
def cloud_hunt(ctx=None):
    """
    Displays a UI to build LQL queries to do threat hunting.
    """
    global lw_ctx  # To be able to pass the grid to widget functions.
    tables = utils.load_yaml_file("tables.yaml")
    table_filters = utils.load_yaml_file("filters.yaml")

    options = [DEFAULT_TABLE_PICK]
    options.extend([x.get("display_name") for x in tables])
    options.append(DEFAULT_CUSTOM_PICK)
    table_list = ipywidgets.Dropdown(options=options,
                                     value=DEFAULT_TABLE_PICK,
                                     description="",
                                     disabled=False)
    table_list.observe(_generate_table_filters)

    table_box = ipywidgets.HBox()
    table_box.children = (ipywidgets.Label("Pick a table: "), table_list)

    verify_button = ipywidgets.Button(
        value=False,
        description="Verify Query",
        disabled=False,
        tooltip="Build the LQL query and verify it",
        icon="check")
    verify_button.on_click(_verify_button)

    execute_button = ipywidgets.Button(
        value=False,
        description="Execute Query",
        button_style="success",
        disabled=False,
        tooltip="Build the LQL query and execute it")
    execute_button.on_click(_execute_button)

    box_layout = ipywidgets.Layout(display="flex",
                                   flex_flow="column",
                                   align_items="stretch",
                                   width="1000px")

    title = ipywidgets.HTML(
        value=("<div align=\"center\"><h1>Cloud Hunting</h1><i>Assistant to "
               "build LQL queries to perform threat hunting within your "
               "environment.</i><br/><br/></div>"))

    start_time, end_time = utils.get_start_and_end_time(ctx)
    start_widget = ipywidgets.Text(value=start_time,
                                   placeholder="YYYY-MM-DDTHH:MM:SSZ",
                                   description="",
                                   disabled=False)
    end_widget = ipywidgets.Text(value=end_time,
                                 placeholder="YYYY-MM-DDTHH:MM:SSZ",
                                 description="",
                                 disabled=False)

    filter_box = ipywidgets.VBox()
    result_label = ipywidgets.HTML()

    grid = ipywidgets.Box(children=[
        title,
        table_box,
        ipywidgets.HBox(children=[
            ipywidgets.Label("Start Time:"), start_widget,
            ipywidgets.Label("End Time:"), end_widget
        ]),
        filter_box,
        ipywidgets.HBox(children=(verify_button, execute_button)),
        result_label,
    ],
                          layout=box_layout)

    ctx.add_state("query_builder", "query_table_box", table_box)
    ctx.add_state("query_builder", "query_start_widget", start_widget)
    ctx.add_state("query_builder", "query_end_widget", end_widget)
    ctx.add_state("query_builder", "query_filter_box", filter_box)
    ctx.add_state("query_builder", "query_label", result_label)

    ctx.add_state("query_builder", "query_tables", tables)
    ctx.add_state("query_builder", "query_filters", table_filters)
    lw_ctx = ctx
    query_builder.lw_ctx = ctx

    display(grid)  # noqa: F821
Exemplo n.º 2
0
    def build(self, compute_handler):
        def on_button_clicked(b):

            if self.filepath.value is None:
                return

            self.out.clear_output()
            with self.out:
                self.button.disabled = True
                compute_handler(
                    self.filepath.value,
                    window_size=self.window_size.value,
                    distance_metric=self.distance_metric.value,
                    direction_sensitive=False,  # self.direction_sensitive.value,
                    method=self.method.value)
                self.button.disabled = False

        corpus_files = sorted(
            glob.glob(os.path.join(self.data_folder, '*.tokenized.zip')))
        distance_metric_options = [('linear', 0), ('inverse', 1),
                                   ('constant', 2)]

        self.filepath = ipywidgets.Dropdown(
            description='Corpus',
            options=corpus_files,
            value=None,
            layout=ipywidgets.Layout(width='400px'))
        self.window_size = ipywidgets.IntSlider(
            description='Window',
            min=2,
            max=40,
            value=5,
            layout=ipywidgets.Layout(width='250px'))
        self.method = ipywidgets.Dropdown(
            description='Method',
            options=['HAL', 'Glove'],
            value='HAL',
            layout=ipywidgets.Layout(width='200px'))
        self.button = ipywidgets.Button(description='Compute',
                                        button_style='Success',
                                        layout=ipywidgets.Layout(
                                            width='115px',
                                            background_color='blue'))
        self.out = ipywidgets.Output()

        self.distance_metric = ipywidgets.Dropdown(
            description='Dist.f.',
            options=distance_metric_options,
            value=2,
            layout=ipywidgets.Layout(width='200px'))
        #self.direction_sensitive = widgets.ToggleButton(description='L/R', value=False, layout=widgets.Layout(width='115px',background_color='blue'))
        #self.zero_diagonal       = widgets.ToggleButton(description='Zero Diag', value=False, layout=widgets.Layout(width='115px',background_color='blue'))

        self.button.on_click(on_button_clicked)

        return ipywidgets.VBox([
            ipywidgets.HBox([
                ipywidgets.VBox([self.filepath, self.method]),
                ipywidgets.VBox([self.window_size, self.distance_metric]),
                ipywidgets.VBox([
                    #self.direction_sensitive,
                    self.button
                ])
            ]),
            self.out
        ])
Exemplo n.º 3
0
def choose_mri_series(sample_mri: str) -> None:
    """Render widgets and plots for cardiac MRIs.

  Visualization is supported for CINE_segmented_SAX_InlineVF series and
  CINE_segmented_LAX series.

  Args:
    sample_mri: The local or Cloud Storage path to the MRI file.
  """
    with tempfile.TemporaryDirectory() as tmpdirname:
        local_path = os.path.join(tmpdirname, os.path.basename(sample_mri))
        try:
            tf.io.gfile.copy(src=sample_mri, dst=local_path)
            with zipfile.ZipFile(local_path, 'r') as zip_ref:
                zip_ref.extractall(tmpdirname)
        except (tf.errors.NotFoundError, tf.errors.PermissionDeniedError) as e:
            display(
                HTML(f'''<div class="alert alert-block alert-danger">
      <b>Warning:</b> Cardiac MRI not available for sample {os.path.basename(sample_mri)}:
      <hr><p><pre>{e.message}</pre></p>
      </div>'''), )
            return

        filtered_dicoms = collections.defaultdict(list)
        series_descriptions = []
        for dcm_file in os.listdir(tmpdirname):
            if not dcm_file.endswith('.dcm'):
                continue
            dcm = pydicom.read_file(os.path.join(tmpdirname, dcm_file))
            series_descriptions.append(dcm.SeriesDescription)
            if 'cine_segmented_lax' in dcm.SeriesDescription.lower():
                filtered_dicoms[dcm.SeriesDescription.lower()].append(dcm)
            if dcm.SeriesDescription.lower() == 'cine_segmented_sax_inlinevf':
                cur_angle = (dcm.InstanceNumber - 1) // MRI_FRAMES
                filtered_dicoms[
                    f'{dcm.SeriesDescription.lower()}_angle_{str(cur_angle)}'].append(
                        dcm)

        print(
            f'{os.path.basename(sample_mri)} contains: {str(sorted(set(series_descriptions)))}.'
        )

        if filtered_dicoms:
            series_name_chooser = widgets.Dropdown(
                options=sorted(list(filtered_dicoms.keys())),
                value=sorted(list(filtered_dicoms.keys()))[0],
                description='Choose the MRI series to visualize:',
                style={'description_width': 'initial'},
                layout=widgets.Layout(width='800px'),
            )
            fig_width_chooser = widgets.IntSlider(
                continuous_update=False,
                value=18,
                min=8,
                description=
                'Desired width of figure (height will be computed using input data)',
                style={'description_width': 'initial'},
                layout=widgets.Layout(width='800px'),
            )
            sax_sides_chooser = widgets.IntSlider(
                continuous_update=False,
                value=7,
                min=1,
                description=
                'How many sides to display for CINE_segmented_SAX_InlineVF',
                style=fig_width_chooser.style,
                layout=fig_width_chooser.layout,
            )
            lax_transpose_chooser = widgets.Checkbox(
                description=
                'Whether to transpose the images when plotting CINE_segmented_LAX',
                style=fig_width_chooser.style,
                layout=fig_width_chooser.layout,
            )
            viz_controls_ui = widgets.VBox(
                [
                    widgets.HTML('<h3>Visualization controls</h3>'),
                    series_name_chooser,
                    fig_width_chooser,
                    sax_sides_chooser,
                    lax_transpose_chooser,
                ],
                layout=widgets.Layout(width='auto', border='solid 1px grey'),
            )
            viz_controls_output = widgets.interactive_output(
                plot_mri_series,
                {
                    'sample_mri': widgets.fixed(sample_mri),
                    'dicoms': widgets.fixed(filtered_dicoms),
                    'series_name': series_name_chooser,
                    'sax_sides': sax_sides_chooser,
                    'lax_transpose': lax_transpose_chooser,
                    'fig_width': fig_width_chooser,
                },
            )
            display(viz_controls_ui, viz_controls_output)
        else:
            display(
                HTML(f'''<div class="alert alert-block alert-warning">
      Neither CINE_segmented_SAX_InlineVF nor CINE_segmented_LAX available in MRI for sample {os.path.basename(sample_mri)}.
      Try a different MRI.
      </div>'''), )
Exemplo n.º 4
0
    def __init__(self):
        self.Widget_List = {}
        self.valid_url = False
        self.order = [
            'name', 'alias', 'contact', 'institution', 'contributors',
            'description', 'fig_url', 'fig_display', 'species', 'region',
            'cell_type', 'scope', 'abstraction', 'license', 'version_text',
            'version_name', 'data_url', 'commit_id', 'version_description',
            'version_parameter', 'submit'
        ]


        self.Widget_List['name'] = interactive(self.f,
                                              x=widgets.Text(\
                                                    value='',
                                                    placeholder='e.g. Layer V Network in CA1',
                                                    description='Name:',
                                                             layout={'width':'70%'}))
        self.Widget_List['alias'] = interactive(self.f_alias, {'manual': True, 'manual_name':'Check validity'},
                                              x=widgets.Text(\
                                                    value='',
                                                    placeholder='e.g. L5-CA1_Ntwk',
                                                    description='Alias:',
                                                             layout={'width':'70%'}))
        self.Widget_List['contact'] = interactive(self.f,
                                                    x=widgets.Text(\
                                                    value='',
                                                    placeholder='e.g. Smith, John D.',
                                                    description='Contact:',
                                                                   layout={'width':'70%'}))

        self.Widget_List['institution'] = interactive(self.f,
                                                    x=widgets.Text(\
                                                    value='',
                                                    placeholder='e.g. CNRS, France',
                                                    description='Institution:',
                                                                   layout={'width':'70%'}))

        self.Widget_List['contributors'] = interactive(self.f,
                                                    x=widgets.Text(\
                                                    value='',
                                                    description_tooltip='e.g. Smith, John D.; Dupont, Jean Paul; Mueller, Jan; Russo, Giovanni',
                                                    placeholder='e.g. Smith, John D.; Dupont, Jean Paul; Mueller, Jan; Russo, Giovanni',
                                                    description='Contributors:',
                                                                   layout={'width':'70%'}))

        self.Widget_List['description'] = interactive(
            self.f,
            x=widgets.Textarea(placeholder='Decribe the model here',
                               description='Description:',
                               layout={
                                   'width': '70%',
                                   'height': '150px'
                               }))
        # optional figure upload
        self.Widget_List['fig_url'] = interactive(self.f_fig,
                                                {'manual': True, 'manual_name':'Upload figure'},
                                                  x=widgets.Text(\
                                                    value='',
                                                    placeholder='e.g. https://raw.github.com/name/repo/branch/fig.png',
                                                    description='Fig. URL:',
                                                                 layout={'width':'70%'}))
        self.Widget_List['fig_display'] = widgets.Image(format='png', width=50)

        self.Widget_List['species'] = interactive(
            self.f,
            x=widgets.Dropdown(options=[
                '', 'Callithrix Jacchus', 'H**o Sapiens', 'Macaca Mulata',
                'Monodelphis Domestica'
                'Rattus Norvegicus', 'Rodentia', 'Mus Musculus', 'Other'
            ],
                               value='',
                               description='Species:',
                               layout={'width': '70%'}))

        self.Widget_List['region'] = interactive(
            self.f,
            x=widgets.Dropdown(
                options=['', 'Cortex', 'Hippocampus', 'Cerebellum', 'Other'],
                value='',
                description='Region:',
                layout={'width': '70%'}))

        # self.Widget_List['cell_type'] = interactive(self.f,
        #                                                 x=widgets.Dropdown(
        #                                                 options=['',
        #                                                          'Pyramidal Cell',
        #                                                          'Interneuron'],
        #                                                 value='',
        #                                                 description='Cell type:'))

        self.Widget_List['cell_type'] = interactive(
            self.f,
            x=widgets.Text(placeholder='e.g. L5 Pyramidal Cell',
                           description='Cell type::',
                           layout={'width': '70%'}))

        self.Widget_List['scope'] = interactive(
            self.f,
            x=widgets.Dropdown(options=[
                '', 'network', 'network: whole brain', 'network: brain region',
                'network: microcircuit', 'single cell', 'subcellular',
                'subcellular: ion channel', 'subcellular: molecular',
                'subcellular: signaling', 'subcellular: spine', 'Other'
            ],
                               value='',
                               description='Model scope:',
                               layout={'width': '70%'}))

        self.Widget_List['abstraction'] = interactive(
            self.f,
            x=widgets.Dropdown(options=[
                '', 'biophysical model', 'cognitive model',
                'population model: neural field',
                'population model: neural mass', 'protein structure',
                'protein structure', 'rate neuron', 'spiking neuron',
                'spiking neuron: integrate and fire',
                'systems biology: continuous', 'systems biology: discrete',
                'systems biology: flux balance', 'systems biology', 'Other'
            ],
                               value='',
                               description='Abstraction level:',
                               layout={'width': '70%'}))

        self.Widget_List['license'] = interactive(
            self.f,
            x=widgets.RadioButtons(
                options=['Free', 'OpenSource', 'CreativeCommons'],
                description='License'))

        self.Widget_List['version_text'] = interactive(
            self.f,
            x=widgets.HTML(placeholder='',
                           value="<b>Add a Version </b> (optional)",
                           layout={'width': '70%'}))
        self.Widget_List['version_name'] = interactive(self.f,
                                              x=widgets.Text(\
                                                    value='',
                                                    placeholder='e.g. v1.0',
                                                    description='Name:',
                                                    layout={'width':'70%'}))
        self.Widget_List['data_url'] = interactive(self.f_url,
                                                {'manual': True, 'manual_name':'Check data availability'},
                                                  x=widgets.Text(\
                                                    value='',
                                                    placeholder='e.g. https://github.com/name/repo',
                                                    description='URL location:'))
        self.Widget_List['commit_id'] = interactive(self.f_commit,
                                                {'manual': True, 'manual_name':'Check commit'},
                                                  x=widgets.Text(\
                                                    value='',
                                            placeholder='If using version control, please provide a commit ID: e.g. 8e4g23j',
                                              description='Commit:',
                                                                 layout={'width':'70%'}))
        self.Widget_List['version_description'] = interactive(
            self.f,
            x=widgets.Textarea(placeholder='Decribe the version',
                               description='Description:',
                               layout={
                                   'width': '70%',
                                   'height': '150px'
                               }))
        self.Widget_List['version_parameter'] = interactive(
            self.f,
            x=widgets.Textarea(
                placeholder=
                'Specific parameters describing this version ?\ne.g. Vrest=-70mV, T=27deg,...',
                description='Parameters:',
                layout={
                    'width': '70%',
                    'height': '150px'
                }))

        self.Widget_List['submit'] = interactive(
            self.f_submission,
            x=widgets.ToggleButton(
                value=False,
                description=' * -> Submit <- * ',
                disabled=False,
                button_style='',
                # tooltip='Description',
                icon='check',
                layout={
                    'width': '70%',
                    'height': '50px'
                }))
Exemplo n.º 5
0
#config="enm_composite_private.yaml"


def search_service_protected(url, apikey):
    return (url, apikey)


def search_service_open(url):
    return (url)


style = {'description_width': 'initial'}
config, config_servers, config_security, auth_object, msg = aa.parseOpenAPI3(
    config=config)
service_widget = widgets.Dropdown(options=config_servers['url'],
                                  description='Service:',
                                  disabled=False,
                                  style=style)
if config_security is None:
    service = interactive(search_service_open, url=service_widget)
else:
    print(msg)
    apikey_widget = widgets.Text(placeholder='',
                                 description=config_security,
                                 disabled=False,
                                 style=style)
    service = interactive(search_service_protected,
                          url=service_widget,
                          apikey=apikey_widget)

display(service)
Exemplo n.º 6
0
 def __init__(self, store_path):
     self.qf = None
     self.subquery = ""
     self.database = ""
     self.store_path = store_path
     self.label = w.Label("Build Your Subquery")
     self.schema = w.Text(
         value="base_views",
         description="Schema:",
         disabled=False,
         layout=w.Layout(height="auto", width="auto"),
     )
     self.table = w.Text(
         value="sales_monthly_close",
         description="Table:",
         disabled=False,
         layout=w.Layout(height="auto", width="auto"),
     )
     self.engine = w.Text(
         value="mssql+pyodbc://acoe_redshift",
         description="Engine:",
         disabled=False,
         layout=w.Layout(height="auto", width="auto"),
     )
     self.button = w.Button(
         description="Get Columns",
         disabled=False,
         layout=w.Layout(height="auto", width="auto"),
     )
     self.btn_update_store = w.Button(
         description="Update Store",
         disabled=False,
         layout=w.Layout(height="auto", width="auto"),
     )
     self._as = w.Text(
         value="",
         description="As:",
         disabled=False,
         layout=w.Layout(height="auto", width="auto"),
     )
     self.type = w.Dropdown(
         options=["dim", "num", ""], description="Type:", value="dim", disabled=False
     )
     self.group_by = w.Dropdown(
         options=["group", "sum"],
         description="Group By:",
         value="group",
         disabled=False,
     )
     self.order_by = w.Text(
         value="",
         description="Oder By:",
         disabled=False,
         layout=w.Layout(height="auto", width="auto"),
     )
     self.custom_type = w.Text(
         value="",
         description="Custom Type:",
         disabled=False,
         layout=w.Layout(height="auto", width="auto"),
     )
     self.options = None
     self.output = None
Exemplo n.º 7
0
class RED:
    def __init__(self):
        self.path = os.getcwd()
        self.stock_path = os.path.join(self.path, "data/stock")
        self.etf_path = os.path.join(self.path, "data/etf")
        self.users_path = os.path.join(self.path, "data/users")
        if not os.path.isdir(self.stock_path):
            os.makedirs(self.stock_path)
        if not os.path.isdir(self.etf_path):
            os.makedirs(self.etf_path)
        if not os.path.isdir(self.users_path):
            os.makedirs(self.users_path)

        try:
            self.total_info = pd.read_csv(self.path + "/data/users/userDB.csv",
                                          encoding="cp949",
                                          index_col=0)
        except FileNotFoundError:
            print('"userDB.csv" 파일을 찾을 수 없습니다. 먼저 userDB를 생성하겠습니다.')
            df = pd.DataFrame(columns=(
                "투자 금액(만 원)",
                "투자 기간",
                "나이",
                "성별",
                "월 정기 수입(만 원)",
                "관심산업분야",
                "금융지식수준",
                "위험추구성향",
                "주식",
                "채권",
                "ETF",
                "날짜",
            ))
            df.to_csv(self.path + "/data/users/userDB.csv", encoding="cp949")
            self.total_info = pd.read_csv(self.path + "/data/users/userDB.csv",
                                          encoding="cp949",
                                          index_col=0)

        self.stock_data = os.listdir(self.path + "/data/stock")
        self.etf_data = os.listdir(self.path + "/data/etf")
        self.start = widgets.Button(description="투자 시작")
        self.to_home_button = widgets.Button(description="뒤로 가기")
        self.crawl_setting = widgets.Button(description="데이터 업데이트")
        self.save = widgets.Button(description="결과 저장")
        self.fontpath = self.path + "/red/interface/font/NanumSquareB.ttf"

    def RED_start(self, change):
        """ "투자 시작" 클릭시 다른 모든 함수들이 실행될 주요함수"""
        self.user_info = [
            RED.capital.value,
            RED.term_dropdown.value,
            RED.age.value,
            RED.gender_dropdown.value,
            RED.income.value,
            RED.sector.value,
            RED.know.value,
            RED.risk.value,
        ]
        clear_output()

        print("입력이 완료되었습니다, 투자자 성향을 판단중입니다")
        print("···")
        time.sleep(1.5)

        self.disposition_viz()
        # 성향을 보고 자본배분 비율 선정
        # 각각 추천 -> 주식: 기간, 알고리즘 고려 / etf: 기간, 수익률, 관심분야 고려
        self.portfolios = self.mk_portfolio()
        # 추천 결과 출력 후 DB 만들고 저장.
        display(self.save)
        self.save.on_click(self.save_info)

    def save_info(self, portfolios):
        df = pd.DataFrame(
            np.array(self.user_info).reshape(1, 8),
            columns=[
                "투자 금액(만 원)",
                "투자 기간",
                "나이",
                "성별",
                "월 정기 수입(만 원)",
                "관심산업분야",
                "금융지식수준",
                "위험추구성향",
            ],
        )

        df["주식"] = [list(self.portfolios[0].items())]
        df["채권"] = [list(self.portfolios[1].items())]
        df["ETF"] = [list(self.portfolios[2].items())]
        df["날짜"] = date.today()
        df = pd.concat([self.total_info, df], ignore_index=True)
        df.to_csv(self.path + "/data/users/userDB.csv", encoding="cp949")
        print("저장되었습니다.")

    def mk_portfolio(self):
        """포트폴리오 만드는 함수, r1: ETF비율, r2 : 채권 비율"""
        capital = self.user_info[0] * 10000
        if self.user_info[7] == self.risk_list[0]:
            r1 = 1
            r2 = 0.67
        elif self.user_info[7] == self.risk_list[1]:
            r1 = 0.8
            r2 = 0.4
        elif self.user_info[7] == self.risk_list[2]:
            r1 = 0.6
            r2 = 0.3
        elif self.user_info[7] == self.risk_list[3]:
            r1 = 0.4
            r2 = 0.1
        elif self.user_info[7] == self.risk_list[4]:
            r1 = 0.2
            r2 = 0

        if self.user_info[1] == self.term_list[0] or self.user_info[
                1] == self.term_list[1]:
            r2 = 0  # 투자 기간이 짧으면 채권 제외

        real_r0 = int((1 - r1) * 100)
        real_r1 = int((r1 - r2) * 100)
        real_r2 = int(r2 * 100)

        recommender = Recommender(self.path, self.stock_path, self.etf_path,
                                  self.user_info[5])

        recommender.cal_weight()
        rec_stock_lst = recommender.rec_stock()

        df = pd.read_csv(self.path + "/data/stock_list2.csv", encoding="cp949")
        names = [i[0] for i in rec_stock_lst]
        a = list(df[df["종목명"].isin(names)][["종목명", "가중치"]].sort_values(
            by="가중치", ascending=False).종목명.values)
        rec_stock_lst.sort(key=lambda x: a.index(x[0]))
        # print(rec_stock_lst)

        # 중복의 경우 처리필요

        res_etf1, res_etf2 = recommender.rec_etf()
        print("\n\n고객님의 포트폴리오입니다.\n")

        주식리스트 = []
        채권리스트 = []
        일반리스트 = []

        주식별금액리스트 = []
        채권별금액리스트 = []
        일반별금액리스트 = []

        self.portfolios1, penny1 = self.dist(capital, rec_stock_lst, 1 - (r1),
                                             10)
        print("\n주식 종목 : {}원\n".format(capital * (1 - r1) - penny1))
        for name, info in self.portfolios1.items():
            print("{}, {}개 매입. {} 전략. 현재가: {}".format(name, info[0],
                                                      info[1][1], info[1][0]))
            주식리스트.append(name)
            주식별금액리스트.append(info[1])

        self.portfolios2, penny2 = self.dist(capital + penny1, res_etf1, r2, 5)
        print("\n채권 ETF 종목 : {}원\n".format((capital + penny1) * r2 - penny2))
        for name, info in self.portfolios2.items():
            print("{}, {}개 매입.기간 내 보유 권장. 현재가: {}".format(
                name, info[0], info[1][0]))
            채권리스트.append(name)
            채권별금액리스트.append(info[1])

        self.portfolios3, penny3 = self.dist(capital + penny2, res_etf2,
                                             r1 - r2, 5)
        print("\n일반 ETF 종목 : {}원\n".format((capital + penny2) * (r1 - r2) -
                                           penny3))
        for name, info in self.portfolios3.items():
            print("{}, {}개 매입. 20일 후 리밸런싱 권장. 현재가: {}".format(
                name, info[0], info[1][0]))
            일반리스트.append(name)
            채권별금액리스트.append(info[1])

        # 포트폴리오 1번 보여주기
        self.portfolio_viz()

        ## 포트폴리오 상세정보
        주식금액 = capital * (1 - r1) - penny1
        채권금액 = (capital + penny1) * r2 - penny2
        일반금액 = (capital + penny2) * (r1 - r2) - penny3

        # 막대 그래프 생성
        kindx = ["주식", "일반 ETF", "채권 ETF"]
        values = [주식금액, 일반금액, 채권금액]
        colors = ["silver", "gold", "lightgray"]

        fm.get_fontconfig_fonts()
        font_name = fm.FontProperties(fname=self.fontpath).get_name()
        plt.rc("font", family=font_name, size=20)

        fig = plt.figure(figsize=(7, 7))
        plt.bar(kindx, values, width=0.6, color=colors, edgecolor="lightgray")

        plt.savefig(self.path + "/red/interface/image/portfolio/bar_chart.png")
        plt.close()

        # 경로별 이미지 불러오기
        im_tend = Image.open(self.path +
                             "/red/interface/image/portfolio/red_3.png")
        im_chart = Image.open(self.path +
                              "/red/interface/image/portfolio/bar_chart.png")
        font = ImageFont.truetype(self.fontpath, 24)

        # 칼라 설정
        b, g, r, a = 0, 0, 0, 0

        # 이미지에 텍스트 삽입
        draw = ImageDraw.Draw(im_tend)

        if real_r0 == 80:  # 80 : 20 : 00
            try:
                draw.text((635, 120),
                          str(주식리스트[0]),
                          font=font,
                          fill=(b, g, r, a))
            except:
                draw.text((0, 0), "", font=font, fill=(b, g, r, a))
            try:
                draw.text((635, 164.333),
                          str(주식리스트[1]),
                          font=font,
                          fill=(b, g, r, a))
            except:
                draw.text((0, 0), "", font=font, fill=(b, g, r, a))
            try:
                draw.text((635, 208.666),
                          str(주식리스트[2]),
                          font=font,
                          fill=(b, g, r, a))
            except:
                draw.text((0, 0), "", font=font, fill=(b, g, r, a))
            try:
                draw.text((635, 253),
                          str(주식리스트[3]),
                          font=font,
                          fill=(b, g, r, a))
            except:
                draw.text((0, 0), "", font=font, fill=(b, g, r, a))
            try:
                draw.text((635, 297.333),
                          str(주식리스트[4]),
                          font=font,
                          fill=(b, g, r, a))
            except:
                draw.text((0, 0), "", font=font, fill=(b, g, r, a))
            try:
                draw.text((635, 341.666),
                          str(일반리스트[0]),
                          font=font,
                          fill=(b, g, r, a))
            except:
                draw.text((0, 0), "", font=font, fill=(b, g, r, a))
            try:
                draw.text((635, 386),
                          str(일반리스트[1]),
                          font=font,
                          fill=(b, g, r, a))
            except:
                draw.text((0, 0), "", font=font, fill=(b, g, r, a))
            try:
                draw.text((805, 430.333), "···", font=font, fill=(b, g, r, a))
            except:
                draw.text((0, 0), "", font=font, fill=(b, g, r, a))
        elif real_r0 == 60:  # 60 : 30 : 10
            if real_r2 == 0:
                try:
                    draw.text((635, 120),
                              str(주식리스트[0]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 164.333),
                              str(주식리스트[1]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 208.666),
                              str(주식리스트[2]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 253),
                              str(주식리스트[3]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 297.333),
                              str(일반리스트[0]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 341.666),
                              str(일반리스트[1]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 386),
                              str(일반리스트[2]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((805, 430.333),
                              "···",
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
            else:
                try:
                    draw.text((635, 120),
                              str(주식리스트[0]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 164.333),
                              str(주식리스트[1]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 208.666),
                              str(주식리스트[2]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 253),
                              str(주식리스트[3]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 297.333),
                              str(채권리스트[0]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 341.666),
                              str(채권리스트[1]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 386),
                              str(일반리스트[0]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((805, 430.333),
                              "···",
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
        elif real_r0 == 40:  # 40 : 30 : 30
            if real_r2 == 0:
                try:
                    draw.text((635, 120),
                              str(주식리스트[0]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 164.333),
                              str(주식리스트[1]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 208.666),
                              str(주식리스트[2]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 253),
                              str(일반리스트[0]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 297.333),
                              str(일반리스트[1]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 341.666),
                              str(일반리스트[2]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 386),
                              str(일반리스트[3]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((805, 430.333),
                              "···",
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
            else:
                try:
                    draw.text((635, 120),
                              str(주식리스트[0]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 164.333),
                              str(주식리스트[1]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 208.666),
                              str(주식리스트[2]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 253),
                              str(채권리스트[0]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 297.333),
                              str(채권리스트[1]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 341.666),
                              str(일반리스트[0]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 386),
                              str(일반리스트[1]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((805, 430.333),
                              "···",
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
        elif real_r0 == 19:  # 19 : 40 : 40
            if real_r2 == 0:
                try:
                    draw.text((635, 120),
                              str(주식리스트[0]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 164.333),
                              str(주식리스트[1]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 208.666),
                              str(일반리스트[0]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 253),
                              str(일반리스트[1]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 297.333),
                              str(일반리스트[2]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 341.666),
                              str(일반리스트[3]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 386),
                              str(일반리스트[4]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((805, 430.333),
                              "···",
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
            else:
                try:
                    draw.text((635, 120),
                              str(주식리스트[0]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 164.333),
                              str(주식리스트[1]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 208.666),
                              str(채권리스트[0]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 253),
                              str(채권리스트[1]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 297.333),
                              str(채권리스트[2]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 341.666),
                              str(일반리스트[0]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 386),
                              str(일반리스트[1]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((805, 430.333),
                              "···",
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
        elif real_r0 == 0:  # 0 : 33 : 67
            if real_r2 == 0:
                try:
                    draw.text((635, 120),
                              str(일반리스트[0]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 164.333),
                              str(일반리스트[1]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 208.666),
                              str(일반리스트[2]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 253),
                              str(일반리스트[3]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 297.333),
                              str(일반리스트[4]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
            else:
                try:
                    draw.text((635, 120),
                              str(채권리스트[0]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 164.333),
                              str(채권리스트[1]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 208.666),
                              str(채권리스트[2]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 253),
                              str(일반리스트[0]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 297.333),
                              str(일반리스트[1]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 341.666),
                              str(일반리스트[2]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((635, 386),
                              str(일반리스트[3]),
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))
                try:
                    draw.text((805, 430.333),
                              "···",
                              font=font,
                              fill=(b, g, r, a))
                except:
                    draw.text((0, 0), "", font=font, fill=(b, g, r, a))

        # 이미지에 파이차트 삽입
        im_tend.paste(im_chart, (30, 10))

        display(im_tend)

        # 마무리
        # portfolios4 = dict(portfolios1, **portfolios2)
        # portfolios4.update(portfolios3)
        return self.portfolios1, self.portfolios2, self.portfolios3

    def dist(self, capital, asset, pro, max_num):
        """자본 배분 알고리즘 (자본, 리스트, 비율, 최대종류)"""
        limit = capital * pro  # 최대 금액
        amount = 0  # 금액
        res = dict()  # 포트폴리오

        while True:
            more = False  # 더 넣을 값이 있는가?
            for i in range(len(asset)):
                if len(res) >= max_num and asset[i][
                        0] not in res:  # 최대 종류 수까지 담았다면
                    break
                if limit >= amount + asset[i][1]:  # 최대금액 미만이라면
                    amount += asset[i][1]
                    res.setdefault(asset[i][0], [0, asset[i][1:]])
                    res[asset[i][0]][0] += 1
                    more = True

            # 더 못 넣는다면
            if more == False:
                break
        # print("배분가능 금액 : ",limit,"실제 배분금액 : ", amount)
        return res, limit - amount

    def data_setting(self, change):  # 실시간 종목추천을 위한 최근 데이터 크롤링 및 전처리
        print("실시간 주가 데이터를 불러오는 중입니다... (약 5분~8분 소요)")
        self.crawling_start()
        print("데이터를 처리합니다.")
        time.sleep(1)
        self.preprocess_start()

    def clear_all(self, change):
        clear_output()  # "뒤로 가기" 클릭시 인터페이스 종료

    def run(self):  # 인터페이스 및 프로그램 실행

        for i in self.user_buttons:
            display(i)

        display(self.crawl_setting)
        display(self.start)
        display(self.to_home_button)
        print("데이터 업데이트를 하신 후, 입력하신 정보를 확인하시고 투자 시작을 눌러주세요.")
        self.start.on_click(self.RED_start)
        self.to_home_button.on_click(self.clear_all)
        self.crawl_setting.on_click(self.data_setting)

    def crawling_start(self):
        scraper = Scraper()
        scraper.runAll()

    def preprocess_start(self):
        for i in tqdm(os.listdir(self.path + "/data/stock")):
            data_dir = self.path + "/data/stock/" + i
            stock_df = pd.read_csv(data_dir, index_col=0, encoding="cp949")
            stock_preprocess = Indicator(stock_df)
            stock_preprocess.runAll()
            stock_df.to_csv(data_dir, encoding="cp949")

        for i in tqdm(os.listdir(self.path + "/data/etf")):
            data_dir = self.path + "/data/etf/" + i
            etf_df = pd.read_csv(data_dir, index_col=0, encoding="cp949")
            etf_preprocess = Indicator(etf_df)
            etf_preprocess.runAll()
            etf_df.to_csv(data_dir, encoding="cp949")
        print("데이터 업데이트가 완료되었습니다.")

    term_list = ["1주 ~ 1개월", "1개월 ~ 6개월", "6개월 ~ 1년", "1년 이상"]
    sector_list = [
        "건설",
        "금융",
        "기계",
        "IT",
        "운수창고",
        "운수장비",
        "유통",
        "의약",
        "전기전자",
        "철강금속",
        "화학",
        "통신",
        "상관없음",
    ]
    know_list = [
        "금융투자상품에 투자해 본 경험이 없음",
        "널리 알려진 금융투자 상품(주식, 채권 및 펀드 등)의 구조 및 위험을 일정 부분 이해하고 있음",
        "널리 알려진 금융투자 상품(주식, 채권 및 펀드 등)의 구조 및 위험을 깊이 있게 이해하고 있음",
        "파생상품을 포함한 대부분의 금융투자상품의 구조 및 위험을 이해하고 있음",
    ]
    risk_list = [
        "예금 또는 적금 수준의 수익률을 기대 / 투자원금의 손실을 원하지 않음",
        "투자원금의 손실 위험을 최소화하고, 안정적인 투자를 목표 / 예금ㆍ적금보다 높은 수익을 위해 단기적인 손실정도는 수용할 수 있고, 자산 중 일부를 위험자산에 투자할 의향이 있음",
        "예금ㆍ적금보다 높은 수익을 기대할 수 있다면 위험을 감수하고 투자할 의향이 있음",
        "투자원금의 보전보다 수익을 추구 / 투자자금의 대부분을 주식, 옵션 등의 위험자산에 투자할 의향이 있음",
        "시장 평균 수익률을 넘어서는 높은 수준의 투자 수익 추구 / 투자자금의 대부분을 주식, 옵션 등의 위험자산에투자할 의향이 있음",
    ]

    style = {"description_width": "initial"}

    capital = widgets.BoundedIntText(
        min=1,
        max=10000,
        value=300,
        continuous_update=True,
        description="투자 금액(만 원)",
        disabled=False,
        style=style,
    )
    term_dropdown = widgets.Dropdown(description="투자 기간 ",
                                     options=term_list,
                                     disabled=False,
                                     style=style)

    age = widgets.BoundedIntText(min=10,
                                 max=100,
                                 value=20,
                                 disabled=False,
                                 description="나이 (만)",
                                 style=style)
    gender_dropdown = widgets.Dropdown(description="성별 ",
                                       options=["남", "여"],
                                       disabled=False,
                                       style=style)

    income = widgets.FloatText(value=100,
                               continuous_update=True,
                               description="월 정기 수입(만 원)",
                               disabled=False,
                               style=style)

    sector = widgets.Dropdown(
        options=sector_list,
        description="관심산업분야",
        disabled=False,
        continuous_update=False,
        layout={"width": "max-content"},
        readout=True,
        style=style,
    )
    know = widgets.Dropdown(
        options=know_list,
        description="금융지식수준",
        disabled=False,
        continuous_update=False,
        layout={"width": "max-content"},
        readout=True,
        style=style,
    )
    risk = widgets.Dropdown(
        options=risk_list,
        description="위험추구성향",
        disabled=False,
        continuous_update=False,
        layout={"width": "max-content"},
        readout=True,
        style=style,
    )
    user_buttons = [
        capital, term_dropdown, age, gender_dropdown, income, sector, know,
        risk
    ]

    def disposition_viz(self):  # 투자 성향 시각화 및 정보확인

        # 경로
        folder_path = ["age/age_", "period/", "sex/", "tend/"]
        extension_path = ".png"

        # 투자성향 파일명
        if self.user_info[7] == self.risk_list[0]:
            tend = "info5"
        elif self.user_info[7] == self.risk_list[1]:
            tend = "info4"
        elif self.user_info[7] == self.risk_list[2]:
            tend = "info3"
        elif self.user_info[7] == self.risk_list[3]:
            tend = "info2"
        elif self.user_info[7] == self.risk_list[4]:
            tend = "info1"

        # 경로별 이미지 불러오기
        im_tend = Image.open(self.path + "/red/interface/image/" +
                             folder_path[3] + tend + extension_path)
        font = ImageFont.truetype(self.fontpath, 22)

        # 칼라 설정
        b, g, r, a = 0, 0, 0, 0

        # 이미지에 텍스트 삽임
        draw = ImageDraw.Draw(im_tend)
        draw.text((162, 352),
                  str(self.user_info[2]) + ("세"),
                  font=font,
                  fill=(b, g, r, a))
        draw.text((162, 391),
                  str(self.user_info[3]) + ("자"),
                  font=font,
                  fill=(b, g, r, a))
        draw.text((202, 429.5),
                  str(self.user_info[1]),
                  font=font,
                  fill=(b, g, r, a))
        draw.text((202, 467),
                  str(self.user_info[0]) + ("만원"),
                  font=font,
                  fill=(b, g, r, a))
        draw.text((249.3, 506),
                  str(self.user_info[5]),
                  font=font,
                  fill=(b, g, r, a))
        display(im_tend)

    def portfolio_viz(self):
        self.to_home_button.on_click(self.RED_start)

        if (self.user_info[6] == self.know_list[0]) or (self.user_info[6]
                                                        == self.know_list[1]):
            danger = Image.open(self.path +
                                "/red/interface/image/portfolio/위험고지.png")
            display(danger)

        # 관심 산업 상관관계 보여주기
        if self.user_info[5] == self.sector_list[0]:
            s1 = Image.open(self.path +
                            "/red/interface/image/industry/건설양.png")
            s2 = Image.open(self.path +
                            "/red/interface/image/industry/건설음.png")
            display(s1)
            display(s2)
        elif self.user_info[5] == self.sector_list[5]:
            s3 = Image.open(self.path +
                            "/red/interface/image/industry/운수장비음.png")
            display(s3)
        elif self.user_info[5] == self.sector_list[7]:
            s4 = Image.open(self.path +
                            "/red/interface/image/industry/의약음.png")
            display(s4)

        # 포트폴리오 비율
        capital = self.user_info[0] * 10000
        if self.user_info[7] == self.risk_list[0]:
            r1 = 1
            r2 = 0.67
        elif self.user_info[7] == self.risk_list[1]:
            r1 = 0.8
            r2 = 0.4
        elif self.user_info[7] == self.risk_list[2]:
            r1 = 0.6
            r2 = 0.3
        elif self.user_info[7] == self.risk_list[3]:
            r1 = 0.4
            r2 = 0.1
        elif self.user_info[7] == self.risk_list[4]:
            r1 = 0.2
            r2 = 0

        if self.user_info[1] == self.term_list[0] or self.user_info[
                1] == self.term_list[1]:
            r2 = 0

        real_r0 = int((1 - r1) * 100)
        real_r1 = int((r1 - r2) * 100)
        real_r2 = int(r2 * 100)

        p_profit = 0
        p_sigma = 0
        p_num = 0
        p_ratio = 0
        for equity in (self.portfolios1, self.portfolios2, self.portfolios3):
            p_num += 1
            if p_num == 1:
                p_ratio = 1 - r1
            elif p_num == 2:
                p_ratio = r2
            else:
                p_ratio = r1 - r2
            cnt = 0
            profit = 0
            sigma = 0

            for name, info in equity.items():
                cnt += info[0]
                profit += info[1][-2] * info[0]
                sigma += info[1][-1] * info[0]
            if cnt > 0:
                profit /= cnt
                sigma /= cnt

            p_profit += profit * p_ratio
            p_sigma += sigma * p_ratio

        수익률 = round(((1 + p_profit / 100)**12 - 1) * 100, 2)
        표준편차 = round(p_sigma * 100, 2)

        # 파이 차트 생성
        if r2 == 0:
            ratio = [real_r0, real_r1]
            labels = ["주식", "일반 ETF"]
            colors = ["silver", "gold"]
            wedgeprops = {"width": 0.7, "edgecolor": "w", "linewidth": 5}

            fm.get_fontconfig_fonts()
            font_name = fm.FontProperties(fname=self.fontpath).get_name()
            matplotlib.rc("font", family=font_name)

            fig = plt.figure(figsize=(7, 7))

            plt.pie(
                ratio,
                labels=labels,
                startangle=90,
                autopct="%.0f%%",
                shadow=True,
                textprops={"fontsize": 20},
                colors=colors,
                wedgeprops=wedgeprops,
            )
            if real_r0 == 19:
                plt.legend(labels, fontsize=13, loc="lower left")
            else:
                plt.legend(labels, fontsize=13, loc="upper left")
            plt.savefig(self.path +
                        "/red/interface/image/portfolio/pie_chart.png")
            plt.close()
        else:
            ratio = [real_r0, real_r1, real_r2]
            labels = ["주식", "일반 ETF", "채권 ETF"]
            colors = ["silver", "gold", "lightgray"]
            wedgeprops = {"width": 0.7, "edgecolor": "w", "linewidth": 5}

            fm.get_fontconfig_fonts()
            font_name = fm.FontProperties(fname=self.fontpath).get_name()
            matplotlib.rc("font", family=font_name)

            fig = plt.figure(figsize=(7, 7))

            plt.pie(
                ratio,
                labels=labels,
                startangle=90,
                autopct="%.0f%%",
                shadow=True,
                textprops={"fontsize": 20},
                colors=colors,
                wedgeprops=wedgeprops,
            )
            if real_r0 == 19:
                plt.legend(labels, fontsize=13, loc="lower right")
            else:
                plt.legend(labels, fontsize=13, loc="lower left")
            plt.savefig(self.path +
                        "/red/interface/image/portfolio/pie_chart.png")
            plt.close()

        # 경로별 이미지 불러오기
        im_tend = Image.open(self.path +
                             "/red/interface/image/portfolio/red.png")
        im_chart = Image.open(self.path +
                              "/red/interface/image/portfolio/pie_chart.png")
        font = ImageFont.truetype(self.fontpath, 22)

        # 칼라 설정
        b, g, r, a = 0, 0, 0, 0

        # 이미지에 텍스트 삽입
        draw = ImageDraw.Draw(im_tend)
        draw.text((228, 80.5),
                  "연 " + str(수익률) + "% 내외 추구",
                  font=font,
                  fill=(b, g, r, a))
        draw.text((228, 244),
                  "평균 위험률 연 " + str(표준편차) + "%",
                  font=font,
                  fill=(b, g, r, a))
        draw.text((228, 405),
                  "전체 주식 비중 " + str(real_r0) + "% 수준",
                  font=font,
                  fill=(b, g, r, a))

        # 이미지에 파이차트 삽입
        im_tend.paste(im_chart, (510, 10))

        display(im_tend)
Exemplo n.º 8
0
    def __init__(self, df):
        """
        + initialize class with dataframe
        + initiatlive all ipywidgets
        """
        self.df = df
        self.split_param = ' - * - '

        self.creative_types = ('traffic driver', 'interactive non video',
                               'branded driver', 'video', 'interactive video',
                               'no match')

        self.df['advert_order'] = self.df[
            'Advertiser'] + self.split_param + self.df['Order']

        self.AO_dropdown = ipywidgets.Dropdown(
            options=sorted(set(self.df['advert_order'])),
            value=list(sorted(set(self.df['advert_order'])))[0],
            disabled=False)

        self.site_dropdown = ipywidgets.Dropdown(options=['qz', 'wrk', 'zty'],
                                                 value='qz',
                                                 disabled=False)

        self.placement_dropdown = ipywidgets.Dropdown(options=[
            'engage mobile', 'engage desktop', 'marquee mobile',
            'marquee desktop', 'inline mobile', 'inline desktop'
        ],
                                                      value='engage mobile',
                                                      disabled=False)

        self.creative_type_dropdown = ipywidgets.Dropdown(
            options=self.creative_types,
            value=self.creative_types[0],
            disabled=False)

        self.metric_measurement = ipywidgets.Dropdown(
            options=['DFP CTR', '3P CTR', 'Viewability', 'VSR', 'IR'],
            value='DFP CTR',
            disabled=False)

        self.d1_DatePicker = ipywidgets.DatePicker(disabled=False)
        self.d2_DatePicker = ipywidgets.DatePicker(disabled=False)

        #CNV - creative.name.version
        self.CNV_multiple = ipywidgets.SelectMultiple(
            options=sorted(set(
                self.df['creative.name.version'].fillna('None'))),
            value=[],
            rows=3,
            description='creative.name.version',
            disabled=False,
            layout=ipywidgets.Layout(width='50%', height='280px'))

        self.aggregate_checkbox = ipywidgets.Checkbox(
            value=False, description='Display aggregate', disabled=False)

        self.button = ipywidgets.Button(description="CHART IT !",
                                        layout=ipywidgets.Layout(
                                            width='100%', height='55px'))

        self.left_box = ipywidgets.VBox([
            self.AO_dropdown, self.site_dropdown, self.placement_dropdown,
            self.creative_type_dropdown, self.metric_measurement,
            self.d1_DatePicker, self.d2_DatePicker, self.aggregate_checkbox,
            self.button
        ])

        self.display = ipywidgets.HBox([self.left_box, self.CNV_multiple])
Exemplo n.º 9
0
 def _create_indicator_dropdown(self, indicators, initial_index):
     dropdown = widgets.Dropdown(options=indicators,
                                 value=indicators[initial_index])
     dropdown.observe(self._on_change, names=['value'])
     return dropdown
Exemplo n.º 10
0
 def _make_layout_selector(self):
     widget = W.Dropdown(description="Layout:", options=self.layouts)
     T.link((self, "cyto_layout"), (widget, "value"))
     return widget
Exemplo n.º 11
0
    disabled=False
)


strand_widget = widgets.RadioButtons(
    options=['+','-'],
    value=defaultstrand,
    description='Strand:',
    disabled=False
)


geneid_widget = widgets.Dropdown(
        options=[defaultgeneid],
        value=defaultgeneid,
        description='GeneID:',
        disabled=False,
        button_style='' # 'success', 'info', 'warning', 'danger' or ''
    )

refseqid_widget = widgets.Dropdown(
        options=[defaultrefseqid],
        value=defaultrefseqid,
        description='RefseqID:',
        disabled=False,
        button_style='' # 'success', 'info', 'warning', 'danger' or ''
    )


## Updating Widgets ##
Exemplo n.º 12
0
def create_gui(geometry=None,
               callback=None,
               opts_choice=None,
               opts_range=None,
               opts_color=None,
               initial_values=None,
               layout=None,
               height=400,
               width=400,
               background='gray',
               orthographic=False,
               camera_position=[0, 0, -10],
               view=(10, -10, -10, 10),
               fov=50,
               add_objects=True,
               add_labels=True,
               show_object_info=False,
               otype_column=None,
               jslink=True):
    """ creates simple gui to visualise 3d geometry,
    with a callback to update geometry according to option widgets 

    Properties
    ----------
    geometry : pandas3js.models.GeometricCollection
    callback : function
        callback(GeometricCollection, options_dict)
    opts_choice : None or dict
        {opt_name:(initial, list)} create dropdown boxes with callbacks to callback
    opts_range : None or dict
        {opt_name:(initial, list)} create select slider with callbacks to callback
    opts_color : None or list
        {opt_name:init_color,...} create select color palette with callbacks to callback
    inital_values : None or dict
        initial values for options (default is first value of list)
    layout : None or list
        (tab_name,[option_name, ...]) pairs, 
        if nested list, then these will be vertically aligned
        by default all go in 'Other' tab
    height : int
        renderer height
    width : int
        renderer width
    background : str
        renderer background color (html)
    orthographic : bool
        use orthographic camera (True) or perspective (False) 
    camera_position : tuple
        position of camera in scene
    view : tuple
        initial view extents (top,bottom,left,right) (orthographic only)
    fov : float
        camera field of view (perspective only)
    add_objects : bool
        add objects to scene
    add_labels : bool
        add object labels to scene
    show_object_info : bool
        if True, show coordinate of object under mouse (currently only works for Perspective)
    jslink : bool
        if True, where possible, create client side links
        http://ipywidgets.readthedocs.io/en/latest/examples/Widget%20Events.html#The-difference-between-linking-in-the-kernel-and-linking-in-the-client     
    
    Returns
    -------
    gui : widgets.Box
        containing rendered scene and option widgets
    gcollect : pandas3js.GeometricCollection
        the collection of current geometric objects
    options_view : dict_items
        a view of the current options values
        
    Examples
    --------

    >>> import pandas3js as pjs
    >>> import pandas as pd
    >>> data = {1:{'id':[0],'position':[(0,0,0)],
    ...              'c1':'red','c2':'blue'},
    ...         2:{'id':[0],'position':[(1,2,3)],
    ...               'c1':'red','c2':'blue'}}
    ...
    >>> def callback(geometry,options):
    ...     df = pd.DataFrame(data[options['config']])
    ...     ctype = options.get('color','c1')
    ...     df['color'] = df[ctype]
    ...     df['label'] = 'myobject'
    ...     df['otype'] = 'pandas3js.models.Sphere'
    ...     geometry.change_by_df(df[['id','position','otype',
    ...                               'color','label']],otype_column='otype')
    ...
    >>> gui, collect, opts = pjs.views.create_gui(callback=callback,
    ...                     opts_choice={'color':['c1','c2']},
    ...                     opts_range={'config':[1,2]})
    ...
    >>> [pjs.utils.obj_to_str(c) for c in gui.children]
    ['ipywidgets.widgets.widget_selectioncontainer.Tab', 'pythreejs.pythreejs.Renderer']
    >>> collect.trait_df().loc[0]
    color                                              red
    groups                                          (all,)
    id                                                   0
    label                                         myobject
    label_color                                        red
    label_transparency                                   1
    label_visible                                    False
    other_info                                            
    otype                 pandas3js.models.idobject.Sphere
    position                               (0.0, 0.0, 0.0)
    radius                                               1
    transparency                                         1
    visible                                           True
    Name: 0, dtype: object
    >>> config_select = gui.children[0].children[1].children[1].children[1]
    >>> pjs.utils.obj_to_str(config_select)
    'ipywidgets.widgets.widget_selection.SelectionSlider'
    >>> config_select.value = 2
    >>> collect.trait_df().loc[0]
    color                                              red
    groups                                          (all,)
    id                                                   0
    label                                         myobject
    label_color                                        red
    label_transparency                                   1
    label_visible                                    False
    other_info                                            
    otype                 pandas3js.models.idobject.Sphere
    position                               (1.0, 2.0, 3.0)
    radius                                               1
    transparency                                         1
    visible                                           True
    Name: 0, dtype: object
    >>> color_select = gui.children[0].children[1].children[1].children[0]
    >>> pjs.utils.obj_to_str(color_select)
    'ipywidgets.widgets.widget_selection.ToggleButtons'
    >>> color_select.value = 'c2'
    >>> collect.trait_df().loc[0]
    color                                             blue
    groups                                          (all,)
    id                                                   0
    label                                         myobject
    label_color                                        red
    label_transparency                                   1
    label_visible                                    False
    other_info                                            
    otype                 pandas3js.models.idobject.Sphere
    position                               (1.0, 2.0, 3.0)
    radius                                               1
    transparency                                         1
    visible                                           True
    Name: 0, dtype: object
    
    """
    ## intialise options
    init_vals = {} if initial_values is None else initial_values

    opts_choice = {} if opts_choice is None else opts_choice
    all_options = {
        label: init_vals[label] if label in init_vals else options[0]
        for label, options in opts_choice.items()
    }
    opts_range = {} if opts_range is None else opts_range
    all_options.update({
        label: init_vals[label] if label in init_vals else options[0]
        for label, options in opts_range.items()
    })
    opts_color = {} if opts_color is None else opts_color
    all_options.update({
        label: init_vals[label] if label in init_vals else init
        for label, init in opts_color.items()
    })

    if len(all_options
           ) != len(opts_choice) + len(opts_range) + len(opts_color):
        raise ValueError(
            'options in opts_choice, opts_slide, and opts_color are not unique'
        )

    ## intialise layout
    layout = [] if layout is None else layout
    layout_dict = OrderedDict(layout)
    if len(layout_dict) != len(layout):
        raise ValueError('layout tab names are not unique')

    ## initialise renderer
    if geometry is None:
        gcollect = pjs.models.GeometricCollection()
    else:
        gcollect = geometry
    scene = pjs.views.create_js_scene_view(gcollect,
                                           add_objects=add_objects,
                                           add_labels=add_labels,
                                           jslink=jslink)
    camera, renderer = pjs.views.create_jsrenderer(
        scene,
        orthographic=orthographic,
        camera_position=camera_position,
        view=view,
        fov=fov,
        height=height,
        width=width,
        background=background)

    ## create minimal callback
    if callback is None:

        def callback(geometry, options):
            return

    ## initialise geometry in renderer
    with renderer.hold_trait_notifications():
        callback(gcollect, all_options)

    ## Create controls and callbacks
    controls = {}

    # a check box for showing labels
    if add_labels:
        toggle = widgets.Checkbox(value=False, description='View Label:')

        def handle_toggle(change):
            for obj in gcollect.idobjects:
                obj.label_visible = change.new

        toggle.observe(handle_toggle, names='value')
        controls['View Label'] = toggle

    # zoom sliders for orthographic
    if orthographic:
        top, bottom, left, right = view
        axiszoom = widgets.FloatSlider(
            value=0,
            min=-10,
            max=10,
            step=0.1,
            description='zoom',
            continuous_update=True,
        )

        def handle_axiszoom(change):
            if change.new > 1:
                zoom = 1. / change.new
            elif change.new < -1:
                zoom = -change.new
            else:
                zoom = 1
            with renderer.hold_trait_notifications():
                camera.left = zoom * left
                camera.right = zoom * right
                camera.top = zoom * top
                camera.bottom = zoom * bottom

        axiszoom.observe(handle_axiszoom, names='value')

        controls['Orthographic Zoom'] = axiszoom

    # add additional options

    dd_min = 4  # min amount of options before switch to toggle buttons
    for label in opts_choice:
        options = opts_choice[label]
        initial = init_vals[label] if label in init_vals else options[0]
        assert initial in list(
            options), "initial value {0} for {1} not in range: {2}".format(
                initial, label, list(options))
        if (len(options) == 2 and True in options and False in options
                and isinstance(options[0], bool)
                and isinstance(options[1], bool)):
            ddown = widgets.Checkbox(value=initial, description=label)
        elif len(options) < dd_min:
            ddown = widgets.ToggleButtons(options=list(options),
                                          description=label,
                                          value=initial)
        else:
            ddown = widgets.Dropdown(options=list(options),
                                     description=label,
                                     value=initial)
        handle = _create_callback(renderer, ddown, callback, gcollect,
                                  all_options)
        ddown.observe(handle, names='value')

        controls[label] = ddown

    for label in opts_range:
        options = opts_range[label]
        initial = init_vals[label] if label in init_vals else options[0]
        assert initial in list(
            options), "initial value {0} for {1} not in range: {2}".format(
                initial, label, list(options))
        slider = widgets.SelectionSlider(description=label,
                                         value=initial,
                                         options=list(options),
                                         continuous_update=False)
        handle = _create_callback(renderer, slider, callback, gcollect,
                                  all_options)
        slider.observe(handle, names='value')

        controls[label] = slider

    for label in opts_color:
        option = init_vals[label] if label in init_vals else opts_color[label]
        color = widgets.ColorPicker(description=label,
                                    value=option,
                                    concise=False)
        handle = _create_callback(renderer, color, callback, gcollect,
                                  all_options)
        color.observe(handle, names='value')

        controls[label] = slider

    # add mouse hover information box
    # TODO doesn't work for orthographic https://github.com/jovyan/pythreejs/issues/101
    if not orthographic and show_object_info:
        # create information box
        click_picker = tjs.Picker(root=scene.children[0], event='mousemove')
        infobox = widgets.HTMLMath()

        def change_info(change):
            if click_picker.object:
                infobox.value = 'Object Coordinate: ({1:.3f}, {2:.3f}, {3:.3f})<br>{0}'.format(
                    click_picker.object.other_info,
                    *click_picker.object.position)
            else:
                infobox.value = ''

        click_picker.observe(change_info, names=['object'])
        renderer.controls = renderer.controls + [click_picker]
        renderer = widgets.HBox([renderer, infobox])

    if not controls:
        return (renderer, gcollect, all_options.viewitems() if hasattr(
            all_options, 'viewitems') else all_options.items()
                )  # python 2/3 compatability

    ## layout tabs and controls
    tabs = OrderedDict()
    for tab_name, clist in layout_dict.items():
        vbox_list = []

        for cname in clist:
            if isinstance(cname, list):
                hbox_list = [controls.pop(subcname) for subcname in cname]
                vbox_list.append(widgets.HBox(hbox_list))
            else:
                vbox_list.append(controls.pop(cname))
        tabs[tab_name] = widgets.VBox(vbox_list)

    if 'Orthographic Zoom' in controls:
        tabs.setdefault('View', widgets.Box())
        tabs['View'] = widgets.VBox(
            [tabs['View'], controls.pop('Orthographic Zoom')])

    if 'View Label' in controls:
        tabs.setdefault('View', widgets.Box())
        tabs['View'] = widgets.VBox([tabs['View'], controls.pop('View Label')])

    # deal with remaining controls
    if controls:
        vbox_list = []
        for cname in natural_sort(controls):
            vbox_list.append(controls.pop(cname))
        tabs.setdefault('Other', widgets.Box())
        tabs['Other'] = widgets.VBox([tabs['Other'], widgets.VBox(vbox_list)])

    options = widgets.Tab(children=tuple(tabs.values()))
    for i, name in enumerate(tabs):
        options.set_title(i, name)

    return (widgets.VBox([options,
                          renderer]), gcollect, all_options.viewitems()
            if hasattr(all_options, 'viewitems') else all_options.items()
            )  # python 2/3 compatability
Exemplo n.º 13
0
    def __init__(self,
                 data,
                 slcs=(slice(None, ), ),
                 title=None,
                 norm=None,
                 fig_handle=None,
                 time_in_title=True,
                 **kwargs):

        self._data, self._slcs, self.im_xlt, self.time_in_title = data, slcs, None, time_in_title
        # # # -------------------- Tab0 --------------------------
        items_layout = Layout(flex='1 1 auto', width='auto')
        # normalization
        # general parameters: vmin, vmax, clip
        self.if_vmin_auto = widgets.Checkbox(value=True,
                                             description='Auto',
                                             layout=items_layout)
        self.if_vmax_auto = widgets.Checkbox(value=True,
                                             description='Auto',
                                             layout=items_layout)
        self.vmin_wgt = widgets.FloatText(value=np.min(data),
                                          description='vmin:',
                                          continuous_update=False,
                                          disabled=self.if_vmin_auto.value,
                                          layout=items_layout)
        self.vlogmin_wgt = widgets.FloatText(value=self.eps,
                                             description='vmin:',
                                             continuous_update=False,
                                             disabled=self.if_vmin_auto.value,
                                             layout=items_layout)
        self.vmax_wgt = widgets.FloatText(value=np.max(data),
                                          description='vmax:',
                                          continuous_update=False,
                                          disabled=self.if_vmin_auto.value,
                                          layout=items_layout)
        self.if_clip_cm = widgets.Checkbox(value=True,
                                           description='Clip',
                                           layout=items_layout)
        # PowerNorm specific
        self.gamma = widgets.FloatText(value=1,
                                       description='gamma:',
                                       continuous_update=False,
                                       layout=items_layout)
        # SymLogNorm specific
        self.linthresh = widgets.FloatText(value=self.eps,
                                           description='linthresh:',
                                           continuous_update=False,
                                           layout=items_layout)
        self.linscale = widgets.FloatText(value=1.0,
                                          description='linscale:',
                                          continuous_update=False,
                                          layout=items_layout)

        # build the widgets tuple
        ln_wgt = (LogNorm,
                  widgets.VBox([
                      widgets.HBox([self.vlogmin_wgt, self.if_vmin_auto]),
                      widgets.HBox([self.vmax_wgt, self.if_vmax_auto]),
                      self.if_clip_cm
                  ]))
        n_wgt = (Normalize,
                 widgets.VBox([
                     widgets.HBox([self.vmin_wgt, self.if_vmin_auto]),
                     widgets.HBox([self.vmax_wgt, self.if_vmax_auto]),
                     self.if_clip_cm
                 ]))
        pn_wgt = (PowerNorm,
                  widgets.VBox([
                      widgets.HBox([self.vmin_wgt, self.if_vmin_auto]),
                      widgets.HBox([self.vmax_wgt, self.if_vmax_auto]),
                      self.if_clip_cm, self.gamma
                  ]))
        sln_wgt = (SymLogNorm,
                   widgets.VBox([
                       widgets.HBox([self.vmin_wgt, self.if_vmin_auto]),
                       widgets.HBox([self.vmax_wgt, self.if_vmax_auto]),
                       self.if_clip_cm, self.linthresh, self.linscale
                   ]))

        # find out default value for norm_selector
        norm_avail = {
            'Log': ln_wgt,
            'Normalize': n_wgt,
            'Power': pn_wgt,
            'SymLog': sln_wgt
        }
        self.norm_selector = widgets.Dropdown(options=norm_avail,
                                              value=norm_avail.get(
                                                  norm, n_wgt),
                                              description='Normalization:')
        # additional care for LorNorm()
        self.__handle_lognorm()
        # re-plot button
        self.norm_btn_wgt = widgets.Button(description='Apply',
                                           disabled=False,
                                           tooltip='set colormap',
                                           icon='refresh')
        tab0 = self.__get_tab0()

        # # # -------------------- Tab1 --------------------------
        # title
        if not title:
            title = osh5vis.default_title(data, show_time=self.time_in_title)
        self.if_reset_title = widgets.Checkbox(value=True, description='Auto')
        self.title = widgets.Text(value=title,
                                  placeholder='data',
                                  continuous_update=False,
                                  description='Title:',
                                  disabled=self.if_reset_title.value)
        # x label
        self.if_reset_xlabel = widgets.Checkbox(value=True, description='Auto')
        self.xlabel = widgets.Text(value=osh5vis.axis_format(
            data.axes[1].long_name, data.axes[1].units),
                                   placeholder='x',
                                   continuous_update=False,
                                   description='X label:',
                                   disabled=self.if_reset_xlabel.value)
        # y label
        self.if_reset_ylabel = widgets.Checkbox(value=True, description='Auto')
        self.ylabel = widgets.Text(value=osh5vis.axis_format(
            data.axes[0].long_name, data.axes[0].units),
                                   placeholder='y',
                                   continuous_update=False,
                                   description='Y label:',
                                   disabled=self.if_reset_ylabel.value)
        # colorbar
        self.if_reset_cbar = widgets.Checkbox(value=True, description='Auto')
        self.cbar = widgets.Text(value=data.units.tex(),
                                 placeholder='a.u.',
                                 continuous_update=False,
                                 description='Colorbar:',
                                 disabled=self.if_reset_cbar.value)

        tab1 = widgets.VBox([
            widgets.HBox([self.title, self.if_reset_title]),
            widgets.HBox([self.xlabel, self.if_reset_xlabel]),
            widgets.HBox([self.ylabel, self.if_reset_ylabel]),
            widgets.HBox([self.cbar, self.if_reset_cbar])
        ])

        # # # -------------------- Tab2 --------------------------
        self.setting_instructions = widgets.Label(
            value="Enter invalid value to reset", layout=items_layout)
        self.apply_range_btn = widgets.Button(description='Apply',
                                              disabled=False,
                                              tooltip='set range',
                                              icon='refresh')
        self.axis_lim_wgt = widgets.HBox(
            [self.setting_instructions, self.apply_range_btn])
        # x axis
        self.x_min_wgt = widgets.FloatText(value=self._data.axes[1].min,
                                           description='xmin:',
                                           continuous_update=False,
                                           layout=items_layout)
        self.x_max_wgt = widgets.FloatText(value=self._data.axes[1].max,
                                           description='xmax:',
                                           continuous_update=False,
                                           layout=items_layout)
        self.x_step_wgt = widgets.FloatText(value=self._data.axes[1].increment,
                                            continuous_update=False,
                                            description='$\Delta x$:',
                                            layout=items_layout)
        self.xaxis_lim_wgt = widgets.HBox(
            [self.x_min_wgt, self.x_max_wgt, self.x_step_wgt])
        # y axis
        self.y_min_wgt = widgets.FloatText(value=self._data.axes[0].min,
                                           description='ymin:',
                                           continuous_update=False,
                                           layout=items_layout)
        self.y_max_wgt = widgets.FloatText(value=self._data.axes[0].max,
                                           description='ymax:',
                                           continuous_update=False,
                                           layout=items_layout)
        self.y_step_wgt = widgets.FloatText(value=self._data.axes[0].increment,
                                            continuous_update=False,
                                            description='$\Delta y$:',
                                            layout=items_layout)
        self.yaxis_lim_wgt = widgets.HBox(
            [self.y_min_wgt, self.y_max_wgt, self.y_step_wgt])
        tab2 = widgets.VBox(
            [self.axis_lim_wgt, self.xaxis_lim_wgt, self.yaxis_lim_wgt])

        # # # -------------------- Tab3 --------------------------
        tab3 = self.if_lineout_wgt = widgets.Checkbox(
            value=False,
            description='X/Y Lineouts (incomplete feature)',
            layout=items_layout)

        # # # -------------------- Tab4 --------------------------
        user_cmap = kwargs.pop('cmap', 'jet')
        self.cmap_selector = widgets.Dropdown(options=self.colormaps_available,
                                              value=user_cmap,
                                              description='Colormap:')
        self.cmap_reverse = widgets.Checkbox(value=False,
                                             description='Reverse',
                                             layout=items_layout)
        tab4 = widgets.HBox([self.cmap_selector, self.cmap_reverse])

        # construct the tab
        self.tab = widgets.Tab()
        self.tab.children = [tab0, tab1, tab2, tab3, tab4]
        [self.tab.set_title(i, tt) for i, tt in enumerate(self.tab_contents)]
        # display(self.tab)

        # link and activate the widgets
        self.if_reset_title.observe(self.__update_title, 'value')
        self.if_reset_xlabel.observe(self.__update_xlabel, 'value')
        self.if_reset_ylabel.observe(self.__update_ylabel, 'value')
        self.if_reset_cbar.observe(self.__update_cbar, 'value')
        self.norm_btn_wgt.on_click(self.update_norm)
        self.if_vmin_auto.observe(self.__update_vmin, 'value')
        self.if_vmax_auto.observe(self.__update_vmax, 'value')
        self.norm_selector.observe(self.__update_norm_wgt, 'value')
        self.cmap_selector.observe(self.update_cmap, 'value')
        self.cmap_reverse.observe(self.update_cmap, 'value')
        self.title.observe(self.update_title, 'value')
        self.xlabel.observe(self.update_xlabel, 'value')
        self.ylabel.observe(self.update_ylabel, 'value')
        self.cbar.observe(self.update_cbar, 'value')
        self.y_max_wgt.observe(self.__update_y_max, 'value')
        self.y_min_wgt.observe(self.__update_y_min, 'value')
        self.x_max_wgt.observe(self.__update_x_max, 'value')
        self.x_min_wgt.observe(self.__update_x_min, 'value')
        self.x_step_wgt.observe(self.__update_delta_x, 'value')
        self.y_step_wgt.observe(self.__update_delta_y, 'value')
        self.apply_range_btn.on_click(self.update_plot_area)
        self.if_lineout_wgt.observe(self.toggle_lineout, 'value')

        # plotting and then setting normalization colors
        self.out = Output()
        self.out_main = Output()
        self.observer_thrd, self.cb = None, None
        self.fig = plt.figure() if fig_handle is None else fig_handle
        self.ax = self.fig.add_subplot(111)
        with self.out_main:
            self.im, self.cb = self.plot_data()
            display(self.fig)
Exemplo n.º 14
0
    def widget(self):
        # Alright let's set this all up.
        grid_contents = []
        for i, view in enumerate(self.grid_views):
            visible = ipywidgets.Checkbox(value=view.visible,
                                          description=f"Level {i}")
            ipywidgets.jslink((visible, "value"), (view, "visible"))
            color_picker = ipywidgets.ColorPicker(value=view.material.color,
                                                  concise=True)
            ipywidgets.jslink((color_picker, "value"),
                              (view.material, "color"))
            line_slider = ipywidgets.FloatSlider(value=view.material.linewidth,
                                                 min=0.0,
                                                 max=10.0)
            ipywidgets.jslink((line_slider, "value"),
                              (view.material, "linewidth"))
            grid_contents.extend([visible, color_picker, line_slider])

        dropdown = ipywidgets.Dropdown(
            options=["inferno", "viridis", "plasma", "magma", "cividis"],
            value="inferno",
            description="Colormap:",
            disable=False,
        )

        traitlets.link((dropdown, "value"), (self, "grid_colormap"))

        button = ipywidgets.Button(description="Add Keyframe")

        def on_button_clicked(b):
            self.position_list = self.position_list + [
                self.renderer.camera.position
            ]
            select.options += ((f"Position {len(self.position_list)}",
                                self.renderer.camera.position), )

        button.on_click(on_button_clicked)

        select = ipywidgets.Select(options=[],
                                   description="Positions:",
                                   disabled=False)

        def on_selection_changed(change):
            self.renderer.camera.position = tuple(change["new"])

        select.observe(on_selection_changed, ["value"])

        return ipywidgets.HBox([
            self.renderer,
            button,
            select,
            ipywidgets.VBox([
                dropdown,
                ipywidgets.GridBox(
                    grid_contents,
                    layout=ipywidgets.Layout(
                        width=r"60%",
                        grid_template_columns=r"30% 10% auto",
                        align_items="stretch",
                    ),
                ),
            ]),
        ])
Exemplo n.º 15
0
 def gui_label (self) :
     choice = ipw.Dropdown(description="Label",
                           options=self.nodes_columns,
                           value=self.opt.nodes.label)
     choice.observe(self.on_label, "value")
     return choice
Exemplo n.º 16
0
    def subproduct(self):

        return widgets.Dropdown(description="Subproduct:",
                                layout=self.item_layout)
Exemplo n.º 17
0
    def interact(self):
        """Drives the interactive display of the plot explorer panels"""
        param_min = self.param_vals[0]
        param_max = self.param_vals[-1]
        param_step = self.param_vals[1] - self.param_vals[0]

        qbt_indices = [
            index for (index, subsystem) in self.sweep.qbt_subsys_list
        ]
        osc_indices = [
            index for (index, subsystem) in self.sweep.osc_subsys_list
        ]

        param_slider = ipywidgets.FloatSlider(
            min=param_min,
            max=param_max,
            step=param_step,
            description=self.param_name,
            continuous_update=False,
        )
        photon_slider = ipywidgets.IntSlider(value=1,
                                             min=1,
                                             max=4,
                                             description="photon number")
        initial_slider = ipywidgets.IntSlider(
            value=0,
            min=0,
            max=self.evals_count,
            description="initial state index")
        final_slider = ipywidgets.IntSlider(value=1,
                                            min=1,
                                            max=self.evals_count,
                                            description="final state index")

        qbt_dropdown = ipywidgets.Dropdown(options=qbt_indices,
                                           description="qubit subsys")
        osc_dropdown = ipywidgets.Dropdown(options=osc_indices,
                                           description="oscillator subsys")

        def update_min_final_index(*args):
            final_slider.min = initial_slider.value + 1

        initial_slider.observe(update_min_final_index, "value")

        out = ipywidgets.interactive_output(
            self.plot_explorer_panels,
            {
                "param_val": param_slider,
                "photonnumber": photon_slider,
                "initial_index": initial_slider,
                "final_index": final_slider,
                "qbt_index": qbt_dropdown,
                "osc_index": osc_dropdown,
            },
        )

        left_box = ipywidgets.VBox([param_slider])
        mid_box = ipywidgets.VBox(
            [initial_slider, final_slider, photon_slider])
        right_box = ipywidgets.VBox([qbt_dropdown, osc_dropdown])

        user_interface = ipywidgets.HBox([left_box, mid_box, right_box])
        display(user_interface, out)
Exemplo n.º 18
0
def complete_function(df1):
    import pandas as pd
    import numpy as np
    import summary as sm
    from matplotlib import pyplot as plt
    import ipywidgets as widgets
    from ipywidgets import HBox, VBox
    from IPython.display import display
    import visualisation as vz

    # dividing variables into categorical and continuous
    categorical = []  # All columns which are categorical in nature
    numerical = []  # All features that are continous in nature
    for x in df1.columns:
        if np.unique(df1[x].astype('str')).size <= 0.1 * len(df1.index):
            categorical.append(x)
        else:
            numerical.append(x)

# all output widgets initiallised

    dataset_sum = widgets.Output()
    var_sum = widgets.Output()
    graphVar1 = widgets.Output()
    graphVar2 = widgets.Output()
    graphVar3 = widgets.Output()

    # all dropdown menus in the dash defined
    var1 = widgets.Dropdown(options=(df1.columns).tolist())
    var_1 = widgets.Dropdown(options=(df1.columns).tolist())
    var_2 = widgets.Dropdown(options=(df1.columns).tolist())
    var__1 = widgets.Dropdown(options=(df1.columns).tolist())
    var__2 = widgets.Dropdown(options=(df1.columns).tolist())
    var__3 = widgets.Dropdown(options=(df1.columns).tolist())

    # tab 2 displays summary of variable and a graph of the variable
    def TAB2(var1_change):
        graphVar1.clear_output()
        with var_sum:
            var_sum.clear_output()
            if var1_change in categorical:
                temp = sm.catsum(df1, var1_change)
            else:
                temp = sm.numsum(df1, var1_change)
            for key, value in temp.items():
                print(key, ' : ', value)

        with graphVar1:
            if var1_change in categorical:
                vz.cat_vis(df1, var1_change)
                plt.show()
            else:
                vz.num_vis(df1, var1_change)
                plt.show()

# tab 3 shows relation between 2 variables

    def TAB3(var_1_change, var_2_change):
        graphVar2.clear_output()
        with graphVar2:
            vz.tab3_vis(df1, var_1_change, var_2_change)
            plt.show()

# tab 4 shows relation between 3 variables, 3rd as a hue

    def TAB4(var__1_change, var__2_change, var__3_change):
        graphVar3.clear_output()
        with graphVar3:
            vz.tab4_viz(df1, var__1_change, var__2_change, var__3_change)
            plt.show()

# event handlers for al variable dropdowns

    def var1_handler(change):
        TAB2(change.new)

    def var_1_handler(change):
        TAB3(change.new, var_2.value)

    def var_2_handler(change):
        TAB3(var_1.value, change.new)

    def var__1_handler(change):
        TAB4(change.new, var__2.value, var__3.value)

    def var__2_handler(change):
        TAB4(var__1.value, change.new, var__3.value)

    def var__3_handler(change):
        TAB4(var__1.value, var__2.value, change.new)


# observer function for all variable dropdowns

    var1.observe(var1_handler, names='value')
    var_1.observe(var_1_handler, names='value')
    var_2.observe(var_2_handler, names='value')
    var__1.observe(var__1_handler, names='value')
    var__2.observe(var__2_handler, names='value')
    var__3.observe(var__3_handler, names='value')

    tab1 = VBox(children=[dataset_sum])
    tab2 = HBox(children=[VBox(children=[var1, var_sum]), graphVar1])
    tab3 = HBox(children=[VBox(children=[var_1, var_2]), graphVar2])
    tab4 = HBox(children=[VBox(children=[var__1, var__2, var__3]), graphVar3])

    tab = widgets.Tab(children=[tab1, tab2, tab3, tab4])
    tab.set_title(0, 'Dataset summary')
    tab.set_title(1, 'Variable summary')
    tab.set_title(2, 'Var1 vs Var2')
    tab.set_title(3, 'Var1 vs Var2 vs Var3')

    dashboard = widgets.VBox([tab])
    display(dashboard)

    return None
Exemplo n.º 19
0
    def __init__(self, multi=False):
        # Find all process labels
        self.multi = multi
        qb = QueryBuilder()
        qb.append(WorkCalculation,
                  project="attributes._process_label",
                  filters={'attributes': {
                      '!has_key': 'source_code'
                  }})
        qb.order_by({WorkCalculation: {'ctime': 'desc'}})
        process_labels = []
        for i in qb.iterall():
            if i[0] not in process_labels:
                process_labels.append(i[0])

        layout = ipw.Layout(width="900px")

        self.mode = ipw.RadioButtons(
            options=['all', 'uploaded', 'edited', 'calculated', 'not used'],
            layout=ipw.Layout(width="25%"))

        # Date range
        self.dt_now = datetime.datetime.now()
        self.dt_end = self.dt_now - datetime.timedelta(days=7)
        self.date_start = ipw.Text(value='',
                                   description='From: ',
                                   style={'description_width': '120px'})

        self.date_end = ipw.Text(value='', description='To: ')

        self.date_text = ipw.HTML(value='<p>Select the date range:</p>')

        self.btn_date = ipw.Button(description='Search',
                                   layout={'margin': '1em 0 0 0'})

        self.age_selection = ipw.VBox([
            self.date_text,
            ipw.HBox([self.date_start, self.date_end]), self.btn_date
        ],
                                      layout={
                                          'border': '1px solid #fafafa',
                                          'padding': '1em'
                                      })

        self.btn_date.on_click(self.search)
        self.mode.observe(self.search, names='value')

        hr = ipw.HTML('<hr>')
        box = ipw.VBox([self.age_selection, hr, ipw.HBox([self.mode])])
        if multi:
            self.results = ipw.SelectMultiple(layout=layout)
        else:
            self.results = ipw.Dropdown(layout=layout)

        self.found = ipw.HTML("", description="found:")
        self.selected = ipw.HTML("", description="selected:")

        self.search()

        if multi:
            super(StructureBrowser, self).__init__(
                [box, hr, self.results,
                 ipw.HBox([self.found, self.selected])])
        else:
            super(StructureBrowser, self).__init__([box, hr, self.results])
Exemplo n.º 20
0
    def __init__(self):
        # dropdown menu for setting asset
        self.asset = ipywidgets.Dropdown(
            options=['atlas-local', 'atlas-s3', 'nsidc-s3'],
            value='atlas-s3',
            description='Asset:',
            disabled=False,
        )

        # dropdown menu for setting data release
        self.release = ipywidgets.Dropdown(
            options=['003', '004'],
            value='004',
            description='Release:',
            disabled=False,
        )

        # dropdown menu for setting surface type
        # 0-land, 1-ocean, 2-sea ice, 3-land ice, 4-inland water
        surface_type_options = [
            'Land', 'Ocean', 'Sea ice', 'Land ice', 'Inland water'
        ]
        self.surface_type = ipywidgets.Dropdown(
            options=surface_type_options,
            value='Land',
            description='Surface Type:',
            disabled=False,
        )

        # slider for setting length of ATL06-SR segment in meters
        self.length = ipywidgets.IntSlider(value=40,
                                           min=5,
                                           max=200,
                                           step=5,
                                           description='Length:',
                                           disabled=False,
                                           continuous_update=False,
                                           orientation='horizontal',
                                           readout=True,
                                           readout_format='d')

        # slider for setting step distance for successive segments in meters
        self.step = ipywidgets.IntSlider(value=20,
                                         min=5,
                                         max=200,
                                         step=5,
                                         description='Step:',
                                         disabled=False,
                                         continuous_update=False,
                                         orientation='horizontal',
                                         readout=True,
                                         readout_format='d')

        # slider for setting confidence level for PE selection
        # eventually would be good to switch this to a IntRangeSlider with value=[0,4]
        self.confidence = ipywidgets.IntSlider(value=4,
                                               min=0,
                                               max=4,
                                               step=1,
                                               description='Confidence:',
                                               disabled=False,
                                               continuous_update=False,
                                               orientation='horizontal',
                                               readout=True,
                                               readout_format='d')

        # selection for land surface classifications
        land_options = [
            'atl08_noise', 'atl08_ground', 'atl08_canopy',
            'atl08_top_of_canopy', 'atl08_unclassified'
        ]
        self.land_class = ipywidgets.SelectMultiple(options=land_options,
                                                    description='Land Class:',
                                                    disabled=False)

        # slider for setting maximum number of iterations
        # (not including initial least-squares-fit selection)
        self.iteration = ipywidgets.IntSlider(value=1,
                                              min=0,
                                              max=20,
                                              step=1,
                                              description='Iterations:',
                                              disabled=False,
                                              continuous_update=False,
                                              orientation='horizontal',
                                              readout=True,
                                              readout_format='d')

        # slider for setting minimum along track spread
        self.spread = ipywidgets.FloatSlider(value=20,
                                             min=1,
                                             max=100,
                                             step=0.1,
                                             description='Spread:',
                                             disabled=False,
                                             continuous_update=False,
                                             orientation='horizontal',
                                             readout=True,
                                             readout_format='0.1f')
        # slider for setting minimum photon event (PE) count
        self.count = ipywidgets.IntSlider(value=10,
                                          min=1,
                                          max=50,
                                          step=1,
                                          description='PE Count:',
                                          disabled=False,
                                          continuous_update=False,
                                          orientation='horizontal',
                                          readout=True,
                                          readout_format='d')

        # slider for setting minimum height of PE window in meters
        self.window = ipywidgets.FloatSlider(value=3,
                                             min=0.5,
                                             max=10,
                                             step=0.1,
                                             description='Window:',
                                             disabled=False,
                                             continuous_update=False,
                                             orientation='horizontal',
                                             readout=True,
                                             readout_format='0.1f')

        # slider for setting maximum robust dispersion in meters
        self.sigma = ipywidgets.FloatSlider(value=5,
                                            min=1,
                                            max=10,
                                            step=0.1,
                                            description='Sigma:',
                                            disabled=False,
                                            continuous_update=False,
                                            orientation='horizontal',
                                            readout=True,
                                            readout_format='0.1f')

        # dropdown menu for setting map projection for polygons
        # Global: Web Mercator (EPSG:3857)
        # North: Alaska Polar Stereographic (EPSG:5936)
        # South: Polar Stereographic South (EPSG:3031)
        projection_list = ['Global', 'North', 'South']
        self.projection = ipywidgets.Dropdown(
            options=projection_list,
            value='Global',
            description='Projection:',
            disabled=False,
        )

        # button and label for output file selection
        self.file = copy.copy(self.filename)
        self.savebutton = ipywidgets.Button(description="Save As")
        self.savelabel = ipywidgets.Text(value=self.file, disabled=False)
        # connect fileselect button with action
        self.savebutton.on_click(self.saveas_file)
        self.savelabel.observe(self.set_savefile)
        # create hbox of file selection
        self.filesaver = ipywidgets.HBox([self.savebutton, self.savelabel])

        # button and label for input file selection
        self.loadbutton = ipywidgets.Button(description="File select")
        self.loadlabel = ipywidgets.Text(value='', disabled=False)
        # connect fileselect button with action
        self.loadbutton.on_click(self.select_file)
        self.loadlabel.observe(self.set_loadfile)
        # create hbox of file selection
        self.fileloader = ipywidgets.HBox([self.loadbutton, self.loadlabel])
Exemplo n.º 21
0
    def __init__(self, func, xmin, xmax, *args, num=100, 
                 xfavunit=None, yfavunit=None, 
                 xlim=None, ylim=None, **kwargs):
        
        self.func = func
        self.name = func.name
        self.xfavunit = xfavunit
        self.yfavunit = yfavunit
        self.xmin = xmin
        self.xmax = xmax
        self.num = num
        
        
        axis_list = ["stretch", "auto", "fixed"]
        self.xaxis_ddw = ipyw.Dropdown(options=axis_list, description="X-Axis scaling:")
        self.yaxis_ddw = ipyw.Dropdown(options=axis_list, description="Y-Axis scaling:")
        
        # Todo : handle xlim/ylim with fixed, stretched, etc
        
        self.ech_x = np.linspace(xmin, xmax, num=num)
        # get favunit for inputs
        import inspect
        sig = inspect.signature(func)
        if not sig.return_annotation == inspect._empty:
            init_values = []
            for k,v in sig.parameters.items():
                init_values.append((v.name, v.annotation, v.name))
            # add favunit for x for plotting
            self.ech_x.favunit = init_values[0][1]
        

        
        self.params = args
        self.params_slider_dict = OrderedDict()
        
        self.state_dict = {}
    
        self.pargs = {}
        self.sliders_dict = {}
    
        
        def _update_data(change):
            #print("update data")
            data = self.data()
            self.line.set_label(self.label)
            self.line.set_data(data)
            _update_cursor_data(None)
            
            self.ax.relim()
            cur_xlims = self.ax.get_xlim()
            cur_ylims = self.ax.get_ylim()
            
            # X
            if self.xaxis_scale == "auto":
                self.ax.autoscale_view(scaley=False)
            elif self.xaxis_scale == "stretch":
                new_lims = [self.ax.dataLim.x0, self.ax.dataLim.x0 + self.ax.dataLim.width]
                new_lims = [
                    new_lims[0] if new_lims[0] < cur_xlims[0] else cur_xlims[0],
                    new_lims[1] if new_lims[1] > cur_xlims[1] else cur_xlims[1],
                ]
                self.ax.set_xlim(new_lims)
                

            if self.yaxis_scale == "auto":
                self.ax.autoscale_view(scalex=False)
            elif self.yaxis_scale == "stretch":
                new_lims = [self.ax.dataLim.y0, self.ax.dataLim.y0 + self.ax.dataLim.height]
                new_lims = [
                    new_lims[0] if new_lims[0] < cur_ylims[0] else cur_ylims[0],
                    new_lims[1] if new_lims[1] > cur_ylims[1] else cur_ylims[1],
                ]
                self.ax.set_ylim(new_lims)
            
            
            self.ax.legend()
            #self.ax.autoscale_view()
        
        sliders_list = []
        for k, v in kwargs.items():
            self.pargs[k] = v
            #slider = ipyw.FloatSlider(v[0], min=v[0], max=v[-1], description=k, step=0.001)
            slider = QuantityTextSlider(v[0], min=v[0], max=v[-1], description=k,
                                       step=(v[-1]-v[0])/1000) # we override a default step
            slider.observe(_update_data, names="value")

            self.sliders_dict[k] = slider

            sliders_list.append(slider)
            
        def _update_cursor_data(change):
            y = self.func(self.get_xcursor(), **self.get_pvalues())
            self.cursor_hline.set_data(asqarray([self.xmin, self.xmax]), asqarray([y, y]))
            self.cursor_vline.set_data(asqarray([self.get_xcursor(), self.get_xcursor()]), asqarray([0*y, y]))
            
        self.cursor_slider = QuantityTextSlider(xmin, min=xmin, max=xmax, description="Cursor",
                                               step=(xmax-xmin)/1000)
        self.cursor_slider.observe(_update_cursor_data, names="value")

        #print(self.sliders_list)
        self.sliders_list = sliders_list
        self.sliders_box = ipyw.VBox(sliders_list +[self.cursor_slider]+[self.xaxis_ddw, self.yaxis_ddw ])
        self.out_w = ipyw.Output()
        
        #print(self.sliders_box)
        self.plot()
        self.plot_cursor()
Exemplo n.º 22
0
    def __init__(self,
                 backend,
                 dataset,
                 x,
                 y=None,
                 z=None,
                 w=None,
                 grid=None,
                 limits=None,
                 shape=128,
                 what="count(*)",
                 f=None,
                 vshape=16,
                 selection=None,
                 grid_limits=None,
                 normalize=None,
                 colormap="afmhot",
                 figure_key=None,
                 fig=None,
                 what_kwargs={},
                 grid_before=None,
                 vcount_limits=None,
                 controls_selection=False,
                 **kwargs):
        super(PlotBase, self).__init__(x=x,
                                       y=y,
                                       z=z,
                                       w=w,
                                       what=what,
                                       vcount_limits=vcount_limits,
                                       grid_limits=grid_limits,
                                       f=f,
                                       **kwargs)
        self.backend = backend
        self.vgrids = [None, None, None]
        self.vcount = None
        self.dataset = dataset
        self.limits = self.get_limits(limits)
        self.shape = shape
        self.selection = selection
        #self.grid_limits = grid_limits
        self.normalize = normalize
        self.colormap = colormap
        self.what_kwargs = what_kwargs
        self.grid_before = grid_before
        self.figure_key = figure_key
        self.fig = fig
        self.vshape = vshape

        self._new_progressbar()

        self.output = widgets.Output()
        # with self.output:
        if 1:
            self._cleanups = []

            self.progress = widgets.FloatProgress(value=0.0,
                                                  min=0.0,
                                                  max=1.0,
                                                  step=0.01)
            self.progress.layout.width = "95%"
            self.progress.layout.max_width = '500px'
            self.progress.description = "progress"

            self.backend.create_widget(self.output, self, self.dataset,
                                       self.limits)
            self.control_widget = widgets.VBox()

            # self.create_tools()
            self.widget = widgets.VBox([
                self.control_widget, self.backend.widget, self.progress,
                self.output
            ])
            if grid is None:
                self.update_grid()
            else:
                self.grid = grid

            self.widget_f = widgets.Dropdown(
                options=[('identity',
                          'identity'), ('log',
                                        'log'), ('log10',
                                                 'log10'), ('log1p', 'log1p')])
            widgets.link((self, 'f'), (self.widget_f, 'value'))
            self.observe(lambda *__: self.update_image(), 'f')
            self.add_control_widget(self.widget_f)

            self.widget_grid_limits_min = widgets.FloatSlider(
                value=0, min=0, max=100, step=0.1, description='vmin%')
            self.widget_grid_limits_max = widgets.FloatSlider(
                value=100, min=0, max=100, step=0.1, description='vmax%')
            widgets.link((self.widget_grid_limits_min, 'value'),
                         (self, 'grid_limits_min'))
            widgets.link((self.widget_grid_limits_max, 'value'),
                         (self, 'grid_limits_max'))
            #widgets.link((self.widget_grid_limits_min, 'f'), (self.widget_f, 'value'))
            self.observe(lambda *__: self.update_image(),
                         ['grid_limits_min', 'grid_limits_max'])
            self.add_control_widget(self.widget_grid_limits_min)
            self.add_control_widget(self.widget_grid_limits_max)

            self.widget_grid_limits = None

        selections = vaex.dataset._ensure_list(self.selection)
        selections = [_translate_selection(k) for k in selections]
        selections = [k for k in selections if k]
        self.widget_selection_active = widgets.ToggleButtons(
            options=list(zip(selections, selections)), description='selection')
        self.controls_selection = controls_selection
        if self.controls_selection:
            self.add_control_widget(self.widget_selection_active)

            modes = ['replace', 'and', 'or', 'xor', 'subtract']
            self.widget_selection_mode = widgets.ToggleButtons(
                options=modes, description='mode')
            self.add_control_widget(self.widget_selection_mode)

            self.widget_selection_undo = widgets.Button(options=modes,
                                                        description='undo',
                                                        icon='arrow-left')
            self.widget_selection_redo = widgets.Button(options=modes,
                                                        description='redo',
                                                        icon='arrow-right')
            self.add_control_widget(
                widgets.HBox([
                    widgets.Label('history', layout={'width': '80px'}),
                    self.widget_selection_undo, self.widget_selection_redo
                ]))

            def redo(*ignore):
                selection = _translate_selection(
                    self.widget_selection_active.value)
                self.dataset.selection_redo(name=selection)
                check_undo_redo()

            self.widget_selection_redo.on_click(redo)

            def undo(*ignore):
                selection = _translate_selection(
                    self.widget_selection_active.value)
                self.dataset.selection_undo(name=selection)
                check_undo_redo()

            self.widget_selection_undo.on_click(undo)

            def check_undo_redo(*ignore):
                selection = _translate_selection(
                    self.widget_selection_active.value)
                self.widget_selection_undo.disabled = not self.dataset.selection_can_undo(
                    selection)
                self.widget_selection_redo.disabled = not self.dataset.selection_can_redo(
                    selection)

            self.widget_selection_active.observe(check_undo_redo, 'value')
            check_undo_redo()

            callback = self.dataset.signal_selection_changed.connect(
                check_undo_redo)
            callback = self.dataset.signal_selection_changed.connect(
                lambda *x: self.update_grid())

        def _on_limits_change(*args):
            self._progressbar.cancel()
            self.update_grid()

        self.backend.observe(_on_limits_change, "limits")
        for attrname in "x y z vx vy vz".split():

            def _on_change(*args, attrname=attrname):
                limits_index = {'x': 0, 'y': 1, 'z': 2}.get(attrname)
                if limits_index is not None:
                    self.backend.limits[limits_index] = None
                self.update_grid()

            self.observe(_on_change, attrname)
        self.observe(lambda *args: self.update_grid(), "what")
        self.observe(lambda *args: self.update_image(), "vcount_limits")
Exemplo n.º 23
0
                                cachename='pc4cancerbots',
                                showcache=False,
                                outcb=outcb)
    else:
        run_button = widgets.Button(
            description='Run',
            button_style=
            'success',  # 'success', 'info', 'warning', 'danger' or ''
            tooltip='Run a simulation',
        )
        run_button.on_click(run_button_cb)

if nanoHUB_flag or hublib_flag:
    read_config = widgets.Dropdown(
        description='Load Config',
        options=get_config_files(),
        tooltip='Config File or Previous Run',
    )
    read_config.style = {
        'description_width': '%sch' % str(len(read_config.description) + 1)
    }
    read_config.observe(read_config_cb, names='value')

tab_height = 'auto'
tab_layout = widgets.Layout(
    width='auto',
    height=tab_height,
    overflow_y='scroll',
)  # border='2px solid black',
#titles = ['About', 'Config Basics', 'Microenvironment', 'User Params', 'Out: Cell Plots', 'Out: Substrate Plots']
titles = [
def makeWidgets():
    studyList = [
        'ACC', 'BLCA', 'BRCA', 'CESC', 'CHOL', 'COAD', 'DLBC', 'ESCA', 'GBM',
        'HNSC', 'KICH', 'KIRC', 'KIRP', 'LAML', 'LGG', 'LIHC', 'LUAD', 'LUSC',
        'MESO', 'OV', 'PAAD', 'PCPG', 'PRAD', 'READ', 'SARC', 'SKCM', 'STAD',
        'TGCT', 'THCA', 'THYM', 'UCEC', 'UCS', 'UVM'
    ]

    study = widgets.Dropdown(options=studyList,
                             value='UCEC',
                             description='',
                             disabled=False)

    FeatureList1 = [
        'Gene Expression', 'Somatic Copy Number', 'MicroRNA Expression',
        'Clinical Numeric'
    ]

    #FeatureList2 = [ 'Gene Expression', 'Somatic Mutation Spearman','Somatic Mutation t-test', 'Somatic Copy Number', 'Clinical Numeric', 'Clinical Categorical', 'MicroRNA Expression'] ;
    FeatureList2 = [
        'Gene Expression', 'Somatic Mutation', 'Somatic Copy Number',
        'Clinical Numeric', 'MicroRNA Expression'
    ]

    feature1 = widgets.Dropdown(options=FeatureList1,
                                value='Gene Expression',
                                description='',
                                disabled=False)

    gene_names = widgets.Text(value='IGF2, ADAM6',
                              placeholder='Type gene names  ',
                              description='',
                              disabled=False)

    feature2 = widgets.Dropdown(options=FeatureList2,
                                value='Gene Expression',
                                description='',
                                disabled=False)

    significance = widgets.SelectionSlider(
        options=['0.05', '0.01', '0.005', '0.001'],
        value='0.01',
        description='',
        disabled=False,
        continuous_update=False,
        orientation='horizontal',
        readout=True)

    size = widgets.IntSlider(value=25, min=5, max=50,
                             description='')  # the n most variable genes

    cohortlist = widgets.FileUpload(
        accept=
        '',  # Accepted file extension e.g. '.txt', '.pdf', 'image/*', 'image/*,.pdf'
        multiple=False  # True to accept multiple files upload else False
    )

    feature1_title = widgets.HTML('<em>Select Feature1 </em>')
    display(widgets.HBox([feature1_title, feature1]))

    genes_title = widgets.HTML('<em>Feature1 labels </em>')
    display(widgets.HBox([genes_title, gene_names]))

    feature2_title = widgets.HTML('<em>Select Feature2 </em>')
    display(widgets.HBox([feature2_title, feature2]))

    study_title = widgets.HTML('<em>Select a study </em>')
    display(widgets.HBox([study_title, study]))

    significance_title = widgets.HTML('<em>Significance level </em>')
    display(widgets.HBox([significance_title, significance]))

    size_title = widgets.HTML('<em>Minimum number of samples</em>')
    display(widgets.HBox([size_title, size]))

    cohort_title = widgets.HTML('<em>Cohort list</em>')
    display(widgets.HBox([cohort_title, cohortlist]))

    return ([
        study, feature1, feature2, gene_names, size, cohortlist, significance
    ])
Exemplo n.º 25
0
                                 'retail_and_recreation_percent_change_from_baseline':np.float,
                                 'grocery_and_pharmacy_percent_change_from_baseline':np.float,
                                 'parks_percent_change_from_baseline':np.float,
                                 'transit_stations_percent_change_from_baseline':np.float,
                                 'workplaces_percent_change_from_baseline':np.float,
                                 'residential_percent_change_from_baseline':np.float},
                          parse_dates = ['date']   ## this is good to know
                )
df.head()


# In[202]:


datasets_list = list(df.columns.values)[5:]
dataset_picker = widgets.Dropdown(options=datasets_list, value=datasets_list[0])
dataset_picker


# In[203]:


state_list = df[df['country_region']=='United States']['sub_region_1'].unique().tolist()[1:]
state_picker = widgets.Dropdown(options=state_list, value=state_list[0])
state_picker


# In[212]:


## County-level Data##
Exemplo n.º 26
0
u_fbar = widgets.Checkbox(value=False,description=r'$U$$\to$$\overline{f}$',disabled=False)
sum_f = widgets.Checkbox(value=False,description=r'Sum $f$',disabled=False)
sum_fb = widgets.Checkbox(value=False,description=r'Sum $\bar{f}$',disabled=False)
# decay rate coefficients
xmin=widgets.BoundedFloatText(value=0, min=0, max=20, step=1, continuous_update=False, description=r'$t_{min}$ [ps]')
xmax=widgets.BoundedFloatText(value=5, min=0, max=20, step=1, continuous_update=False, description=r'$t_{max}$ [ps]')
y_cosh=widgets.BoundedFloatText(value=0.25, min=0, max=10, step=0.1, continuous_update=False, description=r'$y_{\cosh}$ [a.u.]')
y_sinh=widgets.BoundedFloatText(value=0.02, min=0, max=10, step=0.1, continuous_update=False, description=r'$y_{\sinh}$ [a.u.]')
y_cos=widgets.BoundedFloatText(value=0.25, min=0, max=10, step=0.1, continuous_update=False, description=r'$y_{\cos}$ [a.u.]')
y_sin=widgets.BoundedFloatText(value=0.25, min=0, max=10, step=0.1, continuous_update=False, description=r'$y_{\sin}$ [a.u.]')
y_dg=widgets.BoundedFloatText(value=0.5, min=0, max=10, step=0.1, continuous_update=False, description=r'$y_{d\Gamma/dt}$ [a.u.]')
name=widgets.Text(value='plots/coeffs.eps',continuous_update=False,description='Save as:')
save=widgets.ToggleButton(value=False,description='Save')
tagging =widgets.Dropdown(
    options=['MESON', 'TAGGER'],
    value='MESON',
    description='Tagging',
    disabled=False,
)
k_acc = widgets.Checkbox(value=False,description=r'Acceptance',disabled=False)
k_tag = widgets.Checkbox(value=False,description=r'Tagging',disabled=False)
## Decay Rate Coefficients
wbox_amp = HBox([VBox([dm,dg,gs,r,delta,gamma,beta,afs,rez,imz]),
                 VBox([k_tag,a_prod,a_det,omega,d_omega,eff,d_eff,tagging]),
                 VBox([k_acc,a_acc,n_acc,b_acc,beta_acc,cutoff_acc,sigma_t]),
                 VBox([xmin,xmax,y_cosh,y_sinh,y_cos,y_sin,y_dg,name,save]),
                 VBox([b_f,bbar_f,bbar_fbar,b_fbar,u_f,u_fbar,sum_f,sum_fb]),
                ])
amp_pars = interactive_output(plot_amplitudes,{
                'dm':dm,'dg':dg,'gs':gs,'r':r,'delta':delta,'gamma':gamma,'beta':beta,'afs':afs,'rez':rez,'imz':imz,
                'omega':omega,'d_omega':d_omega,'eff':eff,'d_eff':d_eff,'a_prod':a_prod,'a_det':a_det,'sigma_t':sigma_t,
                'xmin':xmin,'xmax':xmax,'y_cosh':y_cosh,'y_sinh':y_sinh,'y_cos':y_cos,'y_sin':y_sin,'y_dg':y_dg,
Exemplo n.º 27
0
    def graph_from_table(table_name):
        '''
        This function creates an interactive plotly graph based on a Qtable taken as input.
        '''
  
        # Putting this here so we don't have to worry about it in the notebooks
        init_notebook_mode(connected=True)
        
        types = ['scatter', 'line', 'bar']
        
        try:
            updated_table = table_name.get_changed_df()
        except NameError:
            print("The variable " +str(name)+ " does not exist. Please make sure you entered the correct table") 
            return

        def graph(x_axes, y_axes,  kind,  title = '', y_name='', x_name=''):
            '''
            This function is to simplify creating a graph from an interactive Qtable and allows 
            us to use it with IPywidgets interactive
            '''
            # Choose plot type
            
            
            if kind == 'line':
                trace = Scatter(x=updated_table[x_axes],
                                y = updated_table[y_axes],
                                mode = 'lines+markers')
            if kind == 'bar':
                trace = Bar(x=updated_table[x_axes], 
                            y = updated_table[y_axes])

            if kind == 'scatter':
                trace = Scatter(x=updated_table[x_axes],
                                y = updated_table[y_axes],
                                mode = 'markers')

            # Choose axes stuff, as well as create defaults
            if x_name != '':
                x_lab = x_name
            else:
                x_lab = "Column: " + x_axes
            #
            if y_name != '':
                y_lab = y_name
            else:
                y_lab = "Column: " + y_axes

            layout = Layout(title = title,
                            xaxis = dict(title = x_lab), 
                            yaxis = dict(title = y_lab)
                           )

            fig = Figure(data = Data([trace]), layout = layout)

            iplot(fig)

        # Now we need to specify our widgets
        x_widget = widgets.Dropdown(
                                    options=updated_table.columns.tolist(),
                                    value=updated_table.columns.tolist()[0],
                                    description='X axis data',
                                    disabled=False,
                                    width = '250px'
                                )

        y_widget = widgets.Dropdown(
                                    options=updated_table.columns.tolist(),
                                    value=updated_table.columns.tolist()[1],
                                    description='Y axis data',
                                    disabled=False
                                )
        kind_widget = widgets.Dropdown(
                                    options=types,
                                    value=types[0],
                                    description='Plot Type',
                                    disabled=False
                                )

                            
        title_widget = widgets.Text(
                                value='',
                                placeholder='Enter plot title',
                                description='Plot title:',
                                disabled=False,
                                continuous_update=False
                                )
        x_name_widget = widgets.Text(
                                value='',
                                placeholder='X axis title',
                                description='X axis label:',
                                disabled=False,
                                continuous_update=False
                                )
        y_name_widget = widgets.Text(
                                value='',
                                placeholder='Y axis title',
                                description='Y axis label:',
                                disabled=False,
                                continuous_update=False
                                )


        graph_widg = interactive(graph, 
                 x_axes = x_widget,
                 y_axes = y_widget,
                 kind = kind_widget,
                 title = title_widget,
                 x_name = x_name_widget,
                 y_name = y_name_widget
                       )
        box_layout = widg_layout(display='flex',
                        flex_flow='column',
                        align_items='center',
                        border='solid',
                        width='100%')

        # Set up widget layout.
        left_box = widgets.VBox([graph_widg.children[i] for i in range(3)])
        right_box = widgets.VBox([graph_widg.children[i] for i in range(3,6)])

        widget_layout = widgets.HBox([left_box, right_box])

        # graph_widg.children[-1] is the output of interactive (plotly plot)
        to_display = widgets.VBox([graph_widg.children[-1], widget_layout], layout=box_layout)

        graph_widg.children = [to_display]
        
        display.display(graph_widg)
Exemplo n.º 28
0
def load_widgets(dfDatabase, dfSelectSubst, dfSelectReact, dfInputReact):
    dirName = 'databases'
    global db_file
    origin = widgets.Dropdown(
        options=getListOfFiles(dirName),
        value=db_file,
        #  description='Available Databases:',
        layout=Layout(width='max-content'))
    # database = fun.Database(db_file)
    # select_subst = multi_checkbox_widget(database.mapSubstances())
    # select_react = multi_checkbox_widget(database.mapReactions())

    tabs = make_tabs_3(dfSelectSubst[db_file], dfSelectReact[db_file],
                       dfInputReact[db_file],
                       ['Substances', 'Reactions', 'Write Reactions'])

    plot_out = widgets.Output()
    plot3d_out = widgets.Output()
    link_out = widgets.Output()
    status_out = widgets.Output()

    box_layout2 = Layout(  #overflow='scroll',
        #border='3px solid black',
        width='max-content',
        height='500px',
        #                flex_direction='row',
        #                display='flex',
        #                align_items = 'stretch',
        color='blue')

    table_out = widgets.Output()  #layout=box_layout2)

    button = widgets.Button(
        value=False,
        description='Calculate',
        disabled=False,
        button_style='success',  # 'success', 'info', 'warning', 'danger' or ''
        tooltip='Calculate Properties',
        #    icon='check'
    )

    def on_dropdown_change(change):
        if change['name'] == 'value' and (change['new'] != change['old']):
            global db_file
            origin.disabled = True
            button.disabled = True
            db_file = change['new']
            global database
            try:
                database = fun.Database(db_file)
                reaction_equations = []
                for r in database.mapReactions().values():
                    reaction_equations.append(r.equation())
                dfSelectReact[db_file] = multi_checkbox_widget(
                    database.mapReactions(), [
                        "logKr", "reaction_gibbs_energy", "reaction_enthalpy",
                        "reaction_entropy", "reaction_heat_capacity_cp",
                        "reaction_volume"
                    ], reaction_equations)
                dfSelectSubst[db_file] = multi_checkbox_widget(
                    database.mapSubstances(), [
                        "gibbs_energy", "enthalpy", "entropy",
                        "heat_capacity_cp", "volume"
                    ])
                dfInputReact[db_file] = input_reactions_widget(
                    database.mapSubstances(), [
                        "logKr", "reaction_gibbs_energy", "reaction_enthalpy",
                        "reaction_entropy", "reaction_heat_capacity_cp",
                        "reaction_volume"
                    ])
                # select_subst_n = multi_checkbox_widget(database.mapSubstances())
                # select_react_n = multi_checkbox_widget(database.mapReactions())
                # select_subst.children = dfSelectSubst[db_file].children
                # select_react.children = dfSelectReact[db_file].children
                #ndx = copy.deepcopy(tabs.selected_index)
                tabs_new = make_tabs_3(
                    dfSelectSubst[db_file], dfSelectReact[db_file],
                    dfInputReact[db_file],
                    ['Substances', 'Reactions', 'Write Reactions'])
                tabs.children = tabs_new.children
                #tabs.selected_index=ndx

                with plot_out:
                    clear_output()
                with plot3d_out:
                    clear_output()
                with table_out:
                    clear_output()
            except Exception as e:
                with status_out:
                    clear_output(wait=True)
                    print(e)
            origin.disabled = False
            button.disabled = False

    origin.observe(on_dropdown_change)

    items = [Label(value='Available Databases:'), origin]

    # box_layout = Layout(
    #                 width='max-content',
    #                 height='',
    #                 flex_direction='row',
    #                 display='flex')
    # carousel = widgets.HBox(children=items, layout=box_layout)

    def on_button_clicked(b):
        #      with output:
        #      print("Button clicked.")
        origin.disabled = True
        button.disabled = True
        global db_file
        #display(select_subst)
        batch = fun.ThermoBatch(database)
        with status_out:
            clear_output(wait=True)
            print('Calculating...')
        batch.setPropertiesUnits(["temperature", "pressure"], ["degC", "bar"])
        batch.setPropertiesDigits([
            "gibbs_energy", "entropy", "volume", "enthalpy",
            "heat_capacity_cp", "logKr", "reaction_gibbs_energy",
            "reaction_entropy", "reaction_volume", "reaction_enthalpy",
            "reaction_heat_capacity_cp", "temperature", "pressure"
        ], [1, 4, 4, 1, 4, 4, 1, 4, 4, 1, 4, 1, 4])
        #properties = ["gibbs_energy", "enthalpy", "entropy"]

        temperature_pressure_pairs = [[50, 1000], [150, 1000], [200, 1000],
                                      [250, 1000], [300, 1000], [350, 1000],
                                      [400, 1000], [450, 1000], [500, 1000],
                                      [550, 1000], [600, 1000], [650, 1000],
                                      [700, 1000], [800, 1000], [900, 1000],
                                      [1000, 1000]]
        global pressures
        global temperatures
        global op

        batch.setBatchPreferences(op)
        batch.setTemperatureIncrement(temperatures[0], temperatures[1],
                                      temperatures[2])
        batch.setPressureIncrement(pressures[0], pressures[1], pressures[2])

        #print(pressures)
        #print(temperatures)

        try:
            if tabs.selected_index == 0:
                selected_options = [
                    w.description for w in
                    dfSelectSubst[db_file].children[0].children[1].children
                    if w.value
                ]
                selected_properties = [
                    w.description for w in
                    dfSelectSubst[db_file].children[1].children[1].children
                    if w.value
                ]
                if (len(selected_options) == 0):
                    selected_options = list(database.mapSubstances().keys())
                batch.thermoPropertiesSubstance(
                    selected_options, selected_properties).toCSV("results.csv")
            elif tabs.selected_index == 1:
                selected_options = [
                    w.description for w in
                    dfSelectReact[db_file].children[0].children[1].children
                    if w.value
                ]
                new_keys = []
                global reac_keys_dic
                for k in selected_options:
                    new_keys.append(reac_keys_dic[k])
                selected_options = new_keys
                selected_properties = [
                    w.description for w in
                    dfSelectReact[db_file].children[1].children[1].children
                    if w.value
                ]
                if (len(selected_options) == 0):
                    selected_options = list(database.mapReactions().keys())
                batch.thermoPropertiesReaction(
                    selected_options, selected_properties).toCSV("results.csv")
            elif tabs.selected_index == 2:
                selected_properties = [
                    w.description for w in
                    dfInputReact[db_file].children[2].children[1].children
                    if w.value
                ]
                selected_options = parse_reactions(
                    dfInputReact[db_file].children[1].value)
                op2 = fun.BatchPreferences()
                op2.isFixed = op.isFixed
                op2.substancePropertiesFromReaction = False
                op2.reactionPropertiesFromReactants = False
                batch.setBatchPreferences(op2)
                batch.thermoPropertiesReaction(
                    selected_options, selected_properties).toCSV("results.csv")

    #        ax=plt.gca()

            with link_out:
                clear_output(wait=True)
                display(create_csv_download_link("results.csv"))

            with status_out:
                clear_output(wait=True)
                print('Reading the results')

            with plot_out:
                clear_output(wait=True)
                df = pd.read_csv('results.csv')
                plot_substances_properties_vs_temperature(
                    'results.csv', selected_options, df['P(bar)'])
                p = pd.unique(df['P(bar)'])
                plt.show()
                print(f'Pressure {p}(bar)')
            with plot3d_out:
                clear_output(wait=True)
                df = pd.read_csv('results.csv')
                cols1 = df.columns

                fig = px.scatter_3d(df,
                                    x=df[cols1[2]],
                                    y=df[cols1[1]],
                                    z=df[cols1[3]],
                                    color='Symbol',
                                    hover_name="Symbol",
                                    width=700,
                                    height=600)

                fig.update_traces(marker=dict(size=4, opacity=0.8),
                                  selector=dict(mode='markers'))

                #buttons1 = [dict(method = "restyle",
                # args = [{'x': [df[cols1[2]]],
                #          'y': [df[cols1[1]]],
                #          'z': [df[cols1[k]]]
                #          #'color': ['Symbol', 'undefined'],
                #          #'hover_name': ['Symbol', 'undefined'],
                #          #'visible':[True, False]
                #          }
                #        ],
                # label = cols1[k])   for k in range(3, len(cols1))]

                fig.update_layout(
                    margin=dict(l=30, r=10, t=20, b=10),
                    scene_camera=dict(eye=dict(x=1.8, y=1.8, z=0.1)))

                fig.show()
            with table_out:
                clear_output(wait=True)
                df = pd.read_csv('results.csv')
                #display(df)
                table = TableDisplay(df)
                display(table)
                print(
                    "Select no record to calculate properties for all records:). "
                )
            with status_out:
                clear_output(wait=True)
                print('Finished')
        except Exception as e:
            with status_out:
                clear_output(wait=True)
                print(e)
        origin.disabled = False
        button.disabled = False

    button.on_click(on_button_clicked)

    #display(carousel)
    ui(Label(value='Available Databases:'), origin)
    display(tabs)
    #display(button)
    hbox = widgets.HBox(children=(button, link_out, status_out))
    display(hbox)

    #display(link_out)
    tabs_results = make_tabs_3(table_out, plot_out, plot3d_out,
                               ['Table', 'Plot 2D', 'Plot 3D'])
    #   hbox=widgets.HBox(children=(table_out, plot_out))
    display(tabs_results)
Exemplo n.º 29
0
    def __init__(self,
                 network: ipycytoscape.CytoscapeWidget = None,
                 model: ViewModel = None):

        self.network: ipycytoscape.CytoscapeWidget = network
        self.model: ViewModel = model

        self._source_folder: widgets.Dropdown = widgets.Dropdown(
            layout={'width': '200px'})
        self._topic_ids: widgets.SelectMultiple = widgets.SelectMultiple(
            description="",
            options=[],
            value=[],
            rows=9,
            layout={'width': '100px'})
        self._top_count: widgets.IntSlider = widgets.IntSlider(
            description='',
            min=3,
            max=200,
            value=50,
            layout={'width': '200px'})

        self._node_spacing: widgets.IntSlider = widgets.IntSlider(
            description='',
            min=3,
            max=500,
            value=50,
            layout={'width': '200px'})
        self._edge_length_val: widgets.IntSlider = widgets.IntSlider(
            description='',
            min=3,
            max=500,
            value=50,
            layout={'width': '200px'})
        self._padding: widgets.IntSlider = widgets.IntSlider(
            description='',
            min=3,
            max=500,
            value=50,
            layout={'width': '200px'})
        self._label: widgets.HTML = widgets.HTML(value='&nbsp;',
                                                 layout={'width': '200px'})
        self._output_format = widgets.Dropdown(
            description='',
            options=['network', 'table', 'gephi'],
            value='network',
            layout={'width': '200px'})
        self._network_layout = widgets.Dropdown(
            description='',
            options=[
                'cola',
                'klay',
                'circle',
                'concentric',
                # 'cise',
                # 'springy',
                # 'ngraph.forcelayout',
                # 'cose-bilkent', 'cose', 'euler', 'fcose', 'spread', 'elk', 'stress', 'force', 'avsdf',
            ],
            value='cola',
            layout={'width': '115px'},
        )
        self._button = widgets.Button(description="Display",
                                      button_style='Success',
                                      layout=widgets.Layout(
                                          width='115px',
                                          background_color='blue'))
        self._relayout = widgets.Button(description="Continue",
                                        button_style='Info',
                                        layout=widgets.Layout(
                                            width='115px',
                                            background_color='blue'))
        self._animate: widgets.Checkbox = widgets.ToggleButton(
            description="Animate",
            icon='check',
            value=True,
            layout={'width': '115px'},
        )
        self._curve_style = widgets.Dropdown(
            description='',
            options=[
                ('Straight line', 'haystack'),
                ('Curve, Bezier', 'bezier'),
                ('Curve, Bezier*', 'unbundled-bezier'),
            ],
            value='haystack',
            layout={'width': '115px'},
        )

        self.loader: Callable[[str], topic_modelling.InferredTopicsData] = None
        self.displayer: Callable[["TopicsTokenNetworkGUI"], None] = None
        self._custom_styles: dict = None
        self._buzy: bool = False
Exemplo n.º 30
0
    def im_line(self,
                z=None,
                zmin=None,
                zmax=None,
                xind=None,
                yind=None,
                cmap='jet'):
        if self._interactive:
            has_xind = xind is not None
            has_yind = yind is not None
            if not z or not has_xind or not has_yind:
                if xind is None:
                    widget_xind = widgets.IntSlider(min=0,
                                                    max=10,
                                                    step=1,
                                                    description='X:')
                else:
                    widget_xind = fixed(xind)

                if yind is None:
                    widget_yind = widgets.IntSlider(min=0,
                                                    max=10,
                                                    step=1,
                                                    description='Y:')
                else:
                    widget_yind = fixed(yind)

                if not z:
                    valid_var_names = list()
                    for dim_names, var_names in self._inspector.dim_names_to_var_names.items(
                    ):
                        no_zero_dim = all([
                            self._inspector.dim_name_to_size[dim] > 0
                            for dim in dim_names
                        ])
                        if no_zero_dim and len(dim_names) == 2:
                            valid_var_names.extend(var_names)
                    valid_var_names = sorted(valid_var_names)
                    value = z if z and z in valid_var_names else valid_var_names[
                        0]
                    widget_var = widgets.Dropdown(options=valid_var_names,
                                                  value=value,
                                                  description='Var:')

                    # noinspection PyUnusedLocal
                    def on_widget_var_change(change):
                        variable = self._inspector.dataset[widget_var.value]
                        if xind is None:
                            widget_xind.max = variable.shape[1] - 1
                        if yind is None:
                            widget_yind.max = variable.shape[0] - 1

                    widget_var.observe(on_widget_var_change, names='value')
                else:
                    widget_var = fixed(z)

                # TODO (forman, 20160709): add sliders for zmin, zmax
                interact(self._plot_im_line,
                         z_name=widget_var,
                         xind=widget_xind,
                         yind=widget_yind,
                         zmin=fixed(zmax),
                         zmax=fixed(zmax),
                         cmap=fixed(cmap))
        else:
            if not z:
                raise ValueError('z_name must be given')
            self._plot_im_line(z,
                               zmin=zmin,
                               zmax=zmin,
                               xind=xind,
                               yind=yind,
                               cmap=cmap)