All checks were successful
Release AstroFrame / packages (push) Successful in 1m8s
63 lines
5.1 KiB
C#
63 lines
5.1 KiB
C#
using AstroFrame.Engine;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
static class QualityRegression
|
|
{
|
|
public static void Run(Action<bool,string> check)
|
|
{
|
|
var stars=Enumerable.Range(0,100).Select(i=>new Star(.08+(i%10)*.09,.08+(i/10)*.09,3000-i*10,4,.1)).ToList();
|
|
Frame Make(int n)=>new(){Id=n.ToString(),Path="quality"+n,Target="Quality",Exposure=30,Width=2160,Height=3840,
|
|
Timestamp=new DateTime(2026,9,20,8,0,0,DateTimeKind.Utc).AddSeconds(n*30),Measured=true,
|
|
StarCount=100,Stars=stars.ToList(),Fwhm=4,Ellipticity=.1,Background=1000,Noise=20,
|
|
CloudMask=new byte[SkyModel.Count],ReferenceConfidence=1,
|
|
AdditionalMeasurements=new(){{"Clear reference member",1},{"Forced flux samples",100},{"Matched shape reference frames",20}}};
|
|
var frames=Enumerable.Range(0,40).Select(Make).ToList();
|
|
var opaque=Make(40);opaque.Stars=stars.Take(25).ToList();opaque.StarCount=25;
|
|
var broad=Make(41);var gradient=Make(42);var uncertain=Make(43);var cohort=Make(44);var trailing=Make(45);
|
|
var subtleShape=Make(46);var insufficient=Make(47);var noisyFlux=Make(48);
|
|
frames.AddRange([opaque,broad,gradient,uncertain,cohort,trailing,subtleShape,insufficient,noisyFlux]);
|
|
foreach(var f in frames)
|
|
{
|
|
Matching.Measure(frames[0],f);f.Transparency=1;f.RegionFlux=Enumerable.Repeat(1.0,12).ToArray();f.RegionMatches=Enumerable.Repeat(8,12).ToArray();
|
|
}
|
|
void Cloud(Frame f,double significance,double coverage,double ratio)
|
|
{
|
|
f.AdditionalMeasurements["Clear reference member"]=0;f.CloudSignificance=significance;f.CloudCoverage=coverage;
|
|
f.AdditionalMeasurements["Cloud connected coverage"]=coverage*.6;
|
|
f.AdditionalMeasurements["Cloud positive coverage"]=coverage*.6;
|
|
f.AdditionalMeasurements["Cloud positive connected coverage"]=coverage*.4;
|
|
f.AdditionalMeasurements["Cloud aperture samples"]=80;f.AdditionalMeasurements["Cloud aperture regions"]=6;
|
|
f.AdditionalMeasurements["Cloud aperture flux ratio"]=ratio;f.AdditionalMeasurements["Cloud aperture flux deviation"]=(1-ratio)/.03;
|
|
}
|
|
Cloud(opaque,100,.9,.05);opaque.Transparency=.05;
|
|
Cloud(broad,15,.5,.85);broad.Transparency=.90;
|
|
Cloud(gradient,15,.5,1);
|
|
Cloud(insufficient,15,.5,.85);insufficient.AdditionalMeasurements["Cloud aperture samples"]=19;
|
|
Cloud(noisyFlux,15,.5,.85);noisyFlux.AdditionalMeasurements["Cloud aperture flux deviation"]=2.9;
|
|
Cloud(uncertain,100,.9,.05);uncertain.Transparency=.05;uncertain.MatchFraction=.1;
|
|
uncertain.AdditionalMeasurements["Alignment verified"]=0;
|
|
cohort.Ellipticity=.3;cohort.AdditionalMeasurements["Matched shape samples"]=100;
|
|
cohort.AdditionalMeasurements["Matched shape change"]=.04;cohort.AdditionalMeasurements["Matched shape uncertainty"]=.01;
|
|
trailing.Ellipticity=.3;trailing.AdditionalMeasurements["Matched shape samples"]=100;
|
|
trailing.AdditionalMeasurements["Matched shape change"]=.2;trailing.AdditionalMeasurements["Matched shape uncertainty"]=.01;
|
|
subtleShape.Ellipticity=.3;subtleShape.AdditionalMeasurements["Matched shape samples"]=100;
|
|
subtleShape.AdditionalMeasurements["Matched shape change"]=.12;subtleShape.AdditionalMeasurements["Matched shape uncertainty"]=.005;
|
|
Classification.Run(frames);
|
|
check(opaque.Automatic==Verdict.Reject,"severe cloud with accurate geometry rejects despite missing reference stars");
|
|
check(broad.Automatic==Verdict.Reject,"broad coherent sky structure with local aperture attenuation rejects");
|
|
check(gradient.Automatic==Verdict.Review,"uncorroborated sky structure stays REVIEW rather than rejecting a possible gradient");
|
|
check(uncertain.Automatic==Verdict.Review,"severe apparent cloud with unverified geometry stays REVIEW");
|
|
check(cohort.Automatic==Verdict.Keep,"matched-star evidence can resolve an elongation flag caused by a changed detection cohort");
|
|
check(trailing.Automatic==Verdict.Review,"matched-star elongation remains REVIEW when other measurements are normal");
|
|
check(subtleShape.Automatic==Verdict.Review,"measurable sub-threshold matched elongation is not promoted to KEEP");
|
|
check(insufficient.Automatic==Verdict.Review&&noisyFlux.Automatic==Verdict.Review,"too few or noisy affected apertures cannot authorize cloud rejection");
|
|
check(frames.Take(40).All(f=>f.Automatic==Verdict.Keep),"quality policy changes preserve unchanged clear comparisons");
|
|
var options=new JsonSerializerOptions{PropertyNameCaseInsensitive=true,Converters={new JsonStringEnumConverter()}};
|
|
var fixture=JsonSerializer.Deserialize<Fixture>(File.ReadAllText(Path.Combine(AppContext.BaseDirectory,"Fixtures","quality-real-frames.json")),options)!;
|
|
var real=fixture.Frames.ToList();Classification.Run(real);
|
|
foreach(var label in fixture.Expected)
|
|
check(real.Single(f=>f.Name==label.Key).Automatic==label.Value,$"real measured regression {label.Key}: {label.Value}");
|
|
}
|
|
sealed record Fixture(string Source,Frame[] Frames,Dictionary<string,Verdict> Expected);
|
|
}
|