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

Add model separability test #6746

Merged
merged 4 commits into from Dec 21, 2017
Merged

Add model separability test #6746

merged 4 commits into from Dec 21, 2017

Conversation

nden
Copy link
Contributor

@nden nden commented Oct 16, 2017

Resolves #6013.

@nden nden added Affects-dev PRs and issues that do not impact an existing Astropy release Enhancement modeling Work in progress labels Oct 16, 2017
@nden nden added this to the v3.0.0 milestone Oct 16, 2017
@nden nden requested a review from pllim October 16, 2017 14:57
@astropy-bot
Copy link

astropy-bot bot commented Oct 16, 2017

Hi there @nden 👋 - thanks for the pull request! I'm just a friendly 🤖 that checks for issues related to the changelog and making sure that this pull request is milestoned and labeled correctly. This is mainly intended for the maintainers, so if you are not a maintainer you can ignore this, and a maintainer will let you know if any action is required on your part 😃.

Everything looks good from my point of view! 👍

If there are any issues with this message, please report them here.

@bsipocz bsipocz removed the Affects-dev PRs and issues that do not impact an existing Astropy release label Oct 16, 2017
@bsipocz
Copy link
Member

bsipocz commented Oct 16, 2017

(@nden - I've removed the "affects dev" label, as we supposed to use it for bugfixes that are only in the dev version, thus they don't need a changelog entry.
This one on the other hand seems to be an added feature, so the changelog entry is definitely required.

@nden
Copy link
Contributor Author

nden commented Oct 16, 2017

@bsipocz Oh, right. Thanks.

Copy link
Member

@pllim pllim left a comment

Choose a reason for hiding this comment

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

PEP8 test failed: astropy/modeling/tests/test_separable.py:108:1: W391 blank line at end of file

Also, I think some public-facing documentation is needed. For example:

  • I want to add a new model, how do I know if my new model is separable or not?
  • Why do I care if the models are separable or not? What happens when my compound model is separable or not?

return self._separable
else:
raise NotImplementedError(
'The "separable" property is not defined for '
Copy link
Member

Choose a reason for hiding this comment

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

Text needs to be indented more. Not sure why PEP8 check didn't complain about this one. Is there a tab in there that I can't see here?


Examples
--------
>>> is_separable(Shift(1) & Shift(2) | Scale(1) & Scale(2))
Copy link
Member

Choose a reason for hiding this comment

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

I have a feeling that this won't pass doctest due to missing imports.

Copy link
Member

Choose a reason for hiding this comment

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

I guess this is more of a question for @bsipocz -- How did this pass the doctest? I thought we test codes inside docstring, right? If so, is a docstring from hidden function (below) tested?

Copy link
Member

Choose a reason for hiding this comment

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

It seems that doctest has access all the imports of a given file, so has access to both is_separable as well as the models used here. I would still suggest to have full working examples in the example section, with doing all the necessary imports.

An array of shape (transform.n_outputs,) of boolean type
Each element represents the separablity of the corresponding output.


Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: Remove extra blank lines in docstring.

Copy link
Member

@pllim pllim left a comment

Choose a reason for hiding this comment

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

Left some more comments. Thank you for your patience.

It indicates whether the outputs are independent and is essential for computing the
separability of compound models using the :func:`~astropy.modeling.is_separable` function.
Having a separable compound model means that it can be decomposed into independent models,
whic in turn is useful in many applications.
Copy link
Member

Choose a reason for hiding this comment

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

whic -> which

separability of compound models using the :func:`~astropy.modeling.is_separable` function.
Having a separable compound model means that it can be decomposed into independent models,
whic in turn is useful in many applications.
Sometimes it is easier to define inverses using the independent parts than the
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure how this sentence relates to "separability," please clarify.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hope it's clearer now but let me know if not.

@@ -124,6 +124,10 @@ value of the `~astropy.modeling.Model.linear` attribute is ``False``. Linear
models should define the ``linear`` class attribute as ``True``. Because this
model is non-linear we can stick with the default.

Models which inherit from `~astropy.modeling.Fittable1DModel` have the
``Model._separable`` property set already to ``True``.
Other models shoul define this property.
Copy link
Member

Choose a reason for hiding this comment

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

  • shoul -> should

@@ -124,6 +124,10 @@ value of the `~astropy.modeling.Model.linear` attribute is ``False``. Linear
models should define the ``linear`` class attribute as ``True``. Because this
model is non-linear we can stick with the default.

Models which inherit from `~astropy.modeling.Fittable1DModel` have the
``Model._separable`` property set already to ``True``.
Copy link
Member

Choose a reason for hiding this comment

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

Cross-ref to the separability section in models.rst.

from astropy.modeling.models import Mapping
import pytest
import numpy as np
from numpy.testing import utils
Copy link
Member

Choose a reason for hiding this comment

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

from numpy.testing import assert_allclose works for me. Is there a reason utils needs to be imported at all? I am afraid this might be confusing down the road because there is also utils in astropy itself.


"""

from astropy.modeling import models
Copy link
Member

Choose a reason for hiding this comment

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

Why is this using absolute import even though you have relative import below? Why not just have all astropy imports be relative imports here?


Examples
--------
>>> is_separable(Shift(1) & Shift(2) | Scale(1) & Scale(2))
Copy link
Member

Choose a reason for hiding this comment

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

I guess this is more of a question for @bsipocz -- How did this pass the doctest? I thought we test codes inside docstring, right? If so, is a docstring from hidden function (below) tested?


from .core import Model, _CompoundModel, ModelDefinitionError
from .mappings import Mapping
from .models import Shift, Scale, Rotation2D, Polynomial2D
Copy link
Member

Choose a reason for hiding this comment

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

Looks like there are only used in examples in the docstrings. Would it be possible to rework those examples to contain all the necessary imports there, otherwise none of those would work as copy pasted for the users.

@nden
Copy link
Contributor Author

nden commented Nov 8, 2017

@bsipocz , @pllim I've addressed your comments, hopefully things are clearer now. Thanks for looking over the PR.

@nden nden changed the title WIP: add separability test Add model separability test Nov 8, 2017
Copy link
Member

@pllim pllim left a comment

Choose a reason for hiding this comment

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

Just one more nitpick. Otherwise LGTM. Thanks!

"""

from .. import models
from ..models import Mapping
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: Group all the local imports together to make it easier for the future. (I am starting to sound like flake8 😱 )

CHANGES.rst Outdated
@@ -54,6 +54,9 @@ astropy.modeling

- A ``deepcopy()`` method was added to models. [#6515]

- Added ``is_separable`` function to modeling totest the
Copy link
Member

Choose a reason for hiding this comment

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

to test

Copy link
Member

Choose a reason for hiding this comment

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

Also should this say 'separable property' instead of 'is_separable function'?

Copy link
Member

Choose a reason for hiding this comment

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

Now I am confused. I thought is_separable is a function that is defined in the new separable module?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is true that this PR adds also Model.separable property which is only of interest when one writes a new model. The important functionality from a user point is the function is_separable. For completeness I added the separable property to the change log as well.

than the entire model.
In other cases, tools using `GWCS <https://gwcs.readthedocs.io/en/latest/>`_,
can be more flexible and take advantage of separable spectral and spatial transforms.

Copy link
Member

Choose a reason for hiding this comment

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

Could you clarify/demonstrate how one would actually decompose a model?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@astrofrog The test tells whether the outputs are independent, it doesn't provide a mechanism for decomposing models. For decomposing you may need other information. This does as much as the example in the is_separable function.
Do you have a specific use case in mind? Or do you find this explanation misleading or unclear?

@pllim
Copy link
Member

pllim commented Dec 12, 2017

Need to rebase to resolve conflict.

@astrofrog , do you think this is okay to merge after rebase?

@pllim pllim added this to Needs decision in 3.0 Feature Planning Dec 13, 2017
@nden
Copy link
Contributor Author

nden commented Dec 14, 2017

rebased and squashed

--------
>>> from astropy.modeling.models import Shift, Rotation2D
>>> _coord_matrix(Shift(1), 'left', 2)
array([[ 1.],
Copy link
Member

Choose a reason for hiding this comment

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

You need to unindent so doctest can pass. FYI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Numpy dev and prerelease report arrays without a space before the values:
arrays([[1], vs array([[ 1], Any ideas how to get around this?

@nden
Copy link
Contributor Author

nden commented Dec 15, 2017

This is a well aged PR that I would like to get into v 3.0 to support further work on gwcs. I am planning to merge tonight, let me know if anyone needs more time to look at it.

@nden nden merged commit 9126c92 into astropy:master Dec 21, 2017
@nden nden deleted the separable branch December 27, 2018 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
3.0 Feature Planning
Needs decision
Development

Successfully merging this pull request may close these issues.

None yet

4 participants