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

query_disc bug #229

Closed
bwinkel opened this issue Mar 16, 2015 · 24 comments
Closed

query_disc bug #229

bwinkel opened this issue Mar 16, 2015 · 24 comments
Assignees

Comments

@bwinkel
Copy link

bwinkel commented Mar 16, 2015

Under rare circumstances query_disc produces wrong results. This seems to happen, when the
sphere edge "touches" the equator (but not always).

import healpy as hp
import numpy as np
import matplotlib.pyplot as plt

radius = 0.1
hpxidx = hp.query_disc(256, hp.ang2vec(np.pi/2 - radius, np.pi), radius, nest=False)
theta, phi = hp.pix2ang(256, hpxidx, nest=False)

plt.plot(phi, np.pi/2 - theta, 'x')
plt.xlabel(r'$\phi\,[\mathrm{rad}]$', fontsize=14)
plt.ylabel(r'$\pi/2 - \theta\,[\mathrm{rad}]$', fontsize=14)
plt.show()

healpy_querydisc_bug

@mreineck
Copy link
Member

This is most likely a bug in the C++ library. I'll try to come up with a fix soon!

@mreineck
Copy link
Member

I think I have a fix. Is it sufficient if I commit this to the Healpix SVN trunk, or do you need it on a specific branch as well, Andrea?

@zonca
Copy link
Member

zonca commented Mar 17, 2015

Trunk is fine
On Mar 17, 2015 6:40 AM, "mreineck" notifications@github.com wrote:

I think I have a fix. Is it sufficient if I commit this to the Healpix SVN
trunk, or do you need it on a specific branch as well, Andrea?


Reply to this email directly or view it on GitHub
#229 (comment).

@mreineck
Copy link
Member

Ok, it's there already.

@lpsinger
Copy link
Member

@mreineck, would you please explain what you changed in r683?

@mreineck
Copy link
Member

Very hard to describe ... the original code always assumed that the whole ring that's currently being processed would lie inside the queried disk if no intersection points could be determined between ring and disk. In the case of a non-inclusive query this could be incorrect, and "no intersection" could in fact mean "ring lies completely outside the disk". I tried to address that problem.

@lpsinger
Copy link
Member

Interesting. Are you going to add a test case to healpix-cxx?

@mreineck
Copy link
Member

I'm thinking about adding the test case above to hpxtest; but a positive result will not necessarily indicate that the algorithm works as expected - it could also just happen to work correctly because of numerical noise. If I can think of a more stringent test, I'll use that!

@lpsinger
Copy link
Member

I don't think it worked... I checked out the latest code from trunk, rebuilt, and ran @bwinkel's test script. The result is attached below. What am I even looking at here?

example

@bwinkel
Copy link
Author

bwinkel commented Mar 19, 2015

Looks fine to me. It's the result of the query_disc plotted in lon/lat coordinates (radians).

@lpsinger
Copy link
Member

Oh! I just realized that those are crosses marking points in a scatter plot; I had thought that they were thin stripes across a HEALPix image.

@mreineck, when is your next opportunity for a healpix-cxx release? It would be great to get this bug fix into both the standalone packages and the source that we are bundling with healpy.

@mreineck
Copy link
Member

Sorry, that took some time ...
I can prepare a new autotools-generated tarball, and upload it to SourceForge. The small problem with this release is that it breaks backwards compatibility not with respect to the library, but with respect to the delivered binaries: the original "alice" code is gone and will be replaced by "alice3". Should this be reflected somehow in the version number? If yes, this might start another political discussion ...

@zonca
Copy link
Member

zonca commented Mar 23, 2015

ok, I updated the healpix git mirror:

healpy/healpixmirror@0422b3a

should I update the healpy git submodule or should we wait for a new
healpix release?

On Mon, Mar 23, 2015 at 3:56 AM, mreineck notifications@github.com wrote:

Sorry, that took some time ...
I can prepare a new autotools-generated tarball, and upload it to
SourceForge. The small problem with this release is that it breaks
backwards compatibility not with respect to the library, but with respect
to the delivered binaries: the original "alice" code is gone and will be
replaced by "alice3". Should this be reflected somehow in the version
number? If yes, this might start another political discussion ...


Reply to this email directly or view it on GitHub
#229 (comment).

@lpsinger
Copy link
Member

The small problem with this release is that it breaks backwards compatibility not with respect to the library, but with respect to the delivered binaries: the original "alice" code is gone and will be replaced by "alice3". Should this be reflected somehow in the version number?

The Makefile.am file will have to be updated to create the new executable.

The new release should have a new version number, but it's up to you which part of the version number should be incremented.

@lpsinger
Copy link
Member

should I update the healpy git submodule or should we wait for a new
healpix release?

Might as well coordinate the changes and simultaneously release new versions of healpix-cxx and healpy.

@lpsinger
Copy link
Member

@mreineck, the last few lines of output from hpxtest are:

checking issue #229
checking issue #229
checking query_disc() (basetype: int)
  PROBLEM: RING pixel sets inconsistent
