Skip to content

Commit

Permalink
Only primary camera links pretty image (#614)
Browse files Browse the repository at this point in the history
* Only primary camera links pretty image
* Add `link_latest` option for `make_pretty_image`.
  • Loading branch information
wtgee authored Sep 21, 2018
1 parent 87a2693 commit c874c9f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
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

0 comments on commit c874c9f

Please sign in to comment.