def _make_level_table(self, irrad, level, c): rows = [] flowables = [] flowables.append(self._make_table_title(irrad, level)) row = Row() for v in ('Pos.', 'L#', 'Sample', 'Note'): row.add_item(value=self._new_paragraph('<b>{}</b>'.format(v))) rows.append(row) srows = sorted([self._make_row(pi, c) for pi in level.positions], key=lambda x: x[0]) rows.extend(srows) ts = self._new_style(header_line_idx=0, header_line_width=2) ts.add('LINEBELOW', (0, 1), (-1, -1), 1.0, colors.black) t = self._new_table(ts, rows) t._argW[0] = 0.35 * inch t._argW[1] = 1. * inch t._argW[2] = 2 * inch flowables.append(t) if self.page_break_between_levels: flowables.append(self._page_break()) else: flowables.append(self._new_spacer(0, 0.25 * inch)) return flowables
def _make_notes(self, data, style): p = os.path.join(paths.template_dir, self.notes_template) if os.path.isfile(p): with open(p, "r") as fp: meta = "" for li in fp: if li.startswith("#-----------"): break meta += li meta = yaml.load(meta) txt = "" for li in fp: txt += li size = meta.get("fontsize", 5) leading = meta.get("leading", 5) bgcolor = meta.get("bgcolor", None) p = self._new_paragraph(txt, leading=leading) r = Row(fontsize=size) r.add_item(value=p, span=-1) data.append(r) if bgcolor: bgcolor = bgcolor.replace(" ", "") if hasattr(colors, bgcolor): idx = len(data) - 1 style.add("BACKGROUND", (0, idx), (-1, idx), getattr(colors, bgcolor))
def _make_notes(self, data, style): p = os.path.join(paths.template_dir, self.notes_template) if os.path.isfile(p): with open(p, 'r') as fp: meta = '' for li in fp: if li.startswith('#-----------'): break meta += li meta = yaml.load(meta) txt = '' for li in fp: txt += li size = meta.get('fontsize', 5) leading = meta.get('leading', 5) bgcolor = meta.get('bgcolor', None) p = self._new_paragraph(txt, leading=leading) r = Row(fontsize=size) r.add_item(value=p, span=-1) data.append(r) if bgcolor: bgcolor = bgcolor.replace(' ', '') if hasattr(colors, bgcolor): idx = len(data) - 1 style.add( 'BACKGROUND', (0, idx), (-1, idx), getattr(colors, bgcolor), )
def _make_notes(self, data, style): p = os.path.join(paths.template_dir, self.notes_template) if os.path.isfile(p): with open(p, 'r') as rfile: meta = '' for li in rfile: if li.startswith('#-----------'): break meta += li meta = yaml.load(meta) txt = '' for li in rfile: txt += li size = meta.get('fontsize', 5) leading = meta.get('leading', 5) bgcolor = meta.get('bgcolor', None) p = self._new_paragraph(txt, leading=leading) r = Row(fontsize=size) r.add_item(value=p, span=-1) data.append(r) if bgcolor: bgcolor = bgcolor.replace(' ', '') if hasattr(colors, bgcolor): idx = len(data) - 1 style.add('BACKGROUND', (0, idx), (-1, idx), getattr(colors, bgcolor))
def _make_flux_row(self, ans): mR = sum(ai.R for ai in ans) / len(ans) j, e = calculate_flux(mR, 1, self.monitor_age) r = Row(fontsize=8) r.add_item(value='<b>J</b>', span=5) r.add_item(value='<b>{}</b>'.format(floatfmt(j))) r.add_item(value='<b>{}</b>'.format(floatfmt(e))) return r
def _make_summary_rows(self, mean, idx, style): platrow = Row(fontsize=7, height=0.25) platrow.add_item(value='<b>Weighted Mean Age</b>', span=5) platrow.add_blank_item(n=10) wa = mean.weighted_age platrow.add_item(value=self._value()(wa)) platrow.add_item(value=u' \u00b1{}'.format(self._error()(wa))) # for s, e in platrow.spans: # style.add('SPAN', (s, idx), (e, idx)) # platrow.add_item(value='Weighted Mean Age') return [platrow]
def _make_summary_rows(self, mean, idx, style): weighted_mean_row = Row(fontsize=6, height=0.15) weighted_mean_row.add_item(value='<b>Weighted Mean Age</b>', span=5, include_width_calc=False) weighted_mean_row.add_blank_item(n=12) wa = mean.weighted_age weighted_mean_row.add_item(value=self._value(n=2)(wa)) weighted_mean_row.add_item(value=u'\u00b1{}'.format(self._error(n=2)(wa))) # for s, e in platrow.spans: # style.add('SPAN', (s, idx), (e, idx)) # platrow.add_item(value='Weighted Mean Age') return [weighted_mean_row]
def _make_weighted_mean_row(self, ans): r = Row(fontsize=8) ages, errors = zip(*[(ai.age.nominal_value, ai.age.std_dev) for ai in ans]) wm, we = calculate_weighted_mean(ages, errors) r.add_item(value='<b>weighted mean</b>', span=2) r.add_blank_item(3) r.add_item(value='<b>{}</b>'.format(floatfmt(wm))) r.add_item(value=u'<b>\u00b1{}</b>'.format(floatfmt(we))) return r
def _make_level_table(self, irrad, level, c): # flowables = [] row = Row() row.add_item(span=-1, value=self._make_table_title(irrad, level), fontsize=18) rows = [row] row = Row() for v in ('', 'Pos.', 'L#', 'Sample', 'Material', 'Project', 'PI', 'Note'): row.add_item(value=self._new_paragraph('<b>{}</b>'.format(v))) rows.append(row) srows = sorted([self._make_row(pi, c) for pi in level.positions], key=lambda x: x[0]) rows.extend(srows) ts = self._new_style(header_line_idx=0, header_line_width=2) ts.add('LINEBELOW', (0, 1), (-1, -1), 1.0, colors.black) cw = self.options.widths() t = self._new_table(ts, rows, colWidths=cw) t.repeatRows = 2 flowables = [t] if self.page_break_between_levels: flowables.append(self._page_break()) else: flowables.append(self._new_spacer(0, 0.25 * inch)) return flowables
def _make_meta_table(self, meta): ts = self._new_style() items = '<b>Load:</b> {load_name}|<b>Loader</b>: {username}|<b>Date</b>: {load_date}'.format( **meta).split('|') row1 = [self._new_paragraph(ti) for ti in items] row1 = Row(items=[RowItem(value=v) for v in row1]) items = '<b>Projects</b>: {projects} | | '.format(**meta).split('|') row2 = [self._new_paragraph(ti) for ti in items] row2 = Row(items=[RowItem(value=v) for v in row2]) table = self._new_table(ts, (row1, row2)) return table
def _make_table(self, positions): data = [ Row(items=[ RowItem('L#'), RowItem('Irradiation'), RowItem('Sample'), RowItem('Positions') ]), ] ts = self._new_style(header_line_idx=0) ts.add('FONTSIZE', (0, 1), (-1, -1), 8) # ts.add('VALIGN', (-3, 1), (-1, -1), 'MIDDLE') for idx, pi in enumerate(positions): # row = (pi.labnumber, pi.irradiation_str, pi.sample, # pi.position_str) items = [ RowItem(i) for i in (pi.labnumber, pi.irradiation_str, pi.sample, pi.position_str) ] row = Row(items=items) data.append(row) c = colors.white if self.options.show_colors: cc = pi.color if sum(cc) < 1.5: ts.add('TEXTCOLOR', (0, idx + 1), (-1, idx + 1), colors.white) c = Color(*cc) elif self.options.use_alternating_background: if idx % 2 == 0: c = self.options.get_alternating_background() if sum(c) < 1.5: ts.add('TEXTCOLOR', (0, idx + 1), (-1, idx + 1), colors.white) ts.add('BACKGROUND', (0, idx + 1), (-1, idx + 1), c) cw = map(lambda x: mm * x, [13, 21, 22, 38]) rh = [mm * 5 for _ in xrange(len(data))] t = self._new_table(ts, data, colWidths=cw, rowHeights=rh) return t
def make_row(level): row = Row() row.add_item(value=level.name) row.add_item(value=level.holder) row.add_item(value=', '.join(level.projects)) return row
def _make_blank_row(self, pos): r = Row() r.add_item(value='[ ]') r.add_item(value=pos) for i in range(6): r.add_item(value='') return r
def _make_footnote_rows(self, data, style): data.append(Row(height=0.1)) fr = FootNoteRow(fontsize=6) #start=0 self._footnotes.append(self._new_paragraph('P: plateau step')) txt = ', '.join([fi.text for fi in self._footnotes]) #span=self._calculate_span(fi, start, fontSize=3) fr.add_item(value=txt, span=-1) #for fi in ['P: plateau step',]: # p=self._new_paragraph(fi) # span=self._calculate_span(p, start, fontSize=8) # fr.add_item(value=p, span=span) # # start+=span # #if self._footnotes: # for fi in self._footnotes: # span=self._calculate_span(fi, start, fontSize=3) # fr.add_item(value=fi, span=span) # start+=span # self.debug("{} {} {}".format(start, start-span, span)) #dsaf data.append(fr)
def _make_footnote_rows(self, data, style): data.append(Row(height=0.1)) blanks = self._get_average_blanks() fontsize = 6 height = self.footnote_height if blanks: co2_blanks, furnace_blanks = blanks average_furnace_blanks = 'Average blanks for Furnace: ({Ar40:0.3f}, {Ar39:0.3f}, {Ar38:0.3f}, ' \ '{Ar37:0.3f}, {Ar36:0.3f}), ' \ 'x10<sup>-{sens_exp:}</sup> ' \ 'for Ar<super>40</super>, Ar<super>39</super>, ' \ 'Ar<super>38</super>, Ar<super>37</super>, Ar<super>36</super> ' \ 'respectively'.format(**furnace_blanks) frow = FooterRow(fontsize=fontsize, height=height) frow.add_item(span=-1, value=self._new_paragraph(average_furnace_blanks)) data.append(frow) fr = FootNoteRow(fontsize=fontsize, height=height) self._footnotes.append(self._new_paragraph('P: plateau step')) txt = ', '.join([fi.text for fi in self._footnotes]) fr.add_item(value=txt, span=-1) data.append(fr)
def _make_header(self): header = Row() S40 = Superscript('40') S39 = Superscript('39') sK = Subscript('K') attrs = ( '', 'N', 'Power', 'Mol. {}Ar'.format(S40), '{}Ar*%'.format(S40), '{}Ar*/{}Ar{}'.format(S40, S39, sK), 'Age', u'\u00b1 1\u03c3', 'K/Ca', u'\u00b1 1\u03c3', ) for a in attrs: header.add_item(value=u'<b>{}</b>'.format(a)) return header
def _make_notes_table(self, canvas): data = [ Row(items=[ RowItem('L#'), RowItem('Irradiation'), RowItem('Sample'), RowItem('Hole'), RowItem('Weight'), RowItem('Note') ]), ] ts = self._new_style() ts.add('LINEBELOW', (0, 0), (-1, 0), 1, colors.black) ts.add('FONTSIZE', (0, 1), (-1, -1), 8) # ts.add('VALIGN', (-3, 1), (-1, -1), 'MIDDLE') idx = 0 prev_irrad = None for pi in sorted(canvas.scene.get_items(LoadIndicator), key=lambda x: int(x.name)): if pi.irradiation: if pi.irradiation == prev_irrad: items = (pi.labnumber_label.text, '', '', pi.name, pi.weight or '', pi.note or '') else: items = (pi.labnumber_label.text, pi.irradiation, pi.sample, pi.name, pi.weight, pi.note) prev_irrad = pi.irradiation data.append(Row(items=[RowItem(ri) for ri in items])) if idx % 2 == 0: ts.add('BACKGROUND', (0, idx + 1), (-1, idx + 1), colors.lightgrey) idx += 1 cw = map(lambda x: mm * x, [15, 22, 22, 22, 22, 80]) rh = [mm * 5 for _ in xrange(len(data))] t = self._new_table(ts, data, colWidths=cw, rowHeights=rh) return t
def _new_row(self, obj, attrs, default_fontsize=6): row = Row(height=self.default_row_height) for args in attrs: if len(args) == 3: attr, fmt, fontsize = args else: attr, fmt = args fontsize = default_fontsize #if attr in ARGON_KEYS: if attr in obj.isotopes: v = obj.isotopes[attr].get_intensity() else: v = getattr(obj, attr) #self.debug('{} {}'.format(attr, v)) row.add_item(value=v, fmt=fmt, fontsize=fontsize) return row
def _make_notes_table(self, positions): data = [ Row(items=[ RowItem('L#'), RowItem('Irradiation'), RowItem('Sample'), RowItem('Hole'), RowItem('Weight'), RowItem('N. Xtals'), RowItem('Note') ]), ] ts = self._new_style() ts.add('LINEBELOW', (0, 0), (-1, 0), 1, colors.black) ts.add('FONTSIZE', (0, 1), (-1, -1), 8) # ts.add('VALIGN', (-3, 1), (-1, -1), 'MIDDLE') idx = 0 prev_id = None for pi in positions: if pi.identifier == prev_id: items = ('', '', '', pi.position, pi.weight, pi.nxtals, pi.note) else: items = (pi.identifier, pi.irradiation_str, pi.sample, pi.position, pi.weight, pi.note) prev_id = pi.identifier data.append(Row(items=[RowItem(ri) for ri in items])) if idx % 2 != 0: ts.add('BACKGROUND', (0, idx + 1), (-1, idx + 1), colors.lightgrey) idx += 1 cw = [mm * x for x in [13, 30, 40, 15, 16, 17, 58]] rh = [mm * 5 for _ in range(len(data))] t = self._new_table(ts, data, colWidths=cw, rowHeights=rh) return t
def _make_row(self, pos, canvas): ln = pos.labnumber sample = '' identifier = '' if ln: if ln.sample: sample = ln.sample.name identifier = ln.identifier r = Row() r.add_item(value=pos.position) r.add_item(value=identifier) r.add_item(value=sample) r.add_item(value='') if sample: item = canvas.scene.get_item(pos.position) item.fill = True return r
def _row_generator(self, samples): attrs = ['name', 'material', 'lithology', 'rock_type', ('lat', '{:0.5f}'), ('lon', '{:0.5f}'), ('elevation', '{}', 'm')] MATERIAL_MAP = {'Groundmass concentrate': 'GMC'} hr = Row() for ai in attrs: if isinstance(ai, tuple): if len(ai) == 2: ai = ai[0] elif len(ai) == 3: ai = '{} ({})'.format(ai[0], ai[2]) if ai == 'lithology': ai = 'composition' h = ' '.join(map(str.capitalize, ai.split('_'))) hr.add_item(value=h) yield hr for si in samples: if si.name.startswith('MB'): r = Row() for ai in attrs: fmt = '{}' if isinstance(ai, tuple): if len(ai) == 2: ai, fmt = ai elif len(ai) == 3: ai, fmt, u = ai v = getattr(si, ai) if ai == 'material': v = MATERIAL_MAP.get(v, v) if ai == 'elevation': v = int(v) if not v: v = '-' else: v = fmt.format(v) r.add_item(value=v) yield r
def _make_footnote_rows(self, data, style): data.append(Row(height=0.1)) def factory(f): r = FootNoteRow(fontsize=6) r.add_item(value=f) return r data.extend([factory(fi) for fi in self._footnotes]) # _get_idxs = lambda x: self._get_idxs(rows, x) _get_se = lambda x: (x[0][0], x[-1][0]) # set for footnot rows footnote_idxs = self._get_idxs(data, FootNoteRow) sidx, eidx = _get_se(footnote_idxs) style.add('VALIGN', (0, sidx), (-1, eidx), 'MIDDLE') for idx, _v in footnote_idxs: style.add('SPAN', (0, idx), (-1, idx))
def _make_level_table(self, irrad, level, c): row = Row() row.add_item(span=-1, value=self._make_table_title(irrad, level), fontsize=18) rows = [row] row = Row() for v in ('', 'Pos.', 'L#', 'Sample', 'Material', 'Project', 'PI', 'Note'): row.add_item(value=self._new_paragraph('<b>{}</b>'.format(v))) rows.append(row) srows = [] spos = sorted(level.positions, key=lambda x: x.position) for i in range(c.scene.nholes): pos = i + 1 item = next((p for p in spos if p.position == pos), None) if not item: row = self._make_blank_row(pos) else: row = self._make_row(item, c) spos.remove(item) srows.append(row) rows.extend(srows) ts = self._new_style(header_line_idx=0, header_line_width=2) ts.add('LINEBELOW', (0, 1), (-1, -1), 1.0, colors.black) cw = self.options.widths() t = self._new_table(ts, rows, colWidths=cw) t.repeatRows = 2 flowables = [t] if self.page_break_between_levels: flowables.append(self._page_break()) else: flowables.append(self._new_spacer(0, 0.25 * inch)) return flowables
def _make_summary_table(self, irrad): ts = self._new_style(header_line_idx=0) header = Row() header.add_item(value='<b>Level</b>') header.add_item(value='<b>Tray</b>') header.add_item(value='<b>Project</b>') def make_row(level): row = Row() row.add_item(value=level.name) row.add_item(value=level.holder) row.add_item(value=', '.join(level.projects)) return row rows = [make_row(li) for li in sorted(irrad.levels, key=lambda x: x.name)] rows.insert(0, header) t = self._new_table(ts, rows, col_widths=[0.5*inch, 1*inch, 5*inch]) return t
def _make_summary_table(self, irrad): ts = self._new_style(header_line_idx=0) header = Row() header.add_item(value='<b>Level</b>') header.add_item(value='<b>Tray</b>') header.add_item(value='<b>Project</b>') def make_row(level): row = Row() row.add_item(value=level.name) row.add_item(value=level.holder) row.add_item(value=', '.join(level.projects)) return row rows = [ make_row(li) for li in sorted(irrad.levels, key=lambda x: x.name) ] rows.insert(0, header) t = self._new_table(ts, rows, col_widths=[0.5 * inch, 1 * inch, 5 * inch]) return t
def _make_footnote_rows(self, data, style): data.append(Row(height=0.1)) height = self.footnote_height blanks = self._get_average_blanks() if blanks: co2_blanks, furnace_blanks = blanks average_co2_blanks = 'Average blanks for CO<sub>2</sub>: ({Ar40:0.3f}, {Ar39:0.3f}, {Ar38:0.3f}, ' \ '{Ar37:0.3f}, {Ar36:0.3f}), ' \ 'x10<sup>-{sens_exp:}</sup> ' \ 'for Ar<super>40</super>, Ar<super>39</super>, ' \ 'Ar<super>38</super>, Ar<super>37</super>, Ar<super>36</super> ' \ 'respectively'.format(**co2_blanks) crow = FooterRow(fontsize=6, height=height) crow.add_item(span=-1, value=self._new_paragraph(average_co2_blanks)) data.append(crow) def factory(f): r = FootNoteRow(fontsize=6, height=height) r.add_item(value=f) return r data.extend([factory(fi) for fi in self._footnotes]) # _get_idxs = lambda x: self._get_idxs(rows, x) _get_se = lambda x: (x[0][0], x[-1][0]) # set for footnot rows footnote_idxs = self._get_idxs(data, FootNoteRow) sidx, eidx = _get_se(footnote_idxs) style.add('VALIGN', (0, sidx), (-1, eidx), 'MIDDLE') for idx, _v in footnote_idxs: style.add('SPAN', (0, idx), (-1, idx)) # =============================================================================== # ============= EOF ============================================= # class TableSpec(HasTraits): # status_width = Int(5) # id_width = Int(20) # power_width = Int(30) # moles_width = Int(50) # # # ar40_width = DefaultInt(value=45) # ar40_error_width = DefaultInt() # ar39_width = DefaultInt(value=45) # ar39_error_width = DefaultInt() # ar38_width = DefaultInt() # ar38_error_width = DefaultInt() # ar37_width = DefaultInt() # ar37_error_width = DefaultInt() # ar36_width = DefaultInt() # ar36_error_width = DefaultInt(value=50) #def _make_meta(self, analyses, style, include_footnotes=False): # ref = analyses[0] # j = ref.j # # #ic = ref.ic_factor # ic = (1, 0) # sample = ref.sample # labnumber = ref.labnumber # material = ref.material # # igsn = '' # # if not isinstance(j, tuple): # j = j.nominal_value, j.std_dev # # if not isinstance(ic, tuple): # ic = ic.nominal_value, ic.std_dev # # line1 = Row(fontsize=8) # line1.add_item(value=NamedParameter('Sample', sample), span=5) # line1.add_item(value=NamedParameter('Lab #', labnumber), span=2) # # js = u'{:0.2E} \u00b1{:0.2E}'.format(j[0], j[1]) # line1.add_item(value=NamedParameter('J', js), span=3) # ics = u'{:0.3f} \u00b1{:0.4f}'.format(ic[0], ic[1]) # if include_footnotes: # foot = self._make_footnote('IC', # 'IC Factor', # 'H1/CDD intercalibration', # '<b>IC</b>', # link_extra=u': {}'.format(ics)) # else: # foot = NamedParameter('IC', ics) # # line1.add_item(value=foot, span=3) # # line2 = Row(fontsize=8) # line2.add_item(value=NamedParameter('Material', material), span=5) # line2.add_item(value=NamedParameter('IGSN', igsn), span=2) # # # self._sample_summary_row1 = line1 # # self._sample_summary_row2 = line2 # title = False # title_row = 0 # sample_row = 0 # if title: # sample_row += 1 # # style.add('LINEBELOW', (0, sample_row), (-1, sample_row), 1.5, colors.black) # # return [line1, line2] #def _make_header(self, style): # sigma = u'\u00b1 1\u03c3' # # sigma = self._plusminus_sigma() # super_ar = lambda x: '{}Ar'.format(Superscript(x)) # # _102fa = '(10{} fA)'.format(Superscript(2)) # _103fa = '(10{} fA)'.format(Superscript(3)) # minus_102fa = '(10{} fA)'.format(Superscript(-2)) # # # blank = self._make_footnote('BLANK', # # 'Blank Type', 'LR= Linear Regression, AVE= Average', # # 'Blank') # # blank = 'Blank Type' # line = [ # ('', ''), # ('N', ''), # (self.extract_label, self.extract_units), # (super_ar(40), ''), # (super_ar(40), _103fa), (sigma, ''), # (super_ar(39), _103fa), (sigma, ''), # (super_ar(38), ''), (sigma, ''), # (super_ar(37), ''), (sigma, ''), # (super_ar(36), ''), (sigma, minus_102fa), # ('%{}*'.format(super_ar(40)), ''), # ('{}*/{}{}'.format(super_ar(40), # super_ar(39), # Subscript('K')), ''), # ('Age', '(Ma)'), (sigma, ''), # ('K/Ca', ''), # (sigma, ''), # # (blank, 'type'), # # (super_ar(40), ''), (sigma, ''), # # (super_ar(39), ''), (sigma, ''), # # (super_ar(38), ''), (sigma, ''), # # (super_ar(37), ''), (sigma, ''), # # (super_ar(36), ''), (sigma, ''), # ] # # name_row, unit_row = zip(*line) # # default_fontsize = 8 # nrow = Row(fontsize=default_fontsize) # for i, ni in enumerate(name_row): # nrow.add_item(value=ni) # # default_fontsize = 7 # urow = Row(fontsize=default_fontsize) # for ni in unit_row: # urow.add_item(value=ni) # # name_row_idx = 2 # unit_row_idx = 3 # # set style for name header # style.add('LINEABOVE', (0, name_row_idx), # (-1, name_row_idx), 1.5, colors.black) # # # set style for unit header # style.add('LINEBELOW', (0, unit_row_idx), # (-1, unit_row_idx), 1.5, colors.black) # # return [ # nrow, # urow # ]
def _make_analysis_row(self, analysis): value = self._value error = self._error attrs = ( ('temp_status', lambda x: '' if x == 0 else 'X'), ('aliquot_step_str', '{}',), ('extract_value', '{}'), ('moles_Ar40', value()), #============================================================== # signals #============================================================== ('Ar40', value(scale=1e3)), ('Ar40', error()), ('Ar39', value(scale=1e3)), ('Ar39', error()), ('Ar38', value()), ('Ar38', error()), ('Ar37', value()), ('Ar37', error()), ('Ar36', value()), ('Ar36', error(scale=1e-2)), #============================================================== # computed #============================================================== ('rad40_percent', value(n=1)), ('F', value(n=5)), ('age', value(n=2)), ('age', error(n=4)), ('kca', value(n=2)), ('kca', error(n=2)), ) default_fontsize = 6 row = self._new_row(analysis, attrs, default_fontsize) battrs = ( #============================================================== # blanks #============================================================== # ('', '{}'), # ('', '{}'), ('', '{}'), ('', '{}'), # ('blank_fit', '{}'), ('Ar40', value(scale=1e3)), ('Ar39', value(scale=1e3)), ('Ar38',), ('Ar37',), ('Ar36', value(scale=1e-2)), # ) blankrow = Row(fontsize=default_fontsize) for args in battrs: efmt = self._error() vfmt = self._value() if len(args) == 2: attr, vfmt = args elif len(args) == 3: attr, vfmt, efmt = args else: attr = args[0] s, e = '', '' if attr: iso = analysis.isotopes.get(attr) if iso: v = iso.blank.uvalue s = vfmt(v) s = self._new_paragraph('<i>{}</i>'.format(s), ) e = efmt(v) e = self._new_paragraph('<i>{}</i>'.format(e)) blankrow.add_item(value=s, ) blankrow.add_item(value=e, ) return row, blankrow
def _make_header(self, style): sigma = u'\u00b1 1\u03c3' # sigma = self._plusminus_sigma() super_ar = lambda x: '{}Ar'.format(Superscript(x)) _102fa = '(10{} fA)'.format(Superscript(2)) _103fa = '(10{} fA)'.format(Superscript(3)) minus_102fa = '(10{} fA)'.format(Superscript(-2)) # blank = self._make_footnote('BLANK', # 'Blank Type', 'LR= Linear Regression, AVE= Average', # 'Blank') # blank = 'Blank Type' line = [ ('', ''), ('N', ''), (self.extract_label, '({})'.format(self.extract_units)), (super_ar(40), ''), (super_ar(40), _103fa), (sigma, ''), (super_ar(39), _103fa), (sigma, ''), (super_ar(38), ''), (sigma, ''), (super_ar(37), ''), (sigma, ''), (super_ar(36), ''), (sigma, minus_102fa), ('Age', '(Ma)'), (sigma, ''), ('%{}*'.format(super_ar(40)), ''), ('{}*/{}{}'.format(super_ar(40), super_ar(39), Subscript('K')), ''), ('K/Ca', ''), (sigma, ''), # (blank, 'type'), # (super_ar(40), ''), (sigma, ''), # (super_ar(39), ''), (sigma, ''), # (super_ar(38), ''), (sigma, ''), # (super_ar(37), ''), (sigma, ''), # (super_ar(36), ''), (sigma, ''), ] name_row, unit_row = zip(*line) default_fontsize = 8 nrow = Row(fontsize=default_fontsize) for i, ni in enumerate(name_row): nrow.add_item(value=ni) default_fontsize = 7 urow = Row(fontsize=default_fontsize) for ni in unit_row: urow.add_item(value=ni) name_row_idx = 2 unit_row_idx = 3 # set style for name header style.add('LINEABOVE', (0, name_row_idx), (-1, name_row_idx), 1.5, colors.black) # set style for unit header style.add('LINEBELOW', (0, unit_row_idx), (-1, unit_row_idx), 1.5, colors.black) return [nrow, urow]
def _make_header(self, style, signal_units='nA'): sigma = u'\u00b1 1\u03c3' super_ar = lambda x: '{}Ar'.format(Superscript(x)) if signal_units == 'nA': mol_scale = '(10{} mol)'.format(Superscript(-16)) unit_scale_40 = '' unit_scale_39 = '' unit_scale_36err = '' else: mol_scale = '(10{} mol)'.format(Superscript(-17)) # = '(10{} {})'.format(Superscript(2), signal_units) unit_scale_40 = '(10{} {})'.format(Superscript(3), signal_units) unit_scale_39 = '(10{} {})'.format(Superscript(3), signal_units) unit_scale_36err = '(10{} {})'.format(Superscript(-2), signal_units) # blank = self._make_footnote('BLANK', # 'Blank Type', 'LR= Linear Regression, AVE= Average', # 'Blank') # blank = 'Blank Type' line = [ ('', ''), ('N', ''), (self.extract_label, '({})'.format(self.extract_units)), (super_ar(40), mol_scale), (super_ar(40), unit_scale_40), (sigma, ''), (super_ar(39), unit_scale_39), (sigma, ''), (super_ar(38), ''), (sigma, ''), (super_ar(37), ''), (sigma, ''), (super_ar(36), ''), (sigma, unit_scale_36err), # ('{}*/{}{}'.format(super_ar(40), # super_ar(39), # Subscript('K')), ''), ('K/Ca', ''), (sigma, ''), ('%{}*'.format(super_ar(40)), ''), ('Age', '(Ma)'), (sigma, ''), # (blank, 'type'), # (super_ar(40), ''), (sigma, ''), # (super_ar(39), ''), (sigma, ''), # (super_ar(38), ''), (sigma, ''), # (super_ar(37), ''), (sigma, ''), # (super_ar(36), ''), (sigma, ''), ] name_row, unit_row = zip(*line) default_fontsize = 7 nrow = Row(fontsize=default_fontsize, height=0.2) for i, ni in enumerate(name_row): nrow.add_item(value=ni) default_fontsize = 6 urow = Row(fontsize=default_fontsize, height=0.2) for ni in unit_row: urow.add_item(value=ni) name_row_idx = 2 unit_row_idx = 3 # set style for name header style.add('LINEABOVE', (0, name_row_idx), (-1, name_row_idx), 1.5, colors.black) # set style for unit header style.add('LINEBELOW', (0, unit_row_idx), (-1, unit_row_idx), 1.5, colors.black) return [nrow, urow]
def _make_meta(self, analyses, style, include_footnotes=False): ref = analyses[0] j = ref.j #ic = ref.ic_factor ic = (1, 0) sample = ref.sample labnumber = ref.labnumber material = ref.material ms = ref.mass_spectrometer igsn = '' if not isinstance(j, tuple): j = j.nominal_value, j.std_dev line1 = Row(fontsize=8) line1.add_item(value=NamedParameter('Sample', sample), span=5) line1.add_item(value=NamedParameter('Lab #', labnumber), span=2) js = u'{:0.2E} \u00b1{:0.2E}'.format(j[0], j[1]) line1.add_item(value=NamedParameter('J', js), span=4) if ms.lower() == 'map': disc = self._get_disc(ref) if include_footnotes: disc = self._make_footnote('Disc.', 'Disc.', '1 amu discrimination', '<b>Disc.</b>', link_extra=u': {}'.format(disc)) else: disc = NamedParameter('Disc.', disc) line1.add_item(value=disc, span=3) else: ics = self._get_ic_factor(ref) if include_footnotes: foot = self._make_footnote('IC', 'IC Factor', 'H1/CDD intercalibration', '<b>IC</b>', link_extra=u': {}'.format(ics)) else: ics = self._get_ic_factor(ref) foot = NamedParameter('IC', ics) line1.add_item(value=foot, span=3) line2 = Row(fontsize=8) line2.add_item(value=NamedParameter('Material', material), span=6) line2.add_item(value=NamedParameter('IGSN', igsn), span=2) line2.add_item(value=NamedParameter('Spectrometer', ms), span=3) # self._sample_summary_row1 = line1 # self._sample_summary_row2 = line2 title = False title_row = 0 sample_row = 0 if title: sample_row += 1 style.add('LINEBELOW', (0, sample_row), (-1, sample_row), 1.5, colors.black) return [line1, line2]
def _make_table(self, irrads): ts = self._new_style(header_line_idx=0, header_line_width=2) ts.add('LINEBELOW', (0, 1), (-1, -1), 1.0, colors.black) header = Row() header.add_item(value='<b>Irradiation</b>') header.add_item(value='<b>Date</b>') header.add_item(value='<b>Duration (hr)</b>') header.add_item(value='<b>Reactor</b>') rows = [header] for i in irrads: r = Row() r.add_item(value=i.name) r.add_item(value=i.date) r.add_item(value='{:0.1f}'.format(i.duration)) r.add_item(value=i.reactor) rows.append(r) t = self._new_table(ts, rows) return t
def _make_summary_rows(self, agroup, idx, style): span = 14 wtd_mean_row = Row(fontsize=7, height=0.2) wtd_mean_row.add_item(value='<b>Weighted Mean Age</b>', span=span) #wtd_mean_row.add_blank_item(n=10) wa = agroup.weighted_age s = u'{} \u00b1{}'.format(self._value()(wa), self._error()(wa)) wtd_mean_row.add_item(value=s, span=-1) inta = agroup.integrated_age int_row = Row(fontsize=7, height=0.2) int_row.add_item(value='<b>Integrated</b>', span=span) s = u'{} \u00b1{}'.format(self._value()(inta), self._error()(inta)) int_row.add_item(value=s, span=-1) #int_row.add_item(value=self._value()(inta)) #int_row.add_item(value=u' \u00b1{}'.format(self._error()(inta))) plat_row = Row(fontsize=7, height=0.2) plat_row.add_item(value='<b>Plateau</b>', span=span - 2) s = '' pa = agroup.plateau_age plat_row.add_item(value='<b>Steps</b>') plat_row.add_item(value=agroup.plateau_steps_str) if agroup.plateau_steps: s = u'{} \u00b1{}'.format(self._value()(pa), self._error()(pa)) #pv=self._value()(pa) #pe=u' \u00b1{}'.format(self._error()(pa)) #wtd_mean_row.add_blank_item(n=10) plat_row.add_item(value=s, span=-1) #plat_row.add_item(value=pv) #plat_row.add_item(value=pe) iso_row = Row(fontsize=7, height=0.2) iso_row.add_item(value='<b>Isochron</b>', span=span) isoa = agroup.isochron_age s = u'{} \u00b1{}'.format(self._value()(isoa), self._error()(isoa)) iso_row.add_item(value=s, span=-1) #iso_row.add_item(value=self._value()(wa)) #iso_row.add_item(value=u' \u00b1{}'.format(self._error()(wa))) return [wtd_mean_row, int_row, plat_row, iso_row]
def _make_interpreted_age_row(self, interpreted_age): age_nsigma = self.options.age_nsigma kca_nsigma = self.options.kca_nsigma #age in Ma age = interpreted_age.age age_err = interpreted_age.age_err if self.options.age_units == 'ka': age *= 1000 age_err *= 1000 age_sig_figs = self.options.age_sig_figs kca_sig_figs = self.options.kca_sig_figs row = Row(height=self.options.default_row_height) row.add_item(value=interpreted_age.sample) row.add_item(value=interpreted_age.identifier) row.add_item(value=interpreted_age.irradiation) row.add_item(value=self._short_material_name(interpreted_age.material)) row.add_item(value=interpreted_age.lithology) row.add_item(value=interpreted_age.age_kind) row.add_item(value=interpreted_age.nanalyses) row.add_item(value=floatfmt(interpreted_age.mswd, n=1)) # row.add_item(value=self._value(n=1)(interpreted_age.weighted_kca)) # row.add_item(value=self._error(n=1)(interpreted_age.weighted_kca)) # row.add_item(value=self._value(n=4)(interpreted_age.weighted_age)) # row.add_item(value=self._error(n=4)(interpreted_age.weighted_age)) row.add_item(value=floatfmt(interpreted_age.kca, n=kca_sig_figs)) row.add_item(value=floatfmt(interpreted_age.kca_err * kca_nsigma, n=kca_sig_figs)) row.add_item(value=floatfmt(age, n=age_sig_figs)) row.add_item(value=floatfmt(age_err * age_nsigma, n=age_sig_figs)) return row
def _make_header(self, style): PMS = u"\u00b1 1\u03c3" pr = Row() pr.add_blank_item(6) pr.add_item(value="Preferred Age", span=-1) # style.add('ALIGN', (0, 3), (0, -1), 'CENTER') self._new_line(style, 0, weight=0.75, start=4, end=-1) r = Row() r.add_item(value="Sample") r.add_item(value="L#") r.add_item(value="Irrad") r.add_item(value="Material") r.add_item(value="Type") r.add_item(value="N") r.add_item(value="MSWD") r.add_item(value="K/Ca") r.add_item(value=PMS) r.add_item(value="Age") r.add_item(value=PMS) return (pr, r)
def _make_meta(self, analyses, style, include_footnotes=False): ref = analyses[0] j = ref.j # ic = ref.ic_factor ic = (1, 0) sample = ref.sample labnumber = ref.labnumber material = ref.material igsn = "" if not isinstance(j, tuple): j = j.nominal_value, j.std_dev line1 = Row(fontsize=8) line1.add_item(value=NamedParameter("Sample", sample), span=5) line1.add_item(value=NamedParameter("Lab #", labnumber), span=2) js = u"{:0.2E} \u00b1{:0.2E}".format(j[0], j[1]) line1.add_item(value=NamedParameter("J", js), span=4) ics = self._get_ic_factor(ref) if include_footnotes: foot = self._make_footnote( "IC", "IC Factor", "H1/CDD intercalibration", "<b>IC</b>", link_extra=u": {}".format(ics) ) else: ics = self._get_ic_factor(ref) foot = NamedParameter("IC", ics) line1.add_item(value=foot, span=3) line2 = Row(fontsize=8) line2.add_item(value=NamedParameter("Material", material), span=5) line2.add_item(value=NamedParameter("IGSN", igsn), span=2) # self._sample_summary_row1 = line1 # self._sample_summary_row2 = line2 title = False title_row = 0 sample_row = 0 if title: sample_row += 1 style.add("LINEBELOW", (0, sample_row), (-1, sample_row), 1.5, colors.black) return [line1, line2]
def _make_interpreted_age_row(self, interpreted_age): row = Row() row.add_item(value=interpreted_age.sample) row.add_item(value=interpreted_age.identifier) row.add_item(value=interpreted_age.irradiation) row.add_item(value=self._short_material_name(interpreted_age.material)) row.add_item(value=interpreted_age.age_kind) row.add_item(value=interpreted_age.nanalyses) row.add_item(value=floatfmt(interpreted_age.mswd, n=1)) # row.add_item(value=self._value(n=1)(interpreted_age.weighted_kca)) # row.add_item(value=self._error(n=1)(interpreted_age.weighted_kca)) # row.add_item(value=self._value(n=4)(interpreted_age.weighted_age)) # row.add_item(value=self._error(n=4)(interpreted_age.weighted_age)) row.add_item(value=floatfmt(interpreted_age.wtd_kca, n=4)) row.add_item(value=floatfmt(interpreted_age.wtd_kca_err, n=4)) row.add_item(value=floatfmt(interpreted_age.age, n=4)) row.add_item(value=floatfmt(interpreted_age.age_err, n=4)) return row
def _make_row(self, pos, canvas): r = Row() sample = pos.sample project, pi, material = '', '', '' if sample: if sample.material: material = sample.material.name[:15] project = sample.project.name pi = sample.project.principal_investigator sample = sample.name if sample == 'FC-2': project, pi, material = '', '', '' r.add_item(value='[ ]') r.add_item(value=pos.position) r.add_item(value=pos.identifier or '') r.add_item(value=sample or '') r.add_item(value=material) r.add_item(value=project) r.add_item(value=pi) r.add_item(value='') if sample: item = canvas.scene.get_item(pos.position) item.fill = True return r
def _make_summary_rows(self, agroup, idx, style): span = 14 height = 0.12 fontsize = 6 wtd_mean_row = Row(fontsize=fontsize, height=height) wtd_mean_row.add_item(value='<b>Weighted Mean Age</b>', span=span, include_width_calc=False) #wtd_mean_row.add_blank_item(n=10) wa = agroup.weighted_age s = u'{} \u00b1{}'.format(self._value(n=2)(wa), self._error(n=2)(wa)) wtd_mean_row.add_item(value=s, span=-1, include_width_calc=False) inta = agroup.integrated_age int_row = Row(fontsize=fontsize, height=height) int_row.add_item(value='<b>Integrated</b>', span=span, include_width_calc=False) s = u'{} \u00b1{}'.format( self._value(n=2)(inta), self._error(n=2)(inta)) int_row.add_item(value=s, span=-1, include_width_calc=False) #int_row.add_item(value=self._value()(inta)) #int_row.add_item(value=u' \u00b1{}'.format(self._error()(inta))) plat_row = Row(fontsize=fontsize, height=height) plat_row.add_item(value='<b>Plateau</b>', span=span - 2, include_width_calc=False) s = '' pa = agroup.plateau_age if agroup.plateau_steps: plat_row.add_item(value='<b>Steps</b>') plat_row.add_item(value=agroup.plateau_steps_str) s = u'{} \u00b1{}'.format( self._value(n=2)(pa), self._error(n=2)(pa)) plat_row.add_item(value=s, span=-1, include_width_calc=False) rows = [wtd_mean_row, int_row, plat_row] include_isochron = False if include_isochron: iso_row = Row(fontsize=fontsize, height=height) iso_row.add_item(value='<b>Isochron</b>', span=span, include_width_calc=False) isoa = agroup.isochron_age s = u'{} \u00b1{}'.format( self._value(n=2)(isoa), self._error(n=2)(isoa)) iso_row.add_item(value=s, span=-1, include_width_calc=False) rows.append(iso_row) return rows
def _make_summary_rows(self, agroup, idx, style): span = 14 height = 0.12 fontsize = 6 wtd_mean_row = Row(fontsize=fontsize, height=height) wtd_mean_row.add_item(value='<b>Weighted Mean Age</b>', span=span, include_width_calc=False) #wtd_mean_row.add_blank_item(n=10) wa = agroup.weighted_age s = u'{} \u00b1{}'.format(self._value(n=2)(wa), self._error(n=2)(wa)) wtd_mean_row.add_item(value=s, span=-1, include_width_calc=False) inta = agroup.integrated_age int_row = Row(fontsize=fontsize, height=height) int_row.add_item(value='<b>Integrated</b>', span=span, include_width_calc=False) s = u'{} \u00b1{}'.format(self._value(n=2)(inta), self._error(n=2)(inta)) int_row.add_item(value=s, span=-1, include_width_calc=False) #int_row.add_item(value=self._value()(inta)) #int_row.add_item(value=u' \u00b1{}'.format(self._error()(inta))) plat_row = Row(fontsize=fontsize, height=height) plat_row.add_item(value='<b>Plateau</b>', span=span - 2, include_width_calc=False) s = '' pa = agroup.plateau_age if agroup.plateau_steps: plat_row.add_item(value='<b>Steps</b>') plat_row.add_item(value=agroup.plateau_steps_str) s = u'{} \u00b1{}'.format(self._value(n=2)(pa), self._error(n=2)(pa)) plat_row.add_item(value=s, span=-1, include_width_calc=False) rows = [wtd_mean_row, int_row, plat_row] include_isochron = False if include_isochron: iso_row = Row(fontsize=fontsize, height=height) iso_row.add_item(value='<b>Isochron</b>', span=span, include_width_calc=False) isoa = agroup.isochron_age s = u'{} \u00b1{}'.format(self._value(n=2)(isoa), self._error(n=2)(isoa)) iso_row.add_item(value=s, span=-1, include_width_calc=False) rows.append(iso_row) return rows
def _make_row(self, pos, canvas): r = Row() sample = pos.sample project, pi, material = '', '', '' if sample: if sample.material: material = sample.material.name material = MATERIAL_MAP.get(material, material) material = material[:15] project = sample.project.name pi = sample.project.principal_investigator.name sample = sample.name if sample == DEFAULT_MONITOR_NAME: project, pi, material = '', '', '' r.add_item(value='[ ]') r.add_item(value=pos.position) r.add_item(value=pos.identifier or '') r.add_item(value=sample or '') r.add_item(value=material, fontsize=8) r.add_item(value=project, fontsize=8) r.add_item(value=pi, fontsize=8) r.add_item(value='') if sample: item = canvas.scene.get_item(pos.position) item.fill = True return r
def _make_header(self, style): PMS_kca = u'\u00b1 {}\u03c3'.format(self.options.kca_nsigma) PMS_age = u'\u00b1 {}\u03c3'.format(self.options.age_nsigma) pr = Row(height=self.options.default_header_height) pr.add_blank_item(7) pr.add_item(value='Preferred Age', span=-1) # style.add('ALIGN', (0, 3), (0, -1), 'CENTER') self._new_line(style, 0, weight=0.75, start=5, end=-1) r = Row(height=self.options.default_header_height) r.add_item(value='Sample') r.add_item(value='L#') r.add_item(value='Irrad') r.add_item(value='Material') r.add_item(value='Lithology') r.add_item(value='Type') r.add_item(value='N') r.add_item(value='MSWD') r.add_item(value='K/Ca') r.add_item(value=PMS_kca) r.add_item(value='Age({})'.format(self.options.age_units)) r.add_item(value=PMS_age) return (pr, r,)
def _make_header(self, style): sigma = u"\u00b1 1\u03c3" # sigma = self._plusminus_sigma() super_ar = lambda x: "{}Ar".format(Superscript(x)) _102fa = "(10{} fA)".format(Superscript(2)) _103fa = "(10{} fA)".format(Superscript(3)) minus_102fa = "(10{} fA)".format(Superscript(-2)) # blank = self._make_footnote('BLANK', # 'Blank Type', 'LR= Linear Regression, AVE= Average', # 'Blank') # blank = 'Blank Type' line = [ ("", ""), ("N", ""), (self.extract_label, "({})".format(self.extract_units)), (super_ar(40), ""), (super_ar(40), _103fa), (sigma, ""), (super_ar(39), _103fa), (sigma, ""), (super_ar(38), ""), (sigma, ""), (super_ar(37), ""), (sigma, ""), (super_ar(36), ""), (sigma, minus_102fa), ("Age", "(Ma)"), (sigma, ""), ("%{}*".format(super_ar(40)), ""), ("{}*/{}{}".format(super_ar(40), super_ar(39), Subscript("K")), ""), ("K/Ca", ""), (sigma, ""), # (blank, 'type'), # (super_ar(40), ''), (sigma, ''), # (super_ar(39), ''), (sigma, ''), # (super_ar(38), ''), (sigma, ''), # (super_ar(37), ''), (sigma, ''), # (super_ar(36), ''), (sigma, ''), ] name_row, unit_row = zip(*line) default_fontsize = 8 nrow = Row(fontsize=default_fontsize) for i, ni in enumerate(name_row): nrow.add_item(value=ni) default_fontsize = 7 urow = Row(fontsize=default_fontsize) for ni in unit_row: urow.add_item(value=ni) name_row_idx = 2 unit_row_idx = 3 # set style for name header style.add("LINEABOVE", (0, name_row_idx), (-1, name_row_idx), 1.5, colors.black) # set style for unit header style.add("LINEBELOW", (0, unit_row_idx), (-1, unit_row_idx), 1.5, colors.black) return [nrow, urow]