Example #1
0
    def build_sheet_out(self):
        """
        """
        sheet = ipysheet.sheet(rows=1 + len(self.li_op_key),
                               columns=2,
                               column_headers=False,
                               row_headers=False)
        sheet.stretch_headers = 'none'
        sheet.column_width = [110, 110]

        style_header = {
            'backgroundColor': '#d0d3d4',
            'fontWeight': 'bold',
            'textAlign': 'right',
            'color': 'black'
        }

        style_title_output = {'textAlign': 'right', 'color': 'black'}

        c = ipysheet.cell(0, 0, 'qty', read_only=True)
        c.style = style_header
        c = ipysheet.cell(0, 1, 'value', read_only=True)
        c.style = style_header

        cells_out = {}

        for k, [key, name] in enumerate(self.li_output_data):
            c = ipysheet.cell(1 + k, 0, name, read_only=True)
            c.style = style_title_output
            cells_out[key] = ipysheet.cell(1 + k, 1, 0, type='numeric')

        self.sheet_out = sheet
        self.cells_out = cells_out
Example #2
0
def test_cell_style():
    cell = ipysheet.cell(0, 0, color='red')
    assert cell.style['color'] == 'red'
    cell = ipysheet.cell(0, 0, background_color='blue')
    assert cell.style['backgroundColor'] == 'blue'
    cell = ipysheet.cell(0, 0, font_style='nice')
    assert cell.style['fontStyle'] == 'nice'
    cell = ipysheet.cell(0, 0, font_weight='bold')
    assert cell.style['fontWeight'] == 'bold'
Example #3
0
def options_input():
    options_sheet = ipysheet.sheet(rows=10, columns=3, column_headers=False)
    cell1 = ipysheet.cell(0, 0, 'C')
    cell2 = ipysheet.cell(0, 1, 'K')
    cell2 = ipysheet.cell(0, 2, 'P')
    for row in range(1, options_sheet.rows):
        for col in range(0, options_sheet.columns):
            ipysheet.cell(row, col, value=0.0, numeric_format='0.00')
    return options_sheet
Example #4
0
def test_to_array():
    sheet = ipysheet.sheet(rows=5, columns=4)
    ipysheet.cell(0, 0, value=True)
    ipysheet.row(1, value=[2, 34, 543, 23])
    ipysheet.column(3, value=[1.2, 1.3, 1.4, 1.5, 1.6])

    arr = ipysheet.to_array(sheet)
    expected = np.array([[True, None, None, 1.2], [2, 34, 543, 1.3],
                         [None, None, None, 1.4], [None, None, None, 1.5],
                         [None, None, None, 1.6]])
    assert np.all(arr == expected)
Example #5
0
def test_calculation():
    sheet = ipysheet.sheet()
    a = ipysheet.cell(0, 0, value=1)
    b = ipysheet.cell(0, 0, value=2)
    c = ipysheet.cell(0, 0, value=0)
    @ipysheet.calculation(inputs=[a, b], output=c)
    def add(a, b):
        return a + b
    assert c.value == 3
    a.value = 10
    assert c.value == 10+2
    b.value = 20
    assert c.value == 10+20
Example #6
0
def test_getitem():
    sheet = ipysheet.sheet()
    cell00 = ipysheet.cell(0, 0, value='0_0')
    cell10 = ipysheet.cell(1, 0, value='1_0')
    cell21 = ipysheet.cell(2, 1, value='2_1')
    assert sheet[0, 0] is cell00
    assert sheet[1, 0] is cell10
    assert sheet[2, 1] is cell21
    with pytest.raises(IndexError):
        sheet[1, 1]
    # TODO: what do we do with copies.. ? now we return the first values
    ipysheet.cell(0, 0, value='0_0')
    assert sheet[0, 0] is cell00
Example #7
0
def test_cell_add():
    sheet1 = ipysheet.sheet()
    sheet2 = ipysheet.sheet()
    ipysheet.cell(0, 0, value='1')
    assert len(sheet1.cells) == 0
    assert len(sheet2.cells) == 1
    ipysheet.sheet(sheet1)
    ipysheet.cell(0, 0, value='2')
    ipysheet.cell(0, 1, value='2')
    assert len(sheet1.cells) == 2
    assert len(sheet2.cells) == 1

    with ipysheet.hold_cells():
        ipysheet.cell(1, 0, value='3')
        ipysheet.cell(1, 1, value='4')
        assert len(sheet1.cells) == 2
        assert len(sheet2.cells) == 1
    assert len(sheet1.cells) == 4
    assert len(sheet2.cells) == 1
