Skip to content

Commit

Permalink
Merge d4c3674 into bb63852
Browse files Browse the repository at this point in the history
  • Loading branch information
C. E. Brasseur committed Dec 20, 2019
2 parents bb63852 + d4c3674 commit 712dbe5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Doc update (explain time column) [#19]
- Adding img_cut and normalize_img [#21]
- Improve cutout filenames, change minmax_cut to minmax_value [#24]
- Add error handling when reading data raises an exception [#28]

0.4 (2019-06-21)
----------------
Expand Down
6 changes: 2 additions & 4 deletions astrocut/cube_cut.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ def _get_cutout_limits(self, cutout_size):
Parameters
----------
center_coord : `~astropy.coordinates.SkyCoord`
The central coordinate for the cutout
cutout_size : array
[ny,nx] in with ints (pixels) or astropy quantities
Expand Down Expand Up @@ -759,12 +757,12 @@ def cube_cut(self, cube_file, coordinates, cutout_size,

if not target_pixel_file:
_, flename = os.path.split(cube_file)
tpf_name = "{}_{:7f}_{:7f}_{}x{}_astrocut.fits".format(flename.rstrip('.fits').rstrip("-cube"),
target_pixel_file = "{}_{:7f}_{:7f}_{}x{}_astrocut.fits".format(flename.rstrip('.fits').rstrip("-cube"),
self.center_coord.ra.value,
self.center_coord.dec.value,
self.cutout_lims[0, 1]-self.cutout_lims[0, 0],
self.cutout_lims[1, 1]-self.cutout_lims[1, 0])
target_pixel_file = os.path.join(output_path, tpf_name)
target_pixel_file = os.path.join(output_path, target_pixel_file)


if verbose:
Expand Down
23 changes: 16 additions & 7 deletions astrocut/cutouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import warnings

from . import __version__
from .exceptions import InputWarning, InvalidQueryError, InvalidInputError
from .exceptions import InputWarning, DataWarning, InvalidQueryError, InvalidInputError


#### FUNCTIONS FOR UTILS ####
Expand Down Expand Up @@ -168,7 +168,8 @@ def _hducut(img_hdu, center_coord, cutout_size, correct_wcs=False, drop_after=No
try:
max_ind = img_hdu.header.index(drop_after)
except ValueError:
warnings.warn("Last desired keyword not found in image header, using the entire header.")
warnings.warn("Last desired keyword not found in image header, using the entire header.",
DataWarning)

hdu_header = fits.Header(img_hdu.header[:max_ind], copy=True)
img_wcs = wcs.WCS(hdu_header)
Expand Down Expand Up @@ -402,8 +403,14 @@ def fits_cut(input_files, coordinates, cutout_size, correct_wcs=False, drop_afte
if verbose:
print("\n{}".format(in_fle))
hdulist = fits.open(in_fle)
cutout = _hducut(hdulist[0], coordinates, cutout_size,
correct_wcs=correct_wcs, drop_after=drop_after, verbose=verbose)

try:
cutout = _hducut(hdulist[0], coordinates, cutout_size,
correct_wcs=correct_wcs, drop_after=drop_after, verbose=verbose)
except OSError as err:
warnings.warn("Error {} encountered when performing cutout on {}.\nFile will be skipped".format(err, in_fle),
DataWarning)

hdulist.close()

# Check that there is data in the cutout image
Expand All @@ -415,7 +422,7 @@ def fits_cut(input_files, coordinates, cutout_size, correct_wcs=False, drop_afte

# If no cutouts contain data, raise exception
if num_empty == len(input_files):
raise InvalidQueryError("Cutout contains to data! (Check image footprint.)")
raise InvalidQueryError("Cutout contains no data! (Check image footprint.)")

# Make sure the output directory exists
if not os.path.exists(output_dir):
Expand All @@ -441,7 +448,8 @@ def fits_cut(input_files, coordinates, cutout_size, correct_wcs=False, drop_afte
for fle in input_files:
cutout = cutout_hdu_dict[fle]
if cutout.header.get("EMPTY"):
warnings.warn("Cutout of {} contains to data and will not be written.".format(fle))
warnings.warn("Cutout of {} contains to data and will not be written.".format(fle),
DataWarning)
continue

cutout_hdus.append(cutout)
Expand Down Expand Up @@ -684,7 +692,8 @@ def img_cut(input_files, coordinates, cutout_size, stretch='asinh', minmax_perce
for fle in input_files:
cutout = cutout_hdu_dict.get(fle)
if cutout is None:
warnings.warn("Cutout of {} contains to data and will not be written.".format(fle))
warnings.warn("Cutout of {} contains to data and will not be written.".format(fle),
DataWarning)
continue

file_path = "{}_{:7f}_{:7f}_{}-x-{}_astrocut.{}".format(os.path.basename(fle).rstrip('.fits'),
Expand Down
7 changes: 7 additions & 0 deletions astrocut/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@ class TypeWarning(AstropyWarning):
Warnings to do with data types.
"""
pass


class DataWarning(AstropyWarning):
"""
Warnings to do with data content.
"""
pass

0 comments on commit 712dbe5

Please sign in to comment.