-
Notifications
You must be signed in to change notification settings - Fork 49
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
Pretty image title #610
Merged
Merged
Pretty image title #610
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e2b094f
* Consistency with `title` parameter.
wtgee 35562b3
Cleanup of image title.
wtgee bcd86b5
Fix for the format call
wtgee 8b72264
Merge branch 'develop' of https://github.com/panoptes/POCS into prett…
wtgee 61d4c1a
Fix comment
wtgee 6844e4f
If `DATE-OBS` is present, try to parse filename for date. If not, use…
wtgee 831b6bc
Added exptime to title
wtgee 4a428d3
Merge branch 'develop' of https://github.com/panoptes/POCS into prett…
wtgee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
|
||
from glob import glob | ||
from copy import copy | ||
from dateutil import parser as date_parser | ||
|
||
from pocs.utils import current_time | ||
from pocs.utils import error | ||
|
@@ -64,30 +65,32 @@ def crop_data(data, box_width=200, center=None, verbose=False): | |
return center | ||
|
||
|
||
def make_pretty_image(fname, timeout=15, link_latest=False, **kwargs): # pragma: no cover | ||
"""Make a pretty image | ||
def make_pretty_image(fname, title=None, 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. | ||
timeout (int, optional): Timeout for image conversion in seconds, | ||
default 15 seconds. | ||
fname {str} -- Name of image file, may be either .fits or .cr2 | ||
title (None|str, optional): Title to be placed on image, default None. | ||
timeout (int, optional): Timeout for conversion, 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. | ||
**kwargs {dict} -- Additional arguments to be passed to external script. | ||
|
||
Returns: | ||
str -- Filename of image that was created | ||
|
||
str -- Filename of image that was created. | ||
""" | ||
assert os.path.exists(fname),\ | ||
warn("File doesn't exist, can't make pretty: {}".format(fname)) | ||
|
||
if fname.endswith('.cr2'): | ||
pretty_path = _make_pretty_from_cr2(fname, timeout=timeout, **kwargs) | ||
pretty_path = _make_pretty_from_cr2(fname, title=title, timeout=timeout, **kwargs) | ||
elif fname.endswith('.fits'): | ||
pretty_path = _make_pretty_from_fits(fname, **kwargs) | ||
pretty_path = _make_pretty_from_fits(fname, title=title, **kwargs) | ||
else: | ||
warn("File must be a Canon CR2 or FITS file.") | ||
return None | ||
|
@@ -110,25 +113,42 @@ def make_pretty_image(fname, timeout=15, link_latest=False, **kwargs): # pragma | |
return pretty_path | ||
|
||
|
||
def _make_pretty_from_fits( | ||
fname=None, figsize=(10, 10 / 1.325), dpi=150, alpha=0.2, number=7, **kwargs): | ||
def _make_pretty_from_fits(fname=None, | ||
title=None, | ||
figsize=(10, 10 / 1.325), | ||
dpi=150, | ||
alpha=0.2, | ||
number_ticks=7, | ||
clip_percent=99.9, | ||
**kwargs): | ||
|
||
with open_fits(fname) as hdu: | ||
header = hdu[0].header | ||
data = hdu[0].data | ||
data = focus_utils.mask_saturated(data) | ||
wcs = WCS(header) | ||
|
||
title = kwargs.get('title', header.get('FIELD', 'Unknown')) | ||
exp_time = header.get('EXPTIME', 'Unknown') | ||
if not title: | ||
field = header.get('FIELD', 'Unknown field') | ||
exp_time = header.get('EXPTIME', 'Unknown exptime') | ||
filter_type = header.get('FILTER', 'Unknown filter') | ||
|
||
try: | ||
date_time = header['DATE-OBS'] | ||
except KeyError: | ||
# If we don't have DATE-OBS, check filename for date | ||
try: | ||
basename = os.path.splitext(os.path.basename(fname))[0] | ||
date_time = date_parser.parse(basename).isoformat() | ||
except Exception: | ||
# Otherwise use now | ||
date_time = current_time(pretty=True) | ||
|
||
filter_type = header.get('FILTER', 'Unknown filter') | ||
date_time = header.get('DATE-OBS', current_time(pretty=True)).replace('T', ' ', 1) | ||
date_time = date_time.replace('T', ' ', 1) | ||
|
||
percent_value = kwargs.get('normalize_clip_percent', 99.9) | ||
title = '{} ({}s {}) {}'.format(field, exp_time, filter_type, date_time) | ||
|
||
title = '{} ({}s {}) {}'.format(title, exp_time, filter_type, date_time) | ||
norm = ImageNormalize(interval=PercentileInterval(percent_value), stretch=LogStretch()) | ||
norm = ImageNormalize(interval=PercentileInterval(clip_percent), stretch=LogStretch()) | ||
|
||
fig = plt.figure(figsize=figsize, dpi=dpi) | ||
|
||
|
@@ -140,7 +160,7 @@ def _make_pretty_from_fits( | |
ra_axis.set_axislabel('Right Ascension') | ||
ra_axis.set_major_formatter('hh:mm') | ||
ra_axis.set_ticks( | ||
number=number, | ||
number=number_ticks, | ||
color='white', | ||
exclude_overlapping=True | ||
) | ||
|
@@ -149,7 +169,7 @@ def _make_pretty_from_fits( | |
dec_axis.set_axislabel('Declination') | ||
dec_axis.set_major_formatter('dd:mm') | ||
dec_axis.set_ticks( | ||
number=number, | ||
number=number_ticks, | ||
color='white', | ||
exclude_overlapping=True | ||
) | ||
|
@@ -171,16 +191,14 @@ def _make_pretty_from_fits( | |
return new_filename | ||
|
||
|
||
def _make_pretty_from_cr2(fname, timeout=15, **kwargs): # pragma: no cover | ||
def _make_pretty_from_cr2(fname, title=None, timeout=15, **kwargs): # pragma: no cover | ||
verbose = kwargs.get('verbose', False) | ||
|
||
title = '{} {}'.format(kwargs.get('title', ''), current_time().isot) | ||
|
||
solve_field = "{}/scripts/cr2_to_jpg.sh".format(os.getenv('POCS')) | ||
cmd = [solve_field, fname, title] | ||
script_name = os.path.join(os.getenv('POCS'), 'scripts', 'cr2_to_jpg.sh') | ||
cmd = [script_name, fname] | ||
|
||
if kwargs.get('primary', False): | ||
cmd.append('link') | ||
if title: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No default title? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, see PR description. |
||
cmd.append(title) | ||
|
||
if verbose: | ||
print(cmd) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A reminder about my request that we have images (plots) that can display on both white and black backgrounds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would normally happen with the
fig.savefig
method, which is part of the OO interface. I've added a note in #608.