Example #8
0
 def new_dep_cell(row,col=3,cell_thk=None):
     c=ipysheet.cell(row,col,value=0,
                 color='black',
                 background_color='grey',
                 numeric_format='0',
                 read_only=True)
     @ipysheet.calculation(inputs=cell_thk, output=c)
     def add(*a):
         return sum(a)
     return c
Example #9
0
 def insert_rho_sliders(rho_sliders,col=0,row_start=0):
     column1 = ipysheet.column(col, rho_sliders,row_start=row_start)
 #     for i,slide in enumerate(rho_sliders):
 #         cell(row_start+i,col,slide)
     cells = []
     for i in range(len(rho_sliders)):
         cells.append(ipysheet.cell(row_start+i,col+1,rho_sliders[i].value,numeric_format='0.0'))
     for c,s in zip(cells,rho_sliders):
         widgets.jslink((c, "value"),(s,"value"))
     return cells
Example #10
0
def test_cell_values():
    cell = ipysheet.cell(0, 0, value=True)
    assert cell.value is True
    assert cell.type == 'checkbox'

    cell = ipysheet.cell(0, 0, value=1.2)
    assert cell.value == 1.2
    assert cell.type == 'numeric'
    cell = ipysheet.cell(0, 0, value=1)
    assert cell.value == 1
    assert cell.type == 'numeric'

    cell = ipysheet.Cell(value='1.2')
    assert cell.value == '1.2'
    assert cell.type is None

    cell = ipysheet.row(0, [True, False])
    assert cell.value == [True, False]
    assert cell.type == 'checkbox'

    cell = ipysheet.row(0, [0, 1.2])
    assert cell.value == [0, 1.2]
    assert cell.type == 'numeric'

    cell = ipysheet.row(0, [0, 1])
    assert cell.value == [0, 1]
    assert cell.type == 'numeric'

    cell = ipysheet.row(0, ['a', 'b'])
    assert cell.value == ['a', 'b']
    assert cell.type == 'text'

    cell = ipysheet.row(0, [True, 0])
    assert cell.type == 'numeric'

    cell = ipysheet.row(0, [True, 'bla'])
    assert cell.type is None

    cell = ipysheet.cell(0, 0, choice=['a', 'b'])
    assert cell.type == 'dropdown'
Example #11
0
def test_calculation():
    ipysheet.sheet()
    a = ipysheet.cell(0, 0, value=1)
    b = ipysheet.cell(0, 0, value=2)
    c = ipysheet.cell(0, 0, value=0)

    @ipysheet.calculation(inputs=[a, (b, 'value')], output=c)
    def add(a, b):  # pylint: disable=unused-variable
        return a + b

    assert c.value == 3
    a.value = 10
    assert c.value == 10 + 2
    b.value = 20
    assert c.value == 10 + 20

    a.value = 1
    b.value = 2
    assert c.row_start == 0

    @ipysheet.calculation(inputs=[a, b], output=(c, 'type'))
    def add2(a, b):  # pylint: disable=unused-variable
        return 'abcdefg'[a + b]

    assert c.type == 'd'
    b.value = 1
    assert c.type == 'c'

    ipysheet.sheet()
    a = ipysheet.cell(0, 0, value=1)
    b = ipysheet.cell(0, 0, value=widgets.IntSlider(value=2))
    c = widgets.IntSlider(max=0)
    d = ipysheet.cell(0, 0, value=1)

    @ipysheet.calculation(inputs=[a, (b, 'value'), (c, 'max')], output=d)
    def add3(a, b, c):  # pylint: disable=unused-variable
        return a + b + c

    assert d.value == 3
    a.value = 10
    assert d.value == 10 + 2
    b.value.value = 20
    assert d.value == 10 + 20
    c.max = 30
    assert d.value == 10 + 20 + 30

    b.value = widgets.IntSlider(value=2)
    assert d.value == 10 + 2 + 30
    b.value = 20
    assert d.value == 10 + 20 + 30

    a.value = widgets.IntSlider(value=100)
    assert d.value == 100 + 20 + 30
    a.value.value = 10
    assert d.value == 10 + 20 + 30
