Files
star-map/src/app/features/galaxy-system/star-readouts.spec.ts
T
SenrokaiandClaude Opus 5.5 5333be615e Estimate a spectral type from each star's colour where no catalogue gives one, and say so
383 695 of the 455 608 stars read "Spectral type Unknown", every Gaia star among them, although
380 884 of them carry a colour. The card now gives those the type of the dwarf whose colour is
nearest, in the colour's own system, marked as an estimate: TRAPPIST-1, BP-RP 4.90, reads
"Spectral type ~M8, from colour", which is how it was classified (M8 V). A star with neither a
type nor a colour gets no subtitle rather than the literal "Unknown".

The colours are Pecaut & Mamajek's mean dwarf sequence (2013, ApJS 208, 9, table 5), as Mamajek
maintains it online (version 2022.04.16, which carries Gaia BP-RP), from B0 to M8.5. B-V cannot
tell O types apart (the whole sequence spans 0.03 of it), and BP-RP turns back past M8.5 and is
tabulated only from B9. A colour outside the table gets no estimate: 186 BP-RP and 41 B-V colours,
among them the blue Gaia DR3 5612323414549657984 at BP-RP -0.15.

380 657 stars get an estimate: F 97 840, G 144 327, K 105 984, M 29 142, A 3 272, B 92. Checked
against catalogued types:
- 19 433 HYG dwarfs with a B-V: 74.3 % within two subclasses, 95.5 % within five.
- 146 Gaia exoplanet hosts the archive types as dwarfs, from BP-RP: 88.4 % within two
  subclasses, 98.6 % within five.
The estimate assumes a dwarf, so a giant reads later than it is (Pollux, K0 III at B-V 0.99,
reads K3). It also ignores reddening. The comment says both.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 23:28:29 +02:00

96 lines
3.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from 'vitest';
import { StarRecord } from '../../shared/models/star.model';
import { catalogueCensus, describingCatalogue, starReadouts, starSubtitle } from './star-readouts';
/** Three kinds of star the catalogue holds, each as the decoder gives it back. */
const HYG_STAR: StarRecord = {
id: 32263,
name: 'Sirius',
x: -0.49,
y: 2.47,
z: -0.75,
magnitude: -1.44,
magnitudeBand: 'V',
spectralType: 'A0m',
colorIndex: 0.009,
colorSystem: 'B-V',
distanceError: 0.004,
distanceFromGaia: false,
source: 'hyg'
};
// A star Gaia alone knows, at 117 pc and good to a tenth.
const GAIA_STAR: StarRecord = {
id: 1000000001,
name: 'Gaia DR3 5612323414549657984',
x: 117,
y: 0,
z: 0,
magnitude: 11.2,
magnitudeBand: 'G',
spectralType: 'Unknown',
colorIndex: 1.43,
colorSystem: 'BP-RP',
distanceError: 0.1,
distanceFromGaia: true,
source: 'gaia'
};
// HYG's description of Proxima, at the place and distance Gaia measures.
const PLACED_BY_GAIA: StarRecord = { ...HYG_STAR, name: 'Proxima Centauri', magnitude: 11.01, colorIndex: 1.807, spectralType: 'M5Ve', distanceFromGaia: true, source: 'gaia' };
function value(readouts: { label: string; value: string }[], label: string): string | undefined {
return readouts.find((readout) => readout.label === label)?.value;
}
describe('starReadouts', () => {
it('names the band of the magnitude, and which colour the colour index is', () => {
expect(value(starReadouts(HYG_STAR, null), 'Magnitude')).toBe('V -1.44');
expect(value(starReadouts(GAIA_STAR, null), 'Magnitude')).toBe('G 11.20');
expect(value(starReadouts(HYG_STAR, null), 'Colour')).toBe('B−V 0.01');
expect(value(starReadouts(GAIA_STAR, null), 'Colour')).toBe('BP−RP 1.43');
});
it('says a stand-in magnitude was not measured, and leaves out a colour there is none of', () => {
const unmeasured = starReadouts({ ...GAIA_STAR, magnitude: 12, magnitudeBand: undefined, colorIndex: null, colorSystem: undefined }, null);
expect(value(unmeasured, 'Magnitude')).toBe('Not measured');
expect(value(unmeasured, 'Colour')).toBeUndefined();
});
it('gives the distance with its uncertainty', () => {
expect(value(starReadouts(GAIA_STAR, null), 'Distance')).toBe('117 ± 12 pc');
});
it('names the catalogue a star comes from, and whose distance it has', () => {
expect(value(starReadouts(GAIA_STAR, null), 'Source')).toBe('Gaia DR3');
expect(value(starReadouts(HYG_STAR, null), 'Source')).toBe('HYG');
expect(value(starReadouts(PLACED_BY_GAIA, null), 'Source')).toBe('HYG, Gaia DR3 distance');
expect(value(starReadouts({ ...HYG_STAR, source: 'exoplanet-archive' }, null), 'Source')).toBe('NASA Exoplanet Archive');
});
it('marks the luminosity as derived', () => {
expect(starReadouts(HYG_STAR, 25.4).find((readout) => readout.label === 'Luminosity')).toEqual({ label: 'Luminosity', value: '25.40 L☉', derived: true });
});
});
describe('starSubtitle', () => {
it("prints the catalogue's classification where it has one", () => {
expect(starSubtitle(HYG_STAR)).toBe('Spectral type A0m');
});
it("estimates one from the colour otherwise, in the colour's own system, and says so", () => {
// 1.43 is a K5 dwarf in BP−RP; read as B−V it would be an M0.
expect(starSubtitle(GAIA_STAR)).toBe('Spectral type ~K5, from colour');
});
it('prints nothing rather than "Unknown" when there is neither', () => {
expect(starSubtitle({ ...GAIA_STAR, colorIndex: null, colorSystem: undefined })).toBe('');
});
});
describe('catalogueCensus', () => {
it('counts the stars by the catalogue describing them, not by whose position they have', () => {
expect(describingCatalogue(PLACED_BY_GAIA)).toBe('HYG');
expect(catalogueCensus([GAIA_STAR, GAIA_STAR, GAIA_STAR, HYG_STAR, PLACED_BY_GAIA])).toBe('Gaia DR3 3 · HYG 2');
});
});