Reputation: 23
So, I'm trying to do a code in which I take my stars sample (M dwarf stars in general) and get only the stars which have a confirmed exoplanet orbiting around it. But the star sample is big (around 178 stars) and I have to automatize it and put the stars with exoplanets in a pandas dataframe, with 3 columns: Star Name, Number of exoplanets, ID of exoplanets.
To make it work I used the Simbad library astroquery.simbad. The idea is to query around a ratio of "0d0m0.02s" around the star and get the planets (perhaps could be a way to do it by the ID of the star, but i didn't know if it was possible, but that's not the problem).
I made some tests to query around just one star with planets, and another without planets, and until there the idea and the code kinda work. Just like that:
from astroquery.simbad import Simbad
from astroquery import open_exoplanet_catalogue as oec
from astroquery.open_exoplanet_catalogue import findvalue
import astropy.units as u
import astropy.coordinates as coord
from astropy.coordinates import SkyCoord
import numpy as np
test = C[1] #Coordinates of a star with plantes
#The coordinates were like that:
# <SkyCoord (ICRS): (ra, dec) in deg
# (343.31971792, -14.26369528)>
#And the query:
result = Simbad.query_region(coord.SkyCoord(SkyCoord(test, unit=(u.hourangle, u.deg)), unit=(u.deg), frame='icrs'), radius='0d0m0.02s')
result
And the output: Output of the query
But when I tried to make it slightly more complex, by using a for loop to get the coordinates of two stars in a list, the code didn't work, and appear the error:
AttributeError: 'list' object has no attribute 'SkyCoord'
The slightly more complex code I am talking about:
from astroquery.simbad import Simbad
from astroquery import open_exoplanet_catalogue as oec
from astroquery.open_exoplanet_catalogue import findvalue
import astropy.units as u
import astropy.coordinates as coord
from astropy.coordinates import SkyCoord
import numpy as np
ie = [ID[0],ID[1]] #This should be the stars ID, for the idenfication sake in the dataframe i want to make
coord = [C[0],C[1]]
#This above are the coordinates of the 2 stars i want to query for tests, them being:
# [<SkyCoord (ICRS): (ra, dec) in deg
# (348.569285, -19.64428167)>, <SkyCoord (ICRS): (ra, dec) in deg
# (343.31971792, -14.26369528)>]
#For loop which seems to be the reason of the problem
for i, j in zip(ie,coord):
#As you know the j variable would be equivalent as de C[0] or C[1] coordinate
query = Simbad.query_region(coord.SkyCoord(SkyCoord(j, unit=(u.hourangle, u.deg)), unit=(u.deg), frame='icrs'), radius='0d0m0.02s')
#And the rest of the code below, that don't seem important to be here
This block of code gives the error:
AttributeError: 'list' object has no attribute 'SkyCoord'
It makes no sense, since the type of the C[0]
is:
<class 'astropy.coordinates.sky_coordinate.SkyCoord'>
And after I run the buggy block code, it makes the previews block codes, like the more simple up there, to no work anymore showing the same error, when I rerun them. When I restart the kernel they, once again, work, if I don't run the buggy block code.
So why does the error appear only when I put it inside a for loop? Why does it make the other simple code not to work anymore? Someone knows how to fix this or have any explanation about that error? It's good to say the months ago I was getting the same problem, but it was showing 'Series' instead of 'list', and it suddenly disapeared.
Sorry if the question is too long, it's my first here in StackOverflow and I'm truly new in astropy and astroquery (and all astronomy related python).
Upvotes: 0
Views: 681
Reputation: 23
Well, as always the error was something so small I would never see, if not for a friend to help.
The problem was I named the list with the coordinates as:
coord = [C[0],C[1]]
And it was bugging the import part of the Skycoord and overwriting it:
import astropy.coordinates as coord
So, here's the solution. Big question, small error.
Upvotes: 0