Example #12
0
    def build_sheet_in(self):
        """
        """
        sheet = ipysheet.sheet(rows=10,
                               columns=5,
                               row_headers=False,
                               column_headers=False)
        sheet.stretch_headers = 'none'
        sheet.column_width = [110, 80, 100, 100, 100]

        cells = {}
        style_header = {
            'backgroundColor': '#d0d3d4',
            'fontWeight': 'bold',
            'textAlign': 'right',
            'color': 'black'
        }
        style_header_2 = {
            'backgroundColor': '#d0d3d4',
            'fontWeight': 'bold',
            'textAlign': 'center',
            'color': 'black'
        }

        for k, h in enumerate(['name', 'symbol', 'value', 'min', 'max']):
            c = ipysheet.cell(0, 0 + k, h, read_only=True, color='black')
            c.style = style_header

        for k, e in enumerate(self.li_input_data):
            r = k + 1
            key, name, symbol, val, val_min, val_max = e
            cells[key] = {}

            ipysheet.cell(r, 0, name, read_only=True, color='black')
            ipysheet.cell(r, 1, symbol, read_only=True, color='black')

            cells[key]['value'] = ipysheet.cell(r, 2, val, type='numeric')
            cells[key]['value_min'] = ipysheet.cell(r,
                                                    3,
                                                    val_min,
                                                    type='numeric')
            cells[key]['value_max'] = ipysheet.cell(r,
                                                    4,
                                                    val_max,
                                                    type='numeric')

        for k, h in enumerate(['Graph', 'Option', 'Nb step', 'x', 'y']):
            c = ipysheet.cell(7, 0 + k, h, read_only=True, color='black')
            c.style = style_header_2

        cells['graph'] = ipysheet.cell(8,
                                       0,
                                       True,
                                       type='checkbox',
                                       style={'textAlign': 'center'})
        cells['graph_state'] = ipysheet.cell(9,
                                             0,
                                             '2D',
                                             style={'textAlign': 'center'})
        cells['option'] = ipysheet.cell(8,
                                        1,
                                        True,
                                        type='checkbox',
                                        style={'textAlign': 'center'})
        cells['option_state'] = ipysheet.cell(9,
                                              1,
                                              'Call',
                                              style={'textAlign': 'center'})
        cells['nb_step'] = ipysheet.cell(8,
                                         2,
                                         '10',
                                         type='dropdown',
                                         choice=['5', '10', '20', '30', '50'])
        cells['x'] = ipysheet.cell(8,
                                   3,
                                   'spot',
                                   type='dropdown',
                                   choice=self.li_ip_key)
        cells['y'] = ipysheet.cell(8,
                                   4,
                                   'mat',
                                   type='dropdown',
                                   choice=self.li_ip_key)

        self.sheet_in = sheet
        self.cells_in = cells
Example #13
0
def test_to_dataframe():
    sheet = ipysheet.sheet(rows=5, columns=4)
    ipysheet.cell(0, 0, value=True)
    ipysheet.row(1, value=[2, 34, 543, 23])
    ipysheet.column(3, value=[1.2, 1.3, 1.4, 1.5, 1.6])

    df = ipysheet.to_dataframe(sheet)
    assert np.all(df['A'].tolist() == [True, 2, None, None, None])
    assert np.all(df['B'].tolist() == [None, 34, None, None, None])
    assert np.all(df['C'].tolist() == [None, 543, None, None, None])
    assert np.all(df['D'].tolist() == [1.2, 1.3, 1.4, 1.5, 1.6])

    sheet = ipysheet.sheet(rows=4,
                           columns=4,
                           column_headers=['c0', 'c1', 'c2', 'c3'],
                           row_headers=['r0', 'r1', 'r2', 'r3'])
    ipysheet.cell_range([
        [2, 34, 543, 23],
        [1, 1, 1, 1],
        [2, 2, 222, 22],
        [2, 0, 111, 11],
    ],
                        row_start=0,
                        column_start=0,
                        transpose=True)

    df = ipysheet.to_dataframe(sheet)
    assert np.all(df['c0'].tolist() == [2, 34, 543, 23])
    assert np.all(df['c1'].tolist() == [1, 1, 1, 1])
    assert np.all(df['c2'].tolist() == [2, 2, 222, 22])
    assert np.all(df['c3'].tolist() == [2, 0, 111, 11])

    sheet = ipysheet.sheet(rows=4,
                           columns=4,
                           column_headers=['t0', 't1', 't2', 't3'])
    ipysheet.cell_range([
        [2, 34, 543, 23],
        [1, 1, 1, 1],
        [2, 2, 222, 22],
        [2, 0, 111, 11],
    ],
                        row_start=0,
                        column_start=0,
                        transpose=False)

    df = ipysheet.to_dataframe(sheet)
    assert np.all(df['t0'].tolist() == [2, 1, 2, 2])
    assert np.all(df['t1'].tolist() == [34, 1, 2, 0])
    assert np.all(df['t2'].tolist() == [543, 1, 222, 111])
    assert np.all(df['t3'].tolist() == [23, 1, 22, 11])

    sheet = ipysheet.sheet(rows=0, columns=0)

    df = ipysheet.to_dataframe(sheet)
    assert np.all(df == pd.DataFrame())

    sheet = ipysheet.sheet(rows=4, columns=1)
    ipysheet.column(0,
                    ['2019/02/28', '2019/02/27', '2019/02/26', '2019/02/25'],
                    type='date')

    df = ipysheet.to_dataframe(sheet)
    assert [_format_date(x) for x in df['A'].tolist()
            ] == ['2019/02/28', '2019/02/27', '2019/02/26', '2019/02/25']
