f



All twisted up over reverse indices!

Greetings all,

I'm slowly working my way through enlightenment with the wonderful "matchal=
l_sph.pro" from Jeremy Bailin.

However, I think I've made a terrible misinterpretation with the indices, a=
nd I'm hoping for clarification.

My problem: I have two catalogs of positions for stars that I'm trying to m=
atch. I'm also interested in multiple matches and distances between said ma=
tches, all of which can be extracted from the reverse indices and other out=
put of "matchall_sph.pro". However, I'm a bit confused as to how to do the =
proper notation for recovery. An idea of my code thus far:

--------------------

match1 =3D matchall_sph(r_bv,d_bv,ra_i,de_i,search_rad,nwithin,distance=3Dd=
)

part_one =3D where(nwithin gt 0) ; Indices of matched BV sources
part_two =3D where(nwithin eq 1) ; same, but only singly matched sources
part_thr =3D where(nwithin gt 1) ; same, but only multiply matched sources

;
; This should extract the RA and Dec of singly matched sources.
;

ra_i_m =3D dblarr(n_elements(part_two))
de_i_m =3D dblarr(n_elements(part_two))

for i=3D0L,n_elements(part_two)-2 do begin

   ra_i_m(i) =3D ra_i(match1[match1[part_two(i)]:match1[part_two(i+1)]-1])
   de_i_m(i) =3D de_i(match1[match1[part_two(i)]:match1[part_two(i+1)]-1])

endfor

----------------------------

Now, I'm pretty sure this worked like a charm, as a later output file conta=
ins the positions from the BV catalog and I catalog, and they make sense, g=
iven my inputs. (I also had to write a one-line command to get the final va=
lue from that loop, because the "i+1" wrecked the loop!! Yes, I'm that new!=
)

Not for want of trying, but I can't wrap my mind around extracting the mult=
iple sources, nor the distances from those sources. For example, I've tried=
 the following: (just to see the multiple matches from this particular inde=
x)

-----------------------

r_tmp =3D ra_i(match1[match1[part_thr(0)]:match1[part_thr(1)]-1])

print,n_elements(r_tmp)

-----------------------

This results in 250 elements, when I know that the number of matched I-band=
 sources to this one BV source is only 2. What subscripting pitfall have I =
stumbled upon? Or is referencing "match1" with the array "part_thr" not app=
ropriate here?

And how would I extract distances given the following in the help file:

-----------------

;    DISTANCE:  Optional output containing the distances between each ;pair=
..
;               The distances are stored in the same order as the Result
;               array but starting at 0, i.e. if j is match number k to
;               element i then
;                   j =3D Result[Result[i]+k]
;               and the distance between points i and j is
;                   DISTANCE[Result[i]+k-Result[0]]

-----------------

Thanks tons to anyone who can help, with any part of this mystery! My brain=
 hurts at this point!

Stephen
0
Stephen
12/16/2016 10:51:40 AM
comp.lang.idl-pvwave 12260 articles. 2 followers. Post Follow

3 Replies
57 Views

Similar Articles

[PageSpeed] 18

On Friday, December 16, 2016 at 5:51:42 AM UTC-5, Stephen Williams wrote:
> Greetings all,
>=20
> I'm slowly working my way through enlightenment with the wonderful "match=
all_sph.pro" from Jeremy Bailin.
>=20
> However, I think I've made a terrible misinterpretation with the indices,=
 and I'm hoping for clarification.
>=20
> My problem: I have two catalogs of positions for stars that I'm trying to=
 match. I'm also interested in multiple matches and distances between said =
matches, all of which can be extracted from the reverse indices and other o=
utput of "matchall_sph.pro". However, I'm a bit confused as to how to do th=
e proper notation for recovery. An idea of my code thus far:
>=20
> --------------------
>=20
> match1 =3D matchall_sph(r_bv,d_bv,ra_i,de_i,search_rad,nwithin,distance=
=3Dd)
>=20
> part_one =3D where(nwithin gt 0) ; Indices of matched BV sources
> part_two =3D where(nwithin eq 1) ; same, but only singly matched sources
> part_thr =3D where(nwithin gt 1) ; same, but only multiply matched source=
s
>=20
> ;
> ; This should extract the RA and Dec of singly matched sources.
> ;
>=20
> ra_i_m =3D dblarr(n_elements(part_two))
> de_i_m =3D dblarr(n_elements(part_two))
>=20
> for i=3D0L,n_elements(part_two)-2 do begin
>=20
>    ra_i_m(i) =3D ra_i(match1[match1[part_two(i)]:match1[part_two(i+1)]-1]=
)
>    de_i_m(i) =3D de_i(match1[match1[part_two(i)]:match1[part_two(i+1)]-1]=
)
>=20
> endfor
>=20
> ----------------------------
>=20
> Now, I'm pretty sure this worked like a charm, as a later output file con=
tains the positions from the BV catalog and I catalog, and they make sense,=
 given my inputs. (I also had to write a one-line command to get the final =
value from that loop, because the "i+1" wrecked the loop!! Yes, I'm that ne=
w!)
>=20
> Not for want of trying, but I can't wrap my mind around extracting the mu=
ltiple sources, nor the distances from those sources. For example, I've tri=
ed the following: (just to see the multiple matches from this particular in=
dex)
>=20
> -----------------------
>=20
> r_tmp =3D ra_i(match1[match1[part_thr(0)]:match1[part_thr(1)]-1])
>=20
> print,n_elements(r_tmp)
>=20
> -----------------------
>=20
> This results in 250 elements, when I know that the number of matched I-ba=
nd sources to this one BV source is only 2. What subscripting pitfall have =
I stumbled upon? Or is referencing "match1" with the array "part_thr" not a=
ppropriate here?
>=20
> And how would I extract distances given the following in the help file:
>=20
> -----------------
>=20
> ;    DISTANCE:  Optional output containing the distances between each ;pa=
ir.
> ;               The distances are stored in the same order as the Result
> ;               array but starting at 0, i.e. if j is match number k to
> ;               element i then
> ;                   j =3D Result[Result[i]+k]
> ;               and the distance between points i and j is
> ;                   DISTANCE[Result[i]+k-Result[0]]
>=20
> -----------------
>=20
> Thanks tons to anyone who can help, with any part of this mystery! My bra=
in hurts at this point!
>=20
> Stephen

