File size: 1,368 Bytes
bf55076
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
import argparse
from pathlib import Path

from PIL import Image

from pydardraw.colormaps.io import load_colormap_from_json
from pydardraw.colormaps.canada_msc import CANADA_MSC_REF
from pydardraw.colormaps.nws_us import NWS_REF
from pydardraw.processing.convert import image_to_dbz, dbz_to_image


def main():
    ap = argparse.ArgumentParser(description="Recolor a radar image to a target dBZ colormap")
    ap.add_argument("input", type=Path, help="Input image (PNG)")
    ap.add_argument("output", type=Path, help="Output image (PNG)")
    ap.add_argument("--src-colormap", type=Path, help="JSON colormap for source (value, #RRGGBB)")
    ap.add_argument("--dst-colormap", type=Path, help="JSON colormap for destination (value, #RRGGBB)")
    ap.add_argument("--fractional", action="store_true", help="Estimate fractional dBZ (xx.xx) using LAB projection")
    args = ap.parse_args()

    src_map = load_colormap_from_json(args.src_colormap) if args.src_colormap else CANADA_MSC_REF
    dst_map = load_colormap_from_json(args.dst_colormap) if args.dst_colormap else NWS_REF

    img = Image.open(args.input).convert("RGBA")
    dbz, alpha = image_to_dbz(img, src_map, fractional=args.fractional)
    out = dbz_to_image(dbz, alpha, dst_map)
    out.save(args.output)
    print(f"Saved: {args.output}")


if __name__ == "__main__":
    main()