TCrB Diagramm verbessert
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,117 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
FILTER_WAVELENGTHS_NM: dict[str, float] = {
|
||||
"U": 366.3,
|
||||
"B": 436.1,
|
||||
"SG": 477.0,
|
||||
"TB": 440.0,
|
||||
"V": 544.8,
|
||||
"TG": 544.8,
|
||||
"CV": 544.8,
|
||||
"SR": 623.1,
|
||||
"R": 640.7,
|
||||
"TR": 640.7,
|
||||
"SI": 762.5,
|
||||
"I": 798.0,
|
||||
"SZ": 909.7,
|
||||
}
|
||||
|
||||
|
||||
FILTER_DESCRIPTIONS: dict[str, str] = {
|
||||
"U": "Johnson U, Ultraviolett, ca. 366,3 nm",
|
||||
"B": "Johnson B, Blau, ca. 436,1 nm",
|
||||
"SG": "Sloan g, ca. 477,0 nm",
|
||||
"TB": "DSLR/OSC Blaukanal, ca. 440,0 nm",
|
||||
"V": "Johnson V, visuell/gruen, ca. 544,8 nm",
|
||||
"TG": "DSLR/OSC Gruenkanal, ca. 544,8 nm",
|
||||
"CV": "Clear auf V referenziert, ca. 544,8 nm",
|
||||
"SR": "Sloan r, ca. 623,1 nm",
|
||||
"R": "Cousins R, Rot, ca. 640,7 nm",
|
||||
"TR": "DSLR/OSC Rotkanal, ca. 640,7 nm",
|
||||
"SI": "Sloan i, ca. 762,5 nm",
|
||||
"I": "Cousins I, nahes Infrarot, ca. 798,0 nm",
|
||||
"SZ": "Sloan z, ca. 909,7 nm",
|
||||
}
|
||||
|
||||
|
||||
def wavelength_to_hex_color(wavelength_nm: float) -> str:
|
||||
if wavelength_nm < 380:
|
||||
return "#1B2A6B"
|
||||
|
||||
if wavelength_nm > 780:
|
||||
return "#7A0018"
|
||||
|
||||
red = 0.0
|
||||
green = 0.0
|
||||
blue = 0.0
|
||||
|
||||
if wavelength_nm < 440:
|
||||
red = -((wavelength_nm - 440) / (440 - 380))
|
||||
blue = 1.0
|
||||
elif wavelength_nm < 490:
|
||||
green = (wavelength_nm - 440) / (490 - 440)
|
||||
blue = 1.0
|
||||
elif wavelength_nm < 510:
|
||||
green = 1.0
|
||||
blue = -((wavelength_nm - 510) / (510 - 490))
|
||||
elif wavelength_nm < 580:
|
||||
red = (wavelength_nm - 510) / (580 - 510)
|
||||
green = 1.0
|
||||
elif wavelength_nm < 645:
|
||||
red = 1.0
|
||||
green = -((wavelength_nm - 645) / (645 - 580))
|
||||
else:
|
||||
red = 1.0
|
||||
|
||||
factor = 1.0
|
||||
if wavelength_nm < 420:
|
||||
factor = 0.3 + 0.7 * ((wavelength_nm - 380) / (420 - 380))
|
||||
elif wavelength_nm > 700:
|
||||
factor = 0.3 + 0.7 * ((780 - wavelength_nm) / (780 - 700))
|
||||
|
||||
gamma = 0.8
|
||||
|
||||
def convert(channel: float) -> int:
|
||||
if channel <= 0.0:
|
||||
return 0
|
||||
return round(255 * pow(channel * factor, gamma))
|
||||
|
||||
return "#{:02X}{:02X}{:02X}".format(convert(red), convert(green), convert(blue))
|
||||
|
||||
|
||||
def build_filter_metadata() -> dict[str, dict[str, object]]:
|
||||
metadata: dict[str, dict[str, object]] = {}
|
||||
for filter_code, wavelength_nm in FILTER_WAVELENGTHS_NM.items():
|
||||
metadata[filter_code] = {
|
||||
"wavelength_nm": wavelength_nm,
|
||||
"color": wavelength_to_hex_color(wavelength_nm),
|
||||
"description": FILTER_DESCRIPTIONS.get(filter_code, filter_code),
|
||||
}
|
||||
return metadata
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description="Erzeugt Filter-Metadaten mit Wellenlaengen und RGB-Farben.")
|
||||
parser.add_argument("--output", help="Pfad zur JSON-Ausgabedatei.")
|
||||
args = parser.parse_args()
|
||||
|
||||
payload = build_filter_metadata()
|
||||
json_text = json.dumps(payload, ensure_ascii=False, indent=2) + "\n"
|
||||
|
||||
if args.output:
|
||||
output_path = Path(args.output)
|
||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
output_path.write_text(json_text, encoding="utf-8")
|
||||
else:
|
||||
print(json_text, end="")
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user