Skip to content

Commit

Permalink
feat(create_mmigs_pano.py): Now has a thumbnail option.
Browse files Browse the repository at this point in the history
  • Loading branch information
rbeyer committed Feb 19, 2024
1 parent 7f5bad1 commit 9371d80
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ Changed
within a given string, not just an exact match.
- Now that pid.instrument_name() is more robust, ImageRecord.__init__() can handle a
wider variety of Yamcs parameter names, should they change in the future.
- create_mmgis_pano.py - create() now takes a thumbsize int or tuple of ints that
will control the creation and size of an output thumbnail JPG file, with naming
convention set by Yamcs/OpenMCT.

0.7.0 (2023-02-05)
------------------
Expand Down
41 changes: 37 additions & 4 deletions src/vipersci/vis/create_mmgis_pano.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import numpy.typing as npt
from skimage.io import imread, imsave # maybe just imageio here?
from skimage.exposure import equalize_adapthist, rescale_intensity
from skimage.transform import resize

Check warning on line 36 in src/vipersci/vis/create_mmgis_pano.py

View check run for this annotation

Codecov / codecov/patch

src/vipersci/vis/create_mmgis_pano.py#L36

Added line #L36 was not covered by tests
from sqlalchemy import create_engine, select
from sqlalchemy.orm import Session

Expand Down Expand Up @@ -110,6 +111,7 @@ def create(
outdir: Path = Path.cwd(),
mapserver: Optional[str] = None,
session: Optional[Session] = None,
thumbsize=(None, 93),
):
"""
Creates an MMGIS Panorama in *outdir*. Returns None.
Expand Down Expand Up @@ -179,20 +181,51 @@ def create(
"uint8"
)

outpath = outdir / source_path.with_suffix(".png").name
outpath = outdir / longname(source_path).with_suffix(".png").name

Check warning on line 184 in src/vipersci/vis/create_mmgis_pano.py

View check run for this annotation

Codecov / codecov/patch

src/vipersci/vis/create_mmgis_pano.py#L184

Added line #L184 was not covered by tests

imsave(str(outpath), image8, check_contrast=False)

d = mmgis_data(pano, yaw)
d["url"] = "not/sure/what/the/path/should/be/to/" + outpath.name
# Decided not to include the URL key in the JSON this program outputs
# as the process that takes these data and publishes them are what
# should set that.
# d["url"] = "not/sure/what/the/path/should/be/to/" + outpath.name

# Make JPG thumbnail
if thumbsize is not None:
if isinstance(int, thumbsize):
max_dim = max(np.shape(image8))
if max_dim > thumbsize:
scale = max_dim / thumbsize
new_shape = tuple(int(x / scale) for x in np.shape(image8))
elif len(thumbsize) == 2:
if thumbsize[0] is not None:
raise ValueError(

Check warning on line 203 in src/vipersci/vis/create_mmgis_pano.py

View check run for this annotation

Codecov / codecov/patch

src/vipersci/vis/create_mmgis_pano.py#L195-L203

Added lines #L195 - L203 were not covered by tests
"Not sure how to handle a non-None first element for thumbsize."
)
scale = np.shape(image8)[1] / thumbsize[1]
new_shape = tuple(int(x / scale) for x in np.shape(image8))

Check warning on line 207 in src/vipersci/vis/create_mmgis_pano.py

View check run for this annotation

Codecov / codecov/patch

src/vipersci/vis/create_mmgis_pano.py#L206-L207

Added lines #L206 - L207 were not covered by tests

image8 = rescale_intensity(

Check warning on line 209 in src/vipersci/vis/create_mmgis_pano.py

View check run for this annotation

Codecov / codecov/patch

src/vipersci/vis/create_mmgis_pano.py#L209

Added line #L209 was not covered by tests
resize(image8, new_shape), in_range="image8", out_range="uint8"
)
outthumb = outpath.with_suffix("") + "_thumb.jpeg"
imsave(outthumb, image8, check_contrast=False)

Check warning on line 213 in src/vipersci/vis/create_mmgis_pano.py

View check run for this annotation

Codecov / codecov/patch

src/vipersci/vis/create_mmgis_pano.py#L212-L213

Added lines #L212 - L213 were not covered by tests

with open(outpath.stem + "_mmgis.json", "w") as f:
with open(outpath.stem + ".json", "w") as f:

Check warning on line 215 in src/vipersci/vis/create_mmgis_pano.py

View check run for this annotation

Codecov / codecov/patch

src/vipersci/vis/create_mmgis_pano.py#L215

Added line #L215 was not covered by tests
json.dump(d, f, indent=2, sort_keys=True)

return


def mmgis_data(pano_data: dict, yaw=0):
def longname(path):

Check warning on line 221 in src/vipersci/vis/create_mmgis_pano.py

View check run for this annotation

Codecov / codecov/patch

src/vipersci/vis/create_mmgis_pano.py#L221

Added line #L221 was not covered by tests
"""Returns a longer iso8601-esque filename."""
# YYYY-MM-DDTHH-mm-ss.SSS-pan
vid = pds.PanoID(path.name)
return vid.date.isoformat() + "T" + vid.time.isformat().replace(":", "-") + "-pan"

Check warning on line 225 in src/vipersci/vis/create_mmgis_pano.py

View check run for this annotation

Codecov / codecov/patch

src/vipersci/vis/create_mmgis_pano.py#L224-L225

Added lines #L224 - L225 were not covered by tests


def mmgis_data(pano_data: dict, yaw=0.0):

Check warning on line 228 in src/vipersci/vis/create_mmgis_pano.py

View check run for this annotation

Codecov / codecov/patch

src/vipersci/vis/create_mmgis_pano.py#L228

Added line #L228 was not covered by tests
d = {
"azmax": yaw + pano_data["rover_pan_max"],
"azmin": yaw + pano_data["rover_pan_min"],
Expand Down

0 comments on commit 9371d80

Please sign in to comment.