Skip to content

Commit 1c6c629

Browse files
ebfortinangularsen
authored andcommitted
Added units for Astronomy. (#680)
* Added units for Astronomy. * Added Luminosity Quantity
1 parent 05a45d8 commit 1c6c629

30 files changed

+3125
-1
lines changed

Common/UnitDefinitions/Length.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,50 @@
293293
"Abbreviations": [ "h", "hh" ]
294294
}
295295
]
296+
},
297+
{
298+
"SingularName": "AstronomicalUnit",
299+
"PluralName": "AstronomicalUnits",
300+
"FromUnitToBaseFunc": "x * 1.4959787070e11",
301+
"FromBaseToUnitFunc": "x / 1.4959787070e11",
302+
"XmlDocSummary": "One Astronomical Unit is the distance from the solar system Star, the sun, to planet Earth.",
303+
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Astronomical_unit",
304+
"Localization": [
305+
{
306+
"Culture": "en-US",
307+
"Abbreviations": [ "au", "ua" ]
308+
}
309+
]
310+
},
311+
{
312+
"SingularName": "Parsec",
313+
"PluralName": "Parsecs",
314+
"FromUnitToBaseFunc": "x * 3.08567758128e16",
315+
"FromBaseToUnitFunc": "x / 3.08567758128e16",
316+
"XmlDocSummary": "A parsec is defined as the distance at which one astronomical unit (AU) subtends an angle of one arcsecond.",
317+
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Parsec",
318+
"Prefixes": [ "Kilo", "Mega" ],
319+
"Localization": [
320+
{
321+
"Culture": "en-US",
322+
"Abbreviations": [ "pc" ]
323+
}
324+
]
325+
},
326+
{
327+
"SingularName": "LightYear",
328+
"PluralName": "LightYears",
329+
"FromUnitToBaseFunc": "x * 9.46073047258e15",
330+
"FromBaseToUnitFunc": "x / 9.46073047258e15",
331+
"XmlDocSummary": "A Light Year (ly) is the distance that light travel during an Earth year, ie 365 days.",
332+
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Light-year",
333+
"Prefixes": [ "Kilo", "Mega" ],
334+
"Localization": [
335+
{
336+
"Culture": "en-US",
337+
"Abbreviations": [ "ly" ]
338+
}
339+
]
296340
}
297341
]
298342
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"Name": "Luminosity",
3+
"BaseUnit": "Watt",
4+
"BaseType": "double",
5+
"XmlDoc": "Luminosity is an absolute measure of radiated electromagnetic power (light), the radiant power emitted by a light-emitting object.",
6+
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Luminosity",
7+
"BaseDimensions": {
8+
"L": 2,
9+
"M": 1,
10+
"T": -3
11+
},
12+
"Units": [
13+
{
14+
"SingularName": "Watt",
15+
"PluralName": "Watts",
16+
"FromUnitToBaseFunc": "x",
17+
"FromBaseToUnitFunc": "x",
18+
"Prefixes": [ "Femto", "Pico", "Nano", "Micro", "Milli", "Deci", "Deca", "Kilo", "Mega", "Giga", "Tera", "Peta" ],
19+
"Localization": [
20+
{
21+
"Culture": "en-US",
22+
"Abbreviations": [ "W" ]
23+
}
24+
]
25+
},
26+
{
27+
"SingularName": "SolarLuminosity",
28+
"PluralName": "SolarLuminosities",
29+
"FromUnitToBaseFunc": "x * 3.846e26",
30+
"FromBaseToUnitFunc": "x / 3.846e26",
31+
"XmlDocRemarks": "https://www.britannica.com/science/luminosity",
32+
"Localization": [
33+
{
34+
"Culture": "en-US",
35+
"Abbreviations": [ "L⊙" ]
36+
}
37+
]
38+
}
39+
]
40+
}