checking query_disc() (basetype: long)
  PROBLEM: RING pixel sets inconsistent
  PROBLEM: RING pixel sets inconsistent
  PROBLEM: RING pixel sets inconsistent
checking query_polygon() (basetype: int)
checking query_polygon() (basetype: long)

Is this related, and what does it mean? Does this constitute a unit test failure? If so, why doesn't hpxtest return a nonzero exit status?

@mreineck
Copy link
Member

It's not (really) a bug and unrelated. Hpxtest isn't really a set of unit tests either ... it reports problems and errors on stdout and probably shouldn't run as part of "make distcheck" before it has been properly adjusted. Unfortunately I haven't found time for this so far.

@lpsinger
Copy link
Member

It's not (really) a bug and unrelated.

Great!

Hpxtest isn't really a set of unit tests either ... it reports problems and errors on stdout and probably shouldn't run as part of "make distcheck" before it has been properly adjusted.

Just testing that it runs without crashing is helpful; we found some issues with OpenMP on extremely esoteric microcontrollers this way. I think we should leave it in the make check target for now.

@mreineck
Copy link
Member

I just made the necessary change ... future releases of hpxtest will return an error status if a regression is detected.

@lpsinger
Copy link
Member

Thank you, @mreineck! Can we add a C++ implementation of @bwinkel's test case too? Here is a quick translation (sorry for my rusty C++):

template<typename I>void check_query_disc_issue_229()
  {
  // check for regression of https://github.com/healpy/healpy/issues/229
  cout << "checking query_disc() healpy/healpy#229 " << bname<I>() << endl;
  int order = 8;
  double radius = 0.1;
  T_Healpix_Base<I> rbase (order,RING);
  rangeset<I> pixset;
  pointing ptg(M_PI_2 - radius, M_PI);
  vec3 p = ptg.to_vec3();
  rbase.query_disc(ptg,radius,pixset);
  vector<I> ipixes = pixset.toVector();
  for (int i = 0; i < ipixes.size(); i ++)
    {
    I ipix = ipixes[i];
    vec3 q = rbase.pix2vec(ipix);
    if (dotprod(p, q) < cos(radius))
      FAIL(cout << "  PROBLEM: regression of https://github.com/healpy/healpy/issues/229 at pixel " << ipix << endl);
    }
  }

One question:

#define FAIL(a) {a; if (++errcount>100) planck_fail("unit test errors");}

Does this mean that the tests fail only if there are 100 or more failures?

@mreineck
Copy link
Member

The tst case is already in: see check_issue_229()

Concerning the FAIL: if more than 100 errors have accumulated, the code stops immediately. Otherwise the tests will run to the end, but then an error will be returned if (errcount>0). This is mostly for the benefit of people who run hpxtest interactively.

@lpsinger
Copy link
Member

Awesome! This bug is most certainly dead now. @zonca, can we close this?

@zonca
Copy link
Member

zonca commented Mar 31, 2015

sure, but are we going to have an Healpix release?

@zonca zonca closed this as completed Mar 31, 2015
@lpsinger
Copy link
Member

sure, but are we going to have an Healpix release?

Yes please!

mamash pushed a commit to TritonDataCenter/pkgsrc-wip that referenced this issue May 30, 2015
    Renamed get_neighbours to get_interp_weights <healpy/healpy#240>
    Updated HEALPix C++ to fix bug in query_disc healpy/healpy#229>

Release 1.8.4, 16 Jan 2015

    Fixed another permission issue on install-sh

Release 1.8.3, 16 Jan 2015

    Fix permission issue in the release tarball <healpy/healpy#220>

Release 1.8.2, 13 Jan 2015

    Several fixes in the build process
    Support for astropy.fits <healpy/healpy#213>

Release 1.8.1, 22 Jun 2014

    Added common.pxd to source tarball
    Check that nside is less than 2^30 <healpy/healpy#193>

Release 1.8.0, 21 Jun 2014

    Python 3 support <healpy/healpy#186>
    Fixed bug in get_interpol_ring: <healpy/healpy#189>
    Performance improvements in _query_disc.pyx: <healpy/healpy#184>

Release 1.7.4, 26 Feb 2014

    Fix bug for MAC OS X build <healpy/healpy#159>

Release 1.7.3, 28 Jan 2014

    Minor cleanup for submitting debian package

Release 1.7.2, 27 Jan 2014

    now package does not require autotools, fixes #155

Release 1.7.1, 23 Jan 2014

    bugfix for Anaconda/Canopy on MAC OSX #152, #153
    fixed packaging issue #154

Release 1.7.0, 14 Jan 2014

    rewritten spherical armonics unit tests, now it uses low res maps included in the repository
    fix in HEALPix C++ build flags allows easier install on MAC-OSX and other python environments (e.g. anaconda)
    orthview: orthografic projection
    fixed bug in monopole removal in anafast

Release 1.6.3, 26 Aug 2013:

    updated C++ sources to 3.11
    verbose=True default for most functions

Release 1.6.2, 11 Jun 2013:

    ez_setup, switch from distribute to the new setuptools

Release 1.6.0, 15th March 2013:

    support for NSIDE>8192, this broke compatibility with 32bit systems
    using the new autotools based build system of healpix_cxx
    pkg-config based install for cfitsio and healpix_cxx
    common definition file for cython modules
    test build script
    new matplotlib based mollview in healpy.newvisufunc

Release 1.5.0, 16th January 2013:

    Healpix C++ sources and cython compiled files removed from the repository,

they are however added for the release tarballs * Added back support for CFITSIO_EXT_INC and CFITSIO_EXT_LIB, but with same definition of HealPix * gauss_beam: gaussian beam transfer function

Release 1.4.1, 5th November 2012:

    Removed support for CFITSIO_EXT_INC and CFITSIO_EXT_LIB
    Support for linking with libcfitsio.so or libcfitsio.dyn

Release 1.4, 4th September 2012:

    Support for building using an external HealPix library, by Leo Singer
    fixes on masked array maps

Release 1.3, 21th August 2012:

    all functions covered with unit testing or doctests
    rewrote setup.py using distutils, by Leo Singer
    all functions accept and return masked arrays created with hp.ma
    read_cl and write_cl support polarization
    matplotlib imported only after first plotting function is called
0-wiz-0 pushed a commit to NetBSD/pkgsrc-wip that referenced this issue Jan 30, 2016
Remove C++ 11 features <healpy/healpy#297>
Streamlined setup.py <healpy/healpy#298>
Plotting fixes for Python 3 <healpy/healpy#303>, <healpy/healpy#304>
Numpy 1.10 fix <healpy/healpy#305>
Release 1.9.0, 17 Sep 2015

updated healpix CXX to 786 (trunk) <healpy/healpy#280>
drop support for Python 2.6 <healpy/healpy#268>
option to read all fields with read_map <healpy/healpy#258>
write_map and read_map support for partial sky maps <healpy/healpy#254>
Allow read_map to also take an HDUList or HDU instance <healpy/healpy#249>
Release 1.8.6, 23 Apr 2015

Renamed get_neighbours to get_interp_weights <healpy/healpy#240>
Updated HEALPix C++ to fix bug in query_disc <healpy/healpy#229>
Release 1.8.4, 16 Jan 2015

Fixed another permission issue on install-sh
Release 1.8.3, 16 Jan 2015

Fix permission issue in the release tarball <healpy/healpy#220>
Release 1.8.2, 13 Jan 2015

Several fixes in the build process
Support for astropy.fits <healpy/healpy#213>
Release 1.8.1, 22 Jun 2014

Added common.pxd to source tarball
Check that nside is less than 2^30 <healpy/healpy#193>
Release 1.8.0, 21 Jun 2014

Python 3 support <healpy/healpy#186>
Fixed bug in get_interpol_ring: <healpy/healpy#189>
Performance improvements in _query_disc.pyx: <healpy/healpy#184>
Release 1.7.4, 26 Feb 2014

Fix bug for MAC OS X build <healpy/healpy#159>
Release 1.7.3, 28 Jan 2014

Minor cleanup for submitting debian package
Release 1.7.2, 27 Jan 2014

now package does not require autotools, fixes #155
Release 1.7.1, 23 Jan 2014

bugfix for Anaconda/Canopy on MAC OSX #152, #153
fixed packaging issue #154
Release 1.7.0, 14 Jan 2014

rewritten spherical armonics unit tests, now it uses low res maps included in the repository
fix in HEALPix C++ build flags allows easier install on MAC-OSX and other python environments (e.g. anaconda)
orthview: orthografic projection
fixed bug in monopole removal in anafast
Release 1.6.3, 26 Aug 2013:

updated C++ sources to 3.11
verbose=True default for most functions
Release 1.6.2, 11 Jun 2013:

ez_setup, switch from distribute to the new setuptools
Release 1.6.0, 15th March 2013:

support for NSIDE>8192, this broke compatibility with 32bit systems
using the new autotools based build system of healpix_cxx
pkg-config based install for cfitsio and healpix_cxx
common definition file for cython modules
test build script
new matplotlib based mollview in healpy.newvisufunc
Release 1.5.0, 16th January 2013:

Healpix C++ sources and cython compiled files removed from the repository,
they are however added for the release tarballs * Added back support for CFITSIO_EXT_INC and CFITSIO_EXT_LIB, but with same definition of HealPix * gauss_beam: gaussian beam transfer function

Release 1.4.1, 5th November 2012:

Removed support for CFITSIO_EXT_INC and CFITSIO_EXT_LIB
Support for linking with libcfitsio.so or libcfitsio.dyn
Release 1.4, 4th September 2012:

Support for building using an external HealPix library, by Leo Singer
fixes on masked array maps
Release 1.3, 21th August 2012:

all functions covered with unit testing or doctests
rewrote setup.py using distutils, by Leo Singer
all functions accept and return masked arrays created with hp.ma
read_cl and write_cl support polarization
matplotlib imported only after first plotting function is called
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants