Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only primary camera links pretty image #614

Merged
merged 3 commits into from
Sep 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pocs/camera/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def process_exposure(self, info, observation_event, exposure_event=None):
self.logger.debug("Extracting pretty image")
img_utils.make_pretty_image(file_path,
title=info['field_name'],
primary=info['is_primary'])
link_latest=info['is_primary'])
except Exception as e:
self.logger.warning('Problem with extracting pretty image: {}'.format(e))

Expand Down
36 changes: 18 additions & 18 deletions pocs/utils/images/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import subprocess
import shutil
import re
from contextlib import suppress

from matplotlib import pyplot as plt
from warnings import warn
Expand Down Expand Up @@ -63,20 +64,18 @@ def crop_data(data, box_width=200, center=None, verbose=False):
return center


def make_pretty_image(fname, timeout=15, **kwargs): # pragma: no cover
""" Make a pretty image
def make_pretty_image(fname, timeout=15, link_latest=False, **kwargs): # pragma: no cover
"""Make a pretty image

This will create a jpg file from either a CR2 (Canon) or FITS file.

Notes:
See `$POCS/scripts/cr2_to_jpg.sh` for CR2 process

Arguments:
fname {str} -- Name of image file, may be either .fits or .cr2
**kwargs {dict} -- Additional arguments to be passed to external script

Keyword Arguments:
timeout {number} -- Process timeout (default: {15})
fname (str): Name of image file, may be either .fits or .cr2.
timeout (int, optional): Timeout for image conversion in seconds,
default 15 seconds.
link_latest (bool, optional): If the pretty picture should be linked to
`$PANDIR/images/latest.jpg`, default False.
**kwargs: Additional keyword arguments passed to the conversion methods.

Returns:
str -- Filename of image that was created
Expand All @@ -94,20 +93,21 @@ def make_pretty_image(fname, timeout=15, **kwargs): # pragma: no cover
return None

# Symlink latest.jpg to the image; first remove the symlink if it already exists.
if os.path.exists(pretty_path) and pretty_path.endswith('.jpg'):
latest_path = '{}/images/latest.jpg'.format(os.getenv('PANDIR'))
try:
if link_latest and os.path.exists(pretty_path):
latest_path = os.path.join(
os.getenv('PANDIR'),
'images',
'latest.jpg'
)
with suppress(FileNotFoundError):
os.remove(latest_path)
except FileNotFoundError:
pass

try:
os.symlink(pretty_path, latest_path)
except Exception as e:
warn("Can't link latest image: {}".format(e))

return pretty_path
else:
return None
return pretty_path


def _make_pretty_from_fits(
Expand Down