Compare commits
6 Commits
08659faea9
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 1d2451ff42 | |||
| 7c851c1d4a | |||
| 4b4cf9aae8 | |||
| 1b9848d14f | |||
| da6bc2a4f7 | |||
| 5e636e082c |
10
README.md
10
README.md
@@ -86,12 +86,14 @@ material codes); copy the template to create your own:
|
||||
cp samples.example.txt samples.txt
|
||||
```
|
||||
|
||||
Lines starting with `#` are ignored. Material names can be any codes.
|
||||
Append ` > REF` to measure that sample's `dE00` against another sample; a
|
||||
bare name (no `>`) is itself a **reference**. Mix samples use the pattern
|
||||
`NAME_A+NAME_B[w1 to w2 mix]`, e.g.:
|
||||
Lines starting with `#` are comments. Lines starting with `note:` are
|
||||
metadata shown above the table in `averaged.html` (not samples). Material
|
||||
names can be any codes. Append ` > REF` to measure that sample's `dE00`
|
||||
against another sample; a bare name (no `>`) is itself a **reference**.
|
||||
Mix samples use the pattern `NAME_A+NAME_B[w1 to w2 mix]`, e.g.:
|
||||
|
||||
```text
|
||||
note: Glaze: CPO1192
|
||||
INK_A
|
||||
INK_B > INK_A
|
||||
INK_A+INK_B[75 to 15 mix] > INK_A
|
||||
|
||||
@@ -133,8 +133,8 @@ scan_samples() {
|
||||
SAMPLES=()
|
||||
while IFS= read -r line; do
|
||||
SAMPLES+=("$line")
|
||||
done < <(grep -v '^#' "$SAMPLES_FILE" | grep -v '^[[:space:]]*$' \
|
||||
| sed -E 's/[[:space:]]*>.*$//')
|
||||
done < <(grep -v '^#' "$SAMPLES_FILE" | grep -iv '^[[:space:]]*note:' \
|
||||
| grep -v '^[[:space:]]*$' | sed -E 's/[[:space:]]*>.*$//')
|
||||
local count="${#SAMPLES[@]}"
|
||||
[[ "$count" -gt 0 ]] || fail "No sample names found in $SAMPLES_FILE"
|
||||
|
||||
@@ -190,7 +190,8 @@ update_average() {
|
||||
info "Step 5/5: Updating $AVERAGED_CSV"
|
||||
|
||||
local expected
|
||||
expected="$(grep -v '^#' "$SAMPLES_FILE" | grep -cv '^[[:space:]]*$' || true)"
|
||||
expected="$(grep -v '^#' "$SAMPLES_FILE" | grep -iv '^[[:space:]]*note:' \
|
||||
| grep -cv '^[[:space:]]*$' || true)"
|
||||
|
||||
# Collect scan CSVs (timestamped files only) with the expected reading count
|
||||
local -a scans=()
|
||||
|
||||
@@ -20,18 +20,22 @@ WHITE_POINT = (96.422, 100.0, 82.521)
|
||||
# (no ">") are references themselves. The " > REF" suffix is stripped to
|
||||
# recover the real sample name used as sample_id.
|
||||
REF_SEP = ">"
|
||||
NOTE_PREFIX = "# note:"
|
||||
NOTE_PREFIX = "note:"
|
||||
|
||||
|
||||
def _is_note_line(line: str) -> bool:
|
||||
return line.strip().lower().startswith(NOTE_PREFIX)
|
||||
|
||||
|
||||
def load_notes(path: Path) -> list[str]:
|
||||
"""Read display notes from '# note: ...' comment lines in the samples file."""
|
||||
"""Read display notes from 'note: ...' lines in the samples file."""
|
||||
if not path.exists():
|
||||
return []
|
||||
notes = []
|
||||
for line in path.read_text(encoding="utf-8").splitlines():
|
||||
stripped = line.strip()
|
||||
if stripped.lower().startswith(NOTE_PREFIX):
|
||||
notes.append(stripped[len(NOTE_PREFIX):].strip())
|
||||
notes.append(stripped[len(NOTE_PREFIX) :].strip())
|
||||
return notes
|
||||
|
||||
|
||||
@@ -48,7 +52,9 @@ def _sample_lines(path: Path) -> list[str]:
|
||||
return [
|
||||
line.strip()
|
||||
for line in path.read_text(encoding="utf-8").splitlines()
|
||||
if line.strip() and not line.strip().startswith("#")
|
||||
if line.strip()
|
||||
and not line.strip().startswith("#")
|
||||
and not _is_note_line(line)
|
||||
]
|
||||
|
||||
|
||||
@@ -117,10 +123,11 @@ def de2000(lab1, lab2) -> float:
|
||||
def add_delta_e(rows: list[dict], references: dict[str, str]) -> bool:
|
||||
"""Add a CIEDE2000 column to each averaged row vs that sample's reference.
|
||||
|
||||
Samples absent from `references` are references themselves (dE00 = 0).
|
||||
Returns True if the column was written (only when at least one sample
|
||||
names a reference). Never raises so the scan pipeline can continue even
|
||||
when a named reference is missing.
|
||||
Samples absent from `references` are references themselves (dE00 left
|
||||
empty — they have no external comparison). Returns True if the column
|
||||
was written (only when at least one sample names a reference). Never
|
||||
raises so the scan pipeline can continue even when a named reference
|
||||
is missing.
|
||||
"""
|
||||
if not rows or not references:
|
||||
return False
|
||||
@@ -131,7 +138,7 @@ def add_delta_e(rows: list[dict], references: dict[str, str]) -> bool:
|
||||
sid = row["sample_id"]
|
||||
ref_id = references.get(sid)
|
||||
if ref_id is None:
|
||||
row[DE_COL] = 0.0
|
||||
row[DE_COL] = ""
|
||||
wrote = True
|
||||
continue
|
||||
ref_row = by_id.get(ref_id)
|
||||
@@ -221,10 +228,10 @@ def write_html(
|
||||
if has_de:
|
||||
raw = r.get(DE_COL, "")
|
||||
if raw == "" or raw is None:
|
||||
cells.append('<td class="de">—</td>')
|
||||
cells.append("<td>—</td>")
|
||||
else:
|
||||
d = float(raw)
|
||||
de_cls = "de win" if is_ref else ("de bad" if d >= 3.5 else "de")
|
||||
de_cls = "de bad" if d >= 3.5 else "de"
|
||||
cells.append(
|
||||
f'<td class="{de_cls}" title="{esc(de_bucket(d))}">{d:.2f}</td>'
|
||||
)
|
||||
@@ -232,7 +239,7 @@ def write_html(
|
||||
|
||||
ref_note = (
|
||||
"ΔE00 is CIEDE2000 against each sample's named reference "
|
||||
"(<code>NAME > REF</code> in samples.txt); tagged "
|
||||
"; tagged "
|
||||
"<b>reference</b> rows have no external reference. Lower is a closer match."
|
||||
if has_de else
|
||||
"No Delta-E column (add <code>NAME > REF</code> lines in samples.txt)."
|
||||
@@ -252,7 +259,7 @@ def write_html(
|
||||
<title>Averaged color measurements</title>
|
||||
<style>
|
||||
:root {{ --text:#1f2328; --text2:#57606a; --text3:#8b949e; --stroke:#d0d7de;
|
||||
--bg:#fff; --fill:#f6f8fa; --good:#1a7f37; --bad:#bc4c00; }}
|
||||
--bg:#fff; --fill:#f6f8fa; --bad:#bc4c00; }}
|
||||
* {{ box-sizing:border-box; }}
|
||||
body {{ margin:0; padding:32px 24px 48px; background:var(--bg); color:var(--text);
|
||||
font:14px/1.5 -apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif; }}
|
||||
@@ -278,7 +285,6 @@ def write_html(
|
||||
.tag {{ font-size:11px; color:var(--text3); border:1px solid var(--stroke);
|
||||
border-radius:4px; padding:0 5px; margin-left:6px; }}
|
||||
.de {{ font-weight:600; }}
|
||||
.win {{ color:var(--good); }}
|
||||
.bad {{ color:var(--bad); }}
|
||||
.faint {{ color:var(--text3); font-size:12px; margin-top:14px; }}
|
||||
@media print {{ body {{ padding:0; }} }}
|
||||
|
||||
@@ -45,7 +45,8 @@ esac
|
||||
|
||||
SAMPLE_COUNT=0
|
||||
if [[ -f samples.txt ]]; then
|
||||
SAMPLE_COUNT="$(grep -cv '^#\|^$' samples.txt || true)"
|
||||
SAMPLE_COUNT="$(grep -v '^#' samples.txt | grep -iv '^[[:space:]]*note:' \
|
||||
| grep -cv '^[[:space:]]*$' || true)"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
@@ -18,13 +18,15 @@ RESET = "\033[0m"
|
||||
|
||||
def load_sample_names(path: Path) -> list[str]:
|
||||
# Optional "NAME > REF": keep only the sample name (before ">").
|
||||
# Skip "#" comments and "note: ..." metadata lines.
|
||||
names = []
|
||||
for line in path.read_text(encoding="utf-8").splitlines():
|
||||
line = line.strip()
|
||||
if line and not line.startswith("#"):
|
||||
if ">" in line:
|
||||
line = line.split(">", 1)[0].strip()
|
||||
names.append(line)
|
||||
if not line or line.startswith("#") or line.lower().startswith("note:"):
|
||||
continue
|
||||
if ">" in line:
|
||||
line = line.split(">", 1)[0].strip()
|
||||
names.append(line)
|
||||
return names
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,8 @@ if [[ -z "$LATEST" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if grep -qv '^#' samples.txt 2>/dev/null && grep -q '[^[:space:]]' samples.txt; then
|
||||
if grep -v '^#' samples.txt 2>/dev/null | grep -iv '^[[:space:]]*note:' \
|
||||
| grep -q '[^[:space:]]'; then
|
||||
./tsv-to-csv.py "$LATEST" -s samples.txt
|
||||
else
|
||||
./tsv-to-csv.py "$LATEST"
|
||||
@@ -24,7 +25,8 @@ fi
|
||||
|
||||
CSV="${LATEST%.tsv}.csv"
|
||||
READING_COUNT="$(($(wc -l < "$LATEST") - 1))"
|
||||
EXPECTED="$(grep -cv '^#\|^$' samples.txt 2>/dev/null || echo 0)"
|
||||
EXPECTED="$(grep -v '^#' samples.txt 2>/dev/null | grep -iv '^[[:space:]]*note:' \
|
||||
| grep -cv '^[[:space:]]*$' || echo 0)"
|
||||
|
||||
echo ""
|
||||
echo "============================================"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# One sample name per line, in measurement order.
|
||||
# Lines starting with # are ignored.
|
||||
# Lines starting with # are comments (ignored). Lines starting with "note:"
|
||||
# are HTML report metadata (not samples).
|
||||
#
|
||||
# Name a Delta-E reference with "NAME > REF": that sample's dE00 (CIEDE2000
|
||||
# in averaged.csv) is measured against REF. A bare name (no ">") is itself a
|
||||
@@ -7,9 +8,11 @@
|
||||
# INK_A
|
||||
# INK_B > INK_A
|
||||
#
|
||||
# Optional notes for averaged.html (one per line, shown above the results table):
|
||||
# note: Glaze: CPO1192
|
||||
# note: Firing Temperature: 1150 C
|
||||
# Optional notes for averaged.html (one per line, NOT starting with #):
|
||||
# note: Print Surface: A4 Paper
|
||||
# note: Temperature: 30 C
|
||||
#
|
||||
# Lines starting with "note:" are metadata for the HTML report, not samples.
|
||||
#
|
||||
# Single materials: just the material name/code, e.g.
|
||||
# INK_A
|
||||
@@ -20,6 +23,8 @@
|
||||
#
|
||||
# Copy this file to samples.txt and replace with your own materials:
|
||||
# cp samples.example.txt samples.txt
|
||||
note: Print Surface: A4 Paper
|
||||
note: Temperature: 30 ℃
|
||||
INK_A
|
||||
INK_B > INK_A
|
||||
INK_C > INK_A
|
||||
|
||||
@@ -9,13 +9,15 @@ from pathlib import Path
|
||||
|
||||
def load_sample_names(path: Path) -> list[str]:
|
||||
# Optional "NAME > REF": keep only the sample name (before ">").
|
||||
# Skip "#" comments and "note: ..." metadata lines.
|
||||
names = []
|
||||
for line in path.read_text(encoding="utf-8").splitlines():
|
||||
line = line.strip()
|
||||
if line and not line.startswith("#"):
|
||||
if ">" in line:
|
||||
line = line.split(">", 1)[0].strip()
|
||||
names.append(line)
|
||||
if not line or line.startswith("#") or line.lower().startswith("note:"):
|
||||
continue
|
||||
if ">" in line:
|
||||
line = line.split(">", 1)[0].strip()
|
||||
names.append(line)
|
||||
return names
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user