Commit 7f2e4446 authored by Gaetano Scandariato's avatar Gaetano Scandariato
Browse files

reporting improved

parent 986cfa21
Loading
Loading
Loading
Loading
Loading
+26 −5
Changes for PyAETNA/reporting/lightcurve_plots.py: 26 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -2449,15 +2449,34 @@ def plot_models(plData, plModel, best_params, param_config,
    # probability density (arbitrary units, increasing to the right), making
    # it easy to see at a glance whether the residuals are Gaussian, skewed,
    # or have heavy tails, without leaving the time-series context.
    _kde_visible = False
    try:
        from scipy.stats import gaussian_kde as _gkde
        if len(residuals) >= 4:
            _kde_visible = True
            # determine vertical range to sample over; use entire residual set
            _res_span = float(residuals.max() - residuals.min())
            _margin   = 0.15 * _res_span if _res_span > 0 else 1e-6
            _y_k = np.linspace(float(residuals.min()) - _margin,
                               float(residuals.max()) + _margin, 300)
            if is_per_inst_plot and visit_colors is not None:
                # Plot overall combined KDE in background
                try:
                    _kde_v = _gkde(residuals)(_y_k)
                    ax_kde.fill_betweenx(_y_k, 0, _kde_v, color='gray', alpha=0.30)
                    ax_kde.plot(_kde_v, _y_k, color='gray', linewidth=1.2, label='Combined')
                except Exception:
                    pass

                # Reference Gaussian with same mean and std (red dashed)
                _mu  = float(np.mean(residuals))
                _sig = float(np.std(residuals))
                if _sig > 0:
                    _gauss = (np.exp(-0.5 * ((_y_k - _mu) / _sig) ** 2)
                              / (_sig * np.sqrt(2.0 * np.pi)))
                    ax_kde.plot(_gauss, _y_k, color='C3', linewidth=1.0,
                                linestyle='--', alpha=0.8, label='Gaussian ref.')

                # plot separate KDEs for each visit using the same colors
                for uv in unique_vis:
                    sel = vis_sorted == uv
@@ -2469,8 +2488,7 @@ def plot_models(plData, plModel, best_params, param_config,
                        ax_kde.plot(kde(_y_k), _y_k, color=visit_colors[uv],
                                    linewidth=1.2, alpha=0.8, label=f'Visit {uv}')
                    except Exception:
                        ax_kde.axhline(np.mean(res_uv), color=visit_colors[uv],
                                       linewidth=1.2, alpha=0.8, label=f'Visit {uv}')
                        pass
                ax_kde.axhline(0, color='k', linestyle='--', linewidth=0.5)
                ax_kde.set_xlim(left=0)
                ax_kde.legend(fontsize=6, loc='upper right')
@@ -2490,15 +2508,18 @@ def plot_models(plData, plModel, best_params, param_config,
                ax_kde.axhline(0, color='k', linestyle='--', linewidth=0.5)
                ax_kde.set_xlim(left=0)
    except ImportError:
        # scipy not available — leave the KDE panel blank
        pass
    except Exception:
        pass  # silently skip KDE on any numerical failure
        _kde_visible = False

    if _kde_visible:
        # Style: suppress y-tick labels (shared with main panel), minimal x-ticks
        ax_kde.tick_params(labelleft=False, labelsize=7)
        ax_kde.set_xlabel('KDE', fontsize=7)
        ax_kde.xaxis.set_major_locator(plt.MaxNLocator(2))

    else:
        # Hide the axis completely (not even showing the axis or anything)
        ax_kde.set_visible(False)
    # Show original BJD on x-axis (plData.time is centered internally by timeCenter)
    time_center = float(getattr(plData, 'timeCenter', 0.0))
    if time_center != 0.0:
+852 −0

File changed.

Preview size limit exceeded, changes collapsed.

+3.96 KiB (783 KiB)

File changed.

No diff preview for this file type.

+430 B (73.3 KiB)

File changed.

No diff preview for this file type.

+208 −0
Changes for tests/PyAETNAouts/test_spectral_mixture.log: 208 added lines, 0 removed lines.
Original line number Diff line number Diff line
2026-06-25 15:10:54 INFO: Log file reset as requested (reset=True)
2026-06-25 15:10:54 INFO: Starting run using config '/dati/software/pyLib/PyAETNA/tests/test_spectral_mixture.yaml'
2026-06-25 15:10:54 INFO: Data working_dir: /dati/software/pyLib/PyAETNA/tests
2026-06-25 15:10:54 INFO: Data file: test_spectral_mixture.dat
2026-06-25 15:10:54 INFO: Successfully changed to data directory
2026-06-25 15:10:54 INFO: JAX version 0.9.0.1
2026-06-25 15:10:54 INFO: JAX devices: [CpuDevice(id=0), CpuDevice(id=1), CpuDevice(id=2), CpuDevice(id=3), CpuDevice(id=4), CpuDevice(id=5), CpuDevice(id=6), CpuDevice(id=7)]
2026-06-25 15:10:54 INFO:   device_kind=cpu, platform=cpu
2026-06-25 15:10:54 INFO:   device_kind=cpu, platform=cpu
2026-06-25 15:10:54 INFO:   device_kind=cpu, platform=cpu
2026-06-25 15:10:54 INFO:   device_kind=cpu, platform=cpu
2026-06-25 15:10:54 INFO:   device_kind=cpu, platform=cpu
2026-06-25 15:10:54 INFO:   device_kind=cpu, platform=cpu
2026-06-25 15:10:54 INFO:   device_kind=cpu, platform=cpu
2026-06-25 15:10:54 INFO:   device_kind=cpu, platform=cpu
2026-06-25 15:10:54 INFO: JAX Environment Info:
2026-06-25 15:10:54 INFO:   jax:    0.9.0.1
2026-06-25 15:10:54 INFO:   jaxlib: 0.9.0.1
2026-06-25 15:10:54 INFO:   numpy:  2.4.2
2026-06-25 15:10:54 INFO:   python: 3.13.14 (main, Jun 11 2026, 12:30:58) [GCC 11.4.0]
2026-06-25 15:10:54 INFO:   device info: cpu-8, 8 local devices"
2026-06-25 15:10:54 INFO:   process_count: 1
2026-06-25 15:10:54 INFO:   platform: uname_result(system='Linux', node='thX280', release='6.8.0-124-generic', version='#124~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 21:05:19 UTC ', machine='x86_64')
2026-06-25 15:10:54 INFO:   XLA_FLAGS=--xla_force_host_platform_device_count=40
2026-06-25 15:10:54
2026-06-25 15:10:54
2026-06-25 15:10:54 ###############################
2026-06-25 15:10:54 #
2026-06-25 15:10:54 #       SAMPLING STARTED
2026-06-25 15:10:54 #
2026-06-25 15:10:54 ###############################
2026-06-25 15:10:54 reset=True: log file deleted and freshly started
2026-06-25 15:10:54 Starting NumPyro sampler...
2026-06-25 15:10:54 walkers_coefficient from YAML: 4 (walkers = first even ≥ 4 × n_free_params, resolved after config parsing)
2026-06-25 15:10:54 No GPU detected. Walkers: 4×n_free_params (TBD), NUTS chains: 2 — CPU parallel mode.
2026-06-25 15:10:54 Available CPU cores: 6
2026-06-25 15:10:54 Loading data from test_spectral_mixture.dat...
2026-06-25 15:10:54 Data loaded: 240 points, 1 visits, 1 instruments
2026-06-25 15:10:54 Loading configuration from /dati/software/pyLib/PyAETNA/tests/test_spectral_mixture.yaml...
2026-06-25 15:10:54 Data types: {'LC': 'LC'}
2026-06-25 15:10:54 GP configuration:
2026-06-25 15:10:54   GP_sm: kernel=SpectralMixture, x_variable=BJD, instruments=['LC']
2026-06-25 15:10:54   GP-enabled instruments: ['LC']
2026-06-25 15:10:54 JAX precision: float32 (manual override via mcmc.use_float64)
2026-06-25 15:10:54 
2026-06-25 15:10:54 
2026-06-25 15:10:54 ==========================================================================================
2026-06-25 15:10:54 PRIOR SUMMARY (v3.0.0 scope-aware)
2026-06-25 15:10:54 ==========================================================================================
2026-06-25 15:10:54 Normalization mode: multiplicative
2026-06-25 15:10:54 
2026-06-25 15:10:54 FREE PARAMETERS:
2026-06-25 15:10:54   log_gp_sigma_0_GP_sm      ('uniform', -2.0, 1.0)                    (global)
2026-06-25 15:10:54   log_gp_sigma_1_GP_sm      ('uniform', -3.0, 0.0)                    (global)
2026-06-25 15:10:54   log_gp_sigma_2_GP_sm      ('uniform', -3.0, 1.0)                    (global)
2026-06-25 15:10:54   log_gp_lengthscale_GP_sm  ('uniform', 1.802585092994046, 2.802585092994046)  (global)
2026-06-25 15:10:54 
2026-06-25 15:10:54 FIXED PARAMETERS:
2026-06-25 15:10:54   gp_freq_GP_sm             0.5                                     
2026-06-25 15:10:54   log_jitter                -inf                                    
2026-06-25 15:10:54   norm                      1.0                                     
2026-06-25 15:10:54   q1                        0.3                                     
2026-06-25 15:10:54   q2                        0.2                                     
2026-06-25 15:10:54   rho_star                  1.0                                     
2026-06-25 15:10:54 
2026-06-25 15:10:54 SpectralMixture kernel components in section '1': 3
2026-06-25 15:10:54 ==========================================================================================
2026-06-25 15:10:54  
2026-06-25 15:10:54 WARNING: internal_warmup_if_nuts=120 is too low for reliable NUTS adaptation (min=500). Clamping to 500.
2026-06-25 15:10:54 Ensemble walkers: 4 × 4 = 16 → 16 (first even number)
2026-06-25 15:10:54 Sampler config: production_sampler=ESS (no warmup), 16 walkers, 500 samples
2026-06-25 15:10:54 
2026-06-25 15:10:54 Fresh start on CPU: direct ESS (16 walkers, no warmup)
2026-06-25 15:10:54 Free params (4): ['log_gp_sigma_0_GP_sm', 'log_gp_sigma_1_GP_sm', 'log_gp_sigma_2_GP_sm', 'log_gp_lengthscale_GP_sm']
2026-06-25 15:10:54 === DIRECT ESS PRODUCTION (no warmup) ===
2026-06-25 15:10:54 Walkers: 16, Samples: 500
2026-06-25 15:10:54   Running 1 pilot sample to trigger JIT compilation…
2026-06-25 15:10:57   JIT compilation + 1 pilot step: 2.9s
2026-06-25 15:10:57 Sampling 500 iterations with checkpoints every 100...
2026-06-25 15:10:57 Checkpoints: PyAETNAouts/test_spectral_mixture.pckl
2026-06-25 15:10:57   Running 1 pilot sample to trigger JIT compilation…
2026-06-25 15:10:58   JIT compilation + 1 pilot sample: 1.2s  — all batch rates below reflect true hardware throughput
2026-06-25 15:11:05 Progress: 101/500 (20.2%) | Rate: 79.168 it/s | SS rate (steady-state): 79.168 it/s | ETA: 5s [ESS=1.3s]
2026-06-25 15:11:13 Progress: 201/500 (40.2%) | Rate: 127.940 it/s | SS rate (steady-state): 97.811 it/s | ETA: 3s [ESS=0.8s]
2026-06-25 15:11:23 Progress: 301/500 (60.2%) | Rate: 120.117 it/s | SS rate (steady-state): 104.265 it/s | ETA: 2s [ESS=0.8s]
2026-06-25 15:11:30 Progress: 401/500 (80.2%) | Rate: 103.804 it/s | SS rate (steady-state): 104.150 it/s | ETA: 1s [ESS=1.0s]
2026-06-25 15:11:38 Progress: 500/500 (100.0%) | Rate: 64.486 it/s | SS rate (steady-state): 92.823 it/s | ETA: 0s [ESS=1.5s]
2026-06-25 15:11:38   Steady-state rate: 92.823 it/s | JIT (pilot): 1.2s | Total: 41s
2026-06-25 15:11:38 === END ESS PRODUCTION ===
2026-06-25 15:11:38 Total MCMC time: 44s
2026-06-25 15:11:38 Saving to PyAETNAouts/test_spectral_mixture.pckl...
2026-06-25 15:11:38 Sampling finished.
2026-06-25 15:11:38 
2026-06-25 15:11:38
2026-06-25 15:11:38
2026-06-25 15:11:38 ###############################
2026-06-25 15:11:38 #
2026-06-25 15:11:38 #       REPORTING STARTED
2026-06-25 15:11:38 #
2026-06-25 15:11:38 ###############################
2026-06-25 15:11:38 INFO: Loading: PyAETNAouts//test_spectral_mixture.pckl
2026-06-25 15:11:38 INFO: Loaded 8000 scalar-param samples (16 chains × 500)
2026-06-25 15:11:38 INFO: 
2026-06-25 15:11:38 INFO: ==========================================================================================
2026-06-25 15:11:38 INFO: MAP SEARCH (Maximum A Posteriori)
2026-06-25 15:11:38 INFO: ==========================================================================================
2026-06-25 15:11:38 INFO: No potential_energy available - evaluating chain endpoints...
2026-06-25 15:11:39 INFO:     Chain 0: energy = -767.971542 (loglike=771.56, logprior=-3.58)
2026-06-25 15:11:39 INFO:     Chain 1: energy = -770.000266 (loglike=773.58, logprior=-3.58)
2026-06-25 15:11:39 INFO:     Chain 2: energy = -769.693652 (loglike=773.28, logprior=-3.58)
2026-06-25 15:11:39 INFO:     Chain 3: energy = -770.747228 (loglike=774.33, logprior=-3.58)
2026-06-25 15:11:39 INFO:     Chain 4: energy = -769.465467 (loglike=773.05, logprior=-3.58)
2026-06-25 15:11:39 INFO:     Chain 5: energy = -769.137485 (loglike=772.72, logprior=-3.58)
2026-06-25 15:11:39 INFO:     Chain 6: energy = -769.794605 (loglike=773.38, logprior=-3.58)
2026-06-25 15:11:39 INFO:     Chain 7: energy = -769.443936 (loglike=773.03, logprior=-3.58)
2026-06-25 15:11:39 INFO:     Chain 8: energy = -768.693777 (loglike=772.28, logprior=-3.58)
2026-06-25 15:11:39 INFO:     Chain 9: energy = -769.657909 (loglike=773.24, logprior=-3.58)
2026-06-25 15:11:39 INFO:     Chain 10: energy = -769.776733 (loglike=773.36, logprior=-3.58)
2026-06-25 15:11:39 INFO:     Chain 11: energy = -769.172531 (loglike=772.76, logprior=-3.58)
2026-06-25 15:11:39 INFO:     Chain 12: energy = -770.069315 (loglike=773.65, logprior=-3.58)
2026-06-25 15:11:40 INFO:     Chain 13: energy = -770.540210 (loglike=774.12, logprior=-3.58)
2026-06-25 15:11:40 INFO:     Chain 14: energy = -769.020568 (loglike=772.60, logprior=-3.58)
2026-06-25 15:11:40 INFO:     Chain 15: energy = -767.797758 (loglike=771.38, logprior=-3.58)
2026-06-25 15:11:40 INFO: Best chain endpoint: chain 3 (energy: -770.7472)
2026-06-25 15:11:40 INFO: Skipping optimization step
2026-06-25 15:11:40 INFO: MAP source: last_samples
2026-06-25 15:11:40 INFO: MAP energy: -770.7472
2026-06-25 15:11:40 INFO: ==========================================================================================
2026-06-25 15:11:40 INFO: 
2026-06-25 15:11:40 INFO: Raw sample summary (before rejecting 100 extra warmup):
2026-06-25 15:11:40 INFO: 
2026-06-25 15:11:40 INFO: ==================================================================================================================================
2026-06-25 15:11:40 INFO: SAMPLING SUMMARY (raw post-warmup samples)
2026-06-25 15:11:40 INFO: Note: These are the raw collected samples. Use the final summary table below (after discard) for analysis.
2026-06-25 15:11:40 INFO: Parameter                              Mean          Std          Q16       Median          Q84        ESS      ESS/s     Rhat
2026-06-25 15:11:40 INFO: ----------------------------------------------------------------------------------------------------------------------------------
2026-06-25 15:11:40 INFO: log_gp_sigma_0_GP_sm              -0.948634     0.235042    -1.177547    -0.951180    -0.721983     5774.7       0.00  0.9999
2026-06-25 15:11:40 INFO: log_gp_sigma_1_GP_sm              -2.218044     0.268908    -2.472574    -2.239032    -1.968655     6521.0       0.00  0.9998
2026-06-25 15:11:40 INFO: log_gp_sigma_2_GP_sm              -2.033365     0.276201    -2.308544    -2.049645    -1.760629     5892.7       0.00  1.0014
2026-06-25 15:11:40 INFO: log_gp_lengthscale_GP_sm           2.255482     0.080088     2.177416     2.256461     2.331224     5271.9       0.00  0.9994
2026-06-25 15:11:40 INFO: ----------------------------------------------------------------------------------------------------------------------------------
2026-06-25 15:11:40 INFO: # * = Rhat > 1.01 (warning), ** = Rhat > 1.1 (poor convergence)
2026-06-25 15:11:40 INFO: # 16 chains, 500 samples/chain, 100 warmup iterations
2026-06-25 15:11:40 INFO: ==================================================================================================================================
2026-06-25 15:11:40 INFO: 
2026-06-25 15:11:40 INFO: ====================================================================================================================================================================================
2026-06-25 15:11:40 INFO: MCMC SUMMARY (after rejecting 100 extra warmup)
2026-06-25 15:11:40 INFO: parameter                              mean          std          q16       median          q84          MAP      P(tail)        ess      ess/s     rhat
2026-06-25 15:11:40 INFO: ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2026-06-25 15:11:40 INFO: log_gp_sigma_0_GP_sm              -0.945665     0.230655     -1.17131    -0.947608    -0.724881     -1.14262   P(<)=19.3%     4735.0       0.00  1.0001
2026-06-25 15:11:40 INFO: log_gp_sigma_1_GP_sm               -2.21627     0.259069     -2.46661     -2.23714     -1.96967     -2.44599   P(<)=18.0%     5164.8       0.00  0.9997
2026-06-25 15:11:40 INFO: log_gp_sigma_2_GP_sm               -2.03999     0.275237     -2.31208     -2.05903     -1.76996     -2.20828   P(<)=28.6%     4705.2       0.00  1.0014
2026-06-25 15:11:40 INFO: log_gp_lengthscale_GP_sm            2.25713    0.0789604      2.18059      2.25816      2.33227      2.22088   P(<)=31.6%     4300.9       0.00  0.9990
2026-06-25 15:11:40 INFO: ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2026-06-25 15:11:40 INFO: # * = rhat > 1.01 (warning), ** = rhat > 1.1 (poor convergence)
2026-06-25 15:11:40 INFO: # MAP source: last_samples
2026-06-25 15:11:40 INFO: # P(tail) = P(param < MAP) or P(param > MAP) depending on whether MAP < or > median
2026-06-25 15:11:40 INFO: # num_chains=16, num_samples_per_chain=400, num_warmup=100
2026-06-25 15:11:40 INFO: ====================================================================================================================================================================================
2026-06-25 15:11:40 INFO: 
2026-06-25 15:11:40 INFO: ==========================================================================================
2026-06-25 15:11:40 INFO: GOODNESS-OF-FIT STATISTICS
2026-06-25 15:11:40 INFO: ==========================================================================================
2026-06-25 15:11:40 INFO: OVERALL (all instruments combined):
2026-06-25 15:11:40 INFO:   Data points (N):            240
2026-06-25 15:11:40 INFO:   Free parameters (k):        4
2026-06-25 15:11:40 INFO:   Degrees of freedom:         236
2026-06-25 15:11:40 INFO:   Chi-squared:                358.8752
2026-06-25 15:11:40 INFO:   Reduced Chi-squared:        1.5207
2026-06-25 15:11:40 INFO: 
2026-06-25 15:11:40 INFO:   Information Criteria:
2026-06-25 15:11:40 INFO:     AIC  = 2k - 2*ln(L)       = -1533.4945
2026-06-25 15:11:40 INFO:     AICc (corrected)          = -1533.3250
2026-06-25 15:11:40 INFO:     BIC  = k*ln(N) - 2*ln(L)  = -1519.5719
2026-06-25 15:11:40 INFO: 
2026-06-25 15:11:40 INFO: 
2026-06-25 15:11:40 INFO: PER-VISIT STATISTICS:
2026-06-25 15:11:40 INFO:   Residuals include GP mean (y − total_model where total = det + GP mean).
2026-06-25 15:11:40 INFO:   sigma_orig  = uncertainties from the data file  (SIGMA column).
2026-06-25 15:11:40 INFO:   sigma_tot   = sqrt(sigma_orig² + jitter²)  (jitter-inflated).
2026-06-25 15:11:40 INFO:   nRMS        = sqrt(chi2/N) = sqrt(mean((r/sigma)²))  [consistent with chi2].
2026-06-25 15:11:40 INFO:   chi2_red uses global n_free_params as a conservative DOF floor.
2026-06-25 15:11:40 INFO: 
2026-06-25 15:11:40 INFO:   LC (LC):
2026-06-25 15:11:40 INFO:     Visit 1  (N = 240):
2026-06-25 15:11:40 INFO:       With sigma_orig (chi2_red >> 1 expected when jitter is large):
2026-06-25 15:11:40 INFO:         chi2_red  = 1.5207
2026-06-25 15:11:40 INFO:         RMS (O-C) = 0.006114
2026-06-25 15:11:40 INFO:         nRMS      = 1.2228
2026-06-25 15:11:40 INFO:         median sigma_orig = 0.005000
2026-06-25 15:11:40 INFO:       With sigma_tot (chi2_red ~ 1 and nRMS ~ 1 expected by design):
2026-06-25 15:11:40 INFO:         chi2_red  = 1.5207
2026-06-25 15:11:40 INFO:         RMS (O-C) = 0.006114
2026-06-25 15:11:40 INFO:         nRMS      = 1.2228
2026-06-25 15:11:40 INFO:         median sigma_tot  = 0.005000
2026-06-25 15:11:40 INFO: 
2026-06-25 15:11:40 INFO: ==========================================================================================
2026-06-25 15:11:40 INFO: Generating PDF report: PyAETNAouts//test_spectral_mixture.pdf
2026-06-25 15:11:40 INFO:   - Corner plot...
2026-06-25 15:11:40 INFO:   - KDE + Trace plots (4 params)...
2026-06-25 15:11:42 INFO:   - Chain comparison plot...
2026-06-25 15:11:42 INFO:   - Computing model components...
2026-06-25 15:11:42 INFO:     Built GP kernel for instrument LC (x_var=BJD)
2026-06-25 15:11:42 INFO:   - Pre-computing sample data for best-fit plots (1000 samples)...
2026-06-25 15:11:43 INFO:     done in 0.3 s
2026-06-25 15:11:43 INFO:   - Skipping per-visit plots (all 1 visits belong to single-visit instruments; redundant with per-instrument)
2026-06-25 15:11:43 INFO:   - Per-instrument best-fit lightcurve: LC
2026-06-25 15:11:43 INFO:   [band grid] 1000 model samples on 275 grid pts (LC-train+gaps, pad=0.000 d) + GP posterior mean [cached]
Loading