我正在研究一个真实的夜空星模型(使用BabylonJS),并发现这个数据库包含了最近恒星的所有位置:
https://raw.githubusercontent.com/astronexus/HYG-Database/master/hygxyz.csv
唯一的问题是,那些x / y / z坐标嵌入了很多其他数据中,我想知道是否有人可以提出一种简单的方法来提取它们以便最终得到一个清理[x,y,z]元素的JavaScript数组?
答案 0 :(得分:2)
与mplungjan的答案略有不同:
info = {...}
tags = []
for image in info['Images']:
for tag in image['Tags']:
if tag['Key'] == 'based_on_ami':
tags.append(tag['Value'])
print(tags)
答案 1 :(得分:1)
像这样:
你可以在内循环中选择你喜欢的那些
你可以预先计算[" StarID"," X"," Y"," Z"] .indexOf(header [j] )保存处理
var csv = `StarID,HIP,HD,HR,Gliese,BayerFlamsteed,ProperName,RA,Dec,Distance,PMRA,PMDec,RV,Mag,AbsMag,Spectrum,ColorIndex,X,Y,Z,VX,VY,VZ
0,,,,,,Sol,0,0,0.000004848,0,0,0,-26.73,4.85,G2V,0.656,0,0,0,0,0,0
1,1,224700,,,,,6.079e-05,01.08901332,282.485875706215,-5.20,-1.88,,9.10,1.84501631012894,F5,0.482,282.43485,0.00449,5.36884,4.9e-08,-7.12e-06,-2.574e-06
2,2,224690,,,,,0.00025315,-19.49883745,45.662100456621,181.21,-0.93,,9.27,5.97222057420059,K3V,0.999,43.04329,0.00285,-15.24144,-7.1e-08,4.0112e-05,-1.94e-07
3,3,224699,,,,,0.00033386,38.85928608,355.871886120996,5.24,-2.91,,6.61,-1.1464684004746,B9,-0.019,277.11358,0.02422,223.27753,3.148e-06,9.04e-06,-3.909e-06
4,4,224707,,,,,0.00055878,-51.89354612,129.032258064516,62.85,0.16,,8.06,2.50650851253155,F0V,0.370,79.62896,0.01164,-101.53103,7.2e-08,3.9313e-05,6.1e-08
5,5,224705,,,,,0.00066435,-40.59122440,348.432055749129,2.53,9.07,,8.55,0.839409483669963,G8III,0.902,264.58918,0.04601,-226.71007,9.967e-06,4.275e-06,1.1633e-05
6,6,,,,,,0.00120942,03.94648893,53.1914893617021,226.29,-12.84,,12.31,8.6807892463184,M0V:,1.336,53.06535,0.0168,3.66089,2.09e-07,5.835e-05,-3.303e-06
7,7,,,,,,0.00150326,20.03660216,56.369785794814,-208.12,-200.79,,9.64,5.88476807747854,G0,0.740,52.95794,0.02084,19.31343,1.8821e-05,-5.6864e-05,-5.1547e-05
8,8,224709,,,,,0.00181944,25.88647445,193.423597678917,19.09,-5.66,,9.05,2.61745271546971,M6e-M8.5e Tc,1.102,174.01562,0.08288,84.44669,2.308e-06,1.7901e-05,-4.774e-06
9,9,224708,,,,,0.00235612,36.58593777,207.900207900208,-6.30,8.42,,8.59,2.00072538186916,G5,1.067,166.9363,0.10297,123.9143,-5.053e-06,-6.352e-06,6.813e-06
10,10,224717,,,,,0.00241687,-50.86707360,92.9368029739777,42.23,40.02,,8.59,3.74906135665185,F6V,0.489,58.65441,0.03711,-72.08957,1.3973e-05,1.9034e-05,1.1379e-05
11,11,224720,,,,,0.00248646,46.94000154,233.100233100233,11.09,-2.02,,7.34,0.502286460923622,A2,0.081,159.15237,0.1036,170.31215,1.659e-06,1.2532e-05,-1.558e-06
12,12,224715,,,,,0.00272783,-35.96022482,246.305418719212,-5.99,-0.10,,8.43,1.47263016788597,K4III,1.484,199.36567,0.14237,-144.63632,-6.5e-08,-7.152e-06,-9.6e-08
13,13,224728,,,,,0.00277864,-22.59468060,286.532951289398,8.45,-10.07,,8.80,1.5141271347959,K0III,1.128,264.5403,0.19243,-110.08871,-5.382e-06,1.1733e-05,-1.2913e-05
14,14,224726,,,,,0.00321812,-00.36042119,195.694716242661,61.75,-11.67,,7.25,0.792104500673564,K0,1.200,195.69077,0.16486,-1.23101,-1.18e-07,5.858e-05,-1.107e-05
15,15,236267,,,,,0.00335392,50.79117384,408.163265306122,13.88,5.47,,8.60,0.545830421822663,K2,1.166,258.01976,0.22655,316.26412,-8.41e-06,2.7456e-05,6.841e-06
16,17,224732,,,,,0.00340663,-40.19232842,162.60162601626,-34.46,-26.37,,8.15,2.09437557887709,F3V,0.425,124.20847,0.11077,-104.93583,-1.339e-05,-2.7174e-05,-1.5878e-05
17,16,,,,,,0.00342723,-54.91412819,1886.79245283019,257.39,-96.63,,11.71,0.331379348003946,,0.421,1084.53445,0.97309,-1543.94618,-0.00072535,0.002353602,-0.000508033
18,18,,,,,,0.00354261,-04.05373813,50.1756146512795,-127.22,23.78,,11.03,7.52753649350244,K5,1.567,50.05006,0.04641,-3.54701,4.37e-07,-3.0944e-05,5.769e-06
19,19,224721,,,,,0.00355446,38.30408636,242.718446601942,-2.50,-15.07,,6.53,-0.395513919834326,G5,0.955,190.46888,0.17724,150.44538,1.0993e-05,-2.931e-06,-1.3914e-05`.split("\n");
var header = csv[0].split(","), items = [];
for (var i=1; i<csv.length;i++) {
var parts = csv[i].split(",");
var item = {};
for (var j=0;j<header.length;j++) {
if (["StarID","X","Y","Z"].indexOf(header[j]) != -1) // comment to take all
item[header[j]] = parts[j];
}
items.push(item);
}
console.log(items)
&#13;