Ejemplo n.ยบ 1
0
# Values
months = ['   ','01','02','03','04','05','06','07','08','09','10','11','12']
years = ['2019','2018','2017','2016','2015','2014']

# Drop Down menues
month_dd=widgets.Dropdown(options=months,value='   ',
    description='Month:',style=style)
year_dd=widgets.Dropdown(options=years,value='2019',
    description='Year:',style=style)

# General choice menus
outliers_choice = widgets.RadioButtons(options=['Remove', 'Keep'],value = 'Remove', description='Ouliers:',style=style)
download_choice = widgets.RadioButtons(options=['CSV','Excel','None'],value = 'CSV', description='Download:',style=style)
output_choice = widgets.RadioButtons(options=['HTML File','Notebook'],value = 'HTML File', description='Output:',style=style)

button = widgets.Button(description = "Run",style=style)
button.style.button_color = 'lightgreen'

prescribing_tab = HBox(children=[bnf_code_dd,prescribing_measures_dd])
prevalence_tab = HBox(children=[prevalence_indications_dd,prevalence_measures_dd])
age_gender_tab = HBox(children=[age_groups_dd,gender_dd,gender_age_measures_dd])
deprivation_tab= HBox(children=[deprivation_dd,deprivation_measures_dd])

tabs = widgets.Tab(children=[prescribing_tab,prevalence_tab, age_gender_tab,deprivation_tab])
tabs.set_title(0, 'Prescribing')
tabs.set_title(1, 'Prevalence')
tabs.set_title(2, 'Age and Gender')
tabs.set_title(3, 'Deprivation')

