9
$\begingroup$

When I enter

AstronomicalData["Earth", "Radius"]

I get Quantity[6.3674447*10^6, "Meters"]

I would have preferred kilometers, but I can live with meters.

Now there is a newfangled PlanetData command which gives the radius of the Earth in miles.

I know I can convert

UnitConvert[PlanetData["Earth", "Radius"], "SI"]
   Quantity[6371.008, "Kilometers"]

But that is just silly! Is there a way to tell Mathematica to always use SI when applicable?

$\endgroup$
5
  • 1
    $\begingroup$ What does $UnitSystem return? I get "Metric", and radius in meters (v11.0, Ubuntu 16.04). $\endgroup$
    – anderstood
    Commented Jan 17, 2018 at 1:49
  • $\begingroup$ May be related: 117916. Something I don't get is why does "SI" returns kilometers. The SI unit for lengths in meter, not km?! $\endgroup$
    – anderstood
    Commented Jan 17, 2018 at 2:00
  • 3
    $\begingroup$ @anderstood. That's because to get true SI base units, you need to leave the target units argument blank, which causes MMA to default to "SIBase": UnitConvert[PlanetData["Earth", "Radius"]] or, equivalently, UnitConvert[PlanetData["Earth", "Radius"], "SIBase"] When you instead specify "SI", MMA selects the "common" metric unit that gives a numeric value closest to 1 ("common" in this case means km, rather than Mm, even though Mm would give a qty closer to 1). As another example, compare: UnitConvert[Quantity[.0001, "Inches"]] to UnitConvert[Quantity[.0001, "Inches"], "SI"] $\endgroup$
    – theorist
    Commented Jan 17, 2018 at 2:22
  • 1
    $\begingroup$ I'll add that km is an accepted SI unit for length (since prefixes are allowed in SI), it's just not the base unit, which is meters. $\endgroup$
    – theorist
    Commented Jan 17, 2018 at 2:34
  • $\begingroup$ @Anderstood $UnitSystem on V10.x MicroS*** returns Imperial. As for getting friendly SI units. I'm good with that. $\endgroup$ Commented Jan 17, 2018 at 5:01

1 Answer 1

10
$\begingroup$

You can use the UnitSystem option of EntityProperty,

EntityValue[Entity["Planet", "Earth"],
 EntityProperty[
  "Planet",
  "Radius",
  UnitSystem -> "Metric"
  ]
 ]
(* Quantity[6371.008, "Kilometers"] *)

Why am I talking about EntityValue when you asked about PlanetData? Because PlanetData calls EntityValue under the hood (as do all newer XXXData functions).

If you still want to use the PlanetData function, you can do the following,

SetOptions[
 EntityProperty,
 UnitSystem -> "Metric"
 ]
(* {UnitSystem -> "Metric"} *)

PlanetData[
 "Earth",
 "Radius"
 ]
(* Quantity[6371.008, "Kilometers"] *)

If you would like this option to be persistent across kernel sessions, you can add the SetOptions line above in your init.m file, whose location is described here.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.