def test_hl_7(): headline("test", properties={"one": "two"}) result = "* test\n :PROPERTIES:\n :one: two\n :END:\n\n\n" assert sys.stdout.getvalue() == result
def org(self): '''Print an org-represention of the plate and data. ''' from pycse.orgmode import table, figure, headline, print_redirect, link import datetime import json import time ts = time.time() st = datetime.datetime.fromtimestamp(ts).strftime('[%Y-%m-%d %a %H:%M:%S]') CWD = os.getcwd() os.chdir(os.path.join(self.base, self.directory)) try: import matplotlib matplotlib.use('TkAgg') A, B = self.metadata['A'], self.metadata['B'] print(f'#+TITLE: {A}-{B}') print(f'#+CREATED: {st}') print('#+STARTUP: showall') print() print('Generated report. Do not edit. Changes may be lost.\n') headline('Summary', tags=[A, B], body=str(self)) link('file+sys', f'./primary_data/{A}col{B}rowdata.xls') link('file+sys', './images', 'Image directory') link('file+sys', './auxillary_data', 'auxillary_data') print() headline('Hydrogen data') headline('Hydrogen production plots', level=2) plt.figure() self.data['mmolH'].plot_mmolH_grid_window() plt.tight_layout() figure('espyranto/kinetics-grid.png', name='fig-kinetics-grid', attributes=[['org', ':width 600']], caption=f'Hydrogen umolH in each well for {A}-{B}.') plt.clf() print() headline('Max production', level=2) ncols, nrows = self.ncols, len(self.data['mmolH'].mmolH) // self.ncols maxh = np.max(self.data['mmolH'].mmolH, axis=1).reshape(nrows, ncols) data = np.round(maxh, 2) # Add row and column labels col_labels = self.A.reshape(nrows, ncols)[0][None, :] row_labels = np.concatenate(([['']], self.B.reshape(nrows, ncols)[:, 0][:, None])) data = np.concatenate((col_labels, data)) data = np.concatenate((row_labels, data), axis=1) data = list(data) data.insert(1, None) data[0][0] = f'{B}\{A}' table(data, name='tab-maxh', caption='Maxh µmol H_{2} produced.') print() self.data['mmolH'].plot_mmolH_max(); plt.tight_layout() figure('espyranto/maxh.png', name='fig-maxh', attributes=[['org', ':width 600']], caption=f'Maximum hydrogen produced for {A}-{B}.') plt.clf() print() tot_conc = (self.A + self.B) # The nself.where deals with the case where A = B = 0.0 x_A = self.A / np.where(tot_conc > 0, tot_conc, 1) plt.figure() plt.scatter(x_A, np.max(self.data['mmolH'].mmolH, axis=1), tot_conc * 20) plt.xlabel(f'$x_{{{A}}}$'); plt.ylabel('$\mu molH$'); print() figure('espyranto/maxh-scatter.png', name='fig-maxh-scatter', attributes=[['org', ':width 600']], caption=f'Scatter plot for maximum hydrogen produced for {A}-{B}.') print() headline('Max rate', level=2) # Heatmap of max rates print() self.data['mmolH'].plot_mmolH_max_derivative_window() figure('espyranto/maxrate.png', name='fig-maxrate', attributes=[['org', ':width 600']], caption=f'Maximum rate (window) of hydrogen produced for {A}-{B}.') # Scatter plot print() mmolH = self.data['mmolH'] t = np.arange(0, len(mmolH[0])) * mmolH.timestep / 3600 rate_data = [] for row in self.data['mmolH'].mmolH: ys = mmolH.smooth_window(row) dydx = np.gradient(ys, t, edge_order=2) rate_data += [np.max(dydx)] # Scatter plot plt.figure() plt.scatter(x_A, rate_data, tot_conc * 20) plt.xlabel(f'$x_{{{A}}}$'); plt.ylabel('$\mu molH/hr$'); print() figure('espyranto/maxrate-scatter.png', name='fig-maxrate-scatter', attributes=[['org', ':width 600']], caption=f'Scatter plot for maximum rate of hydrogen production for {A}-{B}.') print() # For making a table rate_data = np.round(rate_data, 2) rate_data = rate_data.reshape((nrows, ncols)) rate_data = np.concatenate((col_labels, rate_data)) rate_data = np.concatenate((row_labels, rate_data), axis=1) rate_data = list(rate_data) rate_data.insert(1, None) rate_data[0][0] = f'{B}\{A}' table(rate_data, name='tab-maxrate', caption='Max rate µmol/hr H_{2} produced.') print() headline('Metadata') print() print(f'''#+name: metadata #+BEGIN_SRC json {json.dumps(self.metadata, sort_keys=True, indent=2)} #+END_SRC ''') finally: os.chdir(CWD) plt.close('all')
def test_hl_tags(): headline("test", tags=['a', 'b']) assert sys.stdout.getvalue() == "* test :a:b:\n\n"
def test_hl_6(): headline("test", body="some text") assert sys.stdout.getvalue() == '* test\nsome text\n\n'
def test_hl_5(): headline("test", deadline='test') assert sys.stdout.getvalue() == "* test\n DEADLINE: test\n\n"
def test_hl_4(): headline("test", scheduled='test', deadline='test') result = "* test\n SCHEDULED: test DEADLINE: test\n\n" assert sys.stdout.getvalue() == result
def test_hl_3(): headline("test", scheduled='test') assert sys.stdout.getvalue() == "* test\n SCHEDULED: test\n\n"
def test_hl_2(): headline("test", 2) assert sys.stdout.getvalue() == "** test\n\n"
def test_headline_1(): headline("test") assert sys.stdout.getvalue() == "* test\n\n"