Common/UnitDefinitions/Mass.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,40 @@
210210
"Abbreviations": [ "gr" ]
211211
}
212212
]
213+
},
214+
{
215+
"SingularName": "SolarMass",
216+
"PluralName": "SolarMasses",
217+
"BaseUnits": {
218+
"M": "SolarMass"
219+
},
220+
"FromUnitToBaseFunc": "x * 1.98947e30",
221+
"FromBaseToUnitFunc": "x / 1.98947e30",
222+
"XmlDocSummary": "Solar mass is a ratio unit to the mass of the solar system star, the sun.",
223+
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Solar_mass",
224+
"Localization": [
225+
{
226+
"Culture": "en-US",
227+
"Abbreviations": [ "M⊙" ]
228+
}
229+
]
230+
},
231+
{
232+
"SingularName": "EarthMass",
233+
"PluralName": "EarthMasses",
234+
"BaseUnits": {
235+
"M": "EarthMass"
236+
},
237+
"FromUnitToBaseFunc": "x * 5.9722E+24",
238+
"FromBaseToUnitFunc": "x / 5.9722E+24",
239+
"XmlDocSummary": "Earth mass is a ratio unit to the mass of planet Earth.",
240+
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Earth_mass",
241+
"Localization": [
242+
{
243+
"Culture": "en-US",
244+
"Abbreviations": [ "em" ]
245+
}
246+
]
213247
}
214248
]
215249
}

UnitsNet.Tests/CustomCode/LengthTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ public class LengthTests : LengthTestsBase
5757

5858
protected override double HandsInOneMeter => 9.8425196850393701;
5959

60+
protected override double AstronomicalUnitsInOneMeter => 6.6845871222684500000000000E-12;
61+
62+
protected override double KilolightYearsInOneMeter => 1.0570008340247000000000000E-19;
63+
64+
protected override double KiloparsecsInOneMeter => 3.2407790389471100000000000E-20;
65+
66+
protected override double LightYearsInOneMeter => 1.0570008340247000000000000E-16;
67+
68+
protected override double MegalightYearsInOneMeter => 1.0570008340247000000000000E-22;
69+
70+
protected override double MegaparsecsInOneMeter => 3.2407790389471100000000000E-23;
71+
72+
protected override double ParsecsInOneMeter => 3.2407790389471100000000000E-17;
73+
6074
[ Fact]
6175
public void AreaTimesLengthEqualsVolume()
6276
{
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by \generate-code.bat.
4+
//
5+
// Changes to this file will be lost when the code is regenerated.
6+
// The build server regenerates the code before each build and a pre-build
7+
// step will regenerate the code on each local build.
8+
//
9+
// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
10+
//
11+
// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
12+
// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities.
13+
//
14+
// </auto-generated>
15+
//------------------------------------------------------------------------------
16+
17+
// Licensed under MIT No Attribution, see LICENSE file at the root.
18+
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
19+
20+
using System;
21+
22+
namespace UnitsNet.Tests.CustomCode
23+
{
24+
public class LuminosityTests : LuminosityTestsBase
25+
{
26+
// Override properties in base class here
27+
protected override double FemtowattsInOneWatt => 1e15;
28+
29+
protected override double PicowattsInOneWatt => 1e12;
30+
31+
protected override double NanowattsInOneWatt => 1e9;
32+
33+
protected override double MicrowattsInOneWatt => 1e6;
34+
35+
protected override double MilliwattsInOneWatt => 1e3;
36+
37+
protected override double DeciwattsInOneWatt => 1e1;
38+
39+
protected override double WattsInOneWatt => 1;
40+
41+
protected override double DecawattsInOneWatt => 1e-1;
42+
43+
protected override double KilowattsInOneWatt => 1e-3;
44+
45+
protected override double MegawattsInOneWatt => 1e-6;
46+
47+
protected override double GigawattsInOneWatt => 1e-9;
48+
49+
protected override double TerawattsInOneWatt => 1e-12;
50+
51+
protected override double PetawattsInOneWatt => 1e-15;
52+
53+
protected override double SolarLuminositiesInOneWatt => 2.6001040041601700000000000E-27;
54+
55+
}
56+
}

UnitsNet.Tests/CustomCode/MassTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ public class MassTests : MassTestsBase
5757

5858
protected override double ShortHundredweightInOneKilogram => 0.022046226218487758;
5959

60+
protected override double EarthMassesInOneKilogram => 1.6744248350691500000000000E-25;
61+
62+
protected override double SolarMassesInOneKilogram => 5.0264643347223100000000000E-31;
63+
64+
//protected override double SolarMassesTolerance => 0.1;
65+
6066
[Fact]
6167
public void AccelerationTimesMassEqualsForce()
6268
{

0 commit comments

Comments
 (0)