Compare commits
3 Commits
dea851dedc
...
3887505e40
| Author | SHA1 | Date | |
|---|---|---|---|
| 3887505e40 | |||
| d3f6f53955 | |||
| 789a205904 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -5,6 +5,9 @@ averaged.csv
|
||||
formula.csv
|
||||
archive/
|
||||
|
||||
# Your actual material list (copy from samples.example.txt)
|
||||
samples.txt
|
||||
|
||||
# Report-specific artifacts
|
||||
ICJ108_*
|
||||
*.bak
|
||||
|
||||
24
README.md
24
README.md
@@ -59,20 +59,26 @@ sudo ./setup-udev.sh
|
||||
## Sample list
|
||||
|
||||
`samples.txt` defines the sample names, one per line, in measurement
|
||||
order. Lines starting with `#` are ignored. Mix samples use the pattern
|
||||
`INK_A+INK_B[w1 to w2 mix]`, e.g.:
|
||||
order. This file is **not tracked in git** (it holds your specific
|
||||
material codes); copy the template to create your own:
|
||||
|
||||
```bash
|
||||
cp samples.example.txt samples.txt
|
||||
```
|
||||
|
||||
Lines starting with `#` are ignored. Material names can be any codes.
|
||||
Mix samples use the pattern `NAME_A+NAME_B[w1 to w2 mix]`, e.g.:
|
||||
|
||||
```text
|
||||
ICJ/107
|
||||
ICJ/108
|
||||
ICJ/435
|
||||
ICJ/407
|
||||
ICJ/107+ICJ/407[75 to 15 mix]
|
||||
ICJ/107+ICJ/435[30 to 80 mix]
|
||||
INK_A
|
||||
INK_B
|
||||
INK_A+INK_B[75 to 15 mix]
|
||||
INK_A+INK_C[30 to 80 mix]
|
||||
```
|
||||
|
||||
The weights are converted to percentages in the formula table
|
||||
(e.g. `30 to 80` → 27% / 73%).
|
||||
(e.g. `30 to 80` → 27% / 73%), which adds one column per material and
|
||||
discovers the material names automatically from your sample list.
|
||||
|
||||
## Output files
|
||||
|
||||
|
||||
10
auto-scan.sh
10
auto-scan.sh
@@ -96,11 +96,17 @@ check_dependencies() {
|
||||
# ---------------------------------------------------------------- step 2
|
||||
wait_for_instrument() {
|
||||
info "Step 2/5: Waiting for i1Pro 2"
|
||||
while spotread -? 2>&1 | grep -q '\*\* No ports found \*\*'; do
|
||||
local ports
|
||||
while true; do
|
||||
# spotread -? exits 1 (usage), so capture output rather than piping.
|
||||
ports="$(spotread -? 2>&1 || true)"
|
||||
if ! grep -q '\*\* No ports found \*\*' <<<"$ports"; then
|
||||
break
|
||||
fi
|
||||
echo " No instrument detected. Connect the i1Pro 2 via USB."
|
||||
read -r -p " Press Enter to check again (or Ctrl+C to abort)... "
|
||||
done
|
||||
spotread -? 2>&1 | grep -E "^\s+[0-9]+ = " | sed 's/^/ Found:/'
|
||||
grep -E "^\s+[0-9]+ = " <<<"$ports" | sed 's/^/ Found:/' || true
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------- step 3+4
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Build formula table from averaged results and sample mix definitions."""
|
||||
"""Build formula table from averaged results and sample mix definitions.
|
||||
|
||||
Ink/material names are discovered automatically from the sample IDs, so this
|
||||
works for any material codes (not tied to a specific product line).
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import csv
|
||||
@@ -7,31 +11,24 @@ import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
INKS = ("ICJ/107", "ICJ/108", "ICJ/435", "ICJ/407")
|
||||
# Two-material mix, e.g. "INK_A+INK_B[75 to 15 mix]". Names may be any token
|
||||
# that does not contain '+' or '['.
|
||||
MIX_PATTERN = re.compile(
|
||||
r"^(?P<a>ICJ/\d+)\+(?P<b>ICJ/\d+)\[(?P<w1>\d+)\s+to\s+(?P<w2>\d+)\s+mix\]$"
|
||||
r"^(?P<a>[^+\[]+)\+(?P<b>[^+\[]+)\[(?P<w1>\d+)\s+to\s+(?P<w2>\d+)\s+mix\]$"
|
||||
)
|
||||
|
||||
|
||||
def parse_material_pcts(sample_id: str) -> dict[str, int]:
|
||||
percents = {ink: 0 for ink in INKS}
|
||||
|
||||
def parse_components(sample_id: str) -> dict[str, int]:
|
||||
"""Return {material: percent} for a pure material or a two-material mix."""
|
||||
mix = MIX_PATTERN.match(sample_id)
|
||||
if mix:
|
||||
ink_a = mix.group("a")
|
||||
ink_b = mix.group("b")
|
||||
ink_a = mix.group("a").strip()
|
||||
ink_b = mix.group("b").strip()
|
||||
w1 = float(mix.group("w1"))
|
||||
w2 = float(mix.group("w2"))
|
||||
total = w1 + w2
|
||||
percents[ink_a] = round(100.0 * w1 / total)
|
||||
percents[ink_b] = round(100.0 * w2 / total)
|
||||
return percents
|
||||
|
||||
if sample_id in INKS:
|
||||
percents[sample_id] = 100
|
||||
return percents
|
||||
|
||||
return percents
|
||||
return {ink_a: round(100.0 * w1 / total), ink_b: round(100.0 * w2 / total)}
|
||||
return {sample_id.strip(): 100}
|
||||
|
||||
|
||||
def main() -> int:
|
||||
@@ -59,9 +56,19 @@ def main() -> int:
|
||||
with args.input.open(newline="", encoding="utf-8") as f:
|
||||
rows = list(csv.DictReader(f))
|
||||
|
||||
# Discover material columns in order of first appearance.
|
||||
inks: list[str] = []
|
||||
parsed: list[dict[str, int]] = []
|
||||
for row in rows:
|
||||
comps = parse_components(row["sample_id"])
|
||||
parsed.append(comps)
|
||||
for ink in comps:
|
||||
if ink not in inks:
|
||||
inks.append(ink)
|
||||
|
||||
fieldnames = [
|
||||
"sample_id",
|
||||
*INKS,
|
||||
*inks,
|
||||
"n_scans",
|
||||
"L*_mean",
|
||||
"L*_std",
|
||||
@@ -72,8 +79,7 @@ def main() -> int:
|
||||
]
|
||||
|
||||
out_rows = []
|
||||
for row in rows:
|
||||
material_pcts = parse_material_pcts(row["sample_id"])
|
||||
for row, comps in zip(rows, parsed):
|
||||
out = {
|
||||
"sample_id": row["sample_id"],
|
||||
"n_scans": row["n_scans"],
|
||||
@@ -84,8 +90,8 @@ def main() -> int:
|
||||
"b*_mean": row["b*_mean"],
|
||||
"b*_std": row["b*_std"],
|
||||
}
|
||||
for ink in INKS:
|
||||
out[ink] = material_pcts[ink]
|
||||
for ink in inks:
|
||||
out[ink] = comps.get(ink, 0)
|
||||
out_rows.append(out)
|
||||
|
||||
with args.output.open("w", newline="", encoding="utf-8") as f:
|
||||
|
||||
@@ -18,7 +18,9 @@ if ! command -v spotread >/dev/null 2>&1; then
|
||||
fi
|
||||
|
||||
echo "Checking for i1Pro..."
|
||||
if spotread -? 2>&1 | grep -q '\*\* No ports found \*\*'; then
|
||||
# spotread -? exits 1 (usage), so capture output rather than piping under pipefail.
|
||||
PORTS="$(spotread -? 2>&1 || true)"
|
||||
if grep -q '\*\* No ports found \*\*' <<<"$PORTS"; then
|
||||
echo "Error: No USB instrument detected." >&2
|
||||
echo " 1. Connect the i1Pro 2 via USB" >&2
|
||||
echo " 2. Run: sudo ./setup-udev.sh" >&2
|
||||
|
||||
17
samples.example.txt
Normal file
17
samples.example.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
# One sample name per line, in measurement order.
|
||||
# Lines starting with # are ignored.
|
||||
#
|
||||
# Single materials: just the material name/code, e.g.
|
||||
# INK_A
|
||||
#
|
||||
# Two-material mixes: NAME_A+NAME_B[w1 to w2 mix]
|
||||
# where w1/w2 are relative weights, converted to percentages, e.g.
|
||||
# INK_A+INK_B[75 to 15 mix] -> 83% INK_A + 17% INK_B
|
||||
#
|
||||
# Copy this file to samples.txt and replace with your own materials:
|
||||
# cp samples.example.txt samples.txt
|
||||
INK_A
|
||||
INK_B
|
||||
INK_C
|
||||
INK_A+INK_B[75 to 15 mix]
|
||||
INK_A+INK_C[30 to 80 mix]
|
||||
@@ -1,9 +0,0 @@
|
||||
# One sample name per line, in measurement order.
|
||||
# Lines starting with # are ignored.
|
||||
# Example:
|
||||
ICJ/107
|
||||
ICJ/108
|
||||
ICJ/435
|
||||
ICJ/407
|
||||
ICJ/107+ICJ/407[75 to 15 mix]
|
||||
ICJ/107+ICJ/435[30 to 80 mix]
|
||||
Reference in New Issue
Block a user