Data Sources
TerraLab requires several data files to function correctly. This guide explains the required datasets, where to obtain them, and how to organize them.Required Data Files
TerraLab depends on four critical datasets:- DEM Tiles or GeoTIFF: Terrain elevation data
- DVNL GeoTIFF: Light pollution / night lights data
- Gaia Star Catalog: Stellar positions and photometry
- DE421 Ephemeris: Solar system body positions
Directory Structure
Place data files in theTerraLab/data/ directory:
1. Digital Elevation Models (DEM)
TerraLab supports two DEM formats:Format A: Tiled ESRI ASCII Grid (.asc)
Provider: ICGC (Institut Cartogràfic i Geològic de Catalunya) Specifications:- Format: ESRI ASCII Grid (.asc) or NumPy binary cache (.npy)
- Coordinate System: UTM Zone 31N (EPSG:25831)
- Resolution: Typically 5m, 15m, or 30m per pixel
- Coverage: Regional (e.g., Catalonia)
- ICGC Download: https://www.icgc.cat/en/Downloads/Elevation-data
- Select “Digital Elevation Model” (MET)
- Download tiles covering your area of interest
AscRasterProvider in terrain/providers.py:77-134
Format B: Large GeoTIFF
Provider: Copernicus Land Monitoring Service (European Space Agency) Specifications:- Format: Cloud-Optimized GeoTIFF (COG) or standard GeoTIFF
- Coordinate System: Various (auto-detected), typically EPSG:4326 or EPSG:3035
- Resolution: 25m to 90m per pixel
- Coverage: Continental (e.g., all of Europe)
- File Size: Can exceed 18 GB for continental coverage
- Copernicus EU-DEM: https://land.copernicus.eu/imagery-in-situ/eu-dem
- NASA SRTM: https://www.earthdata.nasa.gov/
- USGS Earth Explorer: https://earthexplorer.usgs.gov/
- Click “Browse” and select your GeoTIFF or tiles directory
- Path is saved to
~/.terralab_config.json - Reopen dialog from settings menu to change
- TerraLab uses windowed reading for large files
- Data loaded into RAM for region of interest only
- Coordinate transformations handled automatically
TiffRasterWindowProvider in terrain/providers.py:137-319
Coordinate System Handling
TerraLab internally uses UTM Zone 31N (EPSG:25831 / EPSG:32631) for metric calculations: For Geographic GeoTIFFs (EPSG:4326):- Lat/Lon converted to UTM meters using WGS84 ellipsoid formulas
- Local flat-earth approximation for small regions
- Meters-per-degree scaling: ~111,320 m/deg latitude
- Longitude scaling:
111,320 × cos(latitude)m/deg
- Native CRS detected via rasterio
- Automatic transformation between UTM and native CRS
- Uses rasterio.warp.transform for accuracy
terrain/providers.py:32-76 and 196-232
2. Light Pollution Data (DVNL)
Dataset: Day/Night Visible Lights (DVNL) 2022 Provider: Earth Observation Group (NOAA/Payne Institute) Specifications:- Format: GeoTIFF
- Coordinate System: Equal-area projection (typically EPSG:8857)
- Units: Radiance (nW/cm²/sr)
- Resolution: ~500m globally
- Temporal: Annual composite
- File Size: ~2-5 GB (global) or ~200-500 MB (regional)
- Official source: https://eogdata.mines.edu/products/vnl/
- Select “VIIRS Night Lights - Annual VNL V2”
- Download the most recent year (e.g., 2022)
- Choose the “vcm-orm-ntl” (cloud-masked, outlier-removed) product
TerraLab/data/light_pollution/
Processing Pipeline:
-
Convolution (optional preprocessing):
- Gaussian kernel (σ = 1.5 km) simulates light scatter
- Script:
scripts/dvnl_convolve.py - Creates
*_convolved.tif
-
SQM Calibration:
- Converts radiance → Sky Quality Meter reading
- Formula:
SQM = 22.0 - 2.4 × log₁₀(radiance + 0.001) - Script:
scripts/calibrate_sqm.py
-
Bortle Mapping:
- Converts SQM → Bortle class (1-9)
- Thresholds defined in
light_pollution/bortle.py
light_pollution/dvnl_io.py and terrain/light_pollution_sampler.py
Bortle Class Thresholds
| Bortle | SQM Range | Sky Description | Typical Location |
|---|---|---|---|
| 1 | > 21.89 | Excellent dark sky | Remote mountains |
| 2 | 21.69-21.89 | Typical dark sky | Rural areas |
| 3 | 21.49-21.69 | Rural sky | Villages |
| 4 | 20.49-21.49 | Rural/suburban | Town outskirts |
| 5 | 19.50-20.49 | Suburban | Residential areas |
| 6 | 18.94-19.50 | Bright suburban | City edge |
| 7 | 18.38-18.94 | Suburban/urban | Inner suburbs |
| 8 | 18.00-18.38 | City sky | City center |
| 9 | < 18.00 | Inner city | Industrial zones |
light_pollution/bortle.py
3. Gaia Star Catalog
Dataset: Gaia DR3 (Data Release 3) subset Provider: European Space Agency (ESA) Gaia Mission Specifications:- Format: JSON (list of arrays) or dict format
- Fields required:
source_idorid: Unique star identifierra: Right Ascension (degrees, ICRS)dec: Declination (degrees, ICRS)phot_g_mean_magormag: G-band magnitudebp_rp: Color index (B_P - R_P)designationorname: Star name (optional)
- Typical size: 10,000 to 500,000 stars
- Magnitude range: Typically mag < 7.5 for visual use
- URL: https://gea.esac.esa.int/archive/
- Use ADQL query language
- Example query for bright stars:
- Export as CSV, convert to JSON
- Many astronomy projects provide Gaia subsets
- Check for “visual observing” or “planetarium” catalogs
- Ensure magnitude limit appropriate for your needs
[id, name, ra, dec, mag, bp_rp]
Alternatively, dict format:
.npy cache files on first load:
gaia_cache_ra.npygaia_cache_dec.npygaia_cache_mag.npygaia_cache_r.npy,gaia_cache_g.npy,gaia_cache_b.npy(computed colors)gaia_cache_ids.npygaia_cache_names.npygaia_cache_bprp.npy
CatalogLoaderWorker in sky_widget.py:604-772
Color Calculation
Star RGB colors computed from B_P - R_P index:| bp_rp Range | Color | RGB |
|---|---|---|
| < 0.0 | Hot blue | (160, 190, 255) |
| 0.0 - 0.5 | Blue-white | Interpolated |
| 0.5 - 1.0 | White | (255, 255, 200-255) |
| 1.0 - 2.0 | Yellow-orange | (255, 175-255, 100-200) |
| > 2.0 | Red-orange | (255, 175, 100) |
sky_widget.py:730-742
4. DE421 Ephemeris
Dataset: JPL Development Ephemeris 421 (DE421) Provider: NASA Jet Propulsion Laboratory (JPL) Specifications:- Format: SPICE Binary Kernel (.bsp)
- Coverage: 1900 to 2050
- Bodies included:
- Sun, Moon, Mercury, Venus, Mars
- Jupiter, Saturn, Uranus, Neptune, Pluto
- Earth-Moon barycenter
- Coordinate system: ICRF/J2000
- File size: ~17 MB
- URL: https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/planets/
- Direct file:
de421.bsp - wget command:
SkyfieldLoaderWorker:
sky_widget.py:775-790
Alternatives
DE430 / DE440:- More accurate, larger files (100+ MB)
- Extended coverage (1550-2650 for DE440)
- Use if precision critical or observing distant dates
- Older, smaller (6 MB)
- Coverage: 1600-2200
- Adequate for most visual observing
Configuration File
TerraLab stores configuration in:get_config_value(key, default)set_config_value(key, value)- Auto-saves on every write
common/utils.py and config.py
Data Loading Process
Startup Sequence
-
Configuration Check (
__main__.py:38-49):- Load config from
~/.terralab_config.json - If
raster_pathmissing or invalid, showTerrainConfigDialog - User selects DEM source
- Load config from
-
Catalog Loading (background thread):
CatalogLoaderWorkerloads Gaia JSON- Builds NumPy arrays for vectorized rendering
- Creates binary cache if not present
- Emits
catalog_readysignal
-
Ephemeris Loading (background thread):
SkyfieldLoaderWorkerloads DE421- Initializes timescale
- Emits
skyfield_readysignal
-
First Render:
- Sky canvas renders with available stars
- Horizon profile computed on-demand when location set
Horizon Baking
When location is set or changed:-
Region Preparation:
- Calculate bounding box:
[lat-radius, lon-radius, lat+radius, lon+radius] - Load DEM tiles or GeoTIFF window into memory
- Show progress: ”⏳ Loading maps: X/Y (Z%)”
- Calculate bounding box:
-
Raycasting:
- Cast rays in 360° sweep (default 720 rays, 0.5° spacing)
- Depth bands: 10-60 bands (quality setting)
- Apply Earth curvature correction
- Sample light pollution at ray-terrain intersections
-
Profile Caching:
- Save to
.npzfile in cache directory - Keyed by:
lat_lon_quality_hash - Automatic reload on next session
- Save to
terrain/worker.py and terrain/engine.py
Data Updates and Maintenance
When to Update
Gaia Catalog:- New data releases every ~18-24 months
- Update if working with precision astrometry
- Visual users: Update optional
- Annual releases (e.g., 2021, 2022, 2023)
- Update yearly to track urban light growth
- Critical for accurate Bortle classification
- Update when new LiDAR surveys published
- ICGC updates Catalonia DEM periodically
- Important for mountainous regions with new infrastructure
- Valid until 2050
- Update only if:
- Working beyond 2050
- Requiring higher precision (switch to DE440)
- Studying historical dates before 1900
Verifying Data Integrity
Check File Sizes:gaia_stars.json: 5 MB - 50 MB (depends on star count)de421.bsp: ~17 MBC_DVNL 2022.tif: 200 MB - 5 GB- DEM tiles: Varies widely
[CatalogLoader] Loaded N stars[SkyfieldLoader] Initialized[TiffRasterWindowProvider] Opening dataset- No error messages
Troubleshooting
”Catalog not found” Error
Problem:gaia_stars.json missing or malformed
Solution:
- Verify file exists:
ls TerraLab/data/stars/gaia_stars.json - Check JSON syntax:
python -m json.tool < gaia_stars.json - Fallback: TerraLab generates 500 random stars for testing
”GeoTIFF not found” Error
Problem: DEM path incorrect in config Solution:- Open terrain config dialog (Settings menu)
- Browse to correct path
- Verify path exists:
ls -lh /path/to/dem.tif
”Rasterio error” on GeoTIFF
Problem: Corrupt or unsupported GeoTIFF format Solution:- Verify with gdalinfo:
gdalinfo dem.tif - Check for compression: COG preferred
- Re-download if corrupted
- Convert with:
gdal_translate -co COMPRESS=LZW input.tif output.tif
Slow Star Catalog Loading
Problem: Large JSON file (> 100,000 stars) Solution:- Wait for first load (creates NPY cache)
- Subsequent loads will be ~10× faster
- Consider reducing catalog size (mag < 7.0 sufficient for visual)
Missing Light Pollution Data
Problem: Bortle classification fails Solution:- Check
TerraLab/data/light_pollution/exists - Verify
C_DVNL 2022.tifpresent - Manual Bortle mode: Disable “Auto Bortle” in settings
- Set manual Bortle class (1-9)
Advanced: Custom Data Pipelines
Creating Custom Star Catalogs
Merge multiple catalogs:Preprocessing DVNL for Performance
Convolve and clip to region:Data Licensing and Attribution
Gaia Data:- License: CC BY-SA 3.0 IGO
- Attribution: “This work has made use of data from the European Space Agency (ESA) mission Gaia.”
- License: Public domain (U.S. Government work)
- Attribution: “Earth Observation Group, Payne Institute, Colorado School of Mines.”
- License: CC BY 4.0
- Attribution: “Institut Cartogràfic i Geològic de Catalunya (ICGC)”
- License: Free and open access
- Attribution: “Copernicus Land Monitoring Service, European Environment Agency.”
- License: Public domain (NASA/JPL)
- Attribution: “Jet Propulsion Laboratory, California Institute of Technology.”
README.md:78-87 for complete credits.