diff --git a/src/app/features/body-detail/body-view-model.spec.ts b/src/app/features/body-detail/body-view-model.spec.ts index 4d9d47a..b15fa55 100644 --- a/src/app/features/body-detail/body-view-model.spec.ts +++ b/src/app/features/body-detail/body-view-model.spec.ts @@ -3,7 +3,7 @@ import { describe, expect, it } from 'vitest'; import { BodyRecord, OrbitalElements } from '../../shared/models/body.model'; import { ExoplanetRecord } from '../../shared/models/exoplanet.model'; import { StarRecord, SUN_STAR_ID } from '../../shared/models/star.model'; -import { buildBodyViewModel, heliocentricPeriodDays, starSurfaceOf } from './body-view-model'; +import { buildBodyViewModel, heliocentricPeriodDays, luminosityOf, starSurfaceOf } from './body-view-model'; const orbit = (overrides: Partial = {}): OrbitalElements => ({ semiMajorAxisAu: 1, @@ -123,6 +123,23 @@ describe('buildBodyViewModel', () => { }); }); +describe('luminosityOf', () => { + // KMT-2016-BLG-1107L as the ETL adds it from the archive: no V, no G, so the stand-in 15. + const lens: StarRecord = { id: 1070000536, name: 'KMT-2016-BLG-1107L', x: 6651, y: 0, z: 0, magnitude: 15, spectralType: 'Unknown', colorIndex: null, source: 'exoplanet-archive' }; + const lensB: ExoplanetRecord = { id: 'lens-b', hostStarId: lens.id, hostStarName: lens.name, name: 'KMT-2016-BLG-1107L b', orbit: { semiMajorAxisAu: 0.342 } }; + + it('has none from a magnitude no survey measured, and gives its planets no temperature from it', () => { + expect(luminosityOf(lens)).toBeNull(); + expect(buildBodyViewModel('lens-b', { bodies: [], exoplanets: [lensB], stars: [lens] })?.appearance.equilibriumTemperatureK).toBeNull(); + // The same figure measured in V is a star, 37 L☉ at that distance. + expect(luminosityOf({ ...lens, magnitudeBand: 'V' })).toBeCloseTo(36.8, 0); + }); + + it('is 1 for the Sun, whatever its magnitude is filed under', () => { + expect(luminosityOf(sun)).toBe(1); + }); +}); + describe('starSurfaceOf', () => { // Proxima Centauri as HYG describes it, and one of its planets' archive rows. const proxima: StarRecord = { id: 70666, name: 'Proxima Centauri', x: 1.2959, y: 0, z: 0, magnitude: 11.01, magnitudeBand: 'V', spectralType: 'M5Ve', colorIndex: 1.807, colorSystem: 'B-V' }; diff --git a/src/app/features/body-detail/body-view-model.ts b/src/app/features/body-detail/body-view-model.ts index 1615eb1..f0786e8 100644 --- a/src/app/features/body-detail/body-view-model.ts +++ b/src/app/features/body-detail/body-view-model.ts @@ -18,9 +18,14 @@ export interface BodyCatalogues { * Bolometric luminosity of a star in solar units, from what the catalogue measured: apparent * magnitude in its band, parallax distance, and a bolometric correction read off the colour, or * off the spectral type where there is no colour. + * + * None where no survey measured the star and its magnitude is the ETL's stand-in, which is all + * 309 stars without a band have. The 265 archive hosts among them came out at a median 33 L☉ + * from it, KMT-2016-BLG-1107L, a 0.087 M☉ star, at 37, and OGLE-2005-BLG-390L b, published at + * about 50 K, read 388 K. The Sun is the unit, whatever its magnitude is filed under. */ export function luminosityOf(star: StarRecord | undefined): number | null { - return star ? luminositySolar(photometryOf(star)) : null; + return star && (star.magnitudeBand || star.id === SUN_STAR_ID) ? luminositySolar(photometryOf(star)) : null; } function photometryOf(star: StarRecord): StellarPhotometry { @@ -60,9 +65,9 @@ export function starSurfaceOf(star: StarRecord, planets: readonly ExoplanetRecor if (measured) { return { radiusSolar: measured, radiusDerived: false, temperatureK }; } - // Not from the ETL's stand-in magnitude, which is all 309 stars without a band have: PSR - // J1719-1438 came out 2.3 solar radii, wider than its planet's orbit. - const luminosity = star.magnitudeBand ? luminosityOf(star) : null; + // None from a stand-in magnitude: PSR J1719-1438 came out 2.3 solar radii, wider than its + // planet's orbit. + const luminosity = luminosityOf(star); return { radiusSolar: luminosity !== null && temperatureK !== null ? radiusFromLuminositySolar(luminosity, temperatureK) : null, radiusDerived: true,