button_date_box=HBox(children=[month_dd,year_dd,outliers_choice,download_choice,output_choice,button])
Ejemplo n.ยบ 2
0
class Demo:
    # Cats & Dogs classes
    NUM_CLASSES = 2

    # RGB
    CHANNELS = 3

    RESNET50_POOLING_AVERAGE = 'avg'
    DENSE_LAYER_ACTIVATION = 'softmax'
    OBJECTIVE_FUNCTION = 'categorical_crossentropy'

    # Common accuracy metric for all outputs, but can use different metrics for different output
    LOSS_METRICS = ['accuracy']

    IMAGE_SIZE = 160  # All images will be resized to 160x160
    IMAGE_SHAPE = (IMAGE_SIZE, IMAGE_SIZE, 3)

    batch_size = 32
    epochs = 2
    fine_tune_at = 100

    ngraph_backends = ngraph_bridge.list_backends()
    ngraph_backends.append('DISABLED')
    ngraph_bridge.set_backend(ngraph_backends[0])

    base_model = None
    model = None

    # GUI Elements
    out = widgets.Output(layout={'border': '1px solid black'})
    out_initial = widgets.Output(layout={'border': '1px solid black'})
    out_stats = widgets.Output(layout={'border': '1px solid black'})

    model_dropdown = widgets.Dropdown(options=['ResNet50', 'MobileNet v2'],
                                      value='ResNet50',
                                      description='Model:')
    ngraph_dropdown = widgets.Dropdown(options=ngraph_backends,
                                       value=ngraph_backends[0],
                                       description='nGraph:')

    progress_bar = widgets.IntProgress()
    progress_text = widgets.Label()
    epoch_text = widgets.Label()
    progress_box = widgets.HBox([progress_bar, progress_text, epoch_text])

    batch_slider = widgets.IntSlider(min=1,
                                     max=100,
                                     value=batch_size,
                                     description='Batch Size:')
    epoch_slider = widgets.IntSlider(min=1,
                                     max=16,
                                     value=epochs,
                                     description='Epochs:')
    fine_tune_slider = widgets.IntSlider(min=1,
                                         max=500,
                                         value=fine_tune_at,
                                         description='Fine Tune at Layer:')

    train_button = widgets.Button(description='Train', disabled=True)
    classify_button = widgets.Button(description='Classify', disabled=True)
    fine_tune_button = widgets.Button(description='Fine Tune', disable=True)
    shuffle_button = widgets.Button(description='Shuffle')

    training_tab = widgets.VBox(children=[
        model_dropdown, ngraph_dropdown, batch_slider, epoch_slider,
        train_button, classify_button, shuffle_button
    ])
    fine_tuning_tab = widgets.VBox(children=[
        batch_slider, epoch_slider, fine_tune_slider, fine_tune_button,
        classify_button, shuffle_button
    ])
    tab = widgets.Tab(children=[training_tab, fine_tuning_tab])
    tab.set_title(0, 'Training')
    tab.set_title(1, 'Fine Tuning')
    gui = widgets.VBox(children=[tab, progress_box, out_initial, out])

    def __init__(self, gui=0, training=1):
        self.gui = gui

        if gui:
            self.gui = widgets.VBox(children=[
                self.tab, self.progress_box, self.out_initial, self.out,
                self.out_stats
            ])
            display(self.init_gui())

        # Images
        self.test_class_indices = []
        self.test_dir = None
        self.init_images()

        self.sgd = optimizers.SGD(lr=0.01,
                                  decay=1e-6,
                                  momentum=0.9,
                                  nesterov=True)
        self.predicted_class_indices_init = []
        self.wrong_guesses = []

        self.train_button.disabled = False
        self.fine_tune_button.disabled = False

        self.init_model()

        if training:
            self.train_model(self.train_button)

    def init_images(self):
        zip_file = tf.keras.utils.get_file(
            origin=
            "https://storage.googleapis.com/mledu-datasets/cats_and_dogs_filtered.zip",
            fname="cats_and_dogs_filtered.zip",
            extract=True)
        base_dir, _ = os.path.splitext(zip_file)
        train_dir = os.path.join(base_dir, 'train')
        validation_dir = os.path.join(base_dir, 'validation')
        self.test_dir = os.path.join(base_dir, 'test')
        if not os.path.exists(self.test_dir):
            os.makedirs(self.test_dir)

        # Directory with our training cat pictures
        train_cats_dir = os.path.join(train_dir, 'cats')

        # Directory with our training dog pictures
        train_dogs_dir = os.path.join(train_dir, 'dogs')

        # Directory with our validation cat pictures
        validation_cats_dir = os.path.join(validation_dir, 'cats')

        # Directory with our validation dog pictures
        validation_dogs_dir = os.path.join(validation_dir, 'dogs')

        # Directory with our test cat pictures
        test_cats_dir = os.path.join(self.test_dir, 'cats')
        if not os.path.exists(test_cats_dir):
            os.makedirs(test_cats_dir)
            for i in range(900, 1000):
                os.rename(train_cats_dir + '/cat.' + str(i) + '.jpg',
                          test_cats_dir + '/cat.' + str(i) + '.jpg')

        # Directory with our test dog pictures
        test_dogs_dir = os.path.join(self.test_dir, 'dogs')
        if not os.path.exists(test_dogs_dir):
            os.makedirs(test_dogs_dir)
            for i in range(900, 1000):
                os.rename(train_dogs_dir + '/dog.' + str(i) + '.jpg',
                          test_dogs_dir + '/dog.' + str(i) + '.jpg')

        # Preprocess images
        train_datagen = ImageDataGenerator(
            preprocessing_function=preprocess_input)
        validation_datagen = ImageDataGenerator(
            preprocessing_function=preprocess_input)

        with self.out_stats:
            # Flow training images in batches of 20 using train_datagen generator
            self.train_generator = train_datagen.flow_from_directory(
                train_dir,  # Source directory for the training images
                target_size=(self.IMAGE_SIZE, self.IMAGE_SIZE),
                batch_size=self.batch_size,
                class_mode='categorical')

            # Flow validation images in batches of 20 using test_datagen generator
            self.validation_generator = validation_datagen.flow_from_directory(
                validation_dir,  # Source directory for the validation images
                target_size=(self.IMAGE_SIZE, self.IMAGE_SIZE),
                batch_size=self.batch_size,
                class_mode='categorical')

            # Flow validation images in batches of 20 using test_datagen generator
            self.test_generator = validation_datagen.flow_from_directory(
                self.test_dir,  # Source directory for the test images
                target_size=(self.IMAGE_SIZE, self.IMAGE_SIZE),
                batch_size=self.batch_size,
                class_mode=None,
                shuffle=False,
                seed=42)

        # Test Correct Values (0 Cat, 1 Dog)
        for file in self.test_generator.filenames:
            if "cat" in file:
                self.test_class_indices.append(0)
            elif "dog" in file:
                self.test_class_indices.append(1)
            else:
                print("Error, unclassifiable image " + file)

    def init_model(self, b=None):
        self.out_initial.clear_output()
        self.out.clear_output()
        self.out_stats.clear_output()

        # Initial prediction
        self.progress_bar.max = 13
        self.progress_text.value = "Calculating Initital Predictions"

        with self.out:
            self.compile_model(self.model_dropdown.value)
        predictions_initial = self.model.predict_generator(
            self.test_generator, verbose=0, callbacks=[ProgressBar(self)])
        self.predicted_class_indices_init = np.argmax(predictions_initial,
                                                      axis=1)

        # ~ operator is equivalent to -x-1; so 0 becomes -1, 1 becomes -2; add 2 to implement xnor
        guesses = ~(self.predicted_class_indices_init
                    ^ self.test_class_indices) + 2

        # Randomly select 9 images that guessed incorrectly
        self.wrong_guesses = []
        while len(self.wrong_guesses) < 9:
            randomIndex = random.randint(
                0,
                len(self.predicted_class_indices_init) - 1)
            if not guesses[randomIndex]:
                self.wrong_guesses.append(randomIndex)

        if self.gui:
            with self.out_initial:
                f, ax = plt.subplots(3, 3, figsize=(15, 15))

                for i in range(0, 9):
                    test_image = os.path.join(
                        self.test_dir,
                        self.test_generator.filenames[self.wrong_guesses[i]])
                    imgRGB = mpimg.imread(test_image)

                    predicted_class = "Dog" if self.predicted_class_indices_init[
                        self.wrong_guesses[i]] else "Cat"

                    ax[i // 3, i % 3].imshow(imgRGB)
                    ax[i // 3, i % 3].axis('off')
                    ax[i // 3,
                       i % 3].set_title("Predicted:{}".format(predicted_class),
                                        color='r')

                    if predicted_class.lower(
                    ) in self.test_generator.filenames[self.wrong_guesses[i]]:
                        ax[i // 3, i % 3].set_title(
                            "Predicted:{}".format(predicted_class), color='g')
                plt.show()

    def on_model_change(self, change):
        if change['type'] == 'change' and change['name'] == 'value':
            self.classify_button.disabled = True

            if change['new'] == 'ResNet50':
                self.epoch_slider.min = 1
                self.epoch_slider.max = 16
                self.epoch_slider.value = 2
            if change['new'] == 'MobileNet v2':
                self.epoch_slider.min = 2
                self.epoch_slider.max = 50
                self.epoch_slider.value = 10

    def on_ngraph_change(self, change):
        if change['type'] == 'change' and change['name'] == 'value':
            i = self.ngraph_backends.index(change['new'])

            if self.ngraph_backends[i] == 'DISABLED':
                self.use_ngraph = False
                ngraph_bridge.disable()
            else:
                self.use_ngraph = True
                ngraph_bridge.enable()
                ngraph_bridge.set_backend(self.ngraph_backends[i])

    def init_gui(self):
        self.model_dropdown.observe(self.on_model_change)
        self.ngraph_dropdown.observe(self.on_ngraph_change)
        self.train_button.on_click(self.train_model)
        self.shuffle_button.on_click(self.init_model)
        self.classify_button.on_click(self.classify)
        self.fine_tune_button.on_click(self.train_model)

        return self.gui

    def train_model(self,
                    b=None,
                    epochs=1,
                    batch_size=32,
                    model='ResNet50',
                    fine_tune_at=0):
        if self.gui:
            self.train_button.disabled = True
            self.epochs = self.epoch_slider.value
            self.batch_size = self.batch_slider.value
            model = self.model_dropdown.value
            self.progress_text.value = ''
        else:
            self.epochs = epochs
            self.batch_size = batch_size

        self.out.clear_output()

        if b == self.fine_tune_button:
            fine_tune_at = self.fine_tune_slider.value
        else:
            fine_tune_at = 0

        self.compile_model(model, fine=fine_tune_at)
        steps_per_epoch = self.train_generator.n // self.batch_size
        validation_steps = self.validation_generator.n // self.batch_size

        with self.out_stats:
            history = self.model.fit_generator(
                self.train_generator,
                steps_per_epoch=steps_per_epoch,
                epochs=self.epochs,
                workers=8,
                validation_data=self.validation_generator,
                validation_steps=validation_steps,
                verbose=0,
                callbacks=[ProgressBar(self)])
        self.classify_button.disabled = False
        # Test model immediately after training
        self.classify(b)

        self.train_button.disabled = False

        return history

    def compile_model(self, modelName, fine=0):
        if modelName == 'ResNet50':
            self.base_model = ResNet50(input_shape=self.IMAGE_SHAPE,
                                       include_top=False,
                                       weights='imagenet')
        elif modelName == 'MobileNet v2':
            self.base_model = MobileNetV2(input_shape=self.IMAGE_SHAPE,
                                          include_top=False,
                                          weights='imagenet')

        # GUI element update
        self.fine_tune_slider.max = len(self.base_model.layers)

        with self.out_stats:
            print('Setting base model to ' + modelName)

        # Fine Tuning
        if fine:
            self.base_model.trainable = True
            # Fine tune from this layer onwards
            self.fine_tune_at = fine

            # Freeze all the layers before the `fine_tune_at` layer
            for layer in self.base_model.layers[:self.fine_tune_at]:
                layer.trainable = False

            with self.out_stats:
                print('Fine tuning at layer ' + str(fine))

        # Training
        else:
            self.base_model.trainable = False

        # Add layers
        self.model = tf.keras.Sequential([
            self.base_model,
            keras.layers.GlobalAveragePooling2D(),
            keras.layers.Dense(self.NUM_CLASSES,
                               activation=self.DENSE_LAYER_ACTIVATION)
        ])
        self.model.compile(optimizer=self.sgd,
                           loss=self.OBJECTIVE_FUNCTION,
                           metrics=self.LOSS_METRICS)

    def classify(self, b):
        if b and b.description == 'Classify':
            out.clear_output()

        with self.out_stats:
            probabilities = self.model.predict_generator(
                self.test_generator, verbose=0, callbacks=[ProgressBar(self)])

        predicted_class_indices = np.argmax(probabilities, axis=1)

        if self.gui:
            with self.out:
                f, ax = plt.subplots(3, 3, figsize=(15, 15))

                for i in range(0, 9):
                    test_image = os.path.join(
                        self.test_dir,
                        self.test_generator.filenames[self.wrong_guesses[i]])
                    imgRGB = mpimg.imread(test_image)

                    predicted_class = "Dog" if predicted_class_indices[
                        self.wrong_guesses[i]] else "Cat"

                    ax[i // 3, i % 3].imshow(imgRGB)
                    ax[i // 3, i % 3].axis('off')
                    ax[i // 3,
                       i % 3].set_title("Predicted:{}".format(predicted_class),
                                        color='r')

                    if predicted_class.lower(
                    ) in self.test_generator.filenames[self.wrong_guesses[i]]:
                        ax[i // 3, i % 3].set_title(
                            "Predicted:{}".format(predicted_class), color='g')
                plt.show()

        with self.out_stats:
            wrong = ~(predicted_class_indices ^ self.test_class_indices) + 2
            print("Correct Matrix")
            print(wrong)

        print("Total guessed:", wrong.shape[0])
        print("Accuracy:", np.count_nonzero(wrong) / wrong.shape[0])
Ejemplo n.ยบ 3
0
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 = [
    'About', 'Config Basics', 'Microenvironment', 'Cells', 'User Params',
    'Out: Plots'
]
#tabs = widgets.Tab(children=[about_tab.tab, config_tab.tab, microenv_tab.tab, user_tab.tab, svg.tab, sub.tab],
tabs = widgets.Tab(children=[
    about_tab.tab, config_tab.tab, microenv_tab.tab, cell_tab.tab,
    user_tab.tab, sub.tab
],
                   _titles={i: t
                            for i, t in enumerate(titles)},
                   layout=tab_layout)

homedir = os.getcwd()

tool_title = widgets.Label(r'\(\textbf{pc4biorobots}\)')
if nanoHUB_flag or hublib_flag:
    # define this, but don't use (yet)
    remote_cb = widgets.Checkbox(
        indent=False,
        value=False,
        description='Submit as Batch Job to Clusters/Grid')

    top_row = widgets.HBox(children=[read_config, tool_title])
Ejemplo n.ยบ 4
0
    def __init__(self):
        """Set up all widget GUI elements and class attributes."""
        self.status_output = None
        self.subsys_candidates_dict = self.get_subsys_candidates()
        self.interactions_count = 0
        self.current_interaction_key = ""
        self.interactions_dict = {}

        # == subsystems panel =========================================================
        label = ipywidgets.Label(value="Select subsystems (Ctrl-Click)")
        self.subsys_refresh_button = ipywidgets.Button(
            icon="refresh", layout=ipywidgets.Layout(width="35px")
        )
        self.subsys_toprow = ipywidgets.HBox([label, self.subsys_refresh_button])

        self.subsys_widget = ipywidgets.SelectMultiple(
            options=list(self.subsys_candidates_dict.keys()),
            rows=10,
            description="",
            disabled=False,
            layout=ipywidgets.Layout(width="220px"),
        )
        self.subsys_box = ipywidgets.VBox([self.subsys_toprow, self.subsys_widget])

        # == InteractionTerms list panel ==============================================
        label = ipywidgets.Label(value="Interaction term(s)   ")
        self.interact_new_button = ipywidgets.Button(
            icon="plus", layout=ipywidgets.Layout(width="35px")
        )
        self.interact_del_button = ipywidgets.Button(
            icon="remove", layout=ipywidgets.Layout(width="35px")
        )
        self.interact_buttons = ipywidgets.HBox(
            [label, self.interact_new_button, self.interact_del_button]
        )
        self.interact_list_widget = ipywidgets.Select(
            options=[],
            rows=10,
            description="",
            disabled=False,
            layout=ipywidgets.Layout(width="200px"),
        )
        self.interact_list_box = ipywidgets.VBox(
            [self.interact_buttons, self.interact_list_widget]
        )

        # == Panel for specifying an InteractionTerm ==================================
        self.op1subsys_widget = ipywidgets.Dropdown(
            options=self.subsys_widget.value, description="subsys1", disabled=False
        )
        self.op2subsys_widget = ipywidgets.Dropdown(
            options=self.subsys_widget.value, description="subsys2", disabled=False
        )
        self.op1_ddown_widget = ipywidgets.Dropdown(
            options=self.possible_operators(self.op1subsys_widget.value),
            description="op1",
            disabled=False,
        )
        self.op2_ddown_widget = ipywidgets.Dropdown(
            options=self.possible_operators(self.op2subsys_widget.value),
            description="op2",
            disabled=False,
        )
        self.g_widget = ipywidgets.FloatText(description="g_strength")
        self.addhc_widget = ipywidgets.Dropdown(
            description="add_hc", options=["False", "True"]
        )

        self.interact_box1 = ipywidgets.VBox(
            [
                ipywidgets.Label(value="Specify interaction"),
                self.op1subsys_widget,
                self.op1_ddown_widget,
                self.op2subsys_widget,
                self.op2_ddown_widget,
                self.g_widget,
                self.addhc_widget,
            ]
        )

        self.string_expr_widget = ipywidgets.Text(
            description="expr", placeholder="e.g., EJ * cos(op1 - op2)"
        )
        self.interact_box2 = ipywidgets.VBox(
            [
                ipywidgets.Label(value="Specify interaction"),
                self.string_expr_widget,
                self.op1subsys_widget,
                self.op1_ddown_widget,
                self.op2subsys_widget,
                self.op2_ddown_widget,
                self.addhc_widget,
            ]
        )

        self.tabs_select_interact_type = ipywidgets.Tab(
            layout=ipywidgets.Layout(width="350px")
        )
        self.tabs_select_interact_type.children = [
            self.interact_box1,
            self.interact_box2,
        ]
        self.tabs_select_interact_type.set_title(0, "g * op1 * op2")
        self.tabs_select_interact_type.set_title(1, "Python expr")
        self.tabs_select_interact_type.layout.display = "none"

        # == Central run button, status output field ==================================
        self.run_button = ipywidgets.Button(
            description="Create HilbertSpace object",
            layout=ipywidgets.Layout(width="200px"),
        )
        self.status_output = ipywidgets.Output()

        # == Wrap everything into boxes ===============================================
        self.all_panels = ipywidgets.HBox(
            [self.subsys_box, self.interact_list_box, self.tabs_select_interact_type],
            layout=ipywidgets.Layout(grid_gap="50px"),
        )
        self.ui = ipywidgets.VBox(
            [self.all_panels, self.run_button, self.status_output]
        )

        # == Make GUI connections =====================================================
        self.connect_ui()
Ejemplo n.ยบ 5
0
def eda_num_univ_binary(dataset):
    '''dataset:pd.DataFrame'''
    dataset_num = dataset.select_dtypes(exclude='object')
    if len(dataset_num[dataset_num.columns.values[-1]].unique()) == 2:
        dataset_num = dataset_num.iloc[:, :-1]
    else:
        dataset_num = dataset.select_dtypes(exclude='object')

    tab_contents = [i for i in dataset_num.columns.values]
    children = [widgets.Output() for value in tab_contents]
    tab = widgets.Tab(children=children)
    [tab.set_title(num, name) for num, name in enumerate(tab_contents)]
    display(tab)

    for i, k in enumerate(dataset_num.columns.values):
        # overview table
        count_num = dataset_num[k].count()
        distinct_count_num = dataset_num[k].nunique()
        unique_num = round(100 * (dataset[k].nunique() / len(dataset)), 2)
        missing_num = dataset_num[k].isnull().sum().sum()
        missing_num_perc = 100 * (missing_num / len(dataset_num))
        zeros_num_count = (dataset_num[k] == 0).sum()
        zeros_num_count_perc = 100 * (zeros_num_count / len(dataset))

        df1_num = pd.DataFrame([
            count_num, distinct_count_num, unique_num, missing_num,
            missing_num_perc, zeros_num_count, zeros_num_count_perc
        ],
                               columns=[''],
                               index=[
                                   'Total count', 'Distinct count',
                                   'Unique (%)', 'Missing', 'Missing (%)',
                                   'Zeros', 'Zeros (%)'
                               ])
        df1_num.index.name = 'Overview'
        # descriptive stats table
        df2_num = pd.DataFrame(dataset_num[k].describe().round(2))
        df2_num.columns = ['']
        df2_num = df2_num.drop('count')
        df2_num.loc['kurtosis'] = dataset_num[k].kurtosis(axis=0)
        df2_num.loc['skew'] = dataset_num[k].skew(axis=0)
        df2_num.index.name = 'Descriptive Statistics'
        df2_num = df2_num.style.set_precision(2)
        # Frequency top 7
        freq_top = pd.DataFrame(dataset_num[k].value_counts().sort_values(
            ascending=False).head(10)).rename(columns={
                k: 'Frequency'
            }).reset_index()
        freq_top['Frequency (%)'] = 100 * (freq_top['Frequency'] /
                                           len(dataset))
        freq_top = freq_top.rename(columns={
            'index': k,
            'Frequency': 'Frequency'
        })
        freq_top = freq_top.style.hide_index().set_caption(
            "Frequency top").set_precision(2)

        # Frequency bottom 7
        freq_bottom = pd.DataFrame(dataset_num[k].value_counts().sort_values(
            ascending=False).tail(10)).rename(columns={
                k: 'Frequency'
            }).reset_index()
        freq_bottom['Frequency (%)'] = 100 * (freq_bottom['Frequency'] /
                                              len(dataset))
        freq_bottom = freq_bottom.rename(columns={
            'index': k,
            'Frequency': 'Frequency'
        })
        freq_bottom = freq_bottom.style.hide_index().set_caption(
            "Frequency bottom").set_precision(3)

        out1 = widgets.Output()
        out2 = widgets.Output()
        out3 = widgets.Output()
        out4 = widgets.Output()
        with out1:
            display(df1_num)
        with out2:
            display(df2_num)
        with out3:
            display(freq_top)
        with out4:
            display(freq_bottom)
        hbox = widgets.HBox([out1, out2, out3, out4])

        with children[i]:
            display(hbox)

            x_titles = list(dataset_num.columns)

            fig1 = px.histogram(dataset_num,
                                x=dataset_num[k],
                                labels={
                                    'x': x_titles[i],
                                    'y': 'count'
                                },
                                histnorm='percent')
            fig2 = px.box(dataset_num,
                          y=dataset_num[k],
                          labels={
                              'x': x_titles[i],
                              'y': 'percent'
                          })

            trace1 = fig1['data'][0]
            trace2 = fig2['data'][0]
            fig = make_subplots(rows=1,
                                cols=2,
                                subplot_titles=['Histogram', 'Box plot'])
            fig.layout["xaxis"].title.text = k
            fig.layout["xaxis2"].title.text = ''
            fig.layout["yaxis"].title.text = 'percent'
            fig.layout["yaxis2"].title.text = k

            fig.add_trace(trace1, 1, 1)
            fig.add_trace(trace2, 1, 2)
            fig.update_layout(template='plotly_dark')
            fig.show()
Ejemplo n.ยบ 6
0
    def vis(self):
        ''' display tabbed widget with results from different dataframes, usuallly 2 but more can be shown
        
        dfs is a list of dataframes. They should be of same dimensionalities 
        
        '''
        self.basekey = [key for key in self.dfs.keys()][0]

        wexperiment_name = widgets.Text(
            value=self.basekey,
            placeholder='Type something',
            description='Name of these experiments:',
            layout={'width': '55%'},
            style={'description_width': '45%'})

        wsavefig = widgets.Button(description="Save figure")
        wbut = widgets.HBox([wsavefig, wexperiment_name])

        wfile_folder = widgets.Text(value='test2',
                                    placeholder='Type something',
                                    description='Figure saved in:',
                                    layout={'width': '65%'},
                                    style={'description_width': '25%'},
                                    visible=False,
                                    disabled=True)
        wfile_folder.layout.visibility = 'hidden'

        wopen = widgets.Button(description="Open the saved figures")
        wopen.layout.visibility = 'hidden'

        winputstring = widgets.VBox([wfile_folder, wopen])

        avar = self.dfs[list(self.dfs.keys())[0]].columns
        outlist = [widgets.Output() for var in avar]
        outdiflist = [widgets.Output() for var in avar]
        reslist = [widgets.Output() for var in avar]
        resdiflist = [widgets.Output() for var in avar]
        varouttablist = [
            widgets.Tab(children=[out, outdif, res, resdif]) for out, outdif,
            res, resdif in zip(outlist, outdiflist, reslist, resdiflist)
        ]
        for var, varouttab in zip(avar, varouttablist):
            for i, tabtext in enumerate(
                ['Level', 'Impact', 'Level data', 'Impact data']):
                varouttab.set_title(i, tabtext)

        controllist = [
            widgets.VBox([varouttab]) for varouttab in varouttablist
        ]
        tab = widgets.Tab(children=controllist)

        for i, (var, out) in enumerate(zip(avar, controllist)):
            tab.set_title(i, var)

        def showvar(b):
            wfile_folder.layout.visibility = 'hidden'
            wopen.layout.visibility = 'hidden'

            sel = b['new']
            out = outlist[sel]
            outdif = outdiflist[sel]
            res = reslist[sel]
            resdif = resdiflist[sel]
            var = avar[sel]
            self.selected = sel
            self.selected_var = var
            with out:
                clear_output()
                self.fig_level = self.plot_level(var)
                plt.show(self.fig_level)
            with outdif:
                clear_output()
                self.fig_dif = self.plot_dif(var)
                plt.show(self.fig_dif)
            with res:
                clear_output()
                out = pd.concat([df.loc[:, var] for k, df in self.dfs.items()],
                                axis=1)
                out.columns = [k for k in self.dfs.keys()]
                print(self.trans.get(var, var))
                print(out.to_string(float_format=self.formatnumber(var, out)))
            with resdif:
                clear_output()
                baseline = self.dfs[[
                    k for i, k in enumerate(self.dfs.keys()) if i == 0
                ][0]].loc[:, [var]]
                out = pd.concat([
                    df.loc[:, [var]] - baseline
                    for i, (k, df) in enumerate(self.dfs.items()) if i >= 1
                ],
                                axis=1)
                out.columns = [
                    k for i, k in enumerate(self.dfs.keys()) if i >= 1
                ]
                # out.style.set_caption(self.trans.get(var,var))
                print(self.trans.get(var, var))
                print(out.to_string(float_format=self.formatnumber(var, out)))

        outtab = widgets.VBox([tab, wbut, winputstring])

        def savefig(s):
            self.graph_folde = os.path.join(os.getcwd(), 'experiments',
                                            wexperiment_name.value, 'graph')
            self.figlocation = os.path.join(self.graph_folde,
                                            f'{self.selected_var}')
            self.figlocation_impact = os.path.join(
                self.graph_folde, f'{self.selected_var}-impact')
            wfile_folder.layout.visibility = 'visible'
            if self.showfig:
                wopen.layout.visibility = 'visible'
            else:
                wopen.layout.visibility = 'hidden'

            try:
                if not os.path.exists(self.graph_folde):
                    os.makedirs(self.graph_folde)
            except:
                wfile_folder.value = f"Can't create  {self.graph_folde}"
                return

            try:
                self.fig_level.savefig(self.figlocation + '.svg')
                self.fig_dif.savefig(self.figlocation_impact + '.svg')
                self.fig_level.savefig(self.figlocation + '.pdf')
                self.fig_dif.savefig(self.figlocation_impact + '.pdf')
                wfile_folder.value = self.graph_folde
            except:
                wfile_folder.value = f"Can't write to {self.graph_folde}, remember to close"

        def openfig_svg(s):
            try:
                wb.open(self.figlocation_impact + '.svg', new=2)
                wb.open(self.figlocation + '.svg', new=2)
                # os.system(self.figlocation)
                # os.system(self.figlocation_impact)
            except:
                wfile_folder.layout.visibility = 'visible'
                wfile_folder.value = f"Can't open to {self.figlocation}.svg Try to download the file"

        def openfig_pdf(s):
            try:
                wb.open(self.figlocation_impact + '.pdf')
                wb.open(self.figlocation + '.pdf')
            except:
                wfile_folder.layout.visibility = 'visible'
                wfile_folder.value = f"Can't open to {self.figlocation}.svg Try to download the file"

        if self.showfig: wopen.on_click(openfig_svg)

        wsavefig.on_click(savefig)

        display(outtab)

        showvar({'new': 0})
        tab.observe(showvar, 'selected_index')
    def __init__(self, path_or_url, **kw):
        # data
        self.path = path_or_url
        x, y, w, labels = read2d(path_or_url, **kw)
        if 'labels' not in kw:
            kw['labels'] = labels

        self.x = x
        self.y = y
        self.w = w
        self.kw = kw

        x0 = x[0]
        y0 = y[:, 0]
        xmin, xmax, dx = x[0, 0], x[0, -1], x[0, 1] - x[0, 0]
        ymin, ymax, dy = y[0, 0], y[-1, 0], y[1, 0] - y[0, 0]
        wmin, wmax = np.min(w), np.max(w)
        dw = (wmax - wmin) / 20

        # UI
        self.s_xpos = widgets.FloatSlider(value=(xmin + xmax) / 2,
                                          min=xmin,
                                          max=xmax,
                                          step=dx,
                                          description='x')
        self.s_ypos = widgets.FloatSlider(value=(ymin + ymax) / 2,
                                          min=ymin,
                                          max=ymax,
                                          step=dy,
                                          description='y')
        vb1 = widgets.VBox([self.s_xpos, self.s_ypos])
        self.s_gamma = widgets.IntSlider(value=0,
                                         min=-100,
                                         max=100,
                                         step=10,
                                         description='gamma')
        self.s_vlim = widgets.FloatRangeSlider(value=[wmin, wmax],
                                               min=wmin,
                                               max=wmax,
                                               step=dw,
                                               description='limit')
        self.c_cmap = widgets.Combobox(value='',
                                       placeholder='Choose or type',
                                       options=plt.colormaps(),
                                       description='colormap:',
                                       ensure_option=False,
                                       disabled=False)
        vb2 = widgets.VBox([self.s_gamma, self.s_vlim, self.c_cmap])
        self.b_expMTX = widgets.Button(description='To mtx')
        self.html_exp = widgets.HTML()
        vb3 = widgets.VBox([self.b_expMTX, self.html_exp])
        ui = widgets.Tab(children=[vb1, vb2, vb3])
        [
            ui.set_title(i, j)
            for i, j in zip(range(3), ['linecuts', 'color', 'export'])
        ]
        display(ui)

        # figure
        fig, axs = plt.subplots(1, 2,
                                figsize=(6.5, 2.5))  #main plot and h linecut
        fig.canvas.header_visible = False
        fig.canvas.toolbar_visible = False
        fig.canvas.resizable = False

        plt.subplots_adjust(wspace=0.4, bottom=0.2)
        axs[1].yaxis.tick_right()
        axs[1].tick_params(axis='x', colors='tab:orange')
        axs[1].tick_params(axis='y', colors='tab:orange')
        axv = fig.add_axes(axs[1].get_position(),
                           frameon=False)  #ax vertical linecut
        axv.xaxis.tick_top()
        axv.tick_params(axis='x', colors='tab:blue')
        axv.tick_params(axis='y', colors='tab:blue')
        self.fig = fig
        self.ax = axs[0]
        self.axv = axv
        self.axh = axs[1]

        # plot 2D data
        g = self.s_gamma.value
        v0, v1 = self.s_vlim.value
        self.kw['gamma'], self.kw['vmin'], self.kw['vmax'] = g, v0, v1
        Painter.plot2d(self.x,
                       self.y,
                       self.w,
                       fig=self.fig,
                       ax=self.ax,
                       **self.kw)

        self.im = [
            obj for obj in self.ax.get_children()
            if isinstance(obj, mpl.image.AxesImage)
            or isinstance(obj, mpl.collections.QuadMesh)
        ][0]

        # vlinecut
        xpos = self.s_xpos.value
        indx = np.abs(x0 - xpos).argmin()  # x0 may be a non uniform array
        [self.linev1] = axs[0].plot(x[:, indx], y0, 'tab:blue')
        [self.linev2] = axv.plot(w[:, indx], y0, 'tab:blue')
        self.indx = indx

        # hlinecut
        ypos = self.s_ypos.value
        indy = np.abs(y0 - ypos).argmin()
        [self.lineh1] = axs[0].plot(x0, y[indy, :], 'tab:orange')
        [self.lineh2] = axs[1].plot(x0, w[indy, :], 'tab:orange')
        self.indy = indy

        self.s_gamma.observe(self.on_gamma_change, 'value')
        self.s_vlim.observe(self.on_vlim_change, 'value')
        self.c_cmap.observe(self.on_cmap_change, 'value')
        self.s_xpos.observe(self.on_xpos_change, 'value')
        self.s_ypos.observe(self.on_ypos_change, 'value')
        self.fig.canvas.mpl_connect('button_press_event', self.on_mouse_click)
        self.b_expMTX.on_click(self.exportMTX)
Ejemplo n.ยบ 8
0
tab_layout = widgets.Layout(
    width='auto',
    height=tab_height,
    overflow_y='scroll',
)  # border='2px solid black',

if xml_root.find('.//cell_definitions'):
    titles = [
        'About', 'Config Basics', 'Microenvironment', 'User Params',
        'Cell Types', 'Out: Plots', 'Out: Populations', 'Out: PhysiBoSS',
        'Animate'
    ]
    tabs = widgets.Tab(children=[
        about_tab.tab, config_tab.tab, microenv_tab.tab, user_tab.tab,
        cell_types_tab.tab, sub.tab, populations.tab, physiboss.tab,
        animate_tab.tab
    ],
                       _titles={i: t
                                for i, t in enumerate(titles)},
                       layout=tab_layout)
else:
    titles = [
        'About', 'Config Basics', 'Microenvironment', 'User Params',
        'Out: Plots', 'Out: Populations', 'Out: PhysiBoSS', 'Animate'
    ]
    tabs = widgets.Tab(children=[
        about_tab.tab, config_tab.tab, microenv_tab.tab, user_tab.tab, sub.tab,
        populations.tab, physiboss.tab, animate_tab.tab
    ],
                       _titles={i: t
                                for i, t in enumerate(titles)},
                       layout=tab_layout)
Ejemplo n.ยบ 9
0
 def _handle_new_tab(self, sender):
     """Add new file tab."""
     self.file_pickers.append(FilePicker())
     self.ftabs = ipywidgets.Tab(children=[fp.box for fp in self.file_pickers])
     self._file_picker_tabs.children = [self.ftabs, self.bbox]
Ejemplo n.ยบ 10
0
def analyzeDataInterface(video_dropdown, data_dropdown, data_ref, frame_n):
    def overlapKeypoints(show, video_name, file_added, file_ref, frame_n,
                         show_point, point, thickness, coord, error_type,
                         def_error):
        file_names = list(data_added.options)
        if (show == 'Video'):
            keypointsFromDATACompare(video_name, file_names, file_ref, frame_n,
                                     show_point, point, thickness)
        elif (show == 'Metrics'):
            showMetrics(video_name, file_names, file_ref, point, error_type,
                        def_error)
        else:
            plotTrajectory(video_name, file_names, file_ref, point, coord)

    data_added = wg.Dropdown(options=['None'],
                             description='Compare to:',
                             disabled=False)

    def addDATAClicked(b):
        opt_tmp = list(data_added.options)

        if (opt_tmp[0] == 'None'):
            opt_tmp = [data_dropdown.value]
        else:
            opt_tmp.append(data_dropdown.value)

        data_added.options = opt_tmp
        data_added.value = data_dropdown.value

    def resetDATAClicked(b):
        data_added.options = ['None']
        data_added.value = 'None'

    def saveDATAClicked(b):
        saveData(video_dropdown.value,
                 list(data_added.options),
                 data_ref,
                 plot_name=output_name,
                 pose='Saggital Right')

    add_data = wg.Button(description='Add DATA')
    reset_data = wg.Button(description='Reset DATA')
    save_data = wg.Button(description='Save DATA')

    output_name = wg.Text(value='',
                          placeholder='File output name',
                          description='Comparison name:',
                          disabled=False)

    show = wg.ToggleButtons(
        options=['Video', 'Metrics', 'Trajectory'],
        value='Video',
        disabled=False,
        button_style='',  # 'success', 'info', 'warning', 'danger' or ''
        tooltips=['Show Video', 'Show Metrics', 'Show Trajectory'])

    coord = wg.RadioButtons(options=['x', 'y'],
                            value='x',
                            description='Coordinate:',
                            disabled=False)
    error_type = wg.RadioButtons(
        options=['Error DF', 'False Negatives DF', 'Error Graph'],
        value='Error DF',
        description='Type:',
        disabled=False)

    frame_slider = wg.IntSlider()
    thickness = wg.IntSlider(value=1,
                             min=1,
                             max=20,
                             step=1,
                             description='Thickness',
                             disabled=False)

    point = wg.Dropdown(options=keypoints_mapping,
                        value='Nose',
                        description='Joint:',
                        disabled=False)

    show_point = wg.Checkbox(value=False,
                             description='Show Point',
                             disabled=False,
                             layout=wg.Layout(display='flex',
                                              flex_flow='line',
                                              align_items='flex-start',
                                              justify_content='flex-start',
                                              width='80%'))

    def_error = wg.Checkbox(value=False,
                            description='Per joint',
                            disabled=False,
                            layout=wg.Layout(display='flex',
                                             flex_flow='line',
                                             align_items='flex-start',
                                             justify_content='flex-start',
                                             width='80%'))
    def_error.style.button_width = ''

    wg.jslink((frame_n, 'value'), (frame_slider, 'value'))

    vbox_view = wg.VBox([point, show_point, thickness])
    vbox_metrcis = wg.VBox([error_type, point, def_error])
    vbox_traj = wg.VBox([point, coord])

    tabs = ['Video', 'Metrics', 'Trajectory']
    children = []
    children.append(vbox_view)
    children.append(vbox_metrcis)
    children.append(vbox_traj)
    tab = wg.Tab()
    tab.children = children
    for i in range(len(children)):
        tab.set_title(i, tabs[i])

    video_display = wg.interactive_output(
        overlapKeypoints, {
            "show": show,
            "video_name": video_dropdown,
            "file_added": data_added,
            "file_ref": data_ref,
            "frame_n": frame_n,
            "show_point": show_point,
            "point": point,
            "thickness": thickness,
            "coord": coord,
            "error_type": error_type,
            "def_error": def_error
        })

    hbox_add = wg.HBox([data_dropdown, add_data])
    hbox_remove = wg.HBox([data_added, reset_data])
    hbox_save = wg.HBox([output_name, save_data])

    add_data.on_click(addDATAClicked)
    reset_data.on_click(resetDATAClicked)

    vbox_input = wg.VBox([hbox_add, hbox_remove])
    vbox_input_2 = wg.VBox([video_dropdown, data_ref])

    hbox_input = wg.HBox([vbox_input_2, vbox_input])
    hbox_play = wg.HBox([frame_n, frame_slider])
    vbox_vid = wg.VBox([show, video_display, hbox_play])
    hbox_res = wg.HBox([vbox_vid, tab])
    vbox_res = wg.VBox([hbox_input, hbox_res])

    return vbox_res
Ejemplo n.ยบ 11
0
    def __init__(self):
        # attributes for the graph
        # for the graph
        self.qmin = 0.005
        self.qmax = 0.5
        self.qpnt = 1000
        self.fig = None

        self.ax_data = None
        self.ax_residual = None
        self.ax_sld = None
        # gridspecs specify how the plots are laid out. Gridspec1 is when the
        # residuals plot is displayed. Gridspec2 is when it's not visible
        self._gridspec1 = gridspec.GridSpec(
            2, 2, height_ratios=[5, 1], width_ratios=[1, 1], hspace=0.01
        )
        self._gridspec2 = gridspec.GridSpec(1, 2)

        self.theoretical_plot = None
        self.theoretical_plot_sld = None

        # attributes for a user dataset
        self.dataset = None
        self.objective = None
        self._curvefitter = None
        self.data_plot = None
        self.residuals_plot = None
        self.data_plot_sld = None

        self.dataset_name = widgets.Text(description="dataset:")
        self.dataset_name.disabled = True
        self.chisqr = widgets.FloatText(description="chi-squared:")
        self.chisqr.disabled = True

        # fronting
        slab0 = Slab(0, 0, 0)
        slab1 = Slab(25, 3.47, 3)
        slab2 = Slab(0, 2.07, 3)

        structure = slab0 | slab1 | slab2
        rename_params(structure)
        self.model = ReflectModel(structure)
        structure = slab0 | slab1 | slab2
        self.model = ReflectModel(structure)

        # give some default parameter limits
        self.model.scale.bounds = (0.1, 2)
        self.model.bkg.bounds = (1e-8, 2e-5)
        self.model.dq.bounds = (0, 20)
        for slab in self.model.structure:
            slab.thick.bounds = (0, 2 * slab.thick.value)
            slab.sld.real.bounds = (0, 2 * slab.sld.real.value)
            slab.sld.imag.bounds = (0, 2 * slab.sld.imag.value)
            slab.rough.bounds = (0, 2 * slab.rough.value)

        # the main GUI widget
        self.display_box = widgets.VBox()

        self.tab = widgets.Tab()
        self.tab.set_title(0, "Model")
        self.tab.set_title(1, "Limits")
        self.tab.set_title(2, "Options")
        self.tab.observe(self._on_tab_changed, names="selected_index")

        # an output area for messages.
        self.output = widgets.Output()

        # options tab
        self.plot_type = widgets.Dropdown(
            options=["lin", "logY", "YX4", "YX2"],
            value="lin",
            description="Plot Type:",
            disabled=False,
        )
        self.plot_type.observe(self._on_plot_type_changed, names="value")
        self.use_weights = widgets.RadioButtons(
            options=["Yes", "No"],
            value="Yes",
            description="use dataset weights?",
            style={"description_width": "initial"},
        )
        self.use_weights.observe(self._on_use_weights_changed, names="value")
        self.transform = Transform("lin")
        self.display_residuals = widgets.Checkbox(
            value=False, description="Display residuals"
        )
        self.display_residuals.observe(
            self._on_display_residuals_changed, names="value"
        )

        self.model_view = None
        self.set_model(self.model)
Ejemplo n.ยบ 12
0
def wi12(muscle_force):
    style = {'description_width': 'initial'}
    wi120 = wi.Checkbox(value=True,
                        style=style,
                        description='Plot standard deviation',
                        layout=wi.Layout(width='400px'))
    wi122 = wi.Checkbox(value=True,
                        style=style,
                        description='Plot spectrogram',
                        layout=wi.Layout(width='400px'))
    wi123 = wi.Dropdown(options=['boxcar', 'hamming', 'hann'],
                        value='hann',
                        layout=wi.Layout(width='400px'),
                        style=style,
                        description='Window type:')
    wi124 = wi.IntSlider(value=2000,
                         min=2,
                         max=5000,
                         step=5,
                         layout=wi.Layout(width='400px'),
                         style=style,
                         description='Window length [ms]:')
    wi125 = wi.IntSlider(value=60,
                         min=1,
                         max=2500,
                         step=5,
                         layout=wi.Layout(width='400px'),
                         style=style,
                         description='Window overlap [ms]:')
    wi126 = wi.Checkbox(value=False,
                        style=style,
                        description='Plot Welch \' s periodogram',
                        layout=wi.Layout(width='400px'))
    wi127 = wi.Dropdown(options=['boxcar', 'hamming', 'hann'],
                        value='hann',
                        layout=wi.Layout(width='400px'),
                        style=style,
                        description='Window type:')
    wi128 = wi.IntSlider(value=2000,
                         min=2,
                         max=5000,
                         step=5,
                         layout=wi.Layout(width='400px'),
                         style=style,
                         description='Window length [ms]:')
    wi129 = wi.IntSlider(value=60,
                         min=0,
                         max=2500,
                         step=5,
                         layout=wi.Layout(width='400px'),
                         style=style,
                         description='Window overlap [ms]:')
    wi1210 = wi.FloatRangeSlider(value=[0, muscle_force.t[-1]],
                                 min=0,
                                 max=muscle_force.t[-1],
                                 step=50,
                                 layout=wi.Layout(width='600px'),
                                 style=style,
                                 description='Analysis interval [ms]')
    wi1211 = wi.Checkbox(value=False,
                         description='Plot MU force',
                         layout=wi.Layout(width='400px'),
                         style=style)
    wi1212 = wi.BoundedIntText(value=1,
                               min=1,
                               max=muscle_force.LR,
                               step=1,
                               style=style,
                               description='Motor unit index #:',
                               layout=wi.Layout(width='400px'))
    ws = {
        'add_rms': wi120,
        'add_spec': wi122,
        'spec_w': wi123,
        'spec_w_size': wi124,
        'spec_ol': wi125,
        'add_welch': wi126,
        'welch_w': wi127,
        'welch_w_size': wi128,
        'welch_ol': wi129,
        'a_interval': wi1210,
        'add_mu_c': wi1211,
        'mu_index': wi1212
    }
    moving_average_acc2 = wi.VBox([wi120])
    spectrogram_acc2 = wi.VBox([wi122, wi123, wi124, wi125])
    welch_acc2 = wi.VBox([wi126, wi127, wi128, wi129])
    mu_c2 = wi.VBox([wi1211, wi1212])
    acc12 = wi.Tab(
        children=[moving_average_acc2, spectrogram_acc2, welch_acc2, mu_c2])
    acc12.set_title(0, 'Standard deviation')
    acc12.set_title(1, 'Spectrogram')
    acc12.set_title(2, 'Welch\'s periodogram')
    acc12.set_title(3, 'Motor unit force')
    ui12 = wi.VBox([wi1210, acc12])
    l211 = wi.link((ui12.children[1].children[1].children[2], 'value'),
                   (ui12.children[1].children[1].children[3], 'max'))
    l212 = wi.link((ui12.children[1].children[1].children[3], 'value'),
                   (ui12.children[1].children[1].children[2], 'min'))
    l221 = wi.link((ui12.children[1].children[2].children[2], 'value'),
                   (ui12.children[1].children[2].children[3], 'max'))
    l222 = wi.link((ui12.children[1].children[2].children[3], 'value'),
                   (ui12.children[1].children[2].children[2], 'min'))
    return ui12, ws
Ejemplo n.ยบ 13
0
def wi9(muscle_emg):
    style = {'description_width': 'initial'}
    wi110 = wi.Checkbox(value=True,
                        description='Plot moving RMS',
                        layout=wi.Layout(width='400px'),
                        continuous_update=False,
                        style=style)
    wi111 = wi.IntSlider(value=100,
                         min=1,
                         max=500,
                         layout=wi.Layout(width='400px'),
                         style=style,
                         continuous_update=False,
                         description='Moving RMS window length [ms]:')
    wi112 = wi.Checkbox(value=True,
                        description='Plot Spectrogram',
                        continuous_update=False,
                        style=style,
                        layout=wi.Layout(width='400px'))
    wi113 = wi.Dropdown(options=['boxcar', 'hamming', 'hann'],
                        value='hann',
                        style=style,
                        layout=wi.Layout(width='400px'),
                        continuous_update=False,
                        description='Window type:')
    wi114 = wi.IntSlider(value=120,
                         min=2,
                         max=3000,
                         layout=wi.Layout(width='400px'),
                         style=style,
                         continuous_update=False,
                         description='Window length [ms]:')
    wi115 = wi.IntSlider(value=60,
                         min=1,
                         max=1500,
                         layout=wi.Layout(width='400px'),
                         style=style,
                         continuous_update=False,
                         description='Window overlap [ms]:')
    wi116 = wi.Checkbox(value=False,
                        continuous_update=False,
                        description='Plot Welch \' s periodogram',
                        layout=wi.Layout(width='400px'),
                        style=style)
    wi117 = wi.Dropdown(options=['boxcar', 'hamming', 'hann'],
                        value='hann',
                        continuous_update=False,
                        style=style,
                        description='Window type:',
                        layout=wi.Layout(width='400px'))
    wi118 = wi.IntSlider(value=120,
                         min=2,
                         max=3000,
                         style=style,
                         layout=wi.Layout(width='400px'),
                         continuous_update=False,
                         description='Window length [ms]:')
    wi119 = wi.IntSlider(value=60,
                         min=1,
                         max=1500,
                         layout=wi.Layout(width='400px'),
                         style=style,
                         continuous_update=False,
                         description='Window overlap [ms]:')
    end = muscle_emg.t[-1]
    wi1110 = wi.FloatRangeSlider(value=[0, end],
                                 min=0,
                                 max=end,
                                 step=50,
                                 style=style,
                                 layout=wi.Layout(width='500px'),
                                 continuous_update=False,
                                 description='Analysis interval [ms]')
    wi1111 = wi.Checkbox(value=False,
                         style=style,
                         description='Plot MU contribution',
                         layout=wi.Layout(width='400px'),
                         continuous_update=False)
    wi1112 = wi.BoundedIntText(value=1,
                               min=1,
                               max=muscle_emg.LR,
                               step=1,
                               description='MU index #:',
                               continuous_update=False,
                               style=style,
                               layout=wi.Layout(width='400px'))
    ws11 = {
        'add_rms': wi110,
        'rms_length': wi111,
        'add_spec': wi112,
        'spec_w': wi113,
        'spec_w_size': wi114,
        'spec_ol': wi115,
        'add_welch': wi116,
        'welch_w': wi117,
        'welch_w_size': wi118,
        'welch_ol': wi119,
        'a_interval': wi1110,
        'add_mu_cont': wi1111,
        'mu_c_index': wi1112
    }
    mu_cont_acc = wi.VBox([wi1111, wi1112])
    moving_average_acc = wi.VBox([wi110, wi111])
    spectrogram_acc = wi.VBox([wi112, wi113, wi114, wi115])
    welch_acc = wi.VBox([wi116, wi117, wi118, wi119])
    acc11 = wi.Tab(
        children=[moving_average_acc, spectrogram_acc, welch_acc, mu_cont_acc])
    acc11.set_title(0, 'Moving RMS')
    acc11.set_title(1, 'Spectrogram')
    acc11.set_title(2, 'Welch\'s periodogram')
    acc11.set_title(3, 'MUAP train')
    ui9 = wi.VBox([wi1110, acc11])
    l11 = wi.link((ui9.children[1].children[1].children[2], 'value'),
                  (ui9.children[1].children[1].children[3], 'max'))
    l12 = wi.link((ui9.children[1].children[1].children[3], 'value'),
                  (ui9.children[1].children[1].children[2], 'min'))
    l21 = wi.link((ui9.children[1].children[2].children[2], 'value'),
                  (ui9.children[1].children[2].children[3], 'max'))
    l22 = wi.link((ui9.children[1].children[2].children[3], 'value'),
                  (ui9.children[1].children[2].children[2], 'min'))
    return ui9, ws11
Ejemplo n.ยบ 14
0
def list_overview_widget(groups,
                         help_url_base='',
                         columns=3,
                         min_width_single_widget=300):
    """
    Create an tab-based display of all of the widgets in ``groups``, with
    a separate tab for each key in groups and links to more detail for each
    widget. The first line of the docstring of each widget provides a
    short description of the widget.

    Parameters
    ----------

    groups : dict
        Dictionary whose keys are the names of the widget groups and whose
        values are dictionaries. The dictionaries which are the values of
        ``groups`` should have the name of the widget to be displayed as
        the key and the class of the widget as the value.
    help_url_base : str, optional
        URL to prepend to the help link for each widget.
    columns : int, optional
        Number of columns to use in displaying the widgets.
    min_width_single_widget : int, optional
        Minimum width, in pixels, of a widget displayed on a tab.

    Returns
    -------

    widgets.Tab
        A ``Tab`` widget with one tab for key of groups in which all of
        the widgets in that group are displayed.
    """

    tabs = widgets.Tab()

    if help_url_base is None:
        help_url_base = 'https://ipywidgets.readthedocs.io/en/stable/examples/Widget%20List.html'

    titles = []
    kids = []

    def box_maker(name, widget, group):
        layout = widgets.Layout(grid_template_columns="1fr",
                                border='2px solid gray')
        b = widgets.GridBox(layout=layout)
        module = extract_module_name(widget, full=True)
        #print('    ', widget.__name__, module)
        if 'selection' in module:
            extra_args = dict(options=[1, 2, 3])
        elif 'progress' in widget.__name__.lower():
            extra_args = dict(value=50)
        elif 'gridspeclayout' in widget.__name__.lower():
            extra_args = dict(n_rows=3, n_columns=3)
        else:
            extra_args = {}

        wid = widget(description='A label!', **extra_args)

        try:
            short_description = wid.__doc__.split('\n')[0]
            if not short_description:
                short_description = wid.__doc__.split('\n')[1]
        except AttributeError:
            short_description = ''

        url = f'{help_url_base}#{name}'
        help_link = f'<h3><a href="{url}" rel="nofollow" target="_self" style="color:gray;">{name}</a></h3><p>{short_description}</p>'
        title = widgets.Output()
        title.append_display_data(HTML(help_link))
        title.layout.padding = '10px'
        b.layout.overflow_x = 'hidden'
        b.children = [title, wid]

        return b

    for group, group_widgets in groups.items():
        # print(group)
        titles.append(group)
        col_spec = f"repeat({columns}, minmax({min_width_single_widget}px, 1fr)"
        layout = widgets.Layout(grid_template_columns=col_spec,
                                grid_gap='10px 10px')
        kid = widgets.GridBox(layout=layout)
        kid.children = [
            box_maker(k, v, group) for k, v in group_widgets.items()
        ]
        kids.append(kid)

    tabs.children = kids

    for i, title in enumerate(titles):
        nice = title.replace('_', ' ')
        tabs.set_title(i, nice.title())

    return tabs
Ejemplo n.ยบ 15
0
def preProcessingInterface(video_dropdown, json_dropdown, data_dropdown,
                           frame_n):
    def onPreProcessClicked(b):
        if (video_dropdown.value == "None"):
            print("Choose a video")
            return

        video_path = videos_dir + video_dropdown.value
        video_name = (video_dropdown.value).split(sep='.')[0]

        file_dir = data_dir + video_name + '/'
        if not os.path.exists(file_dir):
            os.makedirs(file_dir)

        files_list = os.listdir(file_dir)
        json_list = ["None"]
        for names in files_list:
            if names.endswith(".json"):
                json_list.append(names)
        data_list = ["None"]
        for names in files_list:
            if names.endswith(".data"):
                data_list.append(names)
        json_dropdown.options = json_list
        data_dropdown.options = data_list

        saveJointFile(video_dropdown.value, json_dropdown.value,
                      output_name.value, joint_pairs, summary.value,
                      miss_points.value)

    def preprocessView(video_name, file_name, persons, custom_person,
                       joint_pose, frame_n, p1_2, p1_5, p2_3, p3_4, p5_6, p6_7,
                       p1_8, p8_9, p9_10, p1_11, p11_12, p12_13, p1_0, p0_14,
                       p14_16, p0_15, p15_17):

        joint_p = []
        if joint_pose == 'Sagittal Left':
            #joint_p = [1,5,9,10,11,12,15,16,4]
            joint_p = [5, 10, 11, 4, 20]
        elif joint_pose == 'Sagittal Right':
            #joint_p = [0,3,6,7,8,12,13,14,2]
            joint_p = [3, 7, 8, 2, 19]
        elif joint_pose == 'Whole Body':
            joint_p = [-1]
        else:
            if p1_2:
                joint_p.append(0)
            if p1_5:
                joint_p.append(1)
            if p2_3:
                joint_p.append(2)
            if p3_4:
                joint_p.append(3)
            if p5_6:
                joint_p.append(4)
            if p6_7:
                joint_p.append(5)
            if p1_8:
                joint_p.append(6)
            if p8_9:
                joint_p.append(7)
            if p9_10:
                joint_p.append(8)
            if p1_11:
                joint_p.append(9)
            if p11_12:
                joint_p.append(10)
            if p12_13:
                joint_p.append(11)
            if p1_0:
                joint_p.append(12)
            if p0_14:
                joint_p.append(13)
            if p14_16:
                joint_p.append(14)
            if p0_15:
                joint_p.append(15)
            if p15_17:
                joint_p.append(16)

        if (joint_pairs != joint_p):
            joint_pairs.clear()
            for p in joint_p:
                joint_pairs.append(p)

        keypointsFromJSON(video_name,
                          file_name,
                          persons,
                          custom_person,
                          joint_pairs,
                          frame_n,
                          read_file=True)

    persons = wg.RadioButtons(options=['Biggest', 'Unsorted', 'All'],
                              value='Biggest',
                              rows=3,
                              description='',
                              disabled=False)
    custom_person = wg.BoundedIntText(value=0,
                                      min=0,
                                      max=10,
                                      step=1,
                                      description='Choose:',
                                      disabled=False,
                                      layout=wg.Layout(
                                          display='flex',
                                          flex_flow='line',
                                          align_items='flex-start',
                                          justify_content='flex-start',
                                          width='90%'))
    joint_pose = wg.RadioButtons(
        options=['Sagittal Left', 'Sagittal Right', 'Whole Body', 'Custom'],
        value='Sagittal Left',
        rows=4,
        description='',
        disabled=False,
        layout=wg.Layout(display='flex', flex_flow='line', width='90%'))
    p1_2 = wg.ToggleButton(value=False,
                           description=pairs_mapping[0],
                           disabled=False,
                           layout=wg.Layout(display='flex',
                                            flex_flow='line',
                                            align_items='flex-start',
                                            justify_content='flex-start',
                                            width='60%'))
    p1_5 = wg.ToggleButton(value=False,
                           description=pairs_mapping[1],
                           disabled=False,
                           layout=wg.Layout(display='flex',
                                            flex_flow='line',
                                            align_items='flex-start',
                                            justify_content='flex-start',
                                            width='60%'))
    p2_3 = wg.ToggleButton(value=False,
                           description=pairs_mapping[2],
                           disabled=False,
                           layout=wg.Layout(display='flex',
                                            flex_flow='line',
                                            align_items='flex-start',
                                            justify_content='flex-start',
                                            width='60%'))
    p3_4 = wg.ToggleButton(value=False,
                           description=pairs_mapping[3],
                           disabled=False,
                           layout=wg.Layout(display='flex',
                                            flex_flow='line',
                                            align_items='flex-start',
                                            justify_content='flex-start',
                                            width='60%'))
    p5_6 = wg.ToggleButton(value=False,
                           description=pairs_mapping[4],
                           disabled=False,
                           layout=wg.Layout(display='flex',
                                            flex_flow='line',
                                            align_items='flex-start',
                                            justify_content='flex-start',
                                            width='60%'))
    p6_7 = wg.ToggleButton(value=False,
                           description=pairs_mapping[5],
                           disabled=False,
                           layout=wg.Layout(display='flex',
                                            flex_flow='line',
                                            align_items='flex-start',
                                            justify_content='flex-start',
                                            width='60%'))
    p1_8 = wg.ToggleButton(value=False,
                           description=pairs_mapping[6],
                           disabled=False,
                           layout=wg.Layout(display='flex',
                                            flex_flow='line',
                                            align_items='flex-start',
                                            justify_content='flex-start',
                                            width='60%'))
    p8_9 = wg.ToggleButton(value=False,
                           description=pairs_mapping[7],
                           disabled=False,
                           layout=wg.Layout(display='flex',
                                            flex_flow='line',
                                            align_items='flex-start',
                                            justify_content='flex-start',
                                            width='60%'))
    p9_10 = wg.ToggleButton(value=False,
                            description=pairs_mapping[8],
                            disabled=False,
                            layout=wg.Layout(display='flex',
                                             flex_flow='line',
                                             align_items='flex-start',
                                             justify_content='flex-start',
                                             width='60%'))
    p1_11 = wg.ToggleButton(value=False,
                            description=pairs_mapping[9],
                            disabled=False,
                            layout=wg.Layout(display='flex',
                                             flex_flow='line',
                                             align_items='flex-start',
                                             justify_content='flex-start',
                                             width='60%'))
    p11_12 = wg.ToggleButton(value=False,
                             description=pairs_mapping[10],
                             disabled=False,
                             layout=wg.Layout(display='flex',
                                              flex_flow='line',
                                              align_items='flex-start',
                                              justify_content='flex-start',
                                              width='60%'))
    p12_13 = wg.ToggleButton(value=False,
                             description=pairs_mapping[11],
                             disabled=False,
                             layout=wg.Layout(display='flex',
                                              flex_flow='line',
                                              align_items='flex-start',
                                              justify_content='flex-start',
                                              width='60%'))
    p1_0 = wg.ToggleButton(value=False,
                           description=pairs_mapping[12],
                           disabled=False,
                           layout=wg.Layout(display='flex',
                                            flex_flow='line',
                                            align_items='flex-start',
                                            justify_content='flex-start',
                                            width='60%'))
    p0_14 = wg.ToggleButton(value=False,
                            description=pairs_mapping[13],
                            disabled=False,
                            layout=wg.Layout(display='flex',
                                             flex_flow='line',
                                             align_items='flex-start',
                                             justify_content='flex-start',
                                             width='60%'))
    p14_16 = wg.ToggleButton(value=False,
                             description=pairs_mapping[14],
                             disabled=False,
                             layout=wg.Layout(display='flex',
                                              flex_flow='line',
                                              align_items='flex-start',
                                              justify_content='flex-start',
                                              width='60%'))
    p0_15 = wg.ToggleButton(value=False,
                            description=pairs_mapping[15],
                            disabled=False,
                            layout=wg.Layout(display='flex',
                                             flex_flow='line',
                                             align_items='flex-start',
                                             justify_content='flex-start',
                                             width='60%'))
    p15_17 = wg.ToggleButton(value=False,
                             description=pairs_mapping[16],
                             disabled=False,
                             layout=wg.Layout(display='flex',
                                              flex_flow='line',
                                              align_items='flex-start',
                                              justify_content='flex-start',
                                              width='60%'))
    miss_points = wg.RadioButtons(
        options=['None', 'Fill w/ Last', 'Fill w/ Kalman', 'Fill w/ Interp'],
        value='None',
        rows=4,
        description='',
        disabled=False,
        layout=wg.Layout(display='flex', flex_flow='line', width='90%'))
    frame_slider = wg.IntSlider()
    preprocess_vid = wg.Button(description='Pre Process Video')
    summary = wg.Textarea(value='',
                          placeholder='description',
                          description='Summary:',
                          disabled=False)
    output_name = wg.Text(value='',
                          placeholder='File output name',
                          description='Output:',
                          disabled=False)
    video_display = wg.interactive_output(
        preprocessView, {
            "video_name": video_dropdown,
            "file_name": json_dropdown,
            "persons": persons,
            "custom_person": custom_person,
            "joint_pose": joint_pose,
            "frame_n": frame_n,
            "p1_2": p1_2,
            "p1_5": p1_5,
            "p2_3": p2_3,
            "p3_4": p3_4,
            "p5_6": p5_6,
            "p6_7": p6_7,
            "p1_8": p1_8,
            "p8_9": p8_9,
            "p9_10": p9_10,
            "p1_11": p1_11,
            "p11_12": p11_12,
            "p12_13": p12_13,
            "p1_0": p1_0,
            "p0_14": p0_14,
            "p14_16": p14_16,
            "p0_15": p0_15,
            "p15_17": p15_17
        })

    preprocess_vid.on_click(onPreProcessClicked)
    wg.jslink((frame_n, 'value'), (frame_slider, 'value'))

    vbox_per = wg.VBox([persons, custom_person],
                       layout=wg.Layout(display='flex',
                                        flex_flow='column',
                                        align_items='flex-start',
                                        justify_content='flex-start'))

    hbox_pose1 = wg.HBox([p1_2, p1_5, p2_3])
    hbox_pose2 = wg.HBox([p3_4, p5_6, p6_7])
    hbox_pose3 = wg.HBox([p1_8, p8_9, p9_10])
    hbox_pose4 = wg.HBox([p1_11, p11_12, p12_13])
    hbox_pose5 = wg.HBox([p1_0, p0_14, p14_16])
    hbox_pose6 = wg.HBox([p0_15, p15_17])
    vbox_pose1 = wg.VBox([
        joint_pose, hbox_pose1, hbox_pose2, hbox_pose3, hbox_pose4, hbox_pose5,
        hbox_pose6
    ])

    hbox_player = wg.HBox([frame_n, frame_slider])

    tabs = ['Person', 'Pose', 'Missing Data']
    children = []
    children.append(vbox_per)
    children.append(vbox_pose1)
    children.append(miss_points)

    tab = wg.Tab()
    tab.children = children
    for i in range(len(children)):
        tab.set_title(i, tabs[i])

    video_player = wg.VBox([video_display, hbox_player])
    hbox_filein = wg.HBox([video_dropdown, json_dropdown])
    vbox_fileout = wg.VBox([output_name, miss_points])

    vbox_config = wg.VBox([tab, output_name, summary, preprocess_vid])
    hbox_res = wg.HBox([video_player, vbox_config])
    vbox_res = wg.VBox([hbox_filein, hbox_res])

    return vbox_res
Ejemplo n.ยบ 16
0
    write_config_file(new_config_file)
#    subprocess.call(["biorobots", xml_file_out])
#    subprocess.call(["myproj", new_config_file])   # spews to shell, but not ctl-C'able
#    subprocess.call(["myproj", new_config_file], shell=True)  # no
    subprocess.Popen(["myproj", new_config_file])

run_button = widgets.Button(
    description='Run',
    button_style='success',  # 'success', 'info', 'warning', 'danger' or ''
    tooltip='Update '+ main_xml_filename +' and run a simulation',
)
run_button.on_click(run_button_cb)

titles = ['Basics', 'User Params', 'Cell Plots', 'Substrate Plots']
tabs = widgets.Tab(children=[basics_tab.tab, user_tab.tab, svg.tab, sub.tab],
                   _titles={i: t for i, t in enumerate(titles)},
                   layout=tab_layout)

#gui = widgets.VBox(children=[tabs, write_button])
gui = widgets.VBox(children=[tabs, run_button])
fill_gui_params(full_xml_filename)

# pass in (relative) directory where output data is located
#svg.update(read_config.value)
output_dir = "output"   # for local desktop
if nanoHUB_flag:
    output_dir = "tmpdir"  # for nanoHUB?
svg.update(output_dir)
sub.update_dropdown_fields(output_dir)
sub.update(output_dir)
Ejemplo n.ยบ 17
0
def vis_alt3(dfs,
             model,
             title='Show variables',
             basename='Baseline',
             altname='Alternative',
             trans={},
             legend=True):
    ''' display tabbed widget with results from different dataframes, usuallly 2 but more can be shown
    
    dfs is a list of dataframes. They should be of same dimensionalities 
    
    '''
    avar = dfs[0].columns
    outlist = [widgets.Output() for var in avar]
    outdiflist = [widgets.Output() for var in avar]
    deplist = [widgets.Output() for var in avar]
    reslist = [widgets.Output() for var in avar]
    attlist = [widgets.Output() for var in avar]
    varouttablist = [
        widgets.Tab(children=[out, outdif, att, dep, res]) for out, outdif,
        att, dep, res in zip(outlist, outdiflist, attlist, deplist, reslist)
    ]
    for var, varouttab in zip(avar, varouttablist):
        for i, tabtext in enumerate(
            ['Level', 'Impact', 'Attribution', 'Dependencies', 'Results']):
            varouttab.set_title(i, tabtext)

    controllist = [widgets.VBox([varouttab]) for varouttab in varouttablist]
    tab = widgets.Tab(children=controllist)
    for i, (var, out) in enumerate(zip(avar, controllist)):
        tab.set_title(i, var)

    def showvar(b):
        sel = b['new']
        out = outlist[sel]
        outdif = outdiflist[sel]
        dep = deplist[sel]
        res = reslist[sel]
        att = attlist[sel]
        var = avar[sel]
        with out:
            clear_output()
            fig, ax = plt.subplots(figsize=(10, 6))
            ax.set_title(trans.get(var, var), fontsize=14)
            ax.spines['right'].set_visible(False)
            #            ax.spines['top'].set_visible(False)
            for i, df in enumerate(dfs):
                alt = i if len(dfs) >= 3 else ''
                data = df.loc[:, var]
                data.name = f'{basename}' if i == 0 else f'{altname}{alt}'
                data.plot(ax=ax, legend=legend, fontsize=14)
                x_pos = data.index[-1]
                if not legend:
                    if i == 0:
                        basevalue = data.values[-1]
                    else:
                        if (abs(data.values[-1] - basevalue) < 0.01 or
                            (abs(basevalue) > 100. and
                             (1. - abs(data.values[-1] / basevalue) < 0.008))):
                            if i == 1:
                                ax.text(x_pos,
                                        data.values[-1],
                                        f' {basename} and {altname}{alt}',
                                        fontsize=14)
                        else:
                            ax.text(x_pos,
                                    data.values[-1],
                                    f' {altname}{alt}',
                                    fontsize=14)
                            ax.text(x_pos,
                                    basevalue,
                                    f' {basename}',
                                    fontsize=14)
            plt.show(fig)
        with outdif:
            clear_output()
            fig, ax = plt.subplots(figsize=(10, 6))
            ax.set_title(trans.get(var, var), fontsize=14)
            ax.spines['right'].set_visible(False)
            for i, df in enumerate(dfs):
                if i == 0:
                    basedata = df.loc[:, var]
                    x_pos = data.index[-1]
                else:
                    data = df.loc[:, var] - basedata
                    data.plot(ax=ax, legend=False, fontsize=14)
                    x_pos = data.index[-1]
                    alt = i if len(dfs) >= 3 else ''
                    ax.text(x_pos,
                            data.values[-1],
                            f' Impact of {altname}{alt}',
                            fontsize=14)
            plt.show(fig)
        with dep:
            clear_output()
            model.draw(var, up=2, down=2, svg=1)
        with res:
            clear_output()
            out = model.get_values(var).T.rename(columns={
                'Base': basename,
                'Last': altname
            })
            out.style.set_caption(trans.get(var, var))
            print(trans.get(var, var))
            print(out)
        with att:
            clear_output()
            #model.smpl(N-20,N)
            if var in model.endogene:
                print(
                    f'What explains the difference between the {basename} and the {altname} run '
                )
                print(model.allvar[var]['frml'])
                model.explain(var, up=0, dec=1, size=(9, 12), svg=1, HR=0)
            else:
                print(
                    f'{var} is exogeneous and attribution can not be performed'
                )

    display(tab)

    showvar({'new': 0})
    tab.observe(showvar, 'selected_index')
    return tab
Ejemplo n.ยบ 18
0
        actual_team_list = Aurora
    else:
        print('Pick a real team')
        return
    declared_list.sort()
    actual_team_list.sort()
    #print(declared_list), print(actual_team_list)
    if declared_list == actual_team_list:
        print('You win!')
        #print(declared_list), print(actual_team_list)
    else:
        print('Sorry, that is not correct. Continue playing.')
        declared_list.clear()
    declare_team.value = 'Pick team'


add_button.on_click(add_button_clicked)
declare_button.on_click(declare_button_clicked)

# defining a list with the contents of our windows
children = [box1, box2, box3]
# initializing a tab
tab = widgets.Tab()
# setting the tab windows
tab.children = children
# changing the title of the first and second window
tab.set_title(0, 'Set up teams')
tab.set_title(1, 'Check other team')
tab.set_title(2, 'Declare team')
tab
Ejemplo n.ยบ 19
0
def track():

    import os
    import sys
    import socket
    import platform
    import datetime as dt
    import glob
    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    import matplotlib as mpl
    import seaborn as sns
    import ipywidgets as widgets
    import imp
    import time
    import pickle
    import threading
    import warnings
    
    from IPython.display import display, HTML, Image, Video
    from ipywidgets import interact, interact_manual, fixed
    from ipywidgets import Label, FloatProgress, FloatSlider, Button
    from ipywidgets.widgets import Layout, HBox, VBox

    warnings.filterwarnings('ignore')

    sns.set()
    plt.rcParams.update({'font.family': 'serif', 'font.weight': 'bold'})

    info = {
        'System ': socket.gethostname(),
        'Platform': platform.platform(),
        'Python Version': sys.version,
        'Python Directory': sys.executable,
        'Current Directory': os.getcwd(),
        'Last Run': dt.datetime.now().strftime('%d %b %Y, %H:%M:%S'),
    }

    dr = {}

    cwd = os.getcwd()
    keys = ['DOC', 'EXT', 'FIG', 'MAT', 'RAW', 'REP', 'STC', 'VID']
    dr.update({k: '%s/%s/' % (cwd, k) for k in keys})
    for k in dr:
        os.makedirs(dr[k], exist_ok=True)

    dpi = 72
    Activity = [
        'Sleeping', 'Drinks', 'Refresh', 'Walk', 'Yoga', 'Gym', 'Breakfast',
        'Driving', 'Management', 'Python', 'Tea', 'Study', 'Lunch', 'Table Tennis',
        'Discussions', 'Report Writing', 'Meetings', 'Presentations',
       'Snacks', 'Stairs', 'Writing', 'Dinner','Housework', 'Family', 'Friends',
        'Meetups', 'Volleyball', 'Housework',
        'Reading non fiction', 'Reading fiction', 'Singing', 'Movie', 'TV Series',
        'YouTube', 'Music', 'Web Surfing', 'Coursera', 'Volleyball', 'Cycling',
        'Traveling', 'Shopping', 'Social Media', 'Entertainment', 'Vocabulary',
        'Thinking','News', 'Video Shooting','Video Editing','Creative Works','Chatting'
    ]

    msg = "Welcome to Time Management !\nSince this is your first time.\nYou have to manually enter your first entry and rerun the cell again to access all features."

    out_0 = widgets.Output()
    out_1 = widgets.Output()
    out_2 = widgets.Output()
    out_3 = widgets.Output()
    out_4 = widgets.Output()
    out_5 = widgets.Output()

    def sync():
        '''
        Sync the timesheets between your local and external sources. It will take no inputs, just run the function.
        It will save 2 minutes of everyday and possible mistakes
        '''

        import shutil
        import time

        if info['Platform'][:7] == 'Windows':
            ep = 'I:/Timesheet.pkl'
        elif info['System ']=='kali':
            ep = '/media/root/UUI/Timesheet.pkl'
        else:
            ep = '/media/prateek/UUI/Timesheet.pkl'

        if not os.path.exists(ep):
            print('%s does not exists ' % (ep))
            return

        lp = dr['MAT'] + 'Timesheet.pkl'

        ext = os.path.getmtime(ep)
        lcl = os.path.getmtime(lp)

        extsz=os.path.getsize(ep)
        lclsz=os.path.getsize(lp)

        print('Local    : %s  %6.2f KB' % (time.ctime(lcl),lclsz/1024.))
        print('External : %s  %6.2f KB' % (time.ctime(ext),extsz/1024.))

        if (lcl > ext) and (lclsz>extsz) :
            shutil.copy(lp, ep)
            print('Copied to external')
        elif (lcl < ext) and (lclsz<extsz) :
            shutil.copy(ep, lp)
            print('Copied to local')
        else:
            print('Already in Sync. Do manually if you do not believe so')

    def update():
        '''
        Update the timesheet from reading the atime logger csv report. Benefits :-
        Save the time spent on manual entries.
        Easily get the time spent upto the second's precision

        This process will always be performed on a local system
        '''

        fn_csv = dr['RAW'] + dt.datetime.today().strftime('report-%d-%m-%Y.csv')

        if not os.path.exists(fn_csv):
            print('%s does not exists' % (fn_csv))
            return

        aa = pd.read_csv(fn_csv)
        idx = aa[aa[aa.columns[0]] == aa.columns[0]].index[0] - 1
        aa1 = aa.loc[0:idx]
        d = read(dr['MAT'] + 'Timesheet.pkl')
        d.iloc[-1]['To']
        b = aa1[pd.to_datetime(aa1['From']) > d.iloc[-1]['To']]
        b1 = {
            'Activity': [i.rstrip() for i in b['Activity type']],
            'From': pd.to_datetime(b['From']),
            'To': pd.to_datetime(b['To']),
            'Notes': b['Comment']
        }
        b11 = pd.DataFrame(b1)
        b12 = b11.reindex(index=b11.index[::-1])
        b12['Duration'] = b12['To'] - b12['From']
        if len(b12) == 0:
            print('Data is already updated')
        else:
            print('%d entries added' % (len(b12)))
        d = pd.concat((d, b12), ignore_index=True)
        d = d.fillna('')
        d.to_pickle(dr['MAT'] + 'Timesheet.pkl')
        d.to_pickle(dr['EXT'] +
                    dt.datetime.now().strftime('Timesheet-%y%m%d-%H%M%S.pkl'))

    @out_5.capture(clear_output=True, wait=True)
    def sync_update():
        '''
        It will sync and update ( from csv) the timesheet
        '''
        sync()
        update()
        sync()
        display(read(dr['MAT'] + 'Timesheet.pkl').tail())

    @out_5.capture(clear_output=True, wait=True)
    def sync_update1(b):
        '''
        It will sync and update ( from csv) the timesheet
        '''
        sync()
        update()
        sync()
        display(read(dr['MAT'] + 'Timesheet.pkl').tail())

    def make_df(lst):
        columns = 'Activity', 'From', 'To', 'Notes'
        a = pd.DataFrame(lst, columns=columns)
        a['Duration'] = a['To'] - a['From']
        return a

    def make_df_id(lst, idx):
        columns = 'Activity', 'From', 'To', 'Notes'
        a = pd.DataFrame(lst, columns=columns, index=[idx - 0.5])
        a['Duration'] = a['To'] - a['From']
        return a


    def read(fn):
        '''
        read the saved variable using pickle library of python.
        '''
        with open(fn, 'rb') as f:
            data = pickle.load(f)
        return data


    def save(dct, fn):
        '''
        It will save the variable using pickle library
        fn : will be the output file name ( can be any .pkl is convention)
        '''
        with open(fn, 'wb') as f:
            pickle.dump(dct, f)


    def loop_1():
        while b_start[1].icon == 'stop':
            To[1].value = str(dt.datetime.today() -
                              pd.to_datetime(From[1].value))[7:-7]
            time.sleep(1)


    def loop_2():
        while b_start[2].icon == 'stop':
            To[2].value = str(dt.datetime.today() -
                              pd.to_datetime(From[2].value))[7:-7]
            time.sleep(1)


    def loop_3():
        while b_start[3].icon == 'stop':
            To[3].value = str(dt.datetime.today() -
                              pd.to_datetime(From[3].value))[7:-7]
            time.sleep(1)


    @out_0.capture(clear_output=True, wait=True)
    def stop_click(b):
        '''
        Function for Manual Time Logging
        '''
        A = Act[0].value
        From_str = From[0].value
        To_str = To[0].value
        N = Notes[0].value

        if os.path.exists(dr['MAT'] + 'Timesheet.pkl'):
            d = read(dr['MAT'] + 'Timesheet.pkl')
        else:
            d = pd.DataFrame(
                columns=['Activity', 'From', 'To', 'Notes', 'Duration'])
        F = pd.to_datetime(From_str)
        T = pd.to_datetime(To_str)
        aa = make_df([[A, F, T, N]])
        d = pd.concat((d, aa), ignore_index=True)
        d.to_pickle(dr['MAT'] + 'Timesheet.pkl')
        d.to_pickle(dr['EXT'] +
                    dt.datetime.now().strftime('Timesheet-%y%m%d-%H%M%S.pkl'))
        display(d.tail())


    @out_1.capture(clear_output=True, wait=True)
    def start_click_1(b):
        '''
        Function for automatic time logging
        '''
        if b_start[1].icon == 'play':
            From[1].value = dt.datetime.today().strftime('%Y-%m-%d %H:%M:%S')
            To[1].value = dt.datetime.today().strftime('%Y-%m-%d %H:%M:%S')
            To[1].description = 'Elapsed Time'
            b_start[1].icon = 'stop'
            b_start[1].button_style = 'danger'
            display(read(dr['MAT'] + 'Timesheet.pkl').tail())
            threading.Thread(target=loop_1).start()

        else:
            To[1].value = dt.datetime.today().strftime('%Y-%m-%d %H:%M:%S')
            To[1].description = 'To'
            b_start[1].icon = 'play'
            b_start[1].button_style = 'success'

            fnn = dr['MAT'] + 'Timesheet.pkl'

            if os.path.exists(fnn):
                d = read(fnn)
            else:
                d = pd.DataFrame(
                    columns=['Activity', 'From', 'To', 'Notes', 'Duration'])
            F = pd.to_datetime(From[1].value)
            T = pd.to_datetime(To[1].value)
            aa = make_df([[Act[1].value, F, T, Notes[1].value]])
            d = pd.concat((d, aa), ignore_index=True)

            d.to_pickle(fnn)
            d.to_pickle(dr['EXT'] +
                        dt.datetime.now().strftime('Timesheet-%y%m%d-%H%M%S.pkl'))

            display(d.tail())


    @out_1.capture(clear_output=True, wait=True)
    def start_click_2(b):
        '''
        Function for automatic time logging
        '''
        if b_start[2].icon == 'play':
            From[2].value = dt.datetime.today().strftime('%Y-%m-%d %H:%M:%S')
            To[2].value = dt.datetime.today().strftime('%Y-%m-%d %H:%M:%S')
            To[2].description = 'Elapsed Time'
            b_start[2].icon = 'stop'
            b_start[2].button_style = 'danger'
            threading.Thread(target=loop_2).start()
            display(read(dr['MAT'] + 'Timesheet.pkl').tail())

        else:
            To[2].value = dt.datetime.today().strftime('%Y-%m-%d %H:%M:%S')
            To[2].description = 'To'
            b_start[2].icon = 'play'
            b_start[2].button_style = 'success'

            fnn = dr['MAT'] + 'Timesheet.pkl'

            if os.path.exists(fnn):
                d = read(fnn)
            else:
                d = pd.DataFrame(
                    columns=['Activity', 'From', 'To', 'Notes', 'Duration'])
            F = pd.to_datetime(From[2].value)
            T = pd.to_datetime(To[2].value)
            aa = make_df([[Act[2].value, F, T, Notes[2].value]])
            d = pd.concat((d, aa), ignore_index=True)

            d.to_pickle(fnn)
            d.to_pickle(dr['EXT'] +
                        dt.datetime.now().strftime('Timesheet-%y%m%d-%H%M%S.pkl'))

            display(d.tail())


    @out_1.capture(clear_output=True, wait=True)
    def start_click_3(b):
        '''
        Function for automatic time logging
        '''
        if b_start[3].icon == 'play':
            From[3].value = dt.datetime.today().strftime('%Y-%m-%d %H:%M:%S')
            To[3].value = dt.datetime.today().strftime('%Y-%m-%d %H:%M:%S')
            To[3].description = 'Elapsed Time'
            b_start[3].icon = 'stop'
            b_start[3].button_style = 'danger'
            threading.Thread(target=loop_3).start()
            display(read(dr['MAT'] + 'Timesheet.pkl').tail())

        else:
            To[3].value = dt.datetime.today().strftime('%Y-%m-%d %H:%M:%S')
            To[3].description = 'To'
            b_start[3].icon = 'play'
            b_start[3].button_style = 'success'

            fnn = dr['MAT'] + 'Timesheet.pkl'

            if os.path.exists(fnn):
                d = read(fnn)
            else:
                d = pd.DataFrame(
                    columns=['Activity', 'From', 'To', 'Notes', 'Duration'])
            F = pd.to_datetime(From[3].value)
            T = pd.to_datetime(To[3].value)
            aa = make_df([[Act[3].value, F, T, Notes[3].value]])
            d = pd.concat((d, aa), ignore_index=True)

            d.to_pickle(fnn)
            d.to_pickle(dr['EXT'] +
                        dt.datetime.now().strftime('Timesheet-%y%m%d-%H%M%S.pkl'))

            display(d.tail())


    @out_2.capture(clear_output=True, wait=True)
    def edit_data_click(b):
        index = IND.value
        col = COL.value
        value = VAL.value
        d = read(dr['MAT'] + 'Timesheet.pkl')
        print('Old Value : %s      New Value : %s' % (d.loc[index, col], value))
        if col == 'Activity':
            if value in Activity:
                d.loc[index, col] = value
            else:
                print(
                    '%s is not in any activity. Please include %s in activity list first'
                    % (value, value))
        elif col in ['From', 'To']:
            value = pd.to_datetime(value)
            d.loc[index, col] = value
        else:
            d.loc[index, col] = value

        d['Duration'] = d['To'] - d['From']
        d.to_pickle(dr['MAT'] + 'Timesheet.pkl')
        d.to_pickle(dr['EXT'] +
                    dt.datetime.now().strftime('Timesheet-%y%m%d-%H%M%S.pkl'))
        print('Here is the new data')
        display(d.loc[index - 2:index + 2])

    @out_2.capture(clear_output=True, wait=True)
    def delete_entry(b):
        idx = IND.value
        d = read(dr['MAT']+'Timesheet.pkl')
        d1=d.drop(idx)
        d1=d1.reset_index(drop=True)
        d1.to_pickle(dr['MAT']+'Timesheet.pkl')
        display(read(dr['MAT']+'Timesheet.pkl').loc[idx-2:idx+2])


    @out_3.capture(clear_output=True, wait=True)
    def stop_click1(b):
        A = Act[4].value
        From_str = From[4].value
        To_str = To[4].value
        N = Notes[4].value
        idx = IND1.value

        F = pd.to_datetime(From_str)
        T = pd.to_datetime(To_str)

        val = make_df_id([[A, F, T, N]], idx)
        d = read(dr['MAT'] + 'Timesheet.pkl')
        d = d.append(val, ignore_index=False)
        d = d.sort_index().reset_index(drop=True)
        d.to_pickle(dr['MAT'] + 'Timesheet.pkl')
        d.to_pickle(dr['EXT'] +
                    dt.datetime.now().strftime('Timesheet-%y%m%d-%H%M%S.pkl'))
        display(d.loc[idx - 2:idx + 2])


    def ana_ui():
        out_0 = widgets.Output()
        out_1 = widgets.Output()
        out_2 = widgets.Output()
        out_3 = widgets.Output()

        def filter_data(k,date):
            date=dt.datetime(date.year,date.month,date.day)
            c1=(d['From']>pd.to_datetime(date))*(d['To']<=pd.to_datetime(date)+pd.to_timedelta('23:59:59'))

            c11=d[c1]
            idx=[i for i in d.index if d['To'][i].day==d['From'][i].day+1]
            c12=d.loc[idx]
            c10=c12[(c12['To']>=date)*(c12['To']<=date+pd.to_timedelta('23:59:59'))]
            c13=pd.concat((c10,c11))

            c2=c13[c13['Activity']==k]

            return c2

        def update_mat(k,mat,tot,date):
            c11=filter_data(k,date)
            tot[date]=c11['Duration'].sum()

            mat[date]=np.zeros(1440)
            ix=[int(np.round(i.total_seconds()/60)) for i in (c11['From']-date)]
            iy=[int(np.round(i.total_seconds()/60)) for i in (c11['To']-date)]
            for i,j in zip(ix,iy):
                if i<0:
                    mat[date][0:j]=1
                    date1=date-dt.timedelta(1)
                    date1=dt.datetime(date1.year,date1.month,date1.day)
                    if date1 >= dt.datetime(date_from.value.year,date_from.value.month,date_from.value.day):
                        ii=i+1440
                        mat[date1][ii:]=1
                else:
                    mat[date][i:j]=1


        def gen_mat(k,from_date,to_date):
            dates = pd.date_range(from_date,to_date)
            mat={}
            tot={}
            for date in dates:
                date=dt.datetime(date.year,date.month,date.day)
                update_mat(k,mat,tot,date)

            return mat,tot

        def plot_ts(k,tot):
            nmin={i.strftime('%a, %d %b'):tot[i].total_seconds()/60. for i in tot}

            a1=pd.Series(tot)
            a33 = pd.Series(nmin)
            a33 = a33.fillna(0)
            v=[str(tot[i])[7:] for i in tot]

            try:

                title = '%s\nMean = %s\n Regularity = %4.1f %% \n Maximum = %s on %s\n Minimum = %s on %s ' % (
                                k, str(a1.mean())[7:15], 100 * len(a33[a33 > 0]) / len(a33),
                                str(a1[a1 > dt.timedelta(0)].max())[7:15], a33[a33 > 0].argmax(),
                                str(a1[a1 > dt.timedelta(0)].min())[7:15], a33[a33 > 0].argmin())

            except ValueError:
                title = 'No \n %s \n Activitiy ' %(k)

            fig, ax = plt.subplots(figsize=(16, 8))
            plt.subplots_adjust(top=0.8, bottom=0.25)
            a33.plot.bar(width=1, ax=ax, color='g')
            ax.set_ylabel('Minutes', fontweight='bold')

            for j, i in enumerate(ax.patches):
                            if v[j] != '00:00:00':
                                if a33[j] < 0.2 * a33[a33 > 0].max():
                                    ax.text(i.get_x() + 0.45,
                                            1.5 * a33[j],
                                            v[j],
                                            fontsize=10,
                                            color='blue',
                                            rotation=90)
                                else:
                                    ax.text(i.get_x() + 0.45,
                                            0.1 * a33[j],
                                            v[j],
                                            fontsize=10,
                                            color='yellow',
                                            rotation=90)

            fig.suptitle(title, fontsize=18, fontweight='bold')
            fig.savefig(dr['FIG']+'ts.jpg',dpi=72)
            plt.close()
            return dr['FIG']+'ts.jpg'

        def plot_matrix(mat):
            dd1=np.zeros((len(mat),1440))
            for i,j in enumerate(mat):
                dd1[i,:]=mat[j]

            freq=100*(len(np.where(dd1.sum(axis=1)>0)[0])/dd1.shape[0])
            fig,ax=plt.subplots(figsize=(15,6))
            ax.imshow(dd1,aspect='auto',cmap=mpl.colors.ListedColormap(['white','g']))
            labels=[j.strftime('%a %d %b') for j in mat]
            plt.yticks(range(len(mat)),labels);
            xticks=np.arange(60,1440,60)
            xticklabels=np.arange(1,24)
            ax.set_xlabel('Time(hours)',fontweight='bold')
            ax.set_ylabel('Day',fontweight='bold')
            plt.xticks(xticks,xticklabels);
            ax.grid(color='y')
            ax.grid('off')
            fig.suptitle('Time Matrix of %s\nDaily frequency(Percent) = %4.1f' %(act_w.value,freq),fontsize=21,fontweight='bold')
            fig.savefig(dr['FIG']+'matrix.jpg',dpi=72)
            plt.close()
            return dr['FIG']+'matrix.jpg'

        @out_3.capture(clear_output=True, wait=True)
        def plot_act(b):
            d = read(dr['MAT']+'Timesheet.pkl')
            mat,tot=gen_mat(act_w.value,date_from.value,date_to.value)
            display(Image(plot_matrix(mat)))
            display(Image(plot_ts(act_w.value,tot)))

        d = read(dr['MAT']+'Timesheet.pkl')
        acts=set(d['Activity'])
        random_act = np.random.choice(list(acts), 1, replace=False)
        act_w=widgets.Dropdown(options=acts,
                                          value=random_act,
                                          description='Activity',
                                          disabled=False,
                                          )

        date_from = widgets.DatePicker(description='From',
                                       value=dt.date.today()-dt.timedelta(21),
                                       disabled=False)

        date_to = widgets.DatePicker(description='Upto',
                                     value=dt.date.today(),
                                     disabled=False)



        b_mat = widgets.Button(description='Show Matrix',
                       icon='play',
                       button_style='warning',
                       )

        b_mat.on_click(plot_act)

        matrix_ui=VBox([HBox([act_w,date_from,date_to,b_mat]),out_3])

        return matrix_ui

    def history_ui():
        date_wid = widgets.DatePicker(description='Pick a Date',
                                     value=dt.datetime.today(),
                                     disabled=False)




        def filter_data(date):
            d = read(dr['MAT']+'Timesheet.pkl')
            date=dt.datetime(date.year,date.month,date.day)
            c1=(d['From']>date)*(d['To']<=date+pd.to_timedelta('23:59:59'))
            c11=d[c1]

            idx=[i for i in d.index if d['To'][i].day==d['From'][i].day+1]
            c12=d.loc[idx]
            c10=c12[(c12['To']>=date)*(c12['To']<=date+pd.to_timedelta('23:59:59'))]

            for j in ['From','To']:
                c11[j]=[c11[j].iloc[i].strftime('%H:%M:%S') for i in range(len(c11[j]))]

            c13=pd.concat((c10,c11))
            display(c13)

        def total_df(date):
            d = read(dr['MAT']+'Timesheet.pkl')
            date=dt.datetime(date.year,date.month,date.day)
            c1=(d['From']>pd.to_datetime(date))*(d['To']<=pd.to_datetime(date)+pd.to_timedelta('23:59:59'))
            c11=d[c1]

            idx=[i for i in d.index if d['To'][i].day==d['From'][i].day+1]
            c12=d.loc[idx]
            c10=c12[(c12['To']>=date)*(c12['To']<=date+pd.to_timedelta('23:59:59'))]
            c13=pd.concat((c10,c11))

            acts=sorted(list(set(c13['Activity'])))

            act1=pd.Series(acts)
            tot=[c13[c13['Activity']==j]['Duration'].sum() for j in act1]
            tot1=pd.Series(tot)
            tot2=pd.DataFrame({'Activity': act1,'Total Duration':tot1})
            tot2 = tot2.sort_values(by='Total Duration',ascending=False)
            tot2 = tot2.reset_index(drop=True)
            display(tot2)



        out1 = widgets.interactive_output(filter_data, {'date': date_wid})
        out2 = widgets.interactive_output(total_df, {'date': date_wid})

        ui = VBox([date_wid,HBox([out1,out2])])

        return ui

    Act = {}
    From = {}
    To = {}
    Notes = {}
    Duration = {}

    random_act = np.random.choice(Activity, 5, replace=False)
    for i in range(5):

        Act[i] = widgets.Dropdown(options=Activity,
                                  value=random_act[i],
                                  description='Activity',
                                  disabled=False,
                                  layout=Layout(width='200px'))

        From[i] = widgets.Text(value='%s' %
                               (dt.datetime.today().strftime('%Y-%m-%d %H:%M:%S')),
                               placeholder='Start time',
                               description='From',
                               disabled=False,
                               layout=Layout(width='230px'))

        To[i] = widgets.Text(value='%s' %
                             (dt.datetime.today().strftime('%Y-%m-%d %H:%M:%S')),
                             placeholder='Start time',
                             description='To',
                             disabled=False,
                             layout=Layout(width='230px'))

        Notes[i] = widgets.Text(value='',
                                placeholder='Type something',
                                description='Notes',
                                disabled=False,
                                layout=Layout(width='220px'))

    b_stop = Button(description='',
                    icon='play',
                    button_style='info',
                    layout=Layout(width='100px'))

    b_stop1 = Button(description='',
                     icon='play',
                     button_style='info',
                     layout=Layout(width='100px'))

    b_stop.on_click(stop_click)

    b_stop1.on_click(stop_click1)

    add_row_ui = VBox([
        HBox([Act[0], From[0], To[0], Notes[0], b_stop],
             layout=Layout(margin='00000')), out_0
    ])

    b_start = {}
    timer_ui = {}

    for i in range(1, 4):
        b_start[i] = Button(description='',
                            icon='play',
                            button_style='success',
                            layout=Layout(width='100px'))

        timer_ui[i] = HBox([Act[i], b_start[i], From[i], To[i], Notes[i]],
                           layout=Layout(margin='00000'))

    b_start[1].on_click(start_click_1)
    b_start[2].on_click(start_click_2)
    b_start[3].on_click(start_click_3)

    COL = widgets.Dropdown(options=['Activity', 'From', 'To', 'Notes'],
                           value='Activity',
                           description='Columns',
                           disabled=False,
                           layout=Layout(width='200px'))

    app1 = VBox([timer_ui[1], timer_ui[2], timer_ui[3], out_1])


    if os.path.exists(dr['MAT'] + 'Timesheet.pkl'):

        sync_update()

        IND = widgets.Dropdown(options=read(dr['MAT'] + 'Timesheet.pkl').index[:],
                               value=read(dr['MAT'] + 'Timesheet.pkl').index[-1],
                               description='Index',
                               disabled=False,
                               layout=Layout(width='200px'))

        IND1 = widgets.Dropdown(options=read(dr['MAT'] + 'Timesheet.pkl').index[:],
                                value=read(dr['MAT'] + 'Timesheet.pkl').index[-1],
                                description='Index',
                                disabled=False,
                                layout=Layout(width='200px'))

        VAL = widgets.Text(value='',
                           placeholder='Type something',
                           description='Value',
                           disabled=False,
                           layout=Layout(width='300px'))

        b_edit = Button(description='Edit',
                        icon='play',
                        button_style='warning',
                        layout=Layout(width='100px'))

        b_del = Button(description='DELETE',
                        icon='play',
                        button_style='Danger',
                        layout=Layout(width='150px'))

        b_update=Button(description='Refresh',
                        icon='play',
                        button_style='warning',
                        layout=Layout(width='150px'))

        b_update.on_click(sync_update1)

        b_edit.on_click(edit_data_click)
        b_del.on_click(delete_entry)

        update_ui=VBox([b_update,out_5])

        edit_row_ui = VBox(
            [HBox([IND, COL, VAL, b_edit, b_del], layout=Layout(margin='00000')), out_2])

        insert_row_ui = VBox([
            HBox([IND1, Act[4], b_stop1]),
            HBox([From[4], To[4], Notes[4]]), out_3
        ])


        analysis_ui=ana_ui()
        hist=history_ui()
        tab = widgets.Tab()
        tab.children = [update_ui, add_row_ui, edit_row_ui, insert_row_ui, app1, analysis_ui,hist]
        tab.set_title(0, 'Updated Timesheet')
        tab.set_title(1, 'Manual Entry')
        tab.set_title(2, 'Edit Entry')
        tab.set_title(3, 'Insert Row')
        tab.set_title(4, 'Timer')
        tab.set_title(5, 'Analysis')
        tab.set_title(6, 'History')
        tab.box_style = 'danger'

    else:
        
        print(msg)
        tab = widgets.Tab()
        tab.children = [add_row_ui]
        tab.set_title(0, 'Manual Entry')

    return tab
Ejemplo n.ยบ 20
0
    def checklist(self):
        """
        Displays a checklist dashboard with reminders for a Data Science project.

        Examples
        --------
        >>> data.checklist()
        """

        data_checkboxes = []
        clean_checkboxes = []
        analysis_checkboxes = [
            [widgets.Label(value="Univariate Analysis")],
            [widgets.Label(value="Multivariate Analysis")],
            [widgets.Label(value="Timeseries Analysis")],
        ]
        issue_checkboxes = []
        preparation_checkboxes = []

        for item in DATA_CHECKLIST:
            data_checkboxes.append(
                widgets.Checkbox(description=item,
                                 layout=Layout(width="100%")))
        data_box = widgets.VBox(data_checkboxes)

        for item in CLEANING_CHECKLIST:
            clean_checkboxes.append(
                widgets.Checkbox(description=item,
                                 layout=Layout(width="100%")))
        clean_box = widgets.VBox(clean_checkboxes)

        for item in UNI_ANALYSIS_CHECKLIST:
            analysis_checkboxes[0].append(
                widgets.Checkbox(description=item,
                                 layout=Layout(width="100%")))
        uni_box = widgets.VBox(analysis_checkboxes[0])

        for item in MULTI_ANALYSIS_CHECKLIST:
            analysis_checkboxes[1].append(
                widgets.Checkbox(description=item,
                                 layout=Layout(width="100%")))

        multi_box = widgets.VBox(analysis_checkboxes[1])

        analysis_box = widgets.HBox([uni_box, multi_box])

        for item in ISSUES_CHECKLIST:
            issue_checkboxes.append(
                widgets.Checkbox(description=item,
                                 layout=Layout(width="100%")))
        issue_box = widgets.VBox(issue_checkboxes)

        for item in PREPARATION_CHECKLIST:
            preparation_checkboxes.append(
                widgets.Checkbox(description=item,
                                 layout=Layout(width="100%")))
        prep_box = widgets.VBox(preparation_checkboxes)

        tab_list = [data_box, clean_box, analysis_box, issue_box, prep_box]

        tab = widgets.Tab()
        tab.children = tab_list
        tab.set_title(0, "Data")
        tab.set_title(1, "Cleaning")
        tab.set_title(2, "Analysis")
        tab.set_title(3, "Issues")
        tab.set_title(4, "Preparation")

        display(tab)
    def play_inline(fPath, **kw):
        '''
        For matplotlib inline mode.
        Generate an interactive 2D plot to play with
        x,y must be uniform spaced, autoflipped.
        '''
        # Data
        x, y, w, labels = read2d(fPath, **kw)
        if 'labels' not in kw:
            kw['labels'] = labels
        x0 = x[0]
        y0 = y[:, 0]
        xmin, xmax, dx = x[0, 0], x[0, -1], x[0, 1] - x[0, 0]
        ymin, ymax, dy = y[0, 0], y[-1, 0], y[1, 0] - y[0, 0]
        wmin, wmax = np.min(w), np.max(w)
        dw = (wmax - wmin) / 20

        # UI
        sxpos = widgets.FloatSlider(value=(xmin + xmax) / 2,
                                    min=xmin,
                                    max=xmax,
                                    step=dx,
                                    description='x')
        sypos = widgets.FloatSlider(value=(ymin + ymax) / 2,
                                    min=ymin,
                                    max=ymax,
                                    step=dy,
                                    description='y')
        vb1 = widgets.VBox([sxpos, sypos])
        sgamma = widgets.IntSlider(value=0,
                                   min=-100,
                                   max=100,
                                   step=10,
                                   description='gamma')
        svlim = widgets.FloatRangeSlider(value=[wmin, wmax],
                                         min=wmin,
                                         max=wmax,
                                         step=dw,
                                         description='limit')
        vb2 = widgets.VBox([sgamma, svlim])
        bexpMTX = widgets.Button(description='To mtx')
        htmlexp = widgets.HTML()
        vb3 = widgets.VBox([bexpMTX, htmlexp])
        ui = widgets.Tab(children=[vb1, vb2, vb3])
        [
            ui.set_title(i, j)
            for i, j in zip(range(3), ['linecuts', 'color', 'export'])
        ]

        # interactive funcion
        indx, indy = 0, 0

        def _play2d(xpos, ypos, gamma, vlim):
            nonlocal indx, indy
            # initialize the figure
            fig, axs = plt.subplots(1, 2, figsize=(6.5, 2.5),
                                    dpi=120)  #main plot and h linecut
            plt.subplots_adjust(wspace=0.4)
            axs[1].yaxis.tick_right()
            axs[1].tick_params(axis='x', colors='tab:orange')
            axs[1].tick_params(axis='y', colors='tab:orange')
            axv = fig.add_axes(axs[1].get_position(),
                               frameon=False)  #ax vertical linecut
            axv.xaxis.tick_top()
            axv.tick_params(axis='x', colors='tab:blue')
            axv.tick_params(axis='y', colors='tab:blue')
            # plot 2D data
            kw = {}
            kw['gamma'], kw['vmin'], kw['vmax'] = gamma, vlim[0], vlim[1]
            Painter.plot2d(x, y, w, fig=fig, ax=axs[0], **kw)
            # vlinecut
            indx = np.abs(x0 - xpos).argmin()  # x0 may be a non uniform array
            axs[0].plot(x[:, indx], y0, 'tab:blue')
            axv.plot(w[:, indx], y0, 'tab:blue')
            # hlinecut
            indy = np.abs(y0 - ypos).argmin()
            axs[0].plot(x0, y[indy, :], 'tab:orange')
            axs[1].plot(x0, w[indy, :], 'tab:orange')

        def _export(_):
            htmlexp.value = 'Saving...'
            fname = os.path.split(fPath)[1]
            fname = os.path.splitext(fname)[0]
            # vlincut
            fnamev = fname + '.vcut.%e.mtx' % x[0, indx]
            Data2d.saveMTX2d(fnamev, y0[np.newaxis], x[np.newaxis, :, indx],
                             w[np.newaxis, :,
                               indx], [labels[i] for i in [1, 0, 2]])
            # hlincut
            fnameh = fname + '.hcut.%e.mtx' % y[indy, 0]
            Data2d.saveMTX2d(fnameh, x0[np.newaxis], y[[indy], :],
                             w[[indy], :], labels)
            # 2d data
            fname2d = fname + '.mtx'
            Data2d.saveMTX2d(fname2d, x, y, w, labels)
            htmlexp.value = 'Files saved:<br>%s<br>%s<br>%s' % (fnamev, fnameh,
                                                                fname2d)

        out = widgets.interactive_output(_play2d, {
            'xpos': sxpos,
            'ypos': sypos,
            'gamma': sgamma,
            'vlim': svlim
        })
        bexpMTX.on_click(_export)
        display(ui, out)
Ejemplo n.ยบ 22
0
    max=100,
    step=1,
    value=initial_number_of_buttons,
    description='Number of buttons',
    style={'description_width': 'initial'})


def on_number_of_buttons_change(change):
    if change['type'] == 'change' and change['name'] == 'value':
        items = make_items(change.new)
        widgetGroup.children = items


number_of_buttons.observe(on_number_of_buttons_change)

tabs = widgets.Tab()
tabs.children = [vbox_style_options, widgetSizeVbox, pythonCode]
tabs.set_title(0, 'Layout options')
tabs.set_title(1, 'Size options')
tabs.set_title(2, 'Python code')

reset_button = widgets.Button(description='Reset')


def on_reset_button(_):
    widgetGroup.layout = widgets.Layout(**default_options)
    pythonCode.value = str(widgetGroup.layout)
    _set_overflow_from_x_y(widgetGroup.layout, 'scroll', 'scroll')
    reset_overflow()
    reset_border()
    justify_content.value = widgetGroup.layout.justify_content
Ejemplo n.ยบ 23
0
    plt.show(fig)


# Displaying components and output together
box_general = widgets.VBox([eventlog, exec_mode, bt_next])
box_simple = widgets.VBox([eta, epsilon, alg_manag, rep, bt_start_simple])
box_opt = widgets.VBox(
    [eta_range, epsilon_range, max_evals, rep_opt, bt_start_opt])
box_write = widgets.VBox([
    file_display, day_display_start, day_display_end, hour_display_start,
    hour_display_end
])

tab = widgets.Tab([box_general, box_simple, box_opt, box_write],
                  layout={
                      'width': '45%',
                      'height': '350px'
                  })
tab.set_title(0, 'General')
tab.set_title(1, 'Simple')
tab.set_title(2, 'Optimizer')
tab.set_title(3, 'Write On Log')

box = widgets.HBox([tab, out])
down_box = widgets.HBox([graph_out, res_out])
frame = widgets.VBox(children=(box, progress, down_box))

# Events assignment
bt_next.on_click(on_next_clicked)
bt_start_simple.on_click(on_start_simple_clicked)
bt_start_opt.on_click(on_start_opt_clicked)
Ejemplo n.ยบ 24
0
    def __init__(self, description=None, **kwargs):
        setup_code_params = {
            "computer": "localhost",
            "description": "pw.x in AiiDAlab container.",
            "label": "pw",
            "input_plugin": "quantumespresso.pw",
            'remote_abs_path': '/usr/bin/pw.x',
        }
        self.code_group = CodeDropdown(input_plugin='quantumespresso.pw',
                                       text="Select code",
                                       setup_code_params=setup_code_params)
        self.code_group.observe(lambda _: self._update_state(),
                                ['selected_code'])

        extra = {
            'style': {
                'description_width': '150px'
            },
            'layout': {
                'max_width': '200px'
            }
        }

        self.number_of_nodes = ipw.BoundedIntText(value=1,
                                                  step=1,
                                                  min=1,
                                                  description="# nodes",
                                                  disabled=False,
                                                  **extra)
        self.cpus_per_node = ipw.BoundedIntText(value=1,
                                                step=1,
                                                min=1,
                                                description="# cpus per node",
                                                **extra)
        self.total_num_cpus = ipw.BoundedIntText(value=1,
                                                 step=1,
                                                 min=1,
                                                 description="# total cpus",
                                                 disabled=True,
                                                 **extra)

        # Update the total # of CPUs int text:
        self.number_of_nodes.observe(self._update_total_num_cpus, 'value')
        self.cpus_per_node.observe(self._update_total_num_cpus, 'value')

        resource_selection_prompt = ipw.HTML(
            "Select the compute resources for this calculation.")
        resource_selection_help = ipw.HTML(
            """<div style="line-height:120%; padding-top:25px;">
            <p>There is no general rule of thumb on how to select the appropriate number of
            nodes and cores. In general:</p>
            <ul>
            <li>Increase the number of nodes if you run out of memory for larger structures.</li>
            <li>Increase the number of nodes and cores if you want to reduce the total runtime.</li>
            </ul>
            <p>However, specifying the optimal configuration of resources is a complex issue and
            simply increasing either cores or nodes may not have the desired effect.</p></div>"""
        )
        self.resources = ipw.HBox(children=[
            ipw.VBox(
                children=[
                    resource_selection_prompt,
                    self.number_of_nodes,
                    self.cpus_per_node,
                    self.total_num_cpus,
                ],
                layout=ipw.Layout(min_width='310px'),
            ),
            resource_selection_help,
        ])

        # Setup pseudofamily potential selection group:
        link_url = "https://www.materialscloud.org/discover/sssp/table/precision"
        pseudo_family_prompt = ipw.HTML(
            f'Select the <a href="{link_url}" target="_blank">pseudopotential library</a> for the calculation.'
        )
        pseudo_family_help = ipw.HTML("""
            <div style="line-height:120%;">If you are unsure what to choose, select 'SSSP efficiency', which for most
            calculations will produce sufficiently accurate results at comparatively small computational cost. If
            your calculation requires a higher accuracy, select 'SSSP accuracy', which will be computationally more
            expensive, but will produce even more accurate results.</div>""")
        self.pseudo_family_selection = ipw.ToggleButtons(options={
            'SSSP efficiency':
            'SSSP_1.1_efficiency',
            'SSSP accuracy':
            'SSSP_1.1_precision',
        }, )
        self.sssp_install_widget = SSSPInstallWidget()

        self.pseudo_family_group = ipw.VBox(children=[
            pseudo_family_prompt,
            ipw.HBox([self.pseudo_family_selection, self.sssp_install_widget]),
            pseudo_family_help,
        ])

        # Clicking on the 'submit' button will trigger the execution of the
        # submit() method.
        self.submit_button = ipw.Button(
            description='Submit',
            tooltip="Submit the calculation with the selected parameters.",
            icon='play',
            button_style='success',
            layout=ipw.Layout(width='auto', flex="1 1 auto"),
            disabled=True)
        self.submit_button.on_click(self._on_submit_button_clicked)

        # The 'skip' button is only shown when the skip() method is implemented.
        self.skip_button = ipw.Button(description='Skip',
                                      icon='fast-forward',
                                      button_style='info',
                                      layout=ipw.Layout(width='auto',
                                                        flex="1 1 auto"),
                                      disabled=True)
        if self.skip:  # skip() method is implemented
            # connect with skip_button
            self.skip_button.on_click(self.skip)  # connect with skip_button
        else:  # skip() not implemented
            # hide the button
            self.skip_button.layout.visibility = 'hidden'

        # Place all buttons at the footer of the widget.
        self.buttons = ipw.HBox(
            children=[self.submit_button, self.skip_button])

        self.config_tabs = ipw.Tab(
            children=[
                self.code_group, self.pseudo_family_group, self.resources
            ],
            layout=ipw.Layout(height='200px'),
        )
        self.config_tabs.set_title(0, 'Code')
        # second tab initialized below
        self.config_tabs.set_title(2, 'Compute resources')

        # Show warning in cofig title when pseudos are not installed:
        def _observe_sssp_installed(change):
            self.config_tabs.set_title(
                1, 'Pseudopotential' +
                ('' if change['new'] else f' {WARNING_ICON}'))
            self._observe_state(change=dict(new=self.state))  # trigger refresh

        self.sssp_install_widget.observe(_observe_sssp_installed, 'installed')
        _observe_sssp_installed(
            change=dict(new=self.sssp_install_widget.installed))  # init

        self.process_status = ProcessStatusWidget()
        ipw.dlink((self, 'process'), (self.process_status, 'process'))

        self.outputs_keys = ipw.Dropdown()
        self.outputs_keys.observe(self._refresh_outputs_view,
                                  names=['options', 'value'])
        self.output_area = ipw.Output(layout={
            'width': 'auto',
            'height': 'auto',
            'border': '1px solid black'
        })
        self.results_view = ipw.VBox(
            children=[self.outputs_keys, self.output_area])

        self.accordion = ipw.Accordion(children=[
            self.config_tabs, self.process_status, self.results_view
        ])
        self.accordion.set_title(0, 'Config')
        self.accordion.set_title(1, 'Status')
        self.accordion.set_title(2, 'Results (0)')

        self.callbacks = list()

        ipw.dlink((self, 'disabled'), (self.skip_button, 'disabled'))
        ipw.dlink((self, 'disabled'), (self.code_group.dropdown, 'disabled'))
        ipw.dlink((self, 'disabled'), (self.number_of_nodes, 'disabled'))
        ipw.dlink((self, 'disabled'), (self.cpus_per_node, 'disabled'))
        ipw.dlink((self, 'disabled'),
                  (self.pseudo_family_selection, 'disabled'))

        # Initialize widget disabled status based on step state.
        self.disabled = self.state != WizardApp.State.READY

        # Set up process monitoring.
        self._monitor_thread = None
        self._monitor_thread_stop = threading.Event()
        self._monitor_thread_lock = threading.Lock()

        super().__init__(children=[
            ipw.Label() if description is None else description,
            self.accordion, self.buttons
        ],
                         **kwargs)
Ejemplo n.ยบ 25
0
def create_tab(titles, children):
    tab = ipw.Tab()
    for idx, title in enumerate(titles):
        tab.set_title(idx, title)
    tab.children = children
    return tab
Ejemplo n.ยบ 26
0
def run(demo_name):

    my_demo = demo.Demo()

    # Functional widget: Text Box
    op_textbox = lambda x: widgets.Text(value=list(my_demo.edsl_snippets[x].values())[0],
                                        placeholder=list(my_demo.edsl_snippets[x].values())[0],
                                        disabled=False)

    # Functional widget: Dropdown
    op_dropdown = lambda x: widgets.Dropdown(options=list(my_demo.edsl_snippets[x].keys()),
                                             value=list(my_demo.edsl_snippets[x].keys())[0],
                                             disabled=False)

    # Functional widget: Contraction op

    contraction_textbox = op_textbox("Contraction")

    contraction_dropdown = op_dropdown("Contraction")

    contraction_boilerplate = widgets.HTML(
        value=my_demo.boilerplate_html[contraction_dropdown.value])

    contraction_out = widgets.Output()
    with contraction_out:
        display(contraction_boilerplate)

    def contraction_dropdown_handler(change):
        contraction_textbox.value = my_demo.edsl_snippets["Contraction"][change["new"]]
        contraction_textbox.placeholder = contraction_textbox.value
        contraction_boilerplate = widgets.HTML(value=my_demo.boilerplate_html[change["new"]])
        contraction_out.clear_output()
        with contraction_out:
            display(contraction_boilerplate)

    contraction_dropdown.observe(contraction_dropdown_handler, names='value')

    contraction_op_widget = widgets.VBox([
        widgets.HBox([widgets.Label(value="Pick an operation:"), contraction_dropdown]),
        contraction_out,
        widgets.VBox([contraction_textbox,
                      widgets.HTML(value=my_demo.boilerplate_html_footer)],
                     layout=widgets.Layout(margin='0 0 0 50px'))
    ])
    # Functional widget: Elementwise op

    elementwise_textbox = op_textbox("Elementwise")

    elementwise_dropdown = op_dropdown("Elementwise")

    elementwise_boilerplate = widgets.HTML(
        value=my_demo.boilerplate_html[elementwise_dropdown.value])

    elementwise_out = widgets.Output()
    with elementwise_out:
        display(elementwise_boilerplate)

    def elementwise_dropdown_handler(change):
        elementwise_textbox.value = my_demo.edsl_snippets["Elementwise"][change["new"]]
        elementwise_textbox.placeholder = elementwise_textbox.value
        elementwise_boilerplate = widgets.HTML(value=my_demo.boilerplate_html[change["new"]])
        elementwise_out.clear_output()
        with elementwise_out:
            display(elementwise_boilerplate)

    elementwise_dropdown.observe(elementwise_dropdown_handler, names='value')

    elementwise_op_widget = widgets.VBox([
        widgets.HBox([widgets.Label(value="Pick an operation:"), elementwise_dropdown]),
        elementwise_out,
        widgets.VBox([elementwise_textbox,
                      widgets.HTML(value=my_demo.boilerplate_html_footer)],
                     layout=widgets.Layout(margin='0 0 0 50px'))
    ])

    textboxes = [contraction_textbox, elementwise_textbox]
    dropdowns = {'Contraction': contraction_dropdown, 'Elementwise': elementwise_dropdown}

    op_tab_titles = list(my_demo.edsl_snippets.keys())
    op_widgets = [contraction_op_widget, elementwise_op_widget]
    op_tabs = widgets.Tab()
    op_tabs.children = op_widgets
    for i in range(len(op_tabs.children)):
        op_tabs.set_title(i, op_tab_titles[i])

    op_run = widgets.Button(description='Run',
                            disabled=False,
                            button_style='success',
                            tooltip='Compiles and executes your EDSL program',
                            icon='check')

    if demo_name == "mlir":

        def createTextarea(text):
            return widgets.Textarea(value=text,
                                    layout=widgets.Layout(width='100%', height='350px'))

        def on_run_click(cb):
            try:
                op_type = op_tab_titles[op_tabs.selected_index]
                textbox_value = textboxes[op_tabs.selected_index].value
                dropdown_value = dropdowns[op_type].value
                program = my_demo.compile(dropdown_value, textbox_value)
                mlir_out.clear_output()
                with mlir_out:
                    display(
                        createTextarea(program.passes[0][1]),
                        createTextarea(program.passes[6][1]),
                        createTextarea(program.passes[-1][1]),
                    )
            except Exception as ex:
                mlir_out.clear_output()
                with mlir_out:
                    display(createTextarea(str(ex)))

        mlir_out = widgets.Output()
        op_run.on_click(on_run_click)

    if demo_name == 'edsl':

        def on_run_click(cb):
            op_type = op_tab_titles[op_tabs.selected_index]
            textbox_value = textboxes[op_tabs.selected_index].value
            dropdown_value = dropdowns[op_type].value
            my_demo.runtime_handler(dropdown_value, textbox_value)

        op_run.on_click(on_run_click)

    # Interactive user interface (visible on the left side of the display)
    left = widgets.VBox([
        widgets.HTML(value="<h2>Code</h2>"),
        widgets.HTML(
            value=
            "First, select a pre-written EDSL snippet from the list below, or write your own custom operation."
        ),
        widgets.HTML(value="Then, press Run to see the EDSL code in action!"), op_tabs, op_run
    ])

    # Live action animation (visible on the right side of the display)
    def output_anim(arg):
        return my_demo.output_anim

    if demo_name == "mlir":
        right = widgets.VBox([widgets.HTML(value="<h2>Passes</h2>"), mlir_out],
                             layout=widgets.Layout(width='100%'))
        title = widgets.HTML(
            value='<div style="text-align:center"><h1>MLIR Lowering Demo</h1></div>')

    if demo_name == "edsl":
        right = widgets.VBox([
            widgets.HBox([
                widgets.VBox([
                    widgets.HTML(value="<h2>Input Array: X</h2>"),
                    draw_widgets.DrawingWidget(my_demo.input_x_anim)
                ]),
                widgets.VBox([
                    widgets.HTML(value="<h2>Input Array: Y</h2>"),
                    draw_widgets.DrawingWidget(my_demo.input_y_anim)
                ])
            ]),
            widgets.HTML(value="<h2>Output Array: R</h2>"),
            draw_widgets.AsyncAnimation(1, output_anim, click_pause=False),
            widgets.Label(value="Note: all matrices are shown in row-major order")
        ])
        title = widgets.HTML(value='<div style="text-align:center"><h1>EDSL Demo</h1></div>')

    # Full-screen layout

    hbox_layout = widgets.Layout()
    hbox_layout.width = '100%'
    hbox_layout.justify_content = 'space-around'

    subdemo = widgets.HBox([left, right])
    subdemo.layout = hbox_layout

    full_demo = widgets.VBox([title, subdemo])
    display(full_demo)
Ejemplo n.ยบ 27
0
    def __create_UI(self):

        self.invisible_layout = {'display': 'none', 'height': 'auto'}
        self.visible_layout = {'display': '', 'height': 'auto'}
        self.flip_button_layout = {
            'width': 'auto',
            'margin': '0px 0px 0px 10px'
        }
        self.picking_info_layout = {
            'width': 'auto',
            'margin': '50px 50px 50px 0px'
        }
        self.slider_layout = {}

        self.geometries_dropdown = widgets.Dropdown(options=[
            (idx, idx) for idx in range(len(self.__drawables))
        ],
                                                    value=0,
                                                    description='Geometry',
                                                    layout=self.visible_layout)

        self.warning_label = widgets.Label(llayout=self.visible_layout,
                                           disabled=False,
                                           continuous_update=True)

        self.flip_x_button = widgets.ToggleButton(
            value=False,
            description='Flip x',
            disabled=False,
            button_style='info',
            tooltip='Flip the visualization range on x axis',
            layout=self.flip_button_layout)

        self.flip_y_button = widgets.ToggleButton(
            value=False,
            description='Flip y',
            disabled=False,
            button_style='info',  # 'success', 'info', 'warning', 'danger' or ''
            tooltip='IFlip the visualization range on y axis',
            layout=self.flip_button_layout)

        self.flip_z_button = widgets.ToggleButton(
            value=False,
            description='Flip z',
            disabled=False,
            button_style='info',  # 'success', 'info', 'warning', 'danger' or ''
            tooltip='Flip the visualization range on z axis',
            layout=self.flip_button_layout)

        x_range = self.mesh.bbox[0][0], self.mesh.bbox[1][0]
        x_step = abs(x_range[0] - x_range[1]) / 100
        self.clipping_slider_x = widgets.FloatRangeSlider(
            value=x_range,
            min=x_range[0] - x_step,
            max=x_range[1] + x_step,
            step=x_step,
            description='X Clipping:',
            disabled=False,
            continuous_update=True,
            orientation='horizontal',
            readout=True,
            readout_format=".1f",
            layout=self.slider_layout)

        y_range = self.mesh.bbox[0][1], self.mesh.bbox[1][1]
        y_step = abs(y_range[0] - y_range[1]) / 100
        self.clipping_slider_y = widgets.FloatRangeSlider(
            value=y_range,
            min=y_range[0] - y_step,
            max=y_range[1] + y_step,
            step=y_step,
            description='Y Clipping:',
            disabled=False,
            continuous_update=True,
            orientation='horizontal',
            readout=True,
            readout_format=".1f",
            layout=self.slider_layout)

        z_range = self.mesh.bbox[0][2], self.mesh.bbox[1][2]
        z_step = abs(z_range[0] - z_range[1]) / 100
        self.clipping_slider_z = widgets.FloatRangeSlider(
            value=z_range,
            min=z_range[0] - z_step,
            max=z_range[1] + z_step,
            step=z_step,
            description='Z Clipping:',
            disabled=False,
            continuous_update=True,
            orientation='horizontal',
            readout=True,
            readout_format=".1f",
            layout=self.slider_layout)

        self.wireframe_opacity_slider = widgets.FloatSlider(
            value=0.4,
            min=0.,
            max=1.,
            step=0.1,
            continuous_update=True,
            readout_format=".1f",
            description='Wireframe',
            disable=False,
        )

        self.color_wireframe = widgets.ColorPicker(
            concise=True,
            value=self.drawable.wireframe.material.color,
            disabled=False,
            layout={'margin': '0 0 0 10px'})

        self.enable_picking_button = widgets.ToggleButton(
            value=False,
            description='Show Picking Info',
            disabled=False,
            button_style='info',  # 'success', 'info', 'warning', 'danger' or ''
            tooltip='Enable the picking functionality',
            layout=self.picking_info_layout)

        self.picking_label = widgets.Label(llayout=self.invisible_layout,
                                           disabled=False,
                                           continuous_update=True)

        tab_titles = ['Poly', 'Vertex', 'Edge', 'Face'
                      ] if self.drawable.geometry.mesh_is_volumetric else [
                          'Poly', 'Vertex', 'Edge'
                      ]
        children = [
            widgets.HTML(value="",
                         layout={
                             'width': '100',
                             'margin': '5 0 0 0'
                         },
                         disabled=False,
                         continuous_update=True) for title in tab_titles
        ]
        self.picking_tab = widgets.Tab(layout=self.invisible_layout,
                                       disabled=True,
                                       width=300,
                                       height=400)
        self.picking_tab.children = children
        for i in range(len(children)):
            self.picking_tab.set_title(i, tab_titles[i])
        self.color_picking_label = widgets.Label(value="Click Color  ",
                                                 layout=self.invisible_layout,
                                                 disabled=False,
                                                 continuous_update=True)

        self.color_map = widgets.Dropdown(
            options=[(i, idx)
                     for idx, i in enumerate(ColorMap.color_maps.keys())],
            value=0,
            description='Color-Map:',
            layout=self.invisible_layout,
        )
        #self.widgets += [self.color_map]

        self.metric_menu = widgets.Dropdown(
            options=[(i, idx)
                     for idx, i in enumerate(self.mesh.simplex_metrics.keys())
                     ],
            value=0,
            description='Metric:',
            layout=self.invisible_layout,
        )
        #self.widgets += [self.metric_menu]

        self.coloring_type_menu = widgets.Dropdown(options=[('Default', 0),
                                                            ('Simplex Quality',
                                                             1), ('Label', 2)],
                                                   value=0,
                                                   description='Color Type:',
                                                   layout=self.visible_layout)
        self.widgets += [
            widgets.HBox([
                widgets.VBox([
                    widgets.HBox(
                        [self.geometries_dropdown, self.warning_label]),
                    widgets.HBox([self.clipping_slider_x, self.flip_x_button]),
                    widgets.HBox([self.clipping_slider_y, self.flip_y_button]),
                    widgets.HBox([self.clipping_slider_z, self.flip_z_button]),
                    widgets.HBox(
                        [self.wireframe_opacity_slider, self.color_wireframe]),
                    widgets.HBox([self.coloring_type_menu]),
                    widgets.HBox([self.color_map, self.metric_menu]),
                    widgets.VBox([
                        widgets.HBox([self.enable_picking_button]),
                        widgets.HBox([self.picking_label]),
                        widgets.HBox([self.picking_tab]),
                    ])
                ]),
            ]),
        ]

        mesh_colors = []
        self.color_internal = widgets.ColorPicker(
            concise=True,
            description='Internal',
            value=colors.rgb2hex(self.drawable._internal_color),
            disabled=False,
            layout=self.invisible_layout
            if self.mesh.mesh_is_surface else self.visible_layout)
        mesh_colors += [self.color_internal]

        self.color_picking = widgets.ColorPicker(
            concise=True,
            description="Click Color",
            value=colors.rgb2hex(colors.purple),
            layout=self.invisible_layout,
            disabled=False,
        )
        self.color_external = widgets.ColorPicker(
            concise=True,
            description='External',
            value=colors.rgb2hex(self.drawable._external_color),
            disabled=False,
        )
        mesh_colors += [self.color_external]
        mesh_colors += [self.color_picking]

        self.widgets += [widgets.HBox(mesh_colors)]

        self.color_label_pickers = [
            widgets.ColorPicker(
                concise=True,
                description='Label ' + str(i),
                value=colors.random_color(return_hex=True),
                disabled=False,
                layout=self.visible_layout,
            ) for i in np.unique(self.mesh.labels)
        ]

        self.color_label_pickers = widgets.HBox(self.color_label_pickers,
                                                layout=self.invisible_layout)
        self.widgets += [self.color_label_pickers]

        self.geometries_dropdown.observe(self.__change_geometry, names='value')
        self.flip_x_button.observe(self.__update_clipping, names='value')
        self.flip_y_button.observe(self.__update_clipping, names='value')
        self.flip_z_button.observe(self.__update_clipping, names='value')
        self.clipping_slider_x.observe(self.__update_clipping, names='value')
        self.clipping_slider_y.observe(self.__update_clipping, names='value')
        self.clipping_slider_z.observe(self.__update_clipping, names='value')
        self.color_internal.observe(self.__update_internal_color,
                                    names='value')
        self.color_external.observe(self.__update_external_color,
                                    names='value')
        self.color_wireframe.observe(self.__update_wireframe_color,
                                     names='value')
        self.wireframe_opacity_slider.observe(self.__update_wireframe_opacity,
                                              names='value')
        self.coloring_type_menu.observe(self.__change_color_type,
                                        names='value')
        self.color_map.observe(self.__change_color_map, names='value')
        self.metric_menu.observe(self.__change_metric, names='value')

        self.enable_picking_button.observe(self.__toggle_picking,
                                           names='value')
        self.click_picker.observe(self.on_click, names=['point'])

        [
            i.observe(self.__change_color_label, names='value')
            for i in self.color_label_pickers.children
        ]
Ejemplo n.ยบ 28
0
    def __init__(self, schema):
        """Construct a Configuration object from a JSON schema definition"""

        self.schema = schema
        self.data = {}
        self.callback = None
        self.children = {}

        # Create GUI
        # Widget objects are collected in a dictionary (for update in __setitem__())
        # as well as a list (together with their description labels to create a VBox for display).
        self.widgets = {}
        self.widgetlist = []
        for name, props in self.schema['properties'].items():
            minimum = props.get('minimum', None)
            maximum = props.get('maximum', None)
            description = props.get('description', '')
            # Containers create new `Configuration` instances - save those children for later
            if props['type'] == 'object':
                subschema = {
                    "title": name,
                    "type": "object",
                    "properties": props['properties']
                }
                self.children[name] = Configuration(subschema)
            else:
                # Scalar data elements are displayed as is
                if props['type'] == 'integer':
                    value = self.data.get(name, props.get('default', 0))
                    widget = ipywidgets.IntSlider(description=name,
                                                  min=minimum,
                                                  max=maximum,
                                                  value=value)
                elif props['type'] == 'number':
                    value = self.data.get(name, props.get('default', 0.0))
                    widget = ipywidgets.FloatSlider(description=name,
                                                    min=minimum,
                                                    max=maximum,
                                                    value=value)
                elif props['type'] == 'string':
                    # also supports drop down
                    value = self.data.get(name, props.get('default', ''))
                    if 'choices' in props:
                        widget = ipywidgets.Dropdown(
                            options=props['choices'].split(';'),
                            value=value,
                            description=name)
                    else:
                        widget = ipywidgets.Text(description=name, value=value)
                elif props['type'] == 'boolean':
                    value = self.data.get(name, props.get('default', False))
                    widget = ipywidgets.Checkbox(description=name, value=value)
                else:
                    widget = ipywidgets.Label(
                        description=name,
                        value=f"Don't know how to draw {props['type']}")

                widget.observe(self.on_value_change, names='value')
                # save for self-reference
                self.widgets[name] = widget
                self.widgetlist.append(
                    ipywidgets.HBox(
                        [widget, ipywidgets.Label(value=description)]))

        # Add all saved children in a Tab
        if self.children:
            widget = ipywidgets.Tab([c._gui for c in self.children.values()])
            for i, c in enumerate(self.children.keys()):
                widget.set_title(i, c)
            widget.observe(self.on_value_change, names='value')
            # save for self-reference
            self.widgets['_children'] = widget
            self.widgetlist.append(widget)

        # Return all widgets in a VBox
        self._gui = ipywidgets.VBox(self.widgetlist)
Ejemplo n.ยบ 29
0
    def _init_widgets(self):
        """Initialize widget dictionary."""
        # Select model to compute Sentence Embeddings
        self.widgets["sent_embedder"] = widgets.RadioButtons(
            options=self.supported_models,
            description="Model for Sentence Embedding",
            style=self.widgets_style,
            layout=widgets.Layout(width="450px", height="50px"),
        )

        # Select granularity of the search
        self.widgets["granularity"] = widgets.ToggleButtons(
            options=["sentences", "articles"],
            value="articles",
            disabled=False,
            style={
                "description_width": "initial",
                "button_width": "80px"
            },
            description="",
        )

        # Select n. of top results to return
        self.widgets["top_results"] = widgets.widgets.IntText(
            value=20, description="Show top ", style=self.widgets_style)

        # Choose whether to print whole paragraph containing sentence
        # highlighted, or just the sentence
        self.widgets["print_paragraph"] = widgets.Checkbox(
            value=True,
            description="Show whole paragraph",
            style=self.widgets_style)

        # Enter Query
        self.widgets["query_text"] = widgets.Textarea(
            value="Glucose is a risk factor for COVID-19",
            layout=widgets.Layout(width="90%", height="80px"),
            description="Query",
            style=self.widgets_style,
        )

        self.widgets["has_journal"] = widgets.Checkbox(
            description="Only articles from journals",
            value=True,
            style=self.widgets_style,
        )

        self.widgets["is_english"] = widgets.Checkbox(
            description="Only articles in English",
            value=True,
            style=self.widgets_style)

        self.widgets["discard_bad_sentences"] = widgets.Checkbox(
            description="Discard sentences flagged as bad quality",
            value=True,
            style=self.widgets_style,
        )

        self.widgets["date_range"] = widgets.IntRangeSlider(
            description="Date Range:",
            continuous_update=False,
            min=1850,
            max=2020,
            value=(2000, 2020),
            layout=widgets.Layout(width="80ch"),
            style=self.widgets_style,
        )
        # Enter Deprioritization Query
        self.widgets["deprioritize_text"] = widgets.Textarea(
            value="",
            layout=widgets.Layout(width="90%", height="80px"),
            description="Deprioritize",
            style=self.widgets_style,
        )

        # Select Deprioritization Strength
        self.widgets["deprioritize_strength"] = widgets.RadioButtons(
            options=[
                "None",
                "Mild",
                "Stronger",
            ],  # ['None', 'Weak', 'Mild', 'Strong', 'Stronger']
            disabled=False,
            style={
                "description_width": "initial",
                "button_width": "80px"
            },
            description="Deprioritization strength",
        )

        # Enter Substrings Exclusions
        self.widgets["exclusion_text"] = widgets.Textarea(
            layout=widgets.Layout(width="90%"),
            value="",
            style=self.widgets_style,
            description="Substring Exclusion (newline separated): ",
            rows=5,
        )
        self.widgets["exclusion_text"].layout.display = "none"

        self.widgets["inclusion_text"] = widgets.Textarea(
            layout=widgets.Layout(width="90%"),
            value="",
            style=self.widgets_style,
            description="Exact phrase matching:",
            rows=5,
            placeholder=textwrap.dedent("""
                    Case insensitive,  one phrase per line. Valid phrases are:
                    1. Single word                      : glucose
                    2. Multiple words                   : risk factor
                    3. Single word with variable suffix : molecul*
                       (matches "molecule", "molecules", "molecular")
                    """).strip(),
        )

        self.widgets["default_value_article_saver"] = widgets.RadioButtons(
            options=[
                (self.saving_labels[_Save.NOTHING], _Save.NOTHING),
                (self.saving_labels[_Save.PARAGRAPH], _Save.PARAGRAPH),
                (self.saving_labels[_Save.ARTICLE], _Save.ARTICLE),
            ],
            value=_Save.ARTICLE,
            disabled=False,
            style={
                "description_width": "initial",
                "button_width": "200px"
            },
            description="Default saving: ",
        )

        # Click to run Information Retrieval!
        self.widgets["investigate_button"] = widgets.Button(
            description="๐Ÿ“š Search Literature!",
            layout=widgets.Layout(width="350px", height="50px"),
        )
        self.widgets["investigate_button"].add_class("bbs_button")

        # Click to Save results
        self.widgets["save_button"] = widgets.Button(
            description="Save",
            icon="download",
            layout=widgets.Layout(width="172px", height="40px"),
        )
        self.widgets["save_button"].add_class("bbs_button")

        # Click to Load results
        self.widgets["load_button"] = widgets.Button(
            description="Load",
            icon="upload",
            layout=widgets.Layout(width="172px", height="40px"),
        )
        self.widgets["load_button"].add_class("bbs_button")

        # Click to run Generate Report!
        self.widgets["report_button"] = widgets.Button(
            description="Generate Report of Search Results",
            layout=widgets.Layout(width="50%"),
        )

        self.widgets["articles_button"] = widgets.Button(
            description="Generate Report of Selected Articles",
            layout=widgets.Layout(width="50%"),
        )

        # Output Area
        self.widgets["out"] = widgets.Output(
            layout={"border": "1px solid black"})

        # Status Area
        self.widgets["status"] = widgets.Output(layout={
            "border": "1px solid black",
            "flex": "1"
        })
        self.widgets["status_clear"] = widgets.Button(
            description="Clear", layout={"max_width": "100px"})
        self.widgets["status_clear"].on_click(
            lambda b: self.widgets["status"].clear_output())

        # Page buttons
        self.widgets["page_back"] = widgets.Button(description="โ†",
                                                   layout={"width": "auto"})
        self.widgets["page_label"] = widgets.Label(value="Page - of -")
        self.widgets["page_forward"] = widgets.Button(description="โ†’",
                                                      layout={"width": "auto"})
        self.widgets["page_back"].on_click(
            lambda b: self.set_page(self.current_page - 1))
        self.widgets["page_forward"].on_click(
            lambda b: self.set_page(self.current_page + 1))

        # Put advanced settings to a tab
        tabs = (
            (
                "Search / View",
                [
                    self.widgets["sent_embedder"],
                    widgets.HBox(children=[
                        self.widgets["top_results"],
                        self.widgets["granularity"],
                    ]),
                    self.widgets["print_paragraph"],
                    self.widgets["default_value_article_saver"],
                ],
            ),
            (
                "Filtering",
                [
                    self.widgets["has_journal"],
                    self.widgets["is_english"],
                    self.widgets["discard_bad_sentences"],
                    self.widgets["date_range"],
                    self.widgets["deprioritize_text"],
                    self.widgets["deprioritize_strength"],
                    self.widgets["exclusion_text"],
                    self.widgets["inclusion_text"],
                ],
            ),
        )
        tab_widget = widgets.Tab(children=[])
        tab_widget.layout.display = "none"
        for i, (tab_name, tab_children) in enumerate(tabs):
            tab_widget.children = tab_widget.children + (
                widgets.VBox(tab_children), )
            tab_widget.set_title(i, tab_name)
        self.widgets["advanced_settings"] = tab_widget

        # Disable advanced settings checkbox
        self.widgets["show_advanced_chb"] = widgets.Checkbox(
            value=False,
            description="Show advanced settings",
        )

        # Callbacks
        self.widgets["investigate_button"].on_click(self._cb_bt_investigate)
        self.widgets["save_button"].on_click(self._cb_bt_save)
        self.widgets["load_button"].on_click(self._cb_bt_load)
        self.widgets["report_button"].on_click(self._cb_bt_pdf_report_search)
        self.widgets["articles_button"].on_click(
            self._cb_bt_pdf_report_article_saver)
        self.widgets["show_advanced_chb"].observe(self._cb_chkb_advanced,
                                                  names="value")
Ejemplo n.ยบ 30
0
def instance_widgets(data, dictlist, ouput_filename, geo_feature_type):

    # instancing filename for global use
    global filename
    global initialdata
    global filtereddict
    global dictlistglobal
    initialdata = data
    filename = ouput_filename
    count = 0
    fieldlist = []
    filtereddict = {}
    widgetslist = []
    dictlistglobal = dictlist

    # iterating through each row in dictlist (each widget)
    for row in dictlist:
        # appending row to fieldlist
        fieldlist.append(row['field'])
        #print row,count
        #raw_input('ddd')
        # instancing a global var for geo_feature_type
        global geotype
        geotype = geo_feature_type

        widget_type = row['type']
        if widget_type == 'FloatSlider' or widget_type == 'IntSlider':
            # getting field and passing in filtereddata/fields
            # as global paramters to wrap the created fruncton
            field = row['field']
            global filtereddata
            global field
            global geotype
            global filename
            global fieldlist
            field = row['field']

            if count == 0:
                # function that takes to min and max
                # then slices df appropriately
                def on_value_change_first(min, max):
                    global filtereddata
                    global field
                    global geotype
                    global filename
                    global filtereddict
                    global initialdata
                    global fieldlist

                    # getting header values
                    header = initialdata.columns.values.tolist()

                    # slicing the df by min/max
                    new = initialdata[(initialdata[field] >= min)
                                      & (initialdata[field] <= max)]
                    '''
					if len(new) == 0:
						make_dummy(header,geo_feature_type)
					else:
						make_type(new,filename,geo_feature_type)
					'''
                    make_dummy(header, geo_feature_type)

                    lastupdate = {'value': True}

                    with open('data.json', 'wb') as jsonfile:
                        json.dump(lastupdate, jsonfile)

                    time.sleep(.5)

                    # updating json object that will be hashed
                    lastupdate = {'value': False}

                    with open('data.json', 'wb') as jsonfile:
                        json.dump(lastupdate, jsonfile)

                    filtereddata = new

                    if len(filtereddict) == 0:
                        filtereddict = {field: filtereddata}
                    else:
                        filtereddict[field] = filtereddata

                    #if dictlistglobal[-1]['field'] == field and len(widgetslist) == len(dictlistglobal) and oldrange == 0:
                    if len(widgetslist) == len(dictlistglobal):
                        count = 0
                        oldrow = fieldlist[0]
                        # code to update slices here
                        for row in fieldlist[:]:
                            count += 1
                            if not dictlistglobal[count -
                                                  1]['type'] == 'Dropdown':
                                minval, maxval = filtereddata[row].min(
                                ), filtereddata[row].max()
                                testval = tabs.children[count - 1].children[
                                    0].children[1].value - tabs.children[
                                        count -
                                        1].children[0].children[0].value
                                print(maxval - minval), testval
                                if (maxval - minval) < testval:
                                    tabs.children[count - 1].children[
                                        0].children[0].value = minval
                                    tabs.children[count - 1].children[
                                        0].children[1].value = maxval
                        make_type(new, filename, geo_feature_type)

                # getting slider 1 and slider2
                slider1, slider2 = row['widget']

                # instantiating widget with the desired range slices/function mapping
                on_value_change_first(initialdata[field].min(),
                                      initialdata[field].max())

                newwidget = widgets.interactive(on_value_change_first,
                                                min=slider1,
                                                max=slider2)
                newwidget = widgets.Box(children=[newwidget])
                widgetslist.append(newwidget)
            else:
                field = row['field']
                global tabs
                global oldrange
                oldrange = 0

                # function that takes to min and max
                # then slices df appropriately
                def on_value_change(min, max):
                    global filtereddata
                    global field
                    global geotype
                    global filename
                    global filtereddict
                    global fieldlist
                    global tabs
                    global oldrange

                    field = fieldlist[-1]

                    if not dictlistglobal[-1]['field'] == field:
                        oldrange = 0

                    if fieldlist[0] == field:
                        filtereddata = filtereddict[field]
                    else:
                        #raw_input('xxx')
                        filtereddata = get_df(field, fieldlist, filtereddict)

                    # getting header value
                    header = filtereddata.columns.values.tolist()

                    # slicing the df by min/max
                    new = filtereddata[(filtereddata[field] >= min)
                                       & (filtereddata[field] <= max)]
                    '''
					if len(new) == 0:
						make_dummy(header,geo_feature_type)
					else:
						make_type(new,filename,geo_feature_type)
					'''
                    make_dummy(header, geo_feature_type)

                    lastupdate = {'value': True}

                    with open('data.json', 'wb') as jsonfile:
                        json.dump(lastupdate, jsonfile)

                    time.sleep(.5)

                    # updating json object that will be hashed
                    lastupdate = {'value': False}

                    with open('data.json', 'wb') as jsonfile:
                        json.dump(lastupdate, jsonfile)

                    filtereddata = new

                    filtereddict[field] = filtereddata

                    #if not dictlistglobal[-1]['field'] == field:
                    #	oldrange = 0

                    #if dictlistglobal[-1]['field'] == field and len(widgetslist) == len(dictlistglobal) and oldrange == 0:
                    if len(widgetslist) == len(dictlistglobal):
                        count = 0
                        oldrow = fieldlist[0]
                        # code to update slices here
                        for row in fieldlist[:]:
                            count += 1
                            if not dictlistglobal[count -
                                                  1]['type'] == 'Dropdown':
                                minval, maxval = filtereddata[row].min(
                                ), filtereddata[row].max()
                                testval = tabs.children[count - 1].children[
                                    0].children[1].value - tabs.children[
                                        count -
                                        1].children[0].children[0].value
                                print(maxval - minval), testval
                                if (maxval - minval) < testval:
                                    tabs.children[count - 1].children[
                                        0].children[0].value = minval
                                    tabs.children[count - 1].children[
                                        0].children[1].value = maxval
                        make_type(new, filename, geo_feature_type)

                # getting slider 1 and slider2
                slider1, slider2 = row['widget']

                # instantiating widget with the desired range slices/function mapping
                on_value_change(initialdata[field].min(),
                                initialdata[field].max())
                newwidget = widgets.interactive(on_value_change,
                                                min=slider1,
                                                max=slider2)
                newwidget = widgets.Box(children=[newwidget])
                widgetslist.append(newwidget)

        elif widget_type == 'Dropdown':
            global fieldcategory
            global filtereddata
            global geotype
            global filename
            global filtereddict
            global fieldlist
            fieldcategory = row['field']
            uniques = ['ALL'] + np.unique(data[fieldcategory]).tolist()

            # function that slices by category input by
            # dropdown box within widget
            def slice_by_category(on_dropdown):
                global filtereddata
                global fieldcategory
                global geo_feature_type
                global filename
                global filtereddict
                global fieldlist

                filtereddata = get_df(fieldcategory, fieldlist, filtereddict)
                # getting header
                header = filtereddata.columns.values.tolist()

                # slicing category by appropriate field
                if not on_dropdown == 'ALL':
                    new = filtereddata[filtereddata[fieldcategory] ==
                                       on_dropdown]
                elif on_dropdown == 'ALL':
                    new = filtereddata

                # updating json object that will be hashed
                lastupdate = {'value': True}

                # checking to see if data actually has values
                if len(new) == 0:
                    make_dummy(header, geotype)
                else:
                    make_type(new, filename, geotype)

                with open('data.json', 'wb') as jsonfile:
                    json.dump(lastupdate, jsonfile)

                time.sleep(.5)

                # updating json object that will be hashed
                lastupdate = {'value': False}

                with open('data.json', 'wb') as jsonfile:
                    json.dump(lastupdate, jsonfile)

                filtereddata = new

                filtereddict[fieldcategory] = filtereddata

                print np.unique(new[fieldcategory])

            # getting drop down feature from current row in dictlist
            dropdownwidget = row['widget']

            # instantiating widget for dropdown categorical values in a field
            slice_by_category('ALL')
            dropdownwidget.observe(slice_by_category, names='on_dropdown')
            newwidget = widgets.interactive(slice_by_category,
                                            on_dropdown=uniques)
            newwidget = widgets.Box(children=[newwidget])
            widgetslist.append(newwidget)
        print count
        count += 1

    tabs = widgets.Tab(children=widgetslist)
    count = 0
    for row in fieldlist:
        tabs.set_title(count, row)
        count += 1
    display(tabs)