Python coding for astronomy (Lengthy, but need help) Somewhat quick explanation
ID: 3874318 • Letter: P
Question
Python coding for astronomy (Lengthy, but need help)
Somewhat quick explanation on the project. I have so far correctly matched spectra of stars between two libraries of different quantites.
All the unmatched stars are supposed to be returned listing their coordinates (RA and DEC), where then I would use what is returned to download their png files
and create a webpage of all the unnmatched spectra. Example so far:
(Matching code)
(Returns)
python sdssDR13spectroquery.py 127.803594774 48.3011272115
python sdssDR13spectroquery.py 127.803594774 48.3011272115
python sdssDR13spectroquery.py 127.803594774 48.3011272115
python sdssDR13spectroquery.py 127.803594774 48.3011272115
python sdssDR13spectroquery.py 127.991699025 48.261116025
python sdssDR13spectroquery.py 127.803594774 48.3011272115
python sdssDR13spectroquery.py 127.991699025 48.261116025 *
python sdssDR13spectroquery.py 127.991699025 48.261116025 *
python sdssDR13spectroquery.py 127.991699025 48.261116025 *
python sdssDR13spectroquery.py 127.840274257 48.2399531789
(Problem)
It is returning duplicates * , and I cannot find why. Also, the list above is in the thousands, so I just put a small example of what is happening.
Please help with this if possible. Panicked.
from astropy.coordinates import SkyCoord from astropy import units as u import fitsio import numpy as np from astropy.io import fits hdulist = fits.open('/d/users/nt rimble/Desktop/Cats/DR120.fits') ral-hdulist [1] . data [ ' RA' ] decl=hdulist [1] .data [ ' DEC' ] DR12Q=SkyCoord (ra-ra1*u.degree, dec=aec1*u.degree) objs=fitsio. read(' /d/users/ntrimble/Desktop/Cats/sequels. fits ' ) w= np . where ( ((objs["EBOSS TARGETO"] & 2**16) !=0 ( (objs["EBOSS TARGETO"] & 2*+17) != 0) objs=objs [w] ra2-objs['RA'] dec2=objs [ ' DEC ' ] sequels = SkyCoord (ra-ra2*u.degree, dec=dec2*u.degree) 1*u.arcsec) idxseq, idxDR, d2d, d3d= DR12Q.search-around-sky ( sequels, #sets array at 0 index matched = np. zeros (len(sequels)) #every match is a 1 matched [idxseq]-1 #unmatched are 0? a = np . where (matched=0) for a in ra2: print ("python sdssDR13spectroquery.py" + str (ra2 [a])+""+ str (dec2 [a]) )Explanation / Answer
Since there is no dataset is provided to test, it doesn't matter, i have provided two options, to replace the last three lines of for loop code.
"mistake which i am able to find is" "for a in ra2", i think you may need to replace "for a in ra2" with "if a in ra2" as option1, if that is not what you are looking then there is option2 which i have provided to get uniques values in ra2 and dec2.
---------------------------------
a=np.where(matched==0)
for a in ra2:
print(.....)
-------------------------
Since it is showing duplicates, and the result is supposed to be unique values, the below should do the work that which you are expecting.
----------------------------------------------------Code to be Replaced---------
for a in ra2:
print ("python sdssDR13spectroquery.py " + str(ra2[a]) + " "+ str(dec2[a]))
----------------------------------------------------
option1:------------------
if a in ra2:
print ("python sdssDR13spectroquery.py " + str(ra2[a]) + " "+ str(dec2[a]))
option1:-----------------
if you are looking for unique values then below option2 code does that part,
option2------------------------------------------------------------------------
def unique(seqlist):
found=set()
return [x for x in seqlist if not (x in found or found.add(x))]
def ra_dec(num1,num2):
for r1,d1 in zip(unique(num1),unique(num2)):
print "python sdssDR13spectroquery.py ",r1," ",d1
ra_dec(ra2,dec2)
----------------------------------------------------------------------
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.