Skip to content

Conversation

@saimn
Copy link
Contributor

@saimn saimn commented Apr 12, 2016

Ref #4773
Currently this PR just add the zscale module from Numdisplay (BSD licensed), and provide an "interval" wrapper. Then a few questions before going on:

  • The zscale implementation works only for 2D images. It seems easy to adapt, but then there may other way to improve / speedup this code. Do we want to stick with the original module, or just use it as a basis and modify it if it is useful ? As Numdisplay is not really actively developed, I think the second option is fine, but feedback is welcome before spending more time on this ;)
  • What is the good way to mention the license of this external code ? Should I add a licenses/NUMDISPLAY_LICENSE.rst ?

@pllim
Copy link
Member

pllim commented Apr 13, 2016

👍 to modifying.

As for license, it is the same as PyFITS license, since it also came out of STScI, which is bound to AURA.

KREJ = 2.5
MAX_ITERATIONS = 5

def zscale (image, nsamples=1000, contrast=0.25, bpmask=None, zmask=None):
Copy link
Member

Choose a reason for hiding this comment

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

Unless you can find a way to use bpmask and zmask, we can just remove them since they are not used (as stated in the docstring). I'll go through this in more detail when I get a chance.

@pllim
Copy link
Member

pllim commented Apr 13, 2016

c/c @larrybradley in case you are interested.

@pllim
Copy link
Member

pllim commented Apr 13, 2016

Also, @parejkoj mentioned this implementation by @ctslater.

interval = ZScaleInterval()
vmin, vmax = interval.get_limits(self.data)
np.testing.assert_allclose(vmin, -20.)
np.testing.assert_allclose(vmax, +60.)
Copy link
Member

Choose a reason for hiding this comment

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

Is the + necessary?

@saimn
Copy link
Contributor Author

saimn commented Apr 13, 2016

@pllim : Currently the zscale module is just a copy/paste from Numdisplay, I just added the docstring with the license. Agreed there is a lot of things to change in it to make it follow Astropy's coding rules, but that's was my point before starting hacking it ;).

Also the implementation from https://github.com/parejkoj/astropy/blob/luptonRGB/astropy/visualization/lupton_rgb.py#L55 already looks much simpler, so we may probably want to use that instead ? How should we proceed for this, @parejkoj @ctslater ? If you want to submit this as a new PR, I can close this one.

@pllim
Copy link
Member

pllim commented Apr 13, 2016

Yeah, the other one looks simpler, but are they interchangable? I am neutral either way.

If you do want to press ahead with this one and worry about performance, I would suggest profiling it first before attempting to optimize it.

@saimn
Copy link
Contributor Author

saimn commented Apr 13, 2016

Ok, I went through the original code and simplified as much as I can. The result is much simpler and easier to understand. It is more similar to the implementation from https://github.com/parejkoj/astropy/blob/luptonRGB/astropy/visualization/lupton_rgb.py#L55, except that it iteratively fits and masks the pixels with extreme values.
I think it also address most of your remarks @pllim. We still have 4 global variables, and I think if we could add these as optional parameters to zscale.zscale (and make this function public, importing it in astropy.visualization, as a complement to ZScaleInterval).

@astrofrog astrofrog added this to the v1.2.0 milestone Apr 14, 2016
@astrofrog
Copy link
Member

@saimn - thanks for working on this! Note that it will need an entry in the changelog for 1.2

@pllim
Copy link
Member

pllim commented Apr 14, 2016

Travis CI failure mentioned something wrong with np.polyfit call. Also if it stills complains about coverage, mark the untested blocks with # pragma: no cover to exclude them from coverage stats.

Sphinx also issued warnings but perhaps a rebase against master would fix those? Not sure.

@pllim
Copy link
Member

pllim commented Apr 14, 2016

When, this is all finalized, it is desirable to squash all the intermediate commits into one before merging.

@bsipocz
Copy link
Member

bsipocz commented Apr 14, 2016

The sphinx build only needs a restart on travis from someone who can.

@saimn
Copy link
Contributor Author

saimn commented Apr 15, 2016

Oh, it seems np.polyfit doesn't have the weight keyword in Numpy 1.6 ... Is it worth considering dropping support for this version ? ;-) (Numpy 1.11 was released recently, so 1.6 is quite old). Otherwise can I just throw an error for Numpy 1.6 in the zscale module ?

About the coverage: it seems the latest build failed for some network reason. The previous build seems fine (https://coveralls.io/builds/5778482) but I am always confused by coveralls' ui: it always display unrelated files, and I cannot find how to see the coverage by line (https://coveralls.io/builds/5778482/source?filename=astropy%2Fvisualization%2Finterval.py is empty, the new zscale module does not appear ...). @pllim Could you tell me how you saw the coverage ?

@saimn
Copy link
Contributor Author

saimn commented May 4, 2016

Rebased on master (and #4784) to get rid of Numpy 1.6 tests !

@pllim
Copy link
Member

pllim commented May 4, 2016

@saimn , how about adding a mention of this in the documentation?

@saimn
Copy link
Contributor Author

saimn commented May 4, 2016

@pllim - Good point, added it.

``clip`` argument is provided to control the behavior of the normalization when
values fall outside the limits::
:class:`~astropy.visualization.PercentileInterval`,
:class:`~astropy.visualization.AsymmetricPercentileInterval` and
Copy link
Member

Choose a reason for hiding this comment

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

Nitpicking: Add an Oxford comma.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pllim - Done, didn't know this Oxford comma :)

@astrofrog
Copy link
Member

astrofrog commented May 10, 2016

@saimn - this looks great, and I can go ahead and merge it, but first, could you change:

# Licensed under a 3-clause BSD style license - see NUMDISPLAY_LICENSE.rst

to

# Licensed under a 3-clause BSD style license - see LICENSE.rst

That is, we are actually relicensing this file (and in the docstring below you can add a mention of NUMDISPLAY_LICENSE.rst if you like)

@saimn
Copy link
Contributor Author

saimn commented May 10, 2016

@astrofrog - ok, done !

@astrofrog
Copy link
Member

@saimn - one quick question: how does this deal with NaN values?

@saimn
Copy link
Contributor Author

saimn commented May 10, 2016

@astrofrog - Oh, good point, and it doesn't deal with ... I have added a commit to filter the invalid values.

@bsipocz
Copy link
Member

bsipocz commented May 10, 2016

@saimn - since it was a regression, maybe it's worth adding a test with NaNs.

@saimn
Copy link
Contributor Author

saimn commented May 10, 2016

@bsipocz - yes indeed, seems reasonable, I will add a NaN in the test case.

@astrofrog
Copy link
Member

This looks good - thanks @saimn!

@astrofrog astrofrog merged commit d001500 into astropy:master May 11, 2016
@saimn
Copy link
Contributor Author

saimn commented May 11, 2016

Thanks :)

@saimn saimn deleted the zscale branch May 11, 2016 13:08
@saimn saimn mentioned this pull request Nov 28, 2016
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.

7 participants