I found this helped (scroll down to the section on reverse indices):=20
http://www.idlcoyote.com/tips/histogram_tutorial.html
0
Paul
12/16/2016 1:37:02 PM
> 
> I found this helped (scroll down to the section on reverse indices): 
> http://www.idlcoyote.com/tips/histogram_tutorial.html

For completeness, I figured out the problem and determined how to extract what I needed. My issue came primarily from improper referencing of the arrays. For example, the following line gave the incorrect indices when used with multiple matches:

ra_i_m(i) = ra_i(match1[match1[part_two(i)]:match1[part_two(i+1)]-1])

The problem is in the end, and should be this:

ra_i_m(i) = ra_i(match1[match1[part_two(i)]:match1[part_two(i)+1]-1])

The parentheses are critical here, as I want the next array element in "match1" and not the next array element in "part_two".

Distances were obtained similarly via the following line:

d(match1[match1[part_thr(i)]:match1[part_thr(i)+1]-1])

That is to say, the above gives the distances for each element in the sub-array denoted by the ":".

I hope this may help someone, I am sure relieved that my problem has been solved.
0
Stephen
12/19/2016 5:37:42 PM
In case anyone is wondering, the reverse indices can be converted into lists or hashes, which make their use much simpler, with

h=histogram(array,_strict_extra=_ex,reverse_indices=ri,locations=locations)
if arg_present(rl) then begin
  rl=list(length=n_elements(h))
  foreach el,h,i do if (el gt 0L) then rl[i]=ri[ri[i]:ri[i+1]-1]
endif
if arg_present(rh) then begin
  rh=!version.release ge '8.3' ? orderedhash(locations) : hash(locations)
  foreach el,h,i do if (el gt 0L) then rh[locations[i]]=ri[ri[i]:ri[i+1]-1]
endif

This is used in my histogram wrapper, histogram_pp (http://www.ppenteado.net/idl/pp_lib/doc/histogram_pp.html):

 vals=randomu(0L,15)*13d0
 h=histogram_pp(vals,reverse_indices=ri,reverse_list=rl,locations=loc,reverse_hash=rh)
 print,h
 ;1           3           0           4           2           1           0           4
 print,ri[ri[0]:ri[1]-1]
 ;13
 foreach el,rl,i do print,i,' : ',el
 ;0 :           13
 ;1 :            8          11          12
 ;2 : !NULL
 ;3 :            0           1           4           6
 ;4 :            9          10
 ;5 :            2
 ;6 : !NULL
 ;7 :            3           5           7          14
 foreach el,loc do print,el,' : ',rh[el]
 ;3.8679500 :           13
 ;4.8679500 :            8          11          12
 ;5.8679500 : !NULL
 ;6.8679500 :            0           1           4           6
 ;7.8679500 :            9          10
 ;8.8679500 :            2
 ;9.8679500 : !NULL
 ;10.867950 :            3           5           7          14

On Monday, December 19, 2016 at 9:37:46 AM UTC-8, Stephen Williams wrote:
> > 
> > I found this helped (scroll down to the section on reverse indices): 
> > http://www.idlcoyote.com/tips/histogram_tutorial.html
> 
> For completeness, I figured out the problem and determined how to extract what I needed. My issue came primarily from improper referencing of the arrays. For example, the following line gave the incorrect indices when used with multiple matches:
> 
> ra_i_m(i) = ra_i(match1[match1[part_two(i)]:match1[part_two(i+1)]-1])
> 
> The problem is in the end, and should be this:
> 
> ra_i_m(i) = ra_i(match1[match1[part_two(i)]:match1[part_two(i)+1]-1])
> 
> The parentheses are critical here, as I want the next array element in "match1" and not the next array element in "part_two".
> 
> Distances were obtained similarly via the following line:
> 
> d(match1[match1[part_thr(i)]:match1[part_thr(i)+1]-1])
> 
> That is to say, the above gives the distances for each element in the sub-array denoted by the ":".
> 
> I hope this may help someone, I am sure relieved that my problem has been solved.

0
Paulo
12/19/2016 8:45:36 PM
Reply: