Skip to main content

SQMCalibrationModel

Calibrates a robust regression model to map DVNL aggregated predictors to SQM measurements. The model uses a log-linear relationship:
SQM = α + β × log₁₀(DVNL_agg + ε) + γ × (elevation / 1000)

Constructor

SQMCalibrationModel(epsilon: float = 1e-3)
epsilon
float
default:"1e-3"
Small offset added to DVNL values to avoid log(0)

Attributes

epsilon
float
The epsilon offset value used in log transformation
model
HuberRegressor
The underlying sklearn HuberRegressor model
fitted
bool
Whether the model has been fitted to training data

Methods

fit

Fits a log-linear model mapping log(DVNL_agg) + Elevation to SQM.
fit(
    aggregated_dvnl: np.ndarray,
    elevation_m: np.ndarray,
    target_sqm: np.ndarray
) -> SQMCalibrationModel

Parameters

aggregated_dvnl
np.ndarray
required
The kernel-aggregated DVNL radiance values
elevation_m
np.ndarray
required
The observer’s elevation in meters
target_sqm
np.ndarray
required
Real SQM measurements to fit against

Returns

self
SQMCalibrationModel
Returns the fitted model instance for method chaining

predict

Predicts the SQM from new kernel-aggregated DVNL data.
predict(
    aggregated_dvnl: np.ndarray,
    elevation_m: np.ndarray
) -> np.ndarray

Parameters

aggregated_dvnl
np.ndarray
required
Aggregated radiance values
elevation_m
np.ndarray | float
required
Elevation map in meters or a scalar value

Returns

sqm_predictions
np.ndarray
Predicted Zenith SQM values in mag/arcsec²

save

Saves the serialized model using joblib.
save(filepath: str) -> None
filepath
str
required
Path where the model will be saved

load

Loads a serialized model from the given path.
load(filepath: str) -> SQMCalibrationModel
filepath
str
required
Path to the saved model file

Returns

self
SQMCalibrationModel
Returns the model instance with loaded parameters

Example

import numpy as np
from light_pollution.calibration import SQMCalibrationModel

# Initialize model
model = SQMCalibrationModel(epsilon=1e-3)

# Prepare training data
agg_dvnl = np.array([0.5, 1.2, 2.3, 0.8])
elevation = np.array([100, 250, 50, 300])
sqm_measurements = np.array([21.5, 20.8, 19.5, 21.9])

# Fit the model
model.fit(agg_dvnl, elevation, sqm_measurements)

# Make predictions
new_dvnl = np.array([0.6, 1.5])
new_elevation = np.array([150, 200])
predicted_sqm = model.predict(new_dvnl, new_elevation)

# Save for later use
model.save("sqm_calibration.pkl")

# Load the model
loaded_model = SQMCalibrationModel().load("sqm_calibration.pkl")

Build docs developers (and LLMs) love