Example #14
0
def test_cell_label():
    sheet = ipysheet.sheet()
    ipysheet.cell(0, 1, label_left='hi')
    assert sheet.cells[-1].value == 'hi'
    with pytest.raises(IndexError):
        ipysheet.cell(0, 0, label_left='hi')
Example #15
0
    def interactive_sheet(self):
        """
        create interactive sheet to open in notebook

        NOTES
        -----
        right now, this just changes the summary table.
        cant really change the cells for indivdual GU and
        IBUS for fermentable and hops table (not big deal though)
        """

        # create a sheet with all the info from the template
        df = pd.read_csv('recipe_template.csv',
                         names=np.arange(0, 20, 1)).replace(np.nan,
                                                            '',
                                                            regex=True)

        sheet1 = sheet(rows=len(df), columns=len(df.columns))
        for i in range(len(df)):
            for j in range(len(df.columns)):
                if df.iloc[i, j] != '':
                    cell(i, j, df.iloc[i, j])
        # add in cells now
        cell_ferms = []
        cell_OG_GU = []
        for i in range(len(self.grain_bill)):
            idx = self.df_grain_bill.index[self.df_grain_bill['id'] ==
                                           self.grain_bill[i][0]].to_list()[0]
            cell(i + 2, 5, self.df_grain_bill.loc[idx, 'name'])
            globals()['cell_ferm_%s' % i] = cell(i + 2,
                                                 6,
                                                 self.grain_bill[i][1],
                                                 background_color='yellow')
            cell_ferms.append(globals()['cell_ferm_%s' % i])
            if self.grain_bill[i][2] == 0:
                cell(i + 2, 7, 'Mash')
            else:
                cell(i + 2, 7, 'Extract')
            OG_GU = self.calc_GU(self.grain_bill[i][1],
                                 self.df_grain_bill.loc[idx, 'yield'],
                                 self.mash_efficiency, self.grain_bill[i][2])
            globals()['cell_OG_GU_%s' % i] = cell(
                i + 2, 8, int(round(OG_GU / self.target_volume, 0)))
            cell_OG_GU.append(globals()['cell_OG_GU_%s' % i])

        cell_ams = []
        cell_times = []
        for i in range(len(self.hop_bill)):
            idx = self.df_hop_bill.index[self.df_hop_bill['id'] ==
                                         self.hop_bill[i][0]].to_list()[0]
            cell(i + 2, 10, self.df_hop_bill.loc[idx, 'name'])
            globals()['cell_ams_%s' % i] = cell(i + 2,
                                                11,
                                                self.hop_bill[i][1],
                                                background_color='yellow')
            cell_ams.append(globals()['cell_ams_%s' % i])
            globals()['cell_times_%s' % i] = cell(i + 2,
                                                  12,
                                                  self.hop_bill[i][2],
                                                  background_color='yellow')
            cell_times.append(globals()['cell_times_%s' % i])
            IBU = self.est_hop_IBU(self.BG, self.hop_bill[i][2],
                                   self.hop_bill[i][1],
                                   self.df_hop_bill.loc[idx, 'alpha'],
                                   self.target_volume)
            cell(i + 2, 13, round(IBU, 1))

        cell_yeast_name = cell(2, 15, self.df_yeast.loc[0, 'name'])
        cell_yeast_atten = cell(2,
                                16,
                                self.df_yeast.loc[0, 'attenuation'],
                                background_color='yellow')
        cell_yeast_atten_adj = cell(2,
                                    17,
                                    self.calc_AA(),
                                    background_color='red')
        cell_yeast_min_temp = cell(
            2, 18, self.df_yeast.loc[0, 'min_temperature'] * 9 / 5 + 32)
        cell_yeast_max_temp = cell(
            2, 19, self.df_yeast.loc[0, 'max_temperature'] * 9 / 5 + 32)

        cell_target_volume = cell(2,
                                  1,
                                  self.target_volume,
                                  background_color='yellow')
        cell_boil_volume = cell(3,
                                1,
                                self.boil_volume,
                                background_color='yellow')
        cell_boil_time = cell(4, 1, self.boil_time, background_color='yellow')
        cell_mash_temp = cell(5, 1, self.mash_temp, background_color='yellow')
        cell_OG = cell(6, 1, self.OG, background_color='red')
        cell_FG = cell(7, 1, self.FG, background_color='red')
        cell_IBU = cell(8, 1, self.IBU, background_color='red')
        cell_color = cell(9, 1, self.color, background_color='red')
        cell_mash_efficiency = cell(10,
                                    1,
                                    self.mash_efficiency,
                                    background_color='yellow')
        cell_ABV = cell(11, 1, self.ABV, background_color='red')

        # brew day cells
        cell_mash_volume = cell(16,
                                1,
                                self.mash_volume,
                                background_color='yellow')
        cell_mash_grav = cell(17, 1, background_color='red')

        @calculation(inputs=cell_ferms +
                     [cell_mash_efficiency, cell_mash_volume],
                     output=cell_mash_grav)
        def cell_calc_mash_grav(*args):
            cell_mash_efficiency = args[-2]
            cell_mash_volume = args[-1]
            MG = self.calc_mash_grav(grain_amounts=args[:-2],
                                     mash_efficiency=cell_mash_efficiency,
                                     mash_volume=cell_mash_volume)
            return MG

        cell_BG = cell(18, 1, background_color='red')

        @calculation(inputs=cell_ferms +
                     [cell_mash_efficiency, cell_boil_volume],
                     output=cell_BG)
        def cell_calc_BG(*args):
            cell_mash_efficiency = args[-2]
            cell_boil_volume = args[-1]
            BG = self.calc_BG(grain_amounts=args[:-2],
                              mash_efficiency=cell_mash_efficiency,
                              boil_volume=cell_boil_volume)
            return BG

        cell_PB_volume = cell(19, 1, background_color='red')

        @calculation(inputs=[cell_boil_volume, cell_boil_time],
                     output=cell_PB_volume)
        def cell_calc_PB_volume(cell_boil_volume, cell_boil_time):
            PB_volume = self.calc_PB_volume(boil_volume=cell_boil_volume,
                                            boil_time=cell_boil_time)
            return PB_volume

        cell_PB_grav = cell(20, 1, background_color='red')

        @calculation(inputs=[cell_BG, cell_boil_volume, cell_boil_time],
                     output=cell_PB_grav)
        def calc_PB_grav(cell_BG, cell_boil_volume, cell_boil_time):
            PB = self.calc_PB_grav(BG=cell_BG,
                                   boil_volume=cell_boil_volume,
                                   boil_time=cell_boil_time)
            return PB

        # add style cells
        cell_OG_style = cell(
            6, 2,
            str(self.df_style.loc[0, 'og_min']) + '-' +
            str(self.df_style.loc[0, 'og_max']))
        cell_FG_style = cell(
            7, 2,
            str(self.df_style.loc[0, 'fg_min']) + '-' +
            str(self.df_style.loc[0, 'fg_max']))
        cell_IBU_style = cell(
            8, 2,
            str(self.df_style.loc[0, 'ibu_min']) + '-' +
            str(self.df_style.loc[0, 'ibu_max']))
        cell_color_style = cell(
            9, 2,
            str(self.df_style.loc[0, 'color_min']) + '-' +
            str(self.df_style.loc[0, 'color_max']))
        cell_ABV_style = cell(
            11, 2,
            str(self.df_style.loc[0, 'abv_min']) + '-' +
            str(self.df_style.loc[0, 'abv_max']))
        # add checks for style
        cell_OG_style_check = cell(6, 3, background_color='red')

        @calculation(inputs=[cell_OG], output=cell_OG_style_check)
        def OG_check(cell_OG):
            if cell_OG < self.df_style.loc[
                    0, 'og_min'] or cell_OG > self.df_style.loc[0, 'og_max']:
                return 'X'
            else:
                return ''

        cell_FG_style_check = cell(7, 3, background_color='red')

        @calculation(inputs=[cell_FG], output=cell_FG_style_check)
        def FG_check(cell_FG):
            if cell_FG < self.df_style.loc[
                    0, 'fg_min'] or cell_FG > self.df_style.loc[0, 'fg_max']:
                return 'X'
            else:
                return ''

        cell_IBU_style_check = cell(8, 3, background_color='red')

        @calculation(inputs=[cell_IBU], output=cell_IBU_style_check)
        def IBU_check(cell_IBU):
            if cell_IBU < self.df_style.loc[
                    0, 'ibu_min'] or cell_IBU > self.df_style.loc[0,
                                                                  'ibu_max']:
                return 'X'
            else:
                return ''

        cell_color_style_check = cell(9, 3, background_color='red')

        @calculation(inputs=[cell_color], output=cell_color_style_check)
        def color_check(cell_color):
            if cell_color < self.df_style.loc[
                    0, 'color_min'] or cell_color > self.df_style.loc[
                        0, 'color_max']:
                return 'X'
            else:
                return ''

        cell_ABV_style_check = cell(11, 3, background_color='red')

        @calculation(inputs=[cell_ABV], output=cell_ABV_style_check)
        def ABV_check(cell_ABV):
            if cell_ABV < self.df_style.loc[
                    0, 'abv_min'] or cell_ABV > self.df_style.loc[0,
                                                                  'abv_max']:
                return 'X'
            else:
                return ''

        # add summary calculations
        @calculation(inputs=[cell_OG, cell_FG], output=cell_ABV)
        def cell_ABV_calc(OG, FG):
            return self.calc_ABV(OG, FG)

        @calculation(inputs=cell_ferms +
                     [cell_mash_efficiency, cell_target_volume],
                     output=cell_OG)
        def cell_calc_OG(*args):
            cell_mash_efficiency = args[-2]
            cell_target_volume = args[-1]
            OG = self.calc_OG(grain_amounts=args[:-2],
                              mash_efficiency=cell_mash_efficiency,
                              target_volume=cell_target_volume)
            return OG

        @calculation(inputs=[cell_yeast_atten, cell_mash_temp],
                     output=cell_yeast_atten_adj)
        def calc_adj_atten(cell_yeast_atten, cell_mash_temp):
            yeast_atten_adj = self.calc_AA(yeast_atten=cell_yeast_atten,
                                           mash_temp=cell_mash_temp)
            return yeast_atten_adj

        @calculation(inputs=cell_ferms + [
            cell_yeast_atten, cell_mash_efficiency, cell_target_volume,
            cell_mash_temp, cell_OG
        ],
                     output=cell_FG)
        def cell_calc_FG(*args):
            cell_yeast_atten = args[-5]
            cell_mash_efficiency = args[-4]
            cell_target_volume = args[-3]
            cell_mash_temp = args[-2]
            cell_OG = args[-1]
            FG = self.calc_FG(OG=cell_OG,
                              yeast_atten=cell_yeast_atten,
                              mash_temp=cell_mash_temp,
                              grain_amounts=args[:-5],
                              mash_efficiency=cell_mash_efficiency,
                              target_volume=cell_target_volume)
            return FG

        @calculation(
            inputs=cell_ams + cell_times + cell_ferms +
            [cell_mash_efficiency, cell_boil_volume, cell_target_volume],
            output=cell_IBU)
        def cell_calc_IBU(*args):
            cell_mash_efficiency = args[-3]
            cell_boil_volume = args[-2]
            cell_target_volume = args[-1]
            IBU = self.calc_IBU(hop_times=args[len(self.hop_bill):2 *
                                               len(self.hop_bill)],
                                hop_amounts=args[:len(self.hop_bill)],
                                grain_amounts=args[2 * len(self.hop_bill):-3],
                                mash_efficiency=cell_mash_efficiency,
                                boil_volume=cell_boil_volume,
                                target_volume=cell_target_volume)
            return IBU

        @calculation(inputs=cell_ferms + [cell_target_volume],
                     output=cell_color)
        def cell_calc_color(*args):
            cell_target_volume = args[-1]
            SRM = self.calc_color(grain_amounts=args[:-1],
                                  target_volume=cell_target_volume)
            return SRM

        return sheet1
