Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pycalibration
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
calibration
pycalibration
Commits
0c3108a8
Commit
0c3108a8
authored
7 months ago
by
Thomas Kluyver
Browse files
Options
Downloads
Patches
Plain Diff
Use DisplayTables in calcat_interface
parent
34077af6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1040
Make constant tables in both markdown & latex format
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/cal_tools/calcat_interface.py
+9
-13
9 additions, 13 deletions
src/cal_tools/calcat_interface.py
src/cal_tools/tools.py
+52
-0
52 additions, 0 deletions
src/cal_tools/tools.py
with
61 additions
and
13 deletions
src/cal_tools/calcat_interface.py
+
9
−
13
View file @
0c3108a8
...
...
@@ -16,7 +16,7 @@ from calibration_client.modules import (
PhysicalDetectorUnit
,
)
from
cal_tools.tools
import
module_index_to_qm
from
cal_tools.tools
import
module_index_to_qm
,
DisplayTables
__all__
=
[
"
CalCatError
"
,
...
...
@@ -754,8 +754,7 @@ class CalibrationData:
Defaults to
"
https://in.xfel.eu/calibration/calibration_constant_versions/
"
.
"""
from
IPython.display
import
Markdown
,
display
from
tabulate
import
tabulate
from
IPython.display
import
display
if
metadata
is
None
:
metadata
=
self
.
metadata
()
...
...
@@ -768,6 +767,8 @@ class CalibrationData:
cal_groups
=
[
list
(
calibrations
)[
x
:
x
+
4
]
for
x
in
range
(
0
,
len
(
calibrations
),
4
)]
tables
=
[]
# Loop over groups of calibrations.
for
cal_group
in
cal_groups
:
table
=
[[
"
Modules
"
]
+
cal_group
]
...
...
@@ -786,22 +787,17 @@ class CalibrationData:
c_mdata
[
"
begin_validity_at
"
]).
strftime
(
"
%Y-%m-%d %H:%M
"
)
mod_consts
.
append
(
f
"
[
{
c_time
}
](
{
ccvs_url
}
/
{
c_mdata
[
'
ccv_id
'
]
}
)
"
)
(
c_time
,
f
"
{
ccvs_url
}
/
{
c_mdata
[
'
ccv_id
'
]
}
"
)
)
else
:
# Constant is not available for this module.
mod_consts
.
append
(
"
___
"
)
table
.
append
([
mod
]
+
mod_consts
)
display
(
Markdown
(
tabulate
(
table
,
tablefmt
=
"
pipe
"
,
headers
=
"
firstrow
"
,
)
)
)
tables
.
append
(
table
)
display
(
DisplayTables
(
tables
))
def
_build_condition
(
self
,
parameters
):
cond
=
dict
()
...
...
This diff is collapsed.
Click to expand it.
src/cal_tools/tools.py
+
52
−
0
View file @
0c3108a8
...
...
@@ -1065,3 +1065,55 @@ def raw_data_location_string(proposal: str, runs: List[int]):
"
a preceding
'
p
'
. Example:
'
p900203
'"
)
return
f
"
proposal:
{
proposal
}
runs:
{
'
'
.
join
(
map
(
str
,
runs
))
}
"
class
DisplayTables
:
def
__init__
(
self
,
tables
):
# list (tables) of lists (rows) of lists (cells). A cell may be str,
# or a (text, url) tuple to make a link.
self
.
tables
=
tables
@staticmethod
def
_build_table
(
table
,
fmt_link
):
res
=
[]
for
row
in
table
:
prepd_row
=
[]
for
cell
in
row
:
if
isinstance
(
cell
,
tuple
):
text
,
url
=
cell
else
:
text
=
cell
url
=
None
if
url
is
None
:
prepd_row
.
append
(
text
)
else
:
prepd_row
.
append
(
fmt_link
(
text
,
url
))
res
.
append
(
prepd_row
)
return
res
def
_repr_markdown_
(
self
):
from
tabulate
import
tabulate
def
fmt_link
(
text
,
url
):
return
f
"
[
{
text
}
](
{
url
}
)
"
prepd_tables
=
[
self
.
_build_table
(
table
,
fmt_link
)
for
table
in
self
.
tables
]
return
'
\n\n
'
.
join
(
tabulate
(
t
,
tablefmt
=
"
pipe
"
,
headers
=
"
firstrow
"
)
for
t
in
prepd_tables
)
def
_repr_latex_
(
self
):
from
tabulate
import
tabulate
def
fmt_link
(
text
,
url
):
return
r
'
\href{%s}{%s}
'
%
(
url
,
text
)
prepd_tables
=
[
self
.
_build_table
(
table
,
fmt_link
)
for
table
in
self
.
tables
]
return
'
\n\n
'
.
join
(
tabulate
(
t
,
tablefmt
=
"
latex_raw
"
,
headers
=
"
firstrow
"
)
for
t
in
prepd_tables
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment