8
$\begingroup$

If any of you have tried to use Mathematica AstronomicalData and its newest replacements like StarData, you may already be familiar with the large data issues, and the almost impossible download times. Below is the steps I use to extract, format, and export different categories of AstronomicalData. Surely, there has to be an easier way? How can I simplify the process? Idea's welcomed. Thanks!

SetDirectory[$UserDocumentsDirectory]

sunMass = AstronomicalData["Sun", "Mass"];
sunLuminosity = AstronomicalData["Sun", "Luminosity"];
sunTemperature = AstronomicalData["Sun", "EffectiveTemperature"];


Length[AstronomicalData["ClassBStar"]]

dataClassBStar1 = Take[AstronomicalData["ClassBStar"], {1, 2000}];
dataClassBStar2 = Take[AstronomicalData["ClassBStar"], {2001, 4000}];
dataClassBStar3 = Take[AstronomicalData["ClassBStar"], {4001, 6000}];
dataClassBStar4 = Take[AstronomicalData["ClassBStar"], {6001, 8541}];



 listClassBStar1 = DeleteCases[
   {AstronomicalData[#, "Name"], AstronomicalData[#, "HDNumber"], 
      AstronomicalData[#, "SpectralClass"], 
      AstronomicalData[#, "BVColorIndex"], 
      AstronomicalData[#, "EffectiveTemperature"]/sunTemperature, 
      AstronomicalData[#, "Mass"]/sunMass, 
      AstronomicalData[#, "Luminosity"]/sunLuminosity, 
      AstronomicalData[#, "AbsoluteMagnitude"], 
      AstronomicalData[#, "ApparentMagnitude"], 
      AstronomicalData[#, "RightAscension"], 
      AstronomicalData[#, "Declination"], 
      AstronomicalData[#, "ConstellationName"]}
     & /@ dataClassBStar1,
   _?(Internal`LiterallyOccurringQ[#, "NotAvailable"] &)];


listClassBStar2 = DeleteCases[
   {AstronomicalData[#, "Name"], AstronomicalData[#, "HDNumber"], 
      AstronomicalData[#, "SpectralClass"], 
      AstronomicalData[#, "BVColorIndex"], 
      AstronomicalData[#, "EffectiveTemperature"]/sunTemperature, 
      AstronomicalData[#, "Mass"]/sunMass, 
      AstronomicalData[#, "Luminosity"]/sunLuminosity, 
      AstronomicalData[#, "AbsoluteMagnitude"], 
      AstronomicalData[#, "ApparentMagnitude"], 
      AstronomicalData[#, "RightAscension"], 
      AstronomicalData[#, "Declination"], 
      AstronomicalData[#, "ConstellationName"]}
     & /@ dataClassBStar2,
   _?(Internal`LiterallyOccurringQ[#, "NotAvailable"] &)];


listClassBStar3 = DeleteCases[
   {AstronomicalData[#, "Name"], AstronomicalData[#, "HDNumber"], 
      AstronomicalData[#, "SpectralClass"], 
      AstronomicalData[#, "BVColorIndex"], 
      AstronomicalData[#, "EffectiveTemperature"]/sunTemperature, 
      AstronomicalData[#, "Mass"]/sunMass, 
      AstronomicalData[#, "Luminosity"]/sunLuminosity, 
      AstronomicalData[#, "AbsoluteMagnitude"], 
      AstronomicalData[#, "ApparentMagnitude"], 
      AstronomicalData[#, "RightAscension"], 
      AstronomicalData[#, "Declination"], 
      AstronomicalData[#, "ConstellationName"]}
     & /@ dataClassBStar3,
   _?(Internal`LiterallyOccurringQ[#, "NotAvailable"] &)];


listClassBStar4 = DeleteCases[
   {AstronomicalData[#, "Name"], AstronomicalData[#, "HDNumber"], 
      AstronomicalData[#, "SpectralClass"], 
      AstronomicalData[#, "BVColorIndex"], 
      AstronomicalData[#, "EffectiveTemperature"]/sunTemperature, 
      AstronomicalData[#, "Mass"]/sunMass, 
      AstronomicalData[#, "Luminosity"]/sunLuminosity, 
      AstronomicalData[#, "AbsoluteMagnitude"], 
      AstronomicalData[#, "ApparentMagnitude"], 
      AstronomicalData[#, "RightAscension"], 
      AstronomicalData[#, "Declination"], 
      AstronomicalData[#, "ConstellationName"]}
     & /@ dataClassBStar4,
   _?(Internal`LiterallyOccurringQ[#, "NotAvailable"] &)];


 listClassBStar = Join[listClassBStar1, listClassBStar2, listClassBStar3, 
   listClassBStar4];

Length[listClassBStar]

tableClassBStar = 
  Prepend[listClassBStar, {"Name", "HDNumber", "SpectralClass", 
    "BVColorIndex", "EffectiveTemperature", "Mass", "Luminosity", 
    "AbsoluteMagnitude", "ApparentMagnitude", "RightAscension", 
    "Declination", "ConstellationName"}];

SetDirectory[$UserDocumentsDirectory]

Export["exportClassBStar.csv", tableClassBStar1, "CSV"]

Then using a selected category of AstronomicalData in plots and graphs, is as easy as importing it from your local hard drive:

importClassAStar = 
  Import["exportClassAStar.csv", {"Data", {All}}, 
   "HeaderLines" -> 1];
importClassBStar = 
  Import["exportClassBStar.csv", {"Data", {All}}, 
   "HeaderLines" -> 1];
importClassFStar = 
  Import["exportClassFStar.csv", {"Data", {All}}, 
   "HeaderLines" -> 1];
importClassGStar = 
  Import["exportClassGStar.csv", {"Data", {All}}, 
   "HeaderLines" -> 1];
importClassMStar = 
  Import["exportClassMStar.csv", {"Data", {All}}, 
   "HeaderLines" -> 1];
importClassOStar = 
  Import["exportClassOStar.csv", {"Data", {All}}, "HeaderLines" -> 1];

importSubgiant = 
  Import["exportSubgiant.csv", {"Data", {All}}, "HeaderLines" -> 1];
importNormalGiant = 
  Import["exportNormalGiant.csv", {"Data", {All}}, "HeaderLines" -> 1];
importSupergiant = 
  Import["exportSupergiant.csv", {"Data", {All}}, "HeaderLines" -> 1];

importVariableStar = 
  Import["exportVariableStar.csv", {"Data", {All}}, 
   "HeaderLines" -> 1];


unionGiants = 
  Union[importSubgiant, importNormalGiant, importSupergiant];

After you follow the above process for every category of star AstronomicalData.

But the process is long and tedious.

Surely there is an easier way???

$\endgroup$
  • $\begingroup$ This is maybe quicker? StarData[ EntityClass["Star", "ClassBStar"], {"SpectralClass", "BVColorIndex", "EffectiveTemperature", "Mass", "Luminosity", "AbsoluteMagnitude", "ApparentMagnitude", "RightAscension", "Declination", "Constellation"}, "Dataset" ] (still running here). I've struggling with this myself. $\endgroup$ – Szabolcs Jul 8 '16 at 17:36
  • $\begingroup$ Don't know how different this is from @Szabolcs answer, but mystardata = EntityValue[ EntityClass["Star", "ClassBStar"], {"Name", "HDNumber", "SpectralClass", "BVColorIndex", "EffectiveTemperature", "Mass", "Luminosity", "AbsoluteMagnitude", "ApparentMagnitude", "RightAscension", "Declination", "Constellation"}, "EntityAssociation"]; is speedier than the OP code. And if you can, use an Association instead of a Dataset (just an opinion) $\endgroup$ – Jason B. Jul 8 '16 at 17:39
  • $\begingroup$ @JasonB Did you time it? Mine is still running ... $\endgroup$ – Szabolcs Jul 8 '16 at 17:42
  • $\begingroup$ Worked with StarData as well, but it feels like the EntityClass structure has serious network(?) performance issues. I can do large extracts of AstronomicalData that never return using StarData. Since the newer data like StarData, GalaxyData, etc uses EntityClass, I will have to figure out the best approach. Haven't used the "Dataset" option on StarData before. Will check into that. Thanks! $\endgroup$ – Joseph Karpinski Jul 8 '16 at 17:49
  • 1
    $\begingroup$ OK, I went for a walk because I couldn't wait for it to finish. It took 39 minutes. The result dataset is 39 MB. Exporting to WDX (the format used by many of these *Data functions) I get 1 MB. My usual download speed is about 1 MB/s. Why couldn't this be downloaded in just a couple of seconds instead of 40 minutes then?! $\endgroup$ – Szabolcs Jul 8 '16 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.