Example #16
0
    return ratchets


val_date_wgt = ipw.DatePicker(description='Val Date', value=date.today())
inventory_wgt = ipw.FloatText(description='Inventory')
ir_wgt = ipw.FloatText(description='Intrst Rate %', step=0.005)
discount_deltas_wgt = ipw.Checkbox(description='Discount Deltas', value=False)
val_inputs_wgt = ipw.VBox(
    [val_date_wgt, inventory_wgt, ir_wgt, discount_deltas_wgt])

# Forward curve
fwd_input_sheet = ips.sheet(rows=num_fwd_rows,
                            columns=2,
                            column_headers=['fwd_start', 'price'])
for row_num in range(0, num_fwd_rows):
    ips.cell(row_num, 0, '', date_format=date_format, type='date')
    ips.cell(row_num, 1, '', type='numeric')

out_fwd_curve = ipw.Output()
smooth_curve_wgt = ipw.Checkbox(description='Apply Smoothing', value=False)
apply_wkend_shaping_wgt = ipw.Checkbox(description='Wkend Shaping',
                                       value=False,
                                       disabled=True)
wkend_factor_wgt = ipw.FloatText(description='Wkend shaping factor',
                                 step=0.005,
                                 disabled=True)
btw_plot_fwd_wgt = ipw.Button(description='Plot Forward Curve')


