rms-picmaker 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
picmaker/__init__.py ADDED
@@ -0,0 +1,95 @@
1
+ """rms-picmaker — convert PDS3/VICAR/FITS images to JPEG, TIFF, etc.
2
+
3
+ The package's public surface is re-exported from this module so that
4
+ consumers can write::
5
+
6
+ from picmaker import images_to_pics, read_one_image_array
7
+
8
+ The top-level pipeline entry point is
9
+ :func:`picmaker.pipeline.images_to_pics`; the single-image reader is
10
+ :func:`picmaker.io.read_one_image_array`. The full set of public
11
+ names is in this module's ``__all__`` list.
12
+ """
13
+
14
+ try:
15
+ from importlib.metadata import PackageNotFoundError
16
+ from importlib.metadata import version as _version
17
+
18
+ __version__ = _version('rms-picmaker')
19
+ except PackageNotFoundError: # pragma: no cover — only fires when the package isn't installed
20
+ try:
21
+ from picmaker._version import __version__
22
+ except ImportError:
23
+ __version__ = '0.0.0+unknown'
24
+
25
+ from picmaker._filters import FILTER_DICT, filter_image
26
+ from picmaker.cli import main
27
+ from picmaker.color import BFUNC, GFUNC, RFUNC, RGB_BY_NM, tinted_colormap
28
+ from picmaker.enhance import (
29
+ apply_colormap,
30
+ apply_gamma,
31
+ fill_zebra_stripes,
32
+ get_limits,
33
+ )
34
+ from picmaker.geometry import (
35
+ circle_mask,
36
+ crop_array,
37
+ get_size,
38
+ pad_image,
39
+ resize_image,
40
+ rotate_array_rgb,
41
+ slice_array,
42
+ wrap_image,
43
+ )
44
+ from picmaker.io import (
45
+ FilterInfo,
46
+ ReadResult,
47
+ get_outfile,
48
+ read_array,
49
+ read_image_array,
50
+ read_one_image_array,
51
+ read_pds_labeled_image_array,
52
+ read_pil,
53
+ )
54
+ from picmaker.options import PicmakerOptions
55
+ from picmaker.pil_utils import array_to_pil, pil_to_array, write_pil
56
+ from picmaker.pipeline import find_common_path, images_to_pics, process_images
57
+
58
+ __all__ = [
59
+ 'BFUNC',
60
+ 'FILTER_DICT',
61
+ 'GFUNC',
62
+ 'RFUNC',
63
+ 'RGB_BY_NM',
64
+ 'FilterInfo',
65
+ 'PicmakerOptions',
66
+ 'ReadResult',
67
+ '__version__',
68
+ 'apply_colormap',
69
+ 'apply_gamma',
70
+ 'array_to_pil',
71
+ 'circle_mask',
72
+ 'crop_array',
73
+ 'fill_zebra_stripes',
74
+ 'filter_image',
75
+ 'find_common_path',
76
+ 'get_limits',
77
+ 'get_outfile',
78
+ 'get_size',
79
+ 'images_to_pics',
80
+ 'main',
81
+ 'pad_image',
82
+ 'pil_to_array',
83
+ 'process_images',
84
+ 'read_array',
85
+ 'read_image_array',
86
+ 'read_one_image_array',
87
+ 'read_pds_labeled_image_array',
88
+ 'read_pil',
89
+ 'resize_image',
90
+ 'rotate_array_rgb',
91
+ 'slice_array',
92
+ 'tinted_colormap',
93
+ 'wrap_image',
94
+ 'write_pil',
95
+ ]
picmaker/_filters.py ADDED
@@ -0,0 +1,60 @@
1
+ """PIL filter dispatch helpers."""
2
+
3
+ from typing import Any
4
+
5
+ from PIL import ImageFilter
6
+
7
+ FILTER_DICT: dict[str, Any] = {
8
+ 'NONE': None,
9
+ 'BLUR': ImageFilter.BLUR,
10
+ 'CONTOUR': ImageFilter.CONTOUR,
11
+ 'DETAIL': ImageFilter.DETAIL,
12
+ 'EDGE_ENHANCE': ImageFilter.EDGE_ENHANCE,
13
+ 'EDGE_ENHANCE_MORE': ImageFilter.EDGE_ENHANCE_MORE,
14
+ 'EMBOSS': ImageFilter.EMBOSS,
15
+ 'FIND_EDGES': ImageFilter.FIND_EDGES,
16
+ 'SMOOTH': ImageFilter.SMOOTH,
17
+ 'SMOOTH_MORE': ImageFilter.SMOOTH_MORE,
18
+ 'SHARPEN': ImageFilter.SHARPEN,
19
+ 'MEDIAN_3': ImageFilter.MedianFilter(3),
20
+ 'MEDIAN_5': ImageFilter.MedianFilter(5),
21
+ 'MEDIAN_7': ImageFilter.MedianFilter(7),
22
+ 'MINIMUM_3': ImageFilter.MinFilter(3),
23
+ 'MINIMUM_5': ImageFilter.MinFilter(5),
24
+ 'MINIMUM_7': ImageFilter.MinFilter(7),
25
+ 'MAXIMUM_3': ImageFilter.MaxFilter(3),
26
+ 'MAXIMUM_5': ImageFilter.MaxFilter(5),
27
+ 'MAXIMUM_7': ImageFilter.MaxFilter(7),
28
+ }
29
+
30
+
31
+ def filter_image(image: Any, filter_name: str) -> Any:
32
+ """Apply an arbitrary filter to a PIL image.
33
+
34
+ Two-byte (16-bit) images are not supported and raise ``ValueError``.
35
+
36
+ Parameters:
37
+ image: A PIL image as 8-bit RGB or grayscale.
38
+ filter_name: Name of the filter to be applied. Valid choices are the
39
+ keys of ``FILTER_DICT`` (case-insensitive). ``'NONE'`` returns
40
+ the input image unchanged.
41
+
42
+ Returns:
43
+ The filtered PIL image. For ``filter_name='NONE'`` the input
44
+ image is returned unchanged.
45
+
46
+ Raises:
47
+ ValueError: If ``image`` is a list (16-bit two-byte image).
48
+ KeyError: If ``filter_name`` (case-folded) is not a key of
49
+ :data:`picmaker._filters.FILTER_DICT`.
50
+ """
51
+ if isinstance(image, list):
52
+ raise ValueError('filtering of 2-byte images is not supported')
53
+
54
+ filter_method = FILTER_DICT[filter_name.upper()]
55
+ if filter_method:
56
+ image = image.filter(filter_method)
57
+ return image
58
+
59
+
60
+ __all__ = ['FILTER_DICT', 'filter_image']
picmaker/_rgb.py ADDED
@@ -0,0 +1,37 @@
1
+ """Wavelength → RGB lookup tables.
2
+
3
+ Maps wavelengths in the 380-750 nm range to an ``(R, G, B)`` triple
4
+ suitable for tinting a grayscale image. ``RGB_BY_NM`` holds the raw
5
+ table; ``RFUNC``, ``GFUNC``, and ``BFUNC`` are
6
+ :class:`tabulation.Tabulation` splines that interpolate between
7
+ adjacent rows so the caller can query at any wavelength.
8
+
9
+ This module imports nothing from the rest of :mod:`picmaker`, which
10
+ lets :mod:`picmaker.color` and :mod:`picmaker.instruments.hst` both
11
+ read the same tables without forming an import cycle.
12
+ """
13
+
14
+ import numpy as np
15
+ from numpy.typing import NDArray
16
+ from tabulation import Tabulation
17
+
18
+ # [wavelength_nm, r, g, b] — values are floats (RGB channels can fall
19
+ # between 60.5 and 255.999), so the dtype is float64, not uint8.
20
+ RGB_BY_NM: NDArray[np.float64] = np.array(
21
+ [
22
+ [380.0, 200.500, 60.500, 255.999], # uv
23
+ [410.0, 200.500, 110.500, 255.999], # violet
24
+ [480.0, 110.500, 110.500, 255.999], # blue
25
+ [540.0, 110.500, 255.999, 110.500], # green
26
+ [580.0, 255.999, 255.999, 110.500], # yellow
27
+ [610.0, 255.999, 180.500, 110.500], # orange
28
+ [650.0, 255.999, 110.500, 110.500], # red
29
+ [750.0, 255.999, 60.500, 60.500], # ir
30
+ ]
31
+ )
32
+
33
+ RFUNC: Tabulation = Tabulation(RGB_BY_NM[:, 0], RGB_BY_NM[:, 1])
34
+ GFUNC: Tabulation = Tabulation(RGB_BY_NM[:, 0], RGB_BY_NM[:, 2])
35
+ BFUNC: Tabulation = Tabulation(RGB_BY_NM[:, 0], RGB_BY_NM[:, 3])
36
+
37
+ __all__ = ['BFUNC', 'GFUNC', 'RFUNC', 'RGB_BY_NM']
picmaker/_version.py ADDED
@@ -0,0 +1,24 @@
1
+ # file generated by vcs-versioning
2
+ # don't change, don't track in version control
3
+ from __future__ import annotations
4
+
5
+ __all__ = [
6
+ "__version__",
7
+ "__version_tuple__",
8
+ "version",
9
+ "version_tuple",
10
+ "__commit_id__",
11
+ "commit_id",
12
+ ]
13
+
14
+ version: str
15
+ __version__: str
16
+ __version_tuple__: tuple[int | str, ...]
17
+ version_tuple: tuple[int | str, ...]
18
+ commit_id: str | None
19
+ __commit_id__: str | None
20
+
21
+ __version__ = version = '1.0.0'
22
+ __version_tuple__ = version_tuple = (1, 0, 0)
23
+
24
+ __commit_id__ = commit_id = None