Repository navigation
Expand file tree
/
Copy pathrender.py
More file actions
574 lines (532 loc) · 19.8 KB
/
Copy pathrender.py
File metadata and controls
574 lines (532 loc) · 19.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
"""Single CLI entry point for all SOLSYS visualizations."""
from __future__ import annotations
import argparse
import shutil
import subprocess
import sys
from pathlib import Path
from typing import Literal
from animate import renderAllAnimations
from animate.scenes.alpha_centauri import renderAlphaCentauriAnimations
from animate.scenes.asteroseismology_cinematic import (
renderAsteroseismologyCinematicAnimations,
)
from animate.scenes.barnards_star import renderBarnardsStarAnimations
from animate.scenes.blender.export_body import exportBodyScene
from animate.scenes.blender.flyby_scene import renderPlanetFlyby, renderPlanetSpin
from animate.scenes.cepheid_ladder_cinematic import renderCepheidLadderCinematicAnimations
from animate.scenes.interstellar_objects import renderInterstellarObjectAnimations
from animate.scenes.kpg_cinematic import renderKpgCinematicAnimations
from animate.scenes.pulsar_cinematic import renderPulsarCinematicAnimations
from animate.scenes.rr_lyrae_cinematic import renderRrLyraeCinematicAnimations
from animate.scenes.sol_centauri_cinematic import renderSolCentauriCinematicAnimations
from animate.scenes.sol_trappist_cinematic import renderSolTrappistCinematicAnimations
from animate.scenes.solar_cycle_cinematic import renderSolarCycleCinematicAnimations
from animate.scenes.tabbys_star import renderTabbysStarAnimations
from animate.scenes.tabbys_star_cinematic import renderTabbysStarCinematicAnimations
from animate.scenes.transit_cinematic import renderTransitCinematicAnimations
from animate.scenes.trappist_1 import renderTrappist1Animations
from animate.scenes.type_ia_cinematic import renderTypeIaCandleCinematicAnimations
from static import renderAll as renderStatic
from static import renderNeighborhood
BLENDER_LOAD_SCRIPT = Path('animate/scenes/blender/load_body.py')
Dimension = Literal['2d', '3d']
# Output geometry lives here so README-friendly sizing is one place to tune.
# Pixel size ≈ inches × dpi.
ANIMATE_FIGURE_SIZE_INCHES = (12.0, 12.0)
ANIMATE_DPI_2D = 100 # original size
ANIMATE_DPI_3D = 50 # half of prior 100 for README
ANIMATE_DPI_CINEMATIC = 100 # Sol→Centauri path needs sharper labels
ANIMATE_DPI_TRANSIT = 84 # full-frame photosphere; keeps the GIF near gallery size
STATIC_FIGURE_SIZE_INCHES = (39.0, 39.0)
STATIC_DPI = 150 # was 300
NEIGHBORHOOD_FIGURE_SIZE_INCHES = (12.0, 12.0)
NEIGHBORHOOD_DPI = 150 # was 300
def _parseDimensions(choice: str) -> tuple[Dimension, ...]:
if choice == 'all':
return ('2d', '3d')
if choice in ('2d', '3d'):
return (choice,) # type: ignore[return-value]
raise ValueError(f'Unknown dimension choice: {choice!r}')
def buildParser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
description='Render SOLSYS visualizations (animate=main, static=side).',
)
subparsers = parser.add_subparsers(dest='command', required=True)
staticParser = subparsers.add_parser('static', help='Side product: static 2D/3D zoom views')
staticParser.add_argument(
'--dimension',
choices=('2d', '3d', 'all'),
default='all',
help='Which projection to render (default: all)',
)
staticParser.add_argument(
'--stars',
default='data/nearby_stars_30.csv',
help='Path to nearby-stars CSV',
)
neighborhoodParser = subparsers.add_parser(
'neighborhood',
help='Side product: 3D interstellar neighborhood star map',
)
neighborhoodParser.add_argument(
'--stars',
default='data/nearby_stars_30.csv',
help='Path to nearby-stars CSV',
)
neighborhoodParser.add_argument(
'--ly',
type=float,
default=10.0,
help='Maximum distance in light years (default: 10)',
)
neighborhoodParser.add_argument(
'--output',
default=None,
help='Output JPG path (default: output/neighborhood/...)',
)
neighborhoodParser.add_argument(
'--show',
action='store_true',
help='Also open an interactive matplotlib window',
)
animateParser = subparsers.add_parser('animate', help='Main product: 2D/3D GIF animations')
animateParser.add_argument(
'--dimension',
choices=('2d', '3d', 'all'),
default='all',
help='Which Solar System animation to render (default: all)',
)
animateParser.add_argument(
'--system',
choices=(
'sol',
'alpha_centauri',
'sol_centauri',
'sol_trappist',
'barnards_star',
'trappist_1',
'tabbys_star',
'tabbys_star_cinematic',
'transit_cinematic',
'asteroseismology_cinematic',
'solar_cycle_cinematic',
'cepheid_ladder_cinematic',
'type_ia_cinematic',
'pulsar_cinematic',
'rr_lyrae_cinematic',
'kpg_cinematic',
'oumuamua',
'interstellar',
'all',
),
default='sol',
help=(
'Which scene set to render (default: sol). '
'sol_centauri = Sol-to-Alpha Centauri cinematic; '
'sol_trappist = Sol-to-TRAPPIST-1 cinematic; '
'tabbys_star_cinematic = Tabby lightcurve cinema (Kepler + photosphere occultation); '
'transit_cinematic = TRAPPIST-1 b transit cinema (TESS fold); '
'asteroseismology_cinematic = red giant weighed by its ringing (Kepler FFT); '
'solar_cycle_cinematic = the Sun\u2019s spots counted and placed (SILSO + butterfly); '
'cepheid_ladder_cinematic = Leavitt\u2019s law fitted from OGLE-IV Cepheids '
'(period\u2013luminosity \u2192 Magellanic Cloud distances); '
'type_ia_cinematic = Type Ia standard candles (Pantheon+ Hubble diagram); '
'pulsar_cinematic = pulsar lighthouse (EPN folded profiles + ATNF ages); '
'rr_lyrae_cinematic = RR Lyrae / horizontal-branch clocks '
'(OGLE-IV Magellanic Bailey diagram); '
'kpg_cinematic = K–Pg / Chicxulub Yucatán cinema (Earth pack); '
'interstellar = 1I/2I/3I GIFs; oumuamua = \u02bbOumuamua only (alias).'
),
)
animateParser.add_argument(
'--object',
default='all',
help=(
'For --system interstellar: object_id from data/interstellar_objects.csv '
'(oumuamua, borisov, atlas, or all). Ignored otherwise.'
),
)
animateParser.add_argument(
'--stars',
default='data/nearby_stars_30.csv',
help='Path to nearby-stars CSV (for multi-star systems)',
)
animateParser.add_argument(
'--blender-bodies',
action='store_true',
help=(
'For --system sol_centauri / sol_trappist: composite Blender spin-loop '
'frames (lazy-loaded; requires prior: blender --spin)'
),
)
allParser = subparsers.add_parser(
'all',
help='Render main animations plus static/neighborhood side products',
)
allParser.add_argument(
'--dimension',
choices=('2d', '3d', 'all'),
default='all',
help='Which projection(s) to render (default: all)',
)
allParser.add_argument(
'--stars',
default='data/nearby_stars_30.csv',
help='Path to nearby-stars CSV',
)
allParser.add_argument(
'--ly',
type=float,
default=10.0,
help='Neighborhood map radius in light years (default: 10)',
)
allParser.add_argument(
'--system',
choices=(
'sol',
'alpha_centauri',
'sol_centauri',
'sol_trappist',
'barnards_star',
'trappist_1',
'tabbys_star',
'tabbys_star_cinematic',
'transit_cinematic',
'asteroseismology_cinematic',
'solar_cycle_cinematic',
'cepheid_ladder_cinematic',
'type_ia_cinematic',
'pulsar_cinematic',
'rr_lyrae_cinematic',
'kpg_cinematic',
'oumuamua',
'interstellar',
'all',
),
default='all',
help='Which scene set(s) to include (default: all)',
)
allParser.add_argument(
'--object',
default='all',
help='For interstellar scenes: object_id or all (default: all)',
)
blenderParser = subparsers.add_parser(
'blender',
help='Export Sol planet/moon catalog state or render Blender close-up flybys',
)
blenderParser.add_argument(
'--body',
default='Earth',
help='PlanetCatalog or MoonCatalog name to export / flyby (default: Earth)',
)
blenderParser.add_argument(
'--frames',
type=int,
default=120,
help='Orbit keyframes for export, or flyby frames when --flyby (default: 120 / 72)',
)
blenderParser.add_argument(
'--output-dir',
default='output/animate/blender',
help='Directory for body-scene JSON / flyby GIFs (default: output/animate/blender)',
)
blenderParser.add_argument(
'--load',
action='store_true',
help='After export, run Blender to ingest the JSON (requires blender on PATH)',
)
blenderParser.add_argument(
'--flyby',
action='store_true',
help='Render polished light/dark flyby GIFs via Blender (requires blender on PATH)',
)
blenderParser.add_argument(
'--spin',
action='store_true',
help=(
'Render fixed-camera RGBA day/night spin loops for cinematic reuse '
'(requires blender on PATH)'
),
)
blenderParser.add_argument(
'--theme',
choices=('light', 'dark', 'all'),
default='all',
help='Theme when using --flyby / --spin (default: all)',
)
blenderParser.add_argument(
'--pipeline',
action='store_true',
help=(
'End-to-end: Earth+Moon Blender spin loops, then Sol→Centauri cinematic '
'with --blender-bodies. Ignores --body.'
),
)
return parser
def _runBlenderLoad(scenePath: Path) -> None:
blenderExecutable = shutil.which('blender')
if blenderExecutable is None:
raise SystemExit(
'blender not found on PATH. Install Blender or omit --load and run:\n'
f' blender --background --python {BLENDER_LOAD_SCRIPT} -- {scenePath}'
)
completed = subprocess.run(
[
blenderExecutable,
'--background',
'--python',
str(BLENDER_LOAD_SCRIPT),
'--',
str(scenePath),
],
check=False,
)
if completed.returncode != 0:
raise SystemExit(f'Blender ingest failed with exit code {completed.returncode}')
def _runBlenderCinematicPipeline(
*,
theme: str,
frames: int,
outputDirectory: str,
starsCsvPath: str,
) -> None:
"""Earth+Moon spin loops, then Sol→Centauri cinematic compositing those frames."""
spinFrames = 48 if frames == 120 else frames
for bodyName in ('Earth', 'Moon'):
print(f'[pipeline] Blender spin loop → {bodyName}')
paths = renderPlanetSpin(
bodyName,
theme=theme,
frameCount=spinFrames,
outputDirectory=outputDirectory,
)
for path in paths:
print(f'Spin ready → {path}')
print('[pipeline] Sol→Centauri cinematic with Blender spin billboards')
renderSolCentauriCinematicAnimations(
figureSizeInches=ANIMATE_FIGURE_SIZE_INCHES,
dpi=ANIMATE_DPI_CINEMATIC,
starsCsvPath=starsCsvPath,
useBlenderBodies=True,
)
print('[pipeline] done')
def _renderLightcurveCinemas(systemChoice: str, starsCsvPath: str) -> None:
"""Flux-timeline episodes. Most need their Blender packs first, so never `all`."""
if systemChoice == 'tabbys_star_cinematic':
# Requires prior: blender --body "Tabby's Star" --spin.
renderTabbysStarCinematicAnimations(
figureSizeInches=ANIMATE_FIGURE_SIZE_INCHES,
dpi=ANIMATE_DPI_CINEMATIC,
starsCsvPath=starsCsvPath,
)
if systemChoice == 'transit_cinematic':
# Requires prior: blender --body "TRAPPIST-1" and "TRAPPIST-1 b" --spin.
renderTransitCinematicAnimations(
figureSizeInches=ANIMATE_FIGURE_SIZE_INCHES,
dpi=ANIMATE_DPI_TRANSIT,
)
if systemChoice == 'asteroseismology_cinematic':
# Requires prior: blender --body "KIC 7944142" and "Sun" --spin.
renderAsteroseismologyCinematicAnimations(
figureSizeInches=ANIMATE_FIGURE_SIZE_INCHES,
dpi=ANIMATE_DPI_TRANSIT,
)
if systemChoice == 'solar_cycle_cinematic':
# Requires prior: blender --body "Sun" --spin.
renderSolarCycleCinematicAnimations(
figureSizeInches=ANIMATE_FIGURE_SIZE_INCHES,
dpi=ANIMATE_DPI_TRANSIT,
)
if systemChoice == 'cepheid_ladder_cinematic':
# Catalogue and photometry only: no Blender pack needed.
renderCepheidLadderCinematicAnimations(
figureSizeInches=ANIMATE_FIGURE_SIZE_INCHES,
dpi=ANIMATE_DPI_TRANSIT,
)
if systemChoice == 'type_ia_cinematic':
# Catalogue and photometry only: no Blender pack needed.
renderTypeIaCandleCinematicAnimations(
figureSizeInches=ANIMATE_FIGURE_SIZE_INCHES,
dpi=ANIMATE_DPI_TRANSIT,
)
if systemChoice == 'pulsar_cinematic':
# Catalogue and folded profiles only: no Blender pack needed.
renderPulsarCinematicAnimations(
figureSizeInches=ANIMATE_FIGURE_SIZE_INCHES,
dpi=ANIMATE_DPI_TRANSIT,
)
if systemChoice == 'rr_lyrae_cinematic':
# Catalogue and photometry only: no Blender pack needed.
renderRrLyraeCinematicAnimations(
figureSizeInches=ANIMATE_FIGURE_SIZE_INCHES,
dpi=ANIMATE_DPI_TRANSIT,
)
def _renderAnimations(
systemChoice: str,
dimensions: tuple[Dimension, ...],
starsCsvPath: str,
objectChoice: str,
*,
useBlenderBodies: bool = False,
) -> None:
if systemChoice in ('sol', 'all'):
for dimension in dimensions:
animateDpi = ANIMATE_DPI_2D if dimension == '2d' else ANIMATE_DPI_3D
renderAllAnimations(
dimension,
figureSizeInches=ANIMATE_FIGURE_SIZE_INCHES,
dpi=animateDpi,
)
if systemChoice in ('alpha_centauri', 'all'):
renderAlphaCentauriAnimations(
figureSizeInches=ANIMATE_FIGURE_SIZE_INCHES,
dpi=ANIMATE_DPI_2D,
starsCsvPath=starsCsvPath,
)
if systemChoice in ('sol_centauri', 'all'):
renderSolCentauriCinematicAnimations(
figureSizeInches=ANIMATE_FIGURE_SIZE_INCHES,
dpi=ANIMATE_DPI_CINEMATIC,
starsCsvPath=starsCsvPath,
useBlenderBodies=useBlenderBodies,
)
if systemChoice in ('sol_trappist', 'all'):
renderSolTrappistCinematicAnimations(
figureSizeInches=ANIMATE_FIGURE_SIZE_INCHES,
dpi=ANIMATE_DPI_CINEMATIC,
starsCsvPath=starsCsvPath,
useBlenderBodies=useBlenderBodies,
)
if systemChoice in ('barnards_star', 'all'):
renderBarnardsStarAnimations(
figureSizeInches=ANIMATE_FIGURE_SIZE_INCHES,
dpi=ANIMATE_DPI_2D,
starsCsvPath=starsCsvPath,
)
if systemChoice in ('trappist_1', 'all'):
renderTrappist1Animations(
figureSizeInches=ANIMATE_FIGURE_SIZE_INCHES,
dpi=ANIMATE_DPI_2D,
starsCsvPath=starsCsvPath,
)
if systemChoice in ('tabbys_star', 'all'):
renderTabbysStarAnimations(
figureSizeInches=ANIMATE_FIGURE_SIZE_INCHES,
dpi=ANIMATE_DPI_2D,
starsCsvPath=starsCsvPath,
)
_renderLightcurveCinemas(systemChoice, starsCsvPath)
if systemChoice == 'kpg_cinematic':
# Requires the Earth Blender pack (textures already in-repo).
renderKpgCinematicAnimations()
if systemChoice == 'oumuamua':
renderInterstellarObjectAnimations(
objectIds=('oumuamua',),
figureSizeInches=ANIMATE_FIGURE_SIZE_INCHES,
dpi=ANIMATE_DPI_2D,
)
elif systemChoice in ('interstellar', 'all'):
objectIds = None if objectChoice == 'all' else (objectChoice,)
renderInterstellarObjectAnimations(
objectIds=objectIds,
figureSizeInches=ANIMATE_FIGURE_SIZE_INCHES,
dpi=ANIMATE_DPI_2D,
)
def _handleBlenderCommand(args: argparse.Namespace) -> None:
if args.pipeline:
_runBlenderCinematicPipeline(
theme=args.theme,
frames=args.frames,
outputDirectory=args.output_dir,
starsCsvPath='data/nearby_stars_30.csv',
)
return
if args.spin:
spinFrames = 48 if args.frames == 120 else args.frames
paths = renderPlanetSpin(
args.body,
theme=args.theme,
frameCount=spinFrames,
outputDirectory=args.output_dir,
)
for path in paths:
print(f'Spin ready → {path}')
return
if args.flyby:
flybyFrames = 72 if args.frames == 120 else args.frames
gifPaths = renderPlanetFlyby(
args.body,
theme=args.theme,
frameCount=flybyFrames,
outputDirectory=args.output_dir,
)
for gifPath in gifPaths:
print(f'Flyby ready → {gifPath}')
return
scenePath = exportBodyScene(
args.body,
frameCount=args.frames,
outputDirectory=args.output_dir,
)
print(f'Exported Blender body scene → {scenePath}')
if args.load:
_runBlenderLoad(scenePath)
return
print(
'Next: dry-run validate with\n'
f' {sys.executable} {BLENDER_LOAD_SCRIPT} {scenePath}\n'
'or ingest with\n'
f' blender --background --python {BLENDER_LOAD_SCRIPT} -- {scenePath}\n'
'or render flybys with\n'
f' {sys.executable} render.py blender --body {args.body} --flyby\n'
'or render spin loops with\n'
f' {sys.executable} render.py blender --body {args.body} --spin\n'
'or run the full Earth/Moon → cinematic pipeline with\n'
f' {sys.executable} render.py blender --pipeline'
)
def main(argv: list[str] | None = None) -> None:
parser = buildParser()
args = parser.parse_args(argv)
if args.command == 'neighborhood':
renderNeighborhood(
starsCsvPath=args.stars,
maxDistanceLightYears=args.ly,
outputPath=args.output,
showPlot=args.show,
figureSizeInches=NEIGHBORHOOD_FIGURE_SIZE_INCHES,
dpi=NEIGHBORHOOD_DPI,
)
return
if args.command == 'blender':
_handleBlenderCommand(args)
return
dimensions = _parseDimensions(args.dimension)
systemChoice = getattr(args, 'system', 'sol')
# Main product first when rendering everything.
if args.command in ('animate', 'all'):
_renderAnimations(
systemChoice,
dimensions,
starsCsvPath=getattr(args, 'stars', 'data/nearby_stars_30.csv'),
objectChoice=getattr(args, 'object', 'all'),
useBlenderBodies=bool(getattr(args, 'blender_bodies', False)),
)
if args.command in ('static', 'all'):
for dimension in dimensions:
renderStatic(
dimension,
starsCsvPath=args.stars,
figureSizeInches=STATIC_FIGURE_SIZE_INCHES,
dpi=STATIC_DPI,
)
if args.command == 'all':
renderNeighborhood(
starsCsvPath=args.stars,
maxDistanceLightYears=args.ly,
figureSizeInches=NEIGHBORHOOD_FIGURE_SIZE_INCHES,
dpi=NEIGHBORHOOD_DPI,
)
if __name__ == '__main__':
main()