def on_smooth_curve_change(change):
    apply_wkend_shaping_wgt.disabled = not change['new']
# %%
from IPython.display import display
from ipywidgets import widgets
import ipysheet

sheet = ipysheet.sheet(
    rows=3,
    columns=4,  # define ncol and nrow of a sheet
    column_headers=False,
    row_headers=False  # define headers
)
sheet
# %%
# change value and return a cell obj
# cell(row, column, value=0.0, ... )
cell_a = ipysheet.cell(0, 1, 1, label_left='a')
cell_b = ipysheet.cell(1, 1, 2, label_left='b')
cell_sum = ipysheet.cell(2, 1, 3, label_left='sum', read_only=True)
# %%
# create a slider linked to cell a
slider = widgets.FloatSlider(min=-10, max=10, description='a')
widgets.jslink(
    (cell_a, 'value'),
    (slider, 'value'
     ))  # jslink(attr1, attr2) -> Link; type(attr1)=tuple:(<widegt, name>)


# %%
# changes in a or b should trigger this function
def calculate(change):
    cell_sum.value = cell_a.value + cell_b.value
Example #18
0
 def new_thk_cell(row,col=2,thk=30):
     if thk is None:
         '''
         dep: set to previous layer
         '''
     return ipysheet.cell(row,col,thk,numeric_format='0')
