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

Allow ImageFileCollections to take a list of file names #403

Merged
merged 11 commits into from Oct 17, 2016

Conversation

mirca
Copy link
Member

@mirca mirca commented Oct 14, 2016

Implements #374.

I added an optional parameter named filenames which should contain the names of the FITS files in the directory which should be added to the collection. If filenames is None and location is not, then all FITS files in location are added to the collection.

Appreciate any feedback on this.

@MSeifert04
Copy link
Contributor

MSeifert04 commented Oct 14, 2016

@mirca Thank you for the PR. I have been working on the same issue but that stalled. So I am very happy you found the time to implement this 👍

Some problems I have encountered which are not adressed in this PR:

  • .refresh simply loads all files from the location again. (intended or broken by design?)
  • it is not possible to load files from different locations (that's not necessary, that could be a further enhancement possibility)

I'll add some additional comments inline.

Copy link
Contributor

@MSeifert04 MSeifert04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks good 👍

However some comments should be adressed and it still needs a Changelog entry (https://github.com/astropy/ccdproc/blob/master/CHANGES.rst).

@@ -57,11 +62,15 @@ class ImageFileCollection(object):
Raised if keywords are set to a combination of '*' and any other
value.
"""
def __init__(self, location=None, keywords=None, info_file=None):
def __init__(self, location=None, filenames=None, keywords=None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New arguments should be added at the end of the list of arguments to ensure backwards-compatibility.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Addressed.

Path to directory containing FITS files.
Default is ``None``.

filenames: str, list of str, or None, optional
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested it but is it possible to provide a single str?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Now it is possible, but ImageFileCollection.files is kept as list.

fn = ['filter_no_object_bias.fit', 'filter_object_light_foo.fit']
img_collection = image_collection.ImageFileCollection(
location=triage_setup.test_dir, filenames=fn, keywords=['filter'])
assert img_collection.files is fn
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is tests are prone to errors, wouldn't == suffice?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

img_collection = image_collection.ImageFileCollection(
location=triage_setup.test_dir, filenames=fn, keywords=['filter'])
assert img_collection.files is fn
assert img_collection.summary is img_collection.summary_info
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is not needed because they are always equal. summary_info is just the deprecated property.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed :)

@mirca
Copy link
Member Author

mirca commented Oct 14, 2016

@MSeifert04 Thank you very much for your review :) For now, location only points to one directory, as you mentioned, but I can work to handle that case (better in a different PR?).

self._files = []
if location:
self._files = self._fits_files_in_directory()
if self._filenames:
if type(self._filenames) is str:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is some convention that one compares types using isinstance: isinstance(self._filenames, six.string_types) (not sure if it's really called that 😄 )

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also fix the Python 2.7 errors (I think it got unicode instead of str there).

@@ -271,7 +284,13 @@ def refresh(self):
"""
keywords = '*' if self._all_keywords else self.keywords
# Re-load list of files
self._files = self._fits_files_in_directory()
if self._filenames:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems exactly like the block in __init__. To ease maintenance could you create a helper-method or check if this block could be put into _fits_files_in_directory?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MSeifert04 I added a helper method called _get_files(), do you like this name? xD

@MSeifert04
Copy link
Contributor

MSeifert04 commented Oct 14, 2016

For now, location only points to one directory, as you mentioned, but I can work to handle that case (better in a different PR?).

@mirca I think having the option to specify files in the location is already a great addition 👍

Let's see what @crawfordsm says, since he proposed the enhancement in #374.

Copy link
Member

@mwcraig mwcraig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, thanks @mirca!

@mirca
Copy link
Member Author

mirca commented Oct 17, 2016

@mwcraig thanks for your review :)

@crawfordsm
Copy link
Member

This looks really great and it is a good addition-- thanks @mirca !

I'm merging this pull request as I think it is useful on its own, but it would be good to still add the ability to add files from different locations so for the time being I'll leave the issue open.

@crawfordsm crawfordsm merged commit 84cf742 into astropy:master Oct 17, 2016
@mirca mirca deleted the issue374 branch October 17, 2016 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants