Skip to content
Snippets Groups Projects

Make constant tables in both markdown & latex format

Merged Thomas Kluyver requested to merge feat/multi-table-format into master
2 unresolved threads

Description

This is an alternative to !1034 (closed). Converting markdown tables to rst (to latex to pdf) is going wrong, so we want a workaround.

This uses Jupyter's machinery to produce both formats simultaneously, and store both in the notebook file. In the live notebook, markdown has higher priority (being based on HTML), so the Latex output is hidden. When converting to rst for the PDF report, the Latex format is preferred.

I've drafted this with the calcat_interface2 module, but we could extend it to anywhere we're generating tables.

How Has This Been Tested?

For now, just in a small test notebook. End to end tests still to be done.

Relevant Documents (optional)

image

Output snippet from nbconvert --to rst

.. code:: ipython3

    agipd_cd.summary_table()




.. math::

    \begin{tabular}{rll}
    \hline
       Modules & Offset                                                                                       & SlopesFF                                                                                     \\
    \hline
             0 & \href{https://in.xfel.eu/calibration/calibration_constant_versions/141880}{2022-09-02 07:42} & \href{https://in.xfel.eu/calibration/calibration_constant_versions/118111}{2022-02-05 13:07} \\
             1 & \href{https://in.xfel.eu/calibration/calibration_constant_versions/141821}{2022-09-02 07:42} & \href{https://in.xfel.eu/calibration/calibration_constant_versions/118138}{2022-02-05 13:07} \\

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the code style of this project.

Reviewers

@ahmedk @schmidtp

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
731 Columns are calibration types, rows are modules.
732 If there are >4 calibrations, the table will be split up into several
733 pieces with up to 4 calibrations in each.
734
735 Args:
736 module_naming (str): modnum, aggregator or qm, to change how the
737 modules are labelled in the table. Defaults to modnum.
738 """
739 from tabulate import tabulate
740
741 if module_naming == "aggregator":
742 modules = self.aggregator_names
743 elif module_naming == "modnum":
744 modules = self.module_nums
745 elif module_naming == "qm":
746 modules = self.qm_names
  • Unrelated to this MR, I think it might be useful to use enums for this as its usage is expanding.

  • For APIs we're exposing to scientists, I prefer to do options like this as strings rather than an enum. I think enums are good for experienced software developers, but they're an extra complication to think about if you're not used to them, and Python has a lot of cases already where we use strings to pick from a finite set of choices.

    We could pass a string in and use an enum to validate it internally. But I'm not sure that's worth it.

  • Make sense, so my focus was more on avoiding string duplication in code. I guess a simple way to avoid this is to define Global constant for them that we check against. And we can leave of course at least the default string values in the method definitions if this will have a better usability.

  • Please register or sign in to reply
  • Karim Ahmed
  • TIL, clever! LGTM

  • added 1 commit

    • 61da3234 - Sync DisplayTables implementation back to calcat_interface2

    Compare with previous version

  • Thomas Kluyver mentioned in commit 80f0e8a2

    mentioned in commit 80f0e8a2

  • Thanks for the review :slight_smile:

  • Philipp Schmidt changed milestone to %3.15.0

    changed milestone to %3.15.0

  • Thomas Kluyver mentioned in merge request !968 (merged)

    mentioned in merge request !968 (merged)

  • Please register or sign in to reply
    Loading