def plan_factory(work_list):
    for r, w in enumerate(work_list):
        # If all field is legal, run plan
        if all(check_list[r]):
            time.sleep(1)
            for c in range(4):
                metadata_sheet[r, c].style = {'backgroundColor': 'lightblue'}
                metadata_sheet[r, c].read_only = True
                global current_log_row
                # current_log_cell = log_sheet[current_log_row,c]
                current_log_cell = cell(current_log_row, c, metadata_sheet[r, c].value)
            print(f'Row {1+r} locked and launch \N{Rocket}')

            yield from mv(det.exp, w.scantime)
            uid = yield from count([det])
            
            log_uid_list.append(uid)

            out = widgets.Output()
            '''
            with out:
                fig = plt.figure()
                plt.imshow(db[uid].primary.read()['det_img'].data.squeeze())
                plt.show()
            cell(current_log_row, 4, fig.canvas)
            '''
            with out:
                #fig = plt.figure()
                #fig.set_size_inches(2,2)
                # cell(current_log_row, 4, fig.canvas)
                
                plt.figure()
                plt.imshow(db[uid].primary.read()['det_img'].data.squeeze())
                plt.show()
            cell(current_log_row, 4, out)
            #cell(current_log_row, 0, value=' ')
            #cell(current_log_row, 1, value=None)
            #cell(current_log_row, 2, value=None)
            #cell(current_log_row, 3, value=None)
            button = widgets.Button(description="Export",
                                   layout=Layout(width='50%', height='25px', left= '100px', top = '100px'))
            button.on_click(export_full_image)
            #button.on_click(on_button_clicked)
            row_of_button[button] = current_log_row
            cell(current_log_row, 5, button)
            
            
            log_sheet.rows = log_sheet.rows + 1
            current_log_row = current_log_row + 1
            #plt.figure()
            # plt.pcolor(db[uid].primary.read()['det_img'].data.squeeze())
            # plt.show()
        else:
            print(f'Skip row {1+r}')
    # Reset back to read_only = False

    for r in range(len(work_list)):
        for c in range(4):
            tmp = metadata_sheet[r,c]
            tmp.read_only=False
            if tmp.style['backgroundColor'] == 'lightblue':
                tmp.style = {'backgroundColor': 'white'}
METADATA_SHEET_COLUMN_RATIO = [1, 1, 1, 1, 2]
HISTORY_SHEET_COLUMN_RATIO = [1, 1, 1, 1, 1, 1]
SAMPLE_LIST = ['CeO2', 'BaTiO3_bulk', 'BaTiO3_nano', 'Aa', 'Bb', 'Cc']
COMPOSITION_LIST = ['Ce O2', 'Ba Ti O3', 'Ba Ti O3', 'A a', 'B b', 'C c']
DESCRIPTION_LIST = ['1mm kapton', ' ', '1mm kapton', ' ', ' ', ' ']
client = amostra.mongo_client.Client(
        f'mongodb://localhost:27017/test_amostra_ipysheet-{uuid.uuid4()!s}')


samples_sheet = sheet(rows=6, columns=4,
                      column_width=SAMPLE_SHEET_COLUMN_RATIO,
                      column_headers=['Sample Name', 'Composition', 'Background', 'UUID'])
