Skip to content

Merge imageutils functionality into astropy core - #3201

Merged
astrofrog merged 109 commits into
astropy:masterfrom
astrofrog:astropy-image
Dec 20, 2014
Merged

astrofrog merged 109 commits into
astropy:masterfrom
astrofrog:astropy-image

Conversation

@astrofrog

Copy link
Copy Markdown
Member

This is a WIP, but is the PR to merge imageutils into the Astropy core package.

Notes:

  • I have attempted to preserve the history but removed code that simply affected affiliated package infrastructure code.
  • The branches and merge history within imageutils is lost since I rebased this, but I think this is actually less confusing this way. We just have a linear history for the package.
  • I also updated issue numbers in the commit messages to always include astropy/imageutils
  • This does not include lacosmicx which can be added separately once the licensing is sorted out. Doing that separately will make reviewing this PR easier anyway
  • It is marked as critical because this was assessed as 1.0-critical (not a critical bug though)

This is not ready for review or merging, and still needs updates to the docs, tests to pass, etc.

cc @larrybradley @cdeil @adonath @eteq @hamogu @ejeschke

@astrofrog
astrofrog force-pushed the astropy-image branch 3 times, most recently from 2b9ec49 to cbbec4d Compare December 14, 2014 14:34
@astrofrog astrofrog added this to the v1.0.0 milestone Dec 14, 2014
@astrofrog astrofrog added the 🔥 Critical label Dec 14, 2014
@astrofrog astrofrog self-assigned this Dec 14, 2014
@astrofrog
astrofrog force-pushed the astropy-image branch 3 times, most recently from e7fcb3e to b422aaa Compare December 15, 2014 08:41
@astrofrog

Copy link
Copy Markdown
Member Author

@cdeil @eteq - given that the normalization stuff applies to arrays of any dimension, should it be its own top-level package? What about other parts of this PR?

Here are remaining to-dos for this PR:

  • decide of final location of the features here (e.g. should normalization be a top-level package, and is anything else more general than just image?)
  • make sure all code here is documented, I think only the normalization stuff is properly documented
  • make sure test coverage is adequate

