AstroFrame/src/AstroFrame.Engine/Models.cs
Elijah 6b56c0b122
All checks were successful
Release AstroFrame / packages (push) Successful in 1m1s
Release 1.0.2 with localized sky overlay and cloud-resistant display fit
2026-10-03 20:36:20 -07:00

97 lines
4.7 KiB
C#
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.

namespace AstroFrame.Engine;
public enum Verdict { Keep, Review, Reject }
public sealed record Star(double X,double Y,double Flux,double Fwhm,double Ellipticity);
public sealed record Region(double Background,double Noise,int Stars);
public sealed record Evidence(string Metric,double Value,double Baseline,double Severity,string Message);
public sealed class Frame
{
public string Id {get;set;}="";
public string Path {get;set;}="";
public long Length {get;set;}
public long Modified {get;set;}
public string Target {get;set;}="";
public string Instrument {get;set;}="";
public string Filter {get;set;}="";
public string Gain {get;set;}="";
public string Bayer {get;set;}="";
public DateTime? Timestamp {get;set;}
public double Exposure {get;set;}
public int Width {get;set;}
public int Height {get;set;}
public double Ra {get;set;}
public double Dec {get;set;}
public string Session {get;set;}="";
public double Background {get;set;}
public double Noise {get;set;}
public int StarCount {get;set;}
public double Fwhm {get;set;}
public double Ellipticity {get;set;}
public double Transparency {get;set;}
public double MatchFraction {get;set;}
public double SpatialLoss {get;set;}
public double BackgroundVariation {get;set;}
public double CloudCoverage {get;set;}
public double CloudSignificance {get;set;}
public double ReferenceConfidence {get;set;}
public byte[] CloudMask {get;set;}=[];
// Pink overlay strength (0–255); independent of the two-sided classification mask.
public byte[] ExcessSkyMask {get;set;}=[];
[System.Text.Json.Serialization.JsonIgnore] public float[] SkyMap {get;set;}=[];
[System.Text.Json.Serialization.JsonIgnore] public float[] SkyNoise {get;set;}=[];
[System.Text.Json.Serialization.JsonIgnore] public double[] ForcedFlux {get;set;}=[];
[System.Text.Json.Serialization.JsonIgnore] public string ForcedReferenceId {get;set;}="";
[System.Text.Json.Serialization.JsonIgnore] public bool CacheDirty {get;set;}
public double Score {get;set;}
public double[] RegionFlux {get;set;}=new double[12];
public double[] RegionLoss {get;set;}=new double[12];
public int[] RegionMatches {get;set;}=new int[12];
public double[] Alignment {get;set;}=[];
public string ReferenceId {get;set;}="";
[System.Text.Json.Serialization.JsonIgnore] public List<Star> Stars {get;set;}=[];
public List<Region> Regions {get;set;}=[];
public List<Evidence> Evidence {get;set;}=[];
public Dictionary<string,double> Baselines {get;set;}=[];
public Dictionary<string,double> AdditionalMeasurements {get;set;}=[];
public Verdict Automatic {get;set;}=Verdict.Review;
public Verdict? Override {get;set;}
public string Note {get;set;}="";
public DateTime? ReviewedAt {get;set;}
public string Error {get;set;}="";
public string Warning {get;set;}="";
public string Cause {get;set;}="Awaiting analysis";
public bool Measured {get;set;}
[System.Text.Json.Serialization.JsonIgnore] public Verdict Effective=>Override??Automatic;
[System.Text.Json.Serialization.JsonIgnore] public string Name=>System.IO.Path.GetFileName(Path);
[System.Text.Json.Serialization.JsonIgnore] public string Status=>Effective.ToString().ToUpperInvariant();
[System.Text.Json.Serialization.JsonIgnore] public string Time=>Timestamp?.ToString("MM-dd HH:mm:ss")??"Unknown time";
[System.Text.Json.Serialization.JsonIgnore] public string Summary=>Override.HasValue?"Manual decision · "+Cause:Cause;
}
public sealed class Project
{
public const string EngineVersion="0.2.0-spatial-reference-1";
public string Version {get;set;}=EngineVersion;
public string Name {get;set;}="Untitled";
public string Source {get;set;}="";
public DateTime Updated {get;set;}=DateTime.UtcNow;
public bool Complete {get;set;}
public List<Frame> Frames {get;set;}=[];
}
public sealed record ProgressInfo(int Done,int Total,string Stage,string File);
public interface IFrameDetector
{
string Name {get;}
void Measure(Frame frame,ImagePlane image,CancellationToken cancellationToken);
}
public static class Robust
{
public static double Median(IEnumerable<double> values)=>Quantile(values,.5);
public static double Quantile(IEnumerable<double> values,double q)
{
var a=values.Where(double.IsFinite).Order().ToArray(); if(a.Length==0)return 0;
double p=Math.Clamp(q,0,1)*(a.Length-1);int i=(int)p;
return a[i]+(a[Math.Min(i+1,a.Length-1)]-a[i])*(p-i);
}
public static double Mad(IEnumerable<double> values)
{var a=values.Where(double.IsFinite).ToArray();double m=Median(a);return 1.4826*Median(a.Select(x=>Math.Abs(x-m)));}
}