Skip to content

Commit

Permalink
Merge pull request #315 from mwcraig/fix-IFC-fname
Browse files Browse the repository at this point in the history
Return base name instead of full path in ImageFileCollection iterators
  • Loading branch information
crawfordsm committed Mar 1, 2016
2 parents 2be0bd2 + aa612d8 commit db10268
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions ccdproc/image_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,8 @@ def _generator(self, return_type,
return_fname : bool, default is False
If True, return the tuple (header, file_name) instead of just
header.
header. The file name returned is the name of the file only,
not the full path to the file.
kwd : dict
Any additional keywords are used to filter the items returned; see
Expand All @@ -606,7 +607,7 @@ def _generator(self, return_type,
({return_type}, str)
If ``return_fname`` is ``True``, yield a tuple of
({name}, ``file path``) for next the item in the collection.
({name}, ``file name``) for the next item in the collection.
"""
# store mask so we can reset at end--must COPY, otherwise
Expand All @@ -626,14 +627,16 @@ def _generator(self, return_type,
hdulist = fits.open(full_path,
do_not_scale_image_data=no_scale)

file_name = path.basename(full_path)

return_options = {'header': hdulist[0].header,
'hdu': hdulist[0],
'data': hdulist[0].data}

try:
yield (return_options[return_type] # pragma: no branch
if (not return_fname) else
(return_options[return_type], full_path))
(return_options[return_type], file_name))
except KeyError:
raise ValueError('No generator for {}'.format(return_type))

Expand Down
2 changes: 1 addition & 1 deletion ccdproc/tests/test_image_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def test_header_and_filename(self, triage_setup):
collection = image_collection.ImageFileCollection(location=triage_setup.test_dir,
keywords=['imagetyp'])
for header, fname in collection.headers(return_fname=True):
assert (fname in collection._paths())
assert (fname in collection.summary['file'])
assert (isinstance(header, fits.Header))

def test_dir_with_no_fits_files(self, tmpdir):
Expand Down

0 comments on commit db10268

Please sign in to comment.