Comment thread astropy/image/array_utils.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe this function could have a more specific name, like get_overlap or get_overlap_slices? (or just overlap_slices, where the get_ is implied?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed

@embray

embray commented Dec 15, 2014

Copy link
Copy Markdown
Member

I realize this is a WIP, but adding some comments anyways.... :D

@astrofrog

Copy link
Copy Markdown
Member Author

@embray - thanks, this is helpful! The contents are actually fine for review, it's more questions to do with organization and docs that are WIP :)

Comment thread astropy/image/normalization/interval.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess this should add an abstractmethod for get_limits, or instead make an abstractproperty called just limits.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'd like to leave get_limits because it is something that is computed on-the-fly and may take a non-trivial time in some cases, but happy to change if more people are in favor of a property.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I don't think that's really the way to think of properties, IMO. This is debatable though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

On second thought, I misinterpreted what this is doing, and that it could return values dependent on the data. In that case this is fine.

@mhvk

mhvk commented Dec 15, 2014

Copy link
Copy Markdown
Contributor

Just saw this now: I do agree that the display stuff is not specific to images and thus should be in a separate module. Since it is somewhat specifc to matplotlib, is it perhaps time to make a display or plot submodule? For the resampling, that really is not all that specific to images either (one could resample 1-d spectra). Doesn't it make more sense as part of nddata?

Bit higher-level: I was not part of the telecon, but I don't understand the rush to add this as a new package. Do we really want to offer long-term support for something this new? It seems ideal to start working on this after 1.0 is released.

@astrofrog

Copy link
Copy Markdown
Member Author

@mhvk - sorry, I should clarify, most of the normalization code is matplotlib-agnostic, and can be used with n-dimensional arrays. It is true that in practice it will be used with images though.

Also, we aren't calling all features in 1.0 "LTS" so it's fine to put this in 1.0. Several packages are depending on this functionality, so it's good to get it in the core and it will mature very fast there. A lot of this is intended for affiliated packages, rather than to be used directly by users.

@astrofrog

Copy link
Copy Markdown
Member Author

Another thing to bear in mind in the discussion of where this should all go. convolution used to be in astropy.nddata.convolution and we decided to give it more visibility by moving it to the top-level. I'm not saying everything should be in the top level, but just something to bear in mind.

Comment thread astropy/image/normalization/interval.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There's no reason to put raise NotImplementedError in an abstractmethod (since it won't be called in the first place if it's not implemented). Better is to just put a docstring and leave the rest empty (in fact, subclasses can still, in principle, call super().get_limits(), which in this case would result in raising NotImplementedError even though it is implemented).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed

@astrofrog

Copy link
Copy Markdown
Member Author

Thinking about this a bit more, maybe normalization does belong where it is here - most of the time it's going to be used for images. Some of the array/index utilities could indeed be moved to e.g. astropy.utils.arrays though.

@larrybradley @cdeil @adonath @eteq @hamogu - what do you think?

@mhvk - just to clarify about your comment on starting to work on this after 1.0, I should say that this has already been worked on for a few months outside of the core, so it's not like it's all untested code. The difficult part is just figuring out where it should go in the core.

If we don't reach an agreement on where things should go in the core, then we have two options:

  • Merge it in as astropy._image so that a few affiliated packages can still start using it from there
  • Defer to 1.1

@cdeil

cdeil commented Dec 16, 2014

Copy link
Copy Markdown
Member

I would prefer to keep array utils in astropy.image or astropy.nddata and not start another namespace astropy.utils.arrays. Arrays are images and thus it's OK to have array utils functions in astropy.image.

I'm also +1 to get this into astropy now ... for the reasons that @astrofrog said: these functions are used (or will be as soon as they land) by several affiliated packages (photutils, ccdproc, gammapy, ...) and the name imageutils is taken on PyPI, so we'd have to release under a different name than the repo name and ... we create extra maintenance work for ourselves.
But @mhvk, your points are very valid ... we will have some pain in the coming months if we want to change something in astropy.image that would break code in the affiliated packages. If absolutely needed they can keep bundling a stable copy of imageutils in extern like photutils is doing at the moment.

@mhvk

mhvk commented Dec 16, 2014

Copy link
Copy Markdown
Contributor

Agreed that we don't need a new namespace for the array manipulation routines. I think those are not 2-D specific (even though many are written as such), and hence in my opinion are more natural in nddata as low-level n-D array manipulation tools. But it depends a little what in the end image is meant to be: is it mostly for things like mosaicing, drizzling, etc.?

The stretch and normalization routines are 2-D specific, but even more they are for displaying arrays, not for manipulating them, and the classes are also seem specific to matplotlib. It does seem that so far in astropy we have separated analysis from display (to the extent we hardly have anything for display!) and I quite like that. I think I'd rather have a new display namespace.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hey ... it takes data and mask ... why not @supports_nddata?
(I'm not seriously suggesting to do this by tomorrow ... but there's a few functions in this PR that might be candidates for a future PR.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Definitely! :)

@astrofrog

Copy link
Copy Markdown
Member Author

@cdeil - I've added a short paragraph about fits2bitmap

@astrofrog

Copy link
Copy Markdown
Member Author

@cdeil - thanks for the detailed review! I think I managed to keep up. One unresolved issue is related to the script but I think that could be a more general bug and may be better addressed in a separate issue.

Does anyone else want to review this before tomorrow evening? :)

@mwcraig

mwcraig commented Dec 19, 2014

Copy link
Copy Markdown
Member

@astrofrog -- I'll try to give this a look Friday

@cdeil

cdeil commented Dec 19, 2014

Copy link
Copy Markdown
Member

This looks great to me, thanks @astrofrog !
👍 to merge from my side.

Comment thread scripts/fits2bitmap Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

-> astropy.visualization.scripts.fits2bitmap

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ahh, thanks! @cdeil, this explains the weird behavior with the script :)

@astrofrog

Copy link
Copy Markdown
Member Author

@mhvk - just for info the transforms now use the inverse property.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These imports should be moved inside the function to minimize the chances of at-import ``ImportError`s

@eteq

eteq commented Dec 19, 2014

Copy link
Copy Markdown
Member

I think I'm happy with this aside from the one comment above.

I'm not a fan of the fact that this now introduces a module that triggers an error on import if you don't have an optional dep (mpl_normalize.py). Up to this point we've strictly kept to the policy that this isn't allowed, because anything that go through all the modules will now fail (i.e. sphinx if matplotlib is missing). But I realize in this case that we're subclassing, so you'd have to put the entire module in a try, which is pretty awkward. So we'll see if we encounter problems/complaints in the beta with this once people give it a spin...

@astrofrog

Copy link
Copy Markdown
Member Author

@eteq - ok, I addressed your comment in 67ddbc8 - now ImageNormalize is importable, though cannot be instantiated, if Matplotlib is not present.

@astrofrog

Copy link
Copy Markdown
Member Author

This can be merged once Travis and AppVeyor pass

@astrofrog

Copy link
Copy Markdown
Member Author

Checked over this again and it's good to go (and no objections above) so merging!

astrofrog added a commit that referenced this pull request Dec 20, 2014
Merge imageutils functionality into astropy core
@astrofrog
astrofrog merged commit 426f0d4 into astropy:master Dec 20, 2014

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍 This was going to be my suggestion but looks like you're way ahead on that ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.