Add i1Pro 2 color measurement workflow scripts
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
12
.gitignore
vendored
Normal file
12
.gitignore
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
# Measurement data (regenerated per session)
|
||||
scan_*.tsv
|
||||
scan_*.csv
|
||||
averaged.csv
|
||||
formula.csv
|
||||
archive/
|
||||
|
||||
# Report-specific artifacts
|
||||
ICJ108_*
|
||||
*.bak
|
||||
*.html
|
||||
match-*.py
|
||||
110
README.md
Normal file
110
README.md
Normal file
@@ -0,0 +1,110 @@
|
||||
# ICJ108 Color Measurements (i1Pro 2)
|
||||
|
||||
Measure CIELab values from colors printed on opaque white using ArgyllCMS,
|
||||
average repeated scans, and relate results to ink mix formulas.
|
||||
|
||||
## Quick start (automated workflow)
|
||||
|
||||
```bash
|
||||
./auto-scan.sh
|
||||
```
|
||||
|
||||
`auto-scan.sh` runs the whole process in one go:
|
||||
|
||||
1. **Checks required software** — verifies `python3` and ArgyllCMS
|
||||
(`spotread`) are available. Installs python3 via apt and downloads
|
||||
ArgyllCMS to `~/.local/bin` automatically if missing.
|
||||
2. **Waits for the instrument** — prompts you to connect the i1Pro 2 via
|
||||
USB and re-checks until it is detected.
|
||||
3. **Scans the samples** — lists the sample names from `samples.txt` in
|
||||
measurement order, then starts `spotread`. You first calibrate on the
|
||||
white tile, then take one reading per sample with the instrument
|
||||
button, and press **Q** when all readings are done. If the number of
|
||||
readings doesn't match `samples.txt`, the scan can be discarded to
|
||||
`archive/` and repeated.
|
||||
4. **Saves a labelled CSV** — converts the spotread TSV log to
|
||||
`scan_<mode>_<timestamp>.csv` with a `sample_id` column taken from
|
||||
`samples.txt`.
|
||||
5. **Updates the averages** — re-averages **all** complete scan CSVs in
|
||||
the folder into `averaged.csv` (L\*, a\*, b\* mean and standard
|
||||
deviation per sample), then asks whether to rebuild the formula table
|
||||
`formula.csv` (default: yes).
|
||||
|
||||
### Options
|
||||
|
||||
```bash
|
||||
./auto-scan.sh # D50 Lab (default)
|
||||
./auto-scan.sh M0 # ISO 13655 M0
|
||||
./auto-scan.sh M1 # ISO 13655 M1
|
||||
./auto-scan.sh M2 # ISO 13655 M2 (UV cut)
|
||||
./auto-scan.sh --average-only # no scanning; just rebuild averaged + formula CSVs
|
||||
./auto-scan.sh --help # usage
|
||||
```
|
||||
|
||||
Note: scans made in different modes are kept separate; the averaged file
|
||||
is built only from scans of the mode you pass (default D50).
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Linux with bash, python3 (auto-installed if missing)
|
||||
- ArgyllCMS (auto-downloaded to `~/.local/bin/Argyll_V3.4.1` if missing)
|
||||
- X-Rite i1Pro 2 with its white calibration tile
|
||||
- (Recommended, one time) udev rules so the instrument works without root:
|
||||
|
||||
```bash
|
||||
sudo ./setup-udev.sh
|
||||
# then unplug and replug the i1Pro 2
|
||||
```
|
||||
|
||||
## 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.:
|
||||
|
||||
```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]
|
||||
```
|
||||
|
||||
The weights are converted to percentages in the formula table
|
||||
(e.g. `30 to 80` → 27% / 73%).
|
||||
|
||||
## Output files
|
||||
|
||||
| File | Contents |
|
||||
|------|----------|
|
||||
| `scan_D50_<timestamp>.tsv` | Raw spotread log (Lab + XYZ + spectrum 380–730 nm) |
|
||||
| `scan_D50_<timestamp>.csv` | Same data as CSV with `sample_id` column |
|
||||
| `averaged.csv` | Per-sample L\*, a\*, b\* mean and std across all scans |
|
||||
| `formula.csv` | Averaged Lab plus one percentage column per ink |
|
||||
| `archive/` | Discarded or superseded scans |
|
||||
|
||||
## Individual tools
|
||||
|
||||
These are used by `auto-scan.sh` but can also be run on their own:
|
||||
|
||||
| Script | Purpose |
|
||||
|--------|---------|
|
||||
| `measure.sh [mode]` | Just the spotread measurement session (TSV output) |
|
||||
| `run-measurement.sh [mode]` | Measurement session + CSV conversion |
|
||||
| `tsv-to-csv.py <tsv> [-s samples.txt]` | Convert a spotread TSV to labelled CSV |
|
||||
| `average-results.py <csv...> -o out.csv` | Average Lab across scan CSVs |
|
||||
| `build-formula-table.py` | Rebuild `formula.csv` from the averaged CSV |
|
||||
| `rebuild-average.sh` | Shortcut for `./auto-scan.sh --average-only` |
|
||||
| `setup-udev.sh` | Install udev rules for USB instrument access (sudo) |
|
||||
|
||||
## Measurement tips
|
||||
|
||||
- Calibrate at the start of each session; recalibrate (press `k` in
|
||||
spotread) if the ambient temperature changes.
|
||||
- Keep the instrument flat on the sample and fully covering the aperture.
|
||||
- Wait ~15 s after calibration before the first reading for best
|
||||
repeatability.
|
||||
- If repeatability degrades, check for i1Pro lamp drift:
|
||||
`spotread -Y L -O /dev/null`, then let the instrument cool a few
|
||||
minutes.
|
||||
217
auto-scan.sh
Executable file
217
auto-scan.sh
Executable file
@@ -0,0 +1,217 @@
|
||||
#!/usr/bin/env bash
|
||||
# auto-scan.sh - end-to-end i1Pro 2 measurement workflow for ink samples.
|
||||
#
|
||||
# Steps:
|
||||
# 1. Check required software (ArgyllCMS, python3); install if missing
|
||||
# 2. Wait for the i1Pro 2 to be connected via USB
|
||||
# 3. Run a spotread session (calibration + one reading per sample in samples.txt)
|
||||
# 4. Convert the readings to a labelled CSV
|
||||
# 5. Re-average all scan CSVs and rebuild averaged.csv (+ formula table)
|
||||
#
|
||||
# Usage:
|
||||
# ./auto-scan.sh measure with D50 Lab (default)
|
||||
# ./auto-scan.sh M1 measure with ISO 13655 M1 (also: M0, M2)
|
||||
# ./auto-scan.sh --average-only skip scanning, just rebuild the averaged CSV
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
ARGYLL_VERSION="3.4.1"
|
||||
ARGYLL_URL="https://www.argyllcms.com/Argyll_V${ARGYLL_VERSION}_linux_x86_64.tgz"
|
||||
SAMPLES_FILE="samples.txt"
|
||||
AVERAGED_CSV="averaged.csv"
|
||||
FORMULA_CSV="formula.csv"
|
||||
|
||||
MODE="D50"
|
||||
AVERAGE_ONLY=0
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
D50|M0|M1|M2) MODE="$arg" ;;
|
||||
--average-only) AVERAGE_ONLY=1 ;;
|
||||
-h|--help)
|
||||
sed -n '2,15p' "$0" | sed 's/^# \{0,1\}//'
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Unknown argument: $arg (use D50, M0, M1, M2, or --average-only)" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
info() { printf '\n\033[1;34m==> %s\033[0m\n' "$*"; }
|
||||
warn() { printf '\033[1;33mWARNING: %s\033[0m\n' "$*" >&2; }
|
||||
fail() { printf '\033[1;31mERROR: %s\033[0m\n' "$*" >&2; exit 1; }
|
||||
|
||||
# ---------------------------------------------------------------- step 1
|
||||
check_dependencies() {
|
||||
info "Step 1/5: Checking required software"
|
||||
|
||||
if ! command -v python3 >/dev/null 2>&1; then
|
||||
warn "python3 not found - attempting to install (needs sudo)"
|
||||
sudo apt-get update && sudo apt-get install -y python3 \
|
||||
|| fail "Could not install python3"
|
||||
fi
|
||||
echo " python3: $(command -v python3)"
|
||||
|
||||
if ! command -v spotread >/dev/null 2>&1; then
|
||||
# Look for an existing local ArgyllCMS install first
|
||||
local argyll_bin
|
||||
argyll_bin="$(ls -d "$HOME"/.local/bin/Argyll_V*/bin 2>/dev/null | sort -V | tail -1 || true)"
|
||||
if [[ -n "$argyll_bin" ]]; then
|
||||
export PATH="$argyll_bin:$PATH"
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! command -v spotread >/dev/null 2>&1; then
|
||||
warn "ArgyllCMS not found - downloading V${ARGYLL_VERSION}"
|
||||
mkdir -p "$HOME/.local/bin"
|
||||
local tgz="$HOME/.local/bin/Argyll_V${ARGYLL_VERSION}.tgz"
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
curl -fL -o "$tgz" "$ARGYLL_URL" || fail "Download failed: $ARGYLL_URL"
|
||||
else
|
||||
wget -O "$tgz" "$ARGYLL_URL" || fail "Download failed: $ARGYLL_URL"
|
||||
fi
|
||||
tar -zxf "$tgz" -C "$HOME/.local/bin"
|
||||
rm -f "$tgz"
|
||||
export PATH="$HOME/.local/bin/Argyll_V${ARGYLL_VERSION}/bin:$PATH"
|
||||
command -v spotread >/dev/null 2>&1 || fail "ArgyllCMS install failed"
|
||||
echo " Installed ArgyllCMS to ~/.local/bin/Argyll_V${ARGYLL_VERSION}"
|
||||
echo " Add this to your ~/.bashrc to make it permanent:"
|
||||
echo " export PATH=\"\$HOME/.local/bin/Argyll_V${ARGYLL_VERSION}/bin:\$PATH\""
|
||||
fi
|
||||
echo " spotread: $(command -v spotread)"
|
||||
|
||||
for helper in tsv-to-csv.py average-results.py; do
|
||||
[[ -f "$helper" ]] || fail "Missing helper script: $helper"
|
||||
done
|
||||
|
||||
if [[ ! -f /etc/udev/rules.d/55-Argyll.rules ]]; then
|
||||
warn "Argyll udev rules not installed. If the instrument is not detected, run: sudo ./setup-udev.sh"
|
||||
fi
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------- step 2
|
||||
wait_for_instrument() {
|
||||
info "Step 2/5: Waiting for i1Pro 2"
|
||||
while spotread -? 2>&1 | grep -q '\*\* No ports found \*\*'; do
|
||||
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:/'
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------- step 3+4
|
||||
scan_samples() {
|
||||
[[ -f "$SAMPLES_FILE" ]] || fail "$SAMPLES_FILE not found"
|
||||
|
||||
mapfile -t SAMPLES < <(grep -v '^#' "$SAMPLES_FILE" | grep -v '^[[:space:]]*$')
|
||||
local count="${#SAMPLES[@]}"
|
||||
[[ "$count" -gt 0 ]] || fail "No sample names found in $SAMPLES_FILE"
|
||||
|
||||
info "Step 3/5: Scanning $count samples (mode: $MODE)"
|
||||
echo " Measure the samples in this exact order:"
|
||||
local i=1
|
||||
for s in "${SAMPLES[@]}"; do
|
||||
printf ' %2d. %s\n' "$i" "$s"
|
||||
i=$((i + 1))
|
||||
done
|
||||
echo ""
|
||||
echo " spotread will start now:"
|
||||
echo " - First calibrate: place the i1Pro 2 on its white tile and follow the prompt"
|
||||
echo " - Then take one reading per sample (press the instrument button)"
|
||||
echo " - After all $count readings, press Q to finish"
|
||||
echo ""
|
||||
read -r -p " Press Enter to start... "
|
||||
|
||||
TIMESTAMP="$(date +%Y%m%d_%H%M%S)"
|
||||
TSV="scan_${MODE}_${TIMESTAMP}.tsv"
|
||||
|
||||
local spotread_args=(-s "$TSV")
|
||||
if [[ "$MODE" == "D50" ]]; then
|
||||
spotread_args=(-i D50 "${spotread_args[@]}")
|
||||
else
|
||||
spotread_args=(-I "$MODE" "${spotread_args[@]}")
|
||||
fi
|
||||
|
||||
spotread "${spotread_args[@]}"
|
||||
|
||||
[[ -f "$TSV" ]] || fail "No readings were saved ($TSV missing)"
|
||||
|
||||
local readings=$(($(wc -l < "$TSV") - 1))
|
||||
if [[ "$readings" -ne "$count" ]]; then
|
||||
warn "Expected $count readings but got $readings."
|
||||
read -r -p " Keep this scan anyway? [y/N] " ans
|
||||
if [[ "${ans,,}" != "y" ]]; then
|
||||
mkdir -p archive
|
||||
mv "$TSV" "archive/${TSV%.tsv}_incomplete.tsv"
|
||||
fail "Scan discarded (moved to archive/). Re-run ./auto-scan.sh"
|
||||
fi
|
||||
fi
|
||||
|
||||
info "Step 4/5: Saving labelled CSV"
|
||||
./tsv-to-csv.py "$TSV" -s "$SAMPLES_FILE"
|
||||
CSV="${TSV%.tsv}.csv"
|
||||
echo " Scan saved: $CSV"
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------- step 5
|
||||
update_average() {
|
||||
info "Step 5/5: Updating $AVERAGED_CSV"
|
||||
|
||||
local expected
|
||||
expected="$(grep -v '^#' "$SAMPLES_FILE" | grep -cv '^[[:space:]]*$' || true)"
|
||||
|
||||
# Collect scan CSVs (timestamped files only) with the expected reading count
|
||||
local -a scans=()
|
||||
local f rows
|
||||
for f in scan_"$MODE"_[0-9]*.csv; do
|
||||
[[ -f "$f" ]] || continue
|
||||
rows=$(($(wc -l < "$f") - 1))
|
||||
if [[ "$rows" -eq "$expected" ]]; then
|
||||
scans+=("$f")
|
||||
else
|
||||
warn "Skipping $f ($rows readings, expected $expected)"
|
||||
fi
|
||||
done
|
||||
|
||||
[[ "${#scans[@]}" -gt 0 ]] || fail "No complete scan CSVs found to average"
|
||||
|
||||
echo " Averaging ${#scans[@]} scan(s):"
|
||||
printf ' %s\n' "${scans[@]}"
|
||||
python3 average-results.py "${scans[@]}" -s "$SAMPLES_FILE" -o "$AVERAGED_CSV"
|
||||
|
||||
if [[ -f build-formula-table.py ]]; then
|
||||
read -r -p " Rebuild $FORMULA_CSV as well? [Y/n] " ans
|
||||
if [[ "${ans,,}" != "n" ]]; then
|
||||
python3 build-formula-table.py -i "$AVERAGED_CSV" -o "$FORMULA_CSV"
|
||||
else
|
||||
echo " Skipped $FORMULA_CSV (rebuild later with: python3 build-formula-table.py)"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo " Averaged L*a*b* values:"
|
||||
python3 - "$AVERAGED_CSV" <<'PY'
|
||||
import csv, sys
|
||||
with open(sys.argv[1], newline="", encoding="utf-8") as f:
|
||||
for row in csv.DictReader(f):
|
||||
print(f" {row['sample_id']}: L*={float(row['L*_mean']):.2f}, "
|
||||
f"a*={float(row['a*_mean']):.2f}, b*={float(row['b*_mean']):.2f} "
|
||||
f"(n={row['n_scans']})")
|
||||
PY
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------- main
|
||||
check_dependencies
|
||||
if [[ "$AVERAGE_ONLY" -eq 1 ]]; then
|
||||
update_average
|
||||
else
|
||||
wait_for_instrument
|
||||
scan_samples
|
||||
update_average
|
||||
fi
|
||||
|
||||
info "All done."
|
||||
104
average-results.py
Executable file
104
average-results.py
Executable file
@@ -0,0 +1,104 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Average colorimetric results from multiple spotread CSV exports."""
|
||||
|
||||
import argparse
|
||||
import csv
|
||||
import statistics
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
LAB_COLS = ("L*", "a*", "b*")
|
||||
|
||||
|
||||
def load_sample_names(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("#")
|
||||
]
|
||||
|
||||
|
||||
def read_measurements(path: Path, sample_names: list[str]) -> list[dict]:
|
||||
with path.open(newline="", encoding="utf-8") as f:
|
||||
rows = list(csv.DictReader(f))
|
||||
|
||||
measurements = []
|
||||
for i, row in enumerate(rows):
|
||||
sample_id = row.get("sample_id", "").strip()
|
||||
if not sample_id:
|
||||
reading = row.get("Reading", str(i + 1))
|
||||
try:
|
||||
idx = int(reading) - 1
|
||||
except ValueError:
|
||||
idx = i
|
||||
sample_id = sample_names[idx] if idx < len(sample_names) else f"sample_{i + 1}"
|
||||
|
||||
values = {}
|
||||
for col in LAB_COLS:
|
||||
if col not in row:
|
||||
raise KeyError(f"{path}: missing column {col}")
|
||||
values[col] = float(row[col])
|
||||
measurements.append({"sample_id": sample_id, **values})
|
||||
return measurements
|
||||
|
||||
|
||||
def average_sets(sets: list[list[dict]]) -> list[dict]:
|
||||
if not sets:
|
||||
return []
|
||||
|
||||
n_sets = len(sets)
|
||||
n_samples = len(sets[0])
|
||||
if any(len(s) != n_samples for s in sets):
|
||||
raise ValueError("All input files must have the same number of readings")
|
||||
|
||||
averaged = []
|
||||
for i in range(n_samples):
|
||||
sample_id = sets[0][i]["sample_id"]
|
||||
if any(s[i]["sample_id"] != sample_id for s in sets[1:]):
|
||||
sample_id = sets[0][i]["sample_id"]
|
||||
|
||||
row = {"sample_id": sample_id, "n_scans": n_sets}
|
||||
for col in LAB_COLS:
|
||||
vals = [s[i][col] for s in sets]
|
||||
row[f"{col}_mean"] = statistics.mean(vals)
|
||||
row[f"{col}_std"] = statistics.stdev(vals) if len(vals) > 1 else 0.0
|
||||
averaged.append(row)
|
||||
return averaged
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description="Average multiple spotread CSV files.")
|
||||
parser.add_argument("csv_files", nargs="+", type=Path, help="CSV files to average")
|
||||
parser.add_argument(
|
||||
"-s", "--samples", type=Path, default=Path("samples.txt"), help="Sample name list"
|
||||
)
|
||||
parser.add_argument(
|
||||
"-o", "--output", type=Path, default=Path("averaged.csv"), help="Output CSV"
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
sample_names = load_sample_names(args.samples) if args.samples.exists() else []
|
||||
|
||||
sets = []
|
||||
for path in args.csv_files:
|
||||
if not path.exists():
|
||||
print(f"Error: {path} not found", file=sys.stderr)
|
||||
return 1
|
||||
sets.append(read_measurements(path, sample_names))
|
||||
|
||||
averaged = average_sets(sets)
|
||||
fieldnames = ["sample_id", "n_scans"]
|
||||
for col in LAB_COLS:
|
||||
fieldnames.extend([f"{col}_mean", f"{col}_std"])
|
||||
|
||||
with args.output.open("w", newline="", encoding="utf-8") as f:
|
||||
writer = csv.DictWriter(f, fieldnames=fieldnames)
|
||||
writer.writeheader()
|
||||
writer.writerows(averaged)
|
||||
|
||||
print(f"Wrote {len(averaged)} averaged sample(s) to {args.output}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
101
build-formula-table.py
Executable file
101
build-formula-table.py
Executable file
@@ -0,0 +1,101 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Build formula table from averaged results and sample mix definitions."""
|
||||
|
||||
import argparse
|
||||
import csv
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
INKS = ("ICJ/107", "ICJ/108", "ICJ/435", "ICJ/407")
|
||||
MIX_PATTERN = re.compile(
|
||||
r"^(?P<a>ICJ/\d+)\+(?P<b>ICJ/\d+)\[(?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}
|
||||
|
||||
mix = MIX_PATTERN.match(sample_id)
|
||||
if mix:
|
||||
ink_a = mix.group("a")
|
||||
ink_b = mix.group("b")
|
||||
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
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description="Build formula table from averaged CSV.")
|
||||
parser.add_argument(
|
||||
"-i",
|
||||
"--input",
|
||||
type=Path,
|
||||
default=Path("averaged.csv"),
|
||||
help="Averaged results CSV",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-o",
|
||||
"--output",
|
||||
type=Path,
|
||||
default=Path("formula.csv"),
|
||||
help="Output formula table CSV",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
if not args.input.exists():
|
||||
print(f"Error: {args.input} not found", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
with args.input.open(newline="", encoding="utf-8") as f:
|
||||
rows = list(csv.DictReader(f))
|
||||
|
||||
fieldnames = [
|
||||
"sample_id",
|
||||
*INKS,
|
||||
"n_scans",
|
||||
"L*_mean",
|
||||
"L*_std",
|
||||
"a*_mean",
|
||||
"a*_std",
|
||||
"b*_mean",
|
||||
"b*_std",
|
||||
]
|
||||
|
||||
out_rows = []
|
||||
for row in rows:
|
||||
material_pcts = parse_material_pcts(row["sample_id"])
|
||||
out = {
|
||||
"sample_id": row["sample_id"],
|
||||
"n_scans": row["n_scans"],
|
||||
"L*_mean": row["L*_mean"],
|
||||
"L*_std": row["L*_std"],
|
||||
"a*_mean": row["a*_mean"],
|
||||
"a*_std": row["a*_std"],
|
||||
"b*_mean": row["b*_mean"],
|
||||
"b*_std": row["b*_std"],
|
||||
}
|
||||
for ink in INKS:
|
||||
out[ink] = material_pcts[ink]
|
||||
out_rows.append(out)
|
||||
|
||||
with args.output.open("w", newline="", encoding="utf-8") as f:
|
||||
writer = csv.DictWriter(f, fieldnames=fieldnames)
|
||||
writer.writeheader()
|
||||
writer.writerows(out_rows)
|
||||
|
||||
print(f"Wrote {len(out_rows)} row(s) to {args.output}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
73
measure.sh
Executable file
73
measure.sh
Executable file
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env bash
|
||||
# Measure reflective print samples with i1Pro 2 via ArgyllCMS spotread.
|
||||
# Usage: ./measure.sh [M-condition]
|
||||
# M-condition: D50 (default), M0, M1, or M2
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
MODE="${1:-D50}"
|
||||
TIMESTAMP="$(date +%Y%m%d_%H%M%S)"
|
||||
OUTPUT="scan_${MODE}_${TIMESTAMP}.tsv"
|
||||
|
||||
if ! command -v spotread >/dev/null 2>&1; then
|
||||
echo "Error: spotread not found. Add ArgyllCMS bin to PATH." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Checking for i1Pro..."
|
||||
if spotread -? 2>&1 | grep -q '\*\* No ports found \*\*'; 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
|
||||
echo " 3. Unplug and replug the device" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SPOTREAD_ARGS=(-s "$OUTPUT")
|
||||
|
||||
case "$MODE" in
|
||||
D50)
|
||||
SPOTREAD_ARGS=(-i D50 "${SPOTREAD_ARGS[@]}")
|
||||
;;
|
||||
M0|M1|M2)
|
||||
SPOTREAD_ARGS=(-I "$MODE" "${SPOTREAD_ARGS[@]}")
|
||||
;;
|
||||
*)
|
||||
echo "Unknown mode: $MODE (use D50, M0, M1, or M2)" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
SAMPLE_COUNT=0
|
||||
if [[ -f samples.txt ]]; then
|
||||
SAMPLE_COUNT="$(grep -cv '^#\|^$' samples.txt || true)"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Output file: $OUTPUT"
|
||||
echo "Mode: $MODE"
|
||||
if [[ "$SAMPLE_COUNT" -gt 0 ]]; then
|
||||
echo "Samples: $SAMPLE_COUNT expected (from samples.txt)"
|
||||
fi
|
||||
echo ""
|
||||
echo "Workflow:"
|
||||
echo " 1. Calibrate on the white tile when prompted"
|
||||
echo " 2. Place i1Pro on each sample and press the button"
|
||||
if [[ "$SAMPLE_COUNT" -gt 0 ]]; then
|
||||
echo " 3. Take exactly $SAMPLE_COUNT readings, in samples.txt order"
|
||||
echo " 4. Press Q to quit when all readings are done"
|
||||
else
|
||||
echo " 3. Press Q to quit when done"
|
||||
fi
|
||||
echo ""
|
||||
echo "Starting spotread..."
|
||||
echo ""
|
||||
|
||||
spotread "${SPOTREAD_ARGS[@]}"
|
||||
|
||||
echo ""
|
||||
echo "Done. Convert to CSV with:"
|
||||
echo " ./tsv-to-csv.py $OUTPUT"
|
||||
10
rebuild-average.sh
Executable file
10
rebuild-average.sh
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
# Rebuild averaged.csv (and formula.csv) from all complete scan CSVs.
|
||||
# Equivalent to: ./auto-scan.sh --average-only
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
exec ./auto-scan.sh --average-only
|
||||
41
run-measurement.sh
Executable file
41
run-measurement.sh
Executable file
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env bash
|
||||
# Interactive measure session, then auto-convert latest TSV to CSV.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
MODE="${1:-D50}"
|
||||
|
||||
./measure.sh "$MODE"
|
||||
|
||||
LATEST="$(ls -t scan_*.tsv 2>/dev/null | head -1)"
|
||||
if [[ -z "$LATEST" ]]; then
|
||||
echo "No TSV output found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if grep -qv '^#' samples.txt 2>/dev/null && grep -q '[^[:space:]]' samples.txt; then
|
||||
./tsv-to-csv.py "$LATEST" -s samples.txt
|
||||
else
|
||||
./tsv-to-csv.py "$LATEST"
|
||||
fi
|
||||
|
||||
CSV="${LATEST%.tsv}.csv"
|
||||
READING_COUNT="$(($(wc -l < "$LATEST") - 1))"
|
||||
EXPECTED="$(grep -cv '^#\|^$' samples.txt 2>/dev/null || echo 0)"
|
||||
|
||||
echo ""
|
||||
echo "============================================"
|
||||
echo "Measurement complete."
|
||||
echo " TSV: $LATEST"
|
||||
echo " CSV: $CSV"
|
||||
echo " Readings: $READING_COUNT"
|
||||
if [[ "$EXPECTED" -gt 0 && "$READING_COUNT" -ne "$EXPECTED" ]]; then
|
||||
echo ""
|
||||
echo "WARNING: Expected $EXPECTED readings but got $READING_COUNT."
|
||||
echo "Re-run ./run-measurement.sh if any samples were missed."
|
||||
fi
|
||||
echo "============================================"
|
||||
read -r -p "Press Enter to close this window..."
|
||||
9
samples.txt
Normal file
9
samples.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
# 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]
|
||||
22
setup-udev.sh
Executable file
22
setup-udev.sh
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
# Install ArgyllCMS udev rules so the i1Pro 2 is accessible without root.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
ARGYLL_USB="${HOME}/.local/bin/Argyll_V3.4.1/usb"
|
||||
RULES_SRC="${ARGYLL_USB}/55-Argyll.rules"
|
||||
RULES_DST="/etc/udev/rules.d/55-Argyll.rules"
|
||||
|
||||
if [[ ! -f "$RULES_SRC" ]]; then
|
||||
echo "Error: $RULES_SRC not found" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Installing udev rules for ArgyllCMS / i1Pro..."
|
||||
sudo cp "$RULES_SRC" "$RULES_DST"
|
||||
sudo udevadm control --reload-rules
|
||||
sudo udevadm trigger
|
||||
|
||||
echo ""
|
||||
echo "Done. Unplug the i1Pro 2, wait 2 seconds, then plug it back in."
|
||||
echo "Verify with: spotread -?"
|
||||
75
tsv-to-csv.py
Executable file
75
tsv-to-csv.py
Executable file
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Convert ArgyllCMS spotread TSV log to CSV, optionally adding sample labels."""
|
||||
|
||||
import argparse
|
||||
import csv
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def load_sample_names(path: Path) -> list[str]:
|
||||
names = []
|
||||
for line in path.read_text(encoding="utf-8").splitlines():
|
||||
line = line.strip()
|
||||
if line and not line.startswith("#"):
|
||||
names.append(line)
|
||||
return names
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Convert spotread TSV output to CSV with optional sample labels."
|
||||
)
|
||||
parser.add_argument("tsv", type=Path, help="Input TSV file from spotread")
|
||||
parser.add_argument(
|
||||
"-o", "--output", type=Path, help="Output CSV path (default: same name as input)"
|
||||
)
|
||||
parser.add_argument(
|
||||
"-s",
|
||||
"--samples",
|
||||
type=Path,
|
||||
help="Text file with one sample name per line (matched to reading order)",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
if not args.tsv.exists():
|
||||
print(f"Error: {args.tsv} not found", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
out = args.output or args.tsv.with_suffix(".csv")
|
||||
sample_names = load_sample_names(args.samples) if args.samples else []
|
||||
|
||||
with args.tsv.open(newline="", encoding="utf-8") as fin:
|
||||
reader = csv.reader(fin, delimiter="\t")
|
||||
rows = list(reader)
|
||||
|
||||
if not rows:
|
||||
print("Error: empty input file", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
header = rows[0]
|
||||
data_rows = rows[1:]
|
||||
|
||||
if sample_names:
|
||||
if len(sample_names) != len(data_rows):
|
||||
print(
|
||||
f"Warning: {len(sample_names)} sample names but {len(data_rows)} readings",
|
||||
file=sys.stderr,
|
||||
)
|
||||
header = ["sample_id"] + header
|
||||
data_rows = [
|
||||
[sample_names[i] if i < len(sample_names) else f"sample_{i + 1}"] + row
|
||||
for i, row in enumerate(data_rows)
|
||||
]
|
||||
|
||||
with out.open("w", newline="", encoding="utf-8") as fout:
|
||||
writer = csv.writer(fout)
|
||||
writer.writerow(header)
|
||||
writer.writerows(data_rows)
|
||||
|
||||
print(f"Wrote {len(data_rows)} reading(s) to {out}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user