# Sample Name    Composition    Scan Time (s)    Grid_X    Grid_Y    Background    user_id
for row in range(samples_sheet.rows):
    sample = client.samples.new(name=' ', composition=' ', description=' ')
    link((cell(row, 0, value=SAMPLE_LIST[row]), 'value'), (sample, 'name'))
    link((cell(row, 1, value=COMPOSITION_LIST[row]), 'value'), (sample, 'composition'))
    link((cell(row, 2, value=DESCRIPTION_LIST[row]), 'value'), (sample, 'description'))
    cell(row, 3, value=' ').value = sample.uuid


class WorkQueueItem(HasTraits):
    name = Unicode()
    scantime = Float()
    gridx = Float(allow_none=True)
    gridy = Float(allow_none=True)
    uuid = Unicode()


def search(change):
    '''
Example #21
0
ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines()

plt.show()



#####

import ipysheet
sheet = ipysheet.sheet()
sheet

sheet = ipysheet.sheet(rows=3, columns=4)
cell1 = ipysheet.cell(0, 0, 'Hello')
cell2 = ipysheet.cell(2, 0, 'World')
cell_value = ipysheet.cell(2,2, 42.)
sheet


########


import ipywidgets as widgets
sheet = ipysheet.sheet(rows=3, columns=2, column_headers=False, row_headers=False)
cell_a = ipysheet.cell(0, 1, 1, label_left='a')
cell_b = ipysheet.cell(1, 1, 2, label_left='b')
cell_sum = ipysheet.cell(2, 1, 3, label_left='sum', read_only=True)

# create a slider linked to cell a
Example #22
0
    def _create_sheet(self):
        """Create ipysheet from table data (self._data)."""
        nr = len(self._data['x'])
        layout = ipy.Layout(min_width='auto',
                            height='auto',
                            border='none',
                            margin='0px 0px 0px 0px')
        sheet = ipysheet.sheet(rows=nr,
                               columns=len(DistTable._headers) + 1,
                               row_headers=False,
                               column_headers=[' '] + DistTable._headers,
                               stretch_headers='none',
                               layout=layout)

        stl = {'textAlign': 'center'}
        gbcg = "#EEEEEE"

        # other data cells
        self._cells.clear()
        self._cells['x'] = ipysheet.column(1,
                                           self._data['x'][1:nr - 1],
                                           row_start=1,
                                           numeric_format=self.num_format)
        self._cells['fix_x'] = ipysheet.column(2,
                                               self._data['fix_x'][1:nr - 1],
                                               row_start=1,
                                               type='checkbox',
                                               style=stl)
        self._cells['y'] = ipysheet.column(3,
                                           self._data['y'][1:nr - 1],
                                           row_start=1,
                                           numeric_format=self.num_format)
        self._cells['fix_y'] = ipysheet.column(4,
                                               self._data['fix_y'][1:nr - 1],
                                               row_start=1,
                                               type='checkbox',
                                               style=stl)

        # x[0] and x[-1] must be always a fixed parameter
        self._cells['00'] = ipysheet.cell(0,
                                          1,
                                          self._data['x'][0],
                                          type='numeric',
                                          numeric_format=self.num_format)
        ipysheet.cell(0, 2, [None], read_only=True, background_color=gbcg)
        self._cells['02'] = ipysheet.cell(0,
                                          3,
                                          self._data['y'][0],
                                          type='numeric',
                                          numeric_format=self.num_format)
        self._cells['03'] = ipysheet.cell(0,
                                          4,
                                          self._data['fix_y'][0],
                                          type='checkbox',
                                          style=stl,
                                          background_color="white")

        self._cells['10'] = ipysheet.cell(nr - 1,
                                          1,
                                          self._data['x'][nr - 1],
                                          type='numeric',
                                          numeric_format=self.num_format)
        ipysheet.cell(nr - 1, 2, [None], read_only=True, background_color=gbcg)
        self._cells['12'] = ipysheet.cell(nr - 1,
                                          3,
                                          self._data['y'][nr - 1],
                                          type='numeric',
                                          numeric_format=self.num_format)
        self._cells['13'] = ipysheet.cell(nr - 1,
                                          4,
                                          self._data['fix_y'][nr - 1],
                                          type='checkbox',
                                          style=stl,
                                          background_color="white")

        # 1st column: check boxes for row selection
        ipysheet.cell(0, 0, [None], read_only=True, background_color=gbcg)
        self._row_select = ipysheet.column(0, (nr - 2) * [False],
                                           row_start=1,
                                           style=stl,
                                           background_color=gbcg)
        ipysheet.cell(nr - 1, 0, [None], read_only=True, background_color=gbcg)
        self.sheet = sheet