Group Abstract Group Abstract

Message Boards Message Boards

1
|
4.8K Views
|
3 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Sorting a list of astronomical objects by distance from Earth

Posted 3 years ago
POSTED BY: Owen Lieberman
3 Replies
Posted 3 years ago

Just realized that you were providing that input to Wolfram|Alpha, not Wolfram Language. I don't know how to sort and convert units in Wolfram|Alpha. Copy the Wolfram Language input from Wolfram|Alpha and wrap it in Hold.

entities = 
  Hold[{Entity["Star", "RigelKentaurusA"][EntityProperty["Star", "DistanceFromEarth"]], 
    Entity["Galaxy", "M31"][EntityProperty["Galaxy", "DistanceFromEarth"]], 
    EntityClass["Galaxy", "ARP244"][EntityProperty["Galaxy", "DistanceFromEarth"]], 
    Entity["StarCluster", "NGC6611"][EntityProperty["StarCluster", "DistanceFromEarth"]], 
    Entity["Planet", "Jupiter"][EntityProperty["Planet", "DistanceFromEarth"]], 
    Entity["PlanetaryMoon", "Moon"][EntityProperty["PlanetaryMoon", "DistanceFromEarth"]], 
    Entity["Nebula", "M42"][EntityProperty["Nebula", "DistanceFromEarth"]], 
    Entity["StarCluster", "M45"][EntityProperty["StarCluster", "DistanceFromEarth"]], 
    Entity["MinorPlanet", "Pluto"][EntityProperty["MinorPlanet", "DistanceFromEarth"]], 
    Entity["Nebula", "M57"][EntityProperty["Nebula", "DistanceFromEarth"]], 
    Entity["Galaxy", "M104"][EntityProperty["Galaxy", "DistanceFromEarth"]], 
    Entity["Star", "Sun"][EntityProperty["Star", "DistanceFromEarth"]]}];

names = entities /. (Entity | EntityClass)[_, e_][___] :> e // ReleaseHold
distances = entities // ReleaseHold // Flatten // DeleteMissing

sorted = AssociationThread[names, distances] // Sort

Convert to whatever distance unit you want e.g.

sorted // UnitConvert[#, "LightYears"] &
POSTED BY: Rohit Namjoshi
POSTED BY: Jack I Houng
POSTED BY: EDITORIAL BOARD
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard