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
Conversation
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. |
(@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. |
@bsipocz Oh, right. Thanks. |
There was a problem hiding this 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?
astropy/modeling/core.py
Outdated
return self._separable | ||
else: | ||
raise NotImplementedError( | ||
'The "separable" property is not defined for ' |
There was a problem hiding this comment.
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?
astropy/modeling/separable.py
Outdated
|
||
Examples | ||
-------- | ||
>>> is_separable(Shift(1) & Shift(2) | Scale(1) & Scale(2)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
astropy/modeling/separable.py
Outdated
An array of shape (transform.n_outputs,) of boolean type | ||
Each element represents the separablity of the corresponding output. | ||
|
||
|
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
docs/modeling/models.rst
Outdated
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whic -> which
docs/modeling/models.rst
Outdated
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
docs/modeling/new.rst
Outdated
@@ -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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- shoul -> should
docs/modeling/new.rst
Outdated
@@ -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``. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
astropy/modeling/separable.py
Outdated
|
||
Examples | ||
-------- | ||
>>> is_separable(Shift(1) & Shift(2) | Scale(1) & Scale(2)) |
There was a problem hiding this comment.
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?
astropy/modeling/separable.py
Outdated
|
||
from .core import Model, _CompoundModel, ModelDefinitionError | ||
from .mappings import Mapping | ||
from .models import Shift, Scale, Rotation2D, Polynomial2D |
There was a problem hiding this comment.
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.
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to test
There was a problem hiding this comment.
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'?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
Need to rebase to resolve conflict. @astrofrog , do you think this is okay to merge after rebase? |
rebased and squashed |
astropy/modeling/separable.py
Outdated
-------- | ||
>>> from astropy.modeling.models import Shift, Rotation2D | ||
>>> _coord_matrix(Shift(1), 'left', 2) | ||
array([[ 1.], |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
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. |
Resolves #6013.