Skip to content

Commit

Permalink
fix bug in unrelated-associations correction when using elliptical er…
Browse files Browse the repository at this point in the history
…rors. added test
  • Loading branch information
JohannesBuchner committed Jul 9, 2020
1 parent 1eba788 commit d66fe43
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 12 deletions.
12 changes: 7 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,13 @@ script:
# test elliptical errors
- cd tests/elltest/
- nway.py --radius=10.0 randomcatX.fits :pos_err randomcatO.fits 0.1 --out=random_circtest.fits --min-prob=0.01
- nway-explain.py random_circtest.fits 95 || exit 1
- nway.py --radius=10.0 randomcatX.fits :a:b randomcatO.fits 0.1 --out=random_asymtest.fits --min-prob=0.01 || exit 1
- nway-explain.py random_asymtest.fits 95 || exit 1
- nway.py --radius=10.0 randomcatX.fits :a:b:phi randomcatO.fits 0.1 --out=random_elltest.fits --min-prob=0.01 || exit 1
- nway-explain.py random_elltest.fits 95 || exit 1
- nway-explain.py random_circtest.fits 95
- nway.py --radius=10.0 randomcatX.fits :a:b randomcatO.fits 0.1 --out=random_asymtest.fits --min-prob=0.01
- nway-explain.py random_asymtest.fits 95
- nway.py --radius=10.0 randomcatX.fits :a:b:phi randomcatO.fits 0.1 --out=random_elltest.fits --min-prob=0.01
- nway-explain.py random_elltest.fits 95
- nway.py --radius=10.0 randomcatX.fits :a:b:phi randomcatR.fits :a:b:phi randomcatO.fits 0.1 --out=random3_elltest.fits --min-prob=0.01
- nway-explain.py random3_elltest.fits 95

- cd -
- python nway-apitest.py
Expand Down
3 changes: 2 additions & 1 deletion nway-explain.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ def converr(err):
pa_errs = numpy.array([pa_err for ra, dec, ra_err, dec_err, pa_err in pos if ra != -99])
r, = plt.plot(convx(ras), convy(decs), marker=marker, mec=color, mfc='None', ms=8, mew=2, ls=' ', label='%s %s' % (col_ra, col_dec))
#plt.circles(ras, decs, errs, facecolor='None', edgecolor=r.get_color())
patches = [Ellipse((convx(ra), convy(dec)), converr(ra_err), converr(dec_err), angle=pa_err)
print(tblname, pa_err)
patches = [Ellipse((convx(ra), convy(dec)), 2 * converr(ra_err), 2 * converr(dec_err), angle=90 - pa_err)
for ra, dec, ra_err, dec_err, pa_err in zip(ras, decs, ra_errs, dec_errs, pa_errs)]
p = PatchCollection(patches)
p.set_facecolor('None')
Expand Down
7 changes: 3 additions & 4 deletions nway.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ def make_separation_table_matrix(kstr, table, table_names):
# identify the prior
prior_j = source_densities[augmented_cats[0]] / numpy.product(source_densities_plus[augmented_cats])
# compute a log_bf
errors_selected = [[errors[k][j]] for k in augmented_cats]
if simple_errors:
errors_selected = [[errors[k][j]] for k in augmented_cats]
separations_selected = [[[separations[k][k2][j]]
for k2 in augmented_cats] for k in augmented_cats]
log_bf_j = bayesdist.log_bf(numpy.array(separations_selected),
Expand All @@ -394,6 +394,8 @@ def make_separation_table_matrix(kstr, table, table_names):
for k2 in augmented_cats] for k in augmented_cats]
separations_selected_dec = [[[separations_dec[k][k2][j]]
for k2 in augmented_cats] for k in augmented_cats]
errors_selected = [([errors[k][0][j]], [errors[k][1][j]], [errors[k][2][j]])
for k in augmented_cats]
log_bf_j = bayesdist.log_bf_elliptical(numpy.array(separations_selected_ra),
numpy.array(separations_selected_dec),
numpy.array(errors_selected))
Expand Down Expand Up @@ -638,6 +640,3 @@ def make_separation_table_matrix(kstr, table, table_names):

import nwaylib.checkupdates
nwaylib.checkupdates.checkupdates()



4 changes: 4 additions & 0 deletions tests/elltest/genrandom_geometric.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
fout.close()

fout = open('randomcatX.csv', 'w')
fout2 = open('randomcatR.csv', 'w')
fout.write('ID,RA,DEC,pos_err,a,b,phi\n')
fout2.write('ID,RA,DEC,pos_err,a,b,phi\n')

id = 1
ractr = rarange.mean()
Expand All @@ -41,6 +43,8 @@
rotangle = angle if (i+1) % 4 == 0 else angle + pi/2

fout.write("%d,%.6f,%.6f,%.6f,%.6f,%.6f,%.6f\n" % (id, ra, dec, symerror*60*60, a*60*60, b*60*60, rotangle/pi*180))
fout2.write("%d,%.6f,%.6f,%.6f,%.6f,%.6f,%.6f\n" % (id, numpy.random.normal(ra, symerror), numpy.random.normal(dec, symerror), symerror*60*60, a*60*60, b*60*60, rotangle/pi*180))
id += 1
lastr = r
fout.close()
fout2.close()
8 changes: 6 additions & 2 deletions tests/elltest/genrandom_geometric.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ python3 genrandom_geometric.py || exit 1
topcat -stilts tcopy in=randomcatX.csv ifmt=CSV out=randomcatX.fits || exit 1
nway-write-header.py randomcatX.fits CHANDRA 0.010 || exit 1

topcat -stilts tcopy in=randomcatR.csv ifmt=CSV out=randomcatR.fits || exit 1
nway-write-header.py randomcatR.fits XMM 0.010 || exit 1

topcat -stilts tcopy in=randomcatO.csv ifmt=CSV out=randomcatO.fits || exit 1
nway-write-header.py randomcatO.fits OPT 0.010 || exit 1

Expand All @@ -12,8 +15,9 @@ nway.py --radius=10.0 randomcatX.fits :a:b randomcatO.fits 0.1 --out=random_asym

nway.py --radius=10.0 randomcatX.fits :a:b:phi randomcatO.fits 0.1 --out=random_elltest.fits --min-prob=0.01 || exit 1

nway.py --radius=10.0 randomcatX.fits :a:b:phi randomcatR.fits :a:b:phi randomcatO.fits 0.1 --out=random3_elltest.fits --min-prob=0.01 || exit 1

echo topcat -stilts plot2sky \
topcat -stilts plot2sky \
xpix=1081 ypix=548 \
crowd=0.9998301109057076 \
clon=150.0338559501912 clat=2.040905749390326 radius=0.003505914272661 \
Expand All @@ -31,7 +35,7 @@ echo topcat -stilts plot2sky \
shading_2=auto \
layer_3=Mark \
lon_3=OPT_RA lat_3=OPT_DEC aux_3=p_i \
shading_3=aux size_3=3 \
shading_3=aux size_3=3


nway-explain.py random_circtest.fits 95 || exit 1
Expand Down
Binary file added tests/elltest/randomcatR.fits
Binary file not shown.
Binary file modified tests/elltest/randomcatX.fits
Binary file not shown.

0 comments on commit d66fe43

Please sign in to comment.