Release 1.1.2: improve processing status and inspect stellar elongation
All checks were successful
Release AstroFrame / packages (push) Successful in 1m9s

This commit is contained in:
Elijah 2026-10-04 12:54:24 -07:00
parent 65ded0b606
commit 5ad7a6a79e
12 changed files with 258 additions and 41 deletions

View file

@ -60,7 +60,7 @@ static class ImageRegression
}
finally{Directory.Delete(directory,true);}
}
static void WriteFits(string path,float[] pixels,int width,int height,int n)
internal static void WriteFits(string path,float[] pixels,int width,int height,int n)
{
string Card(string key,string value)=>(key.PadRight(8)+"= "+value).PadRight(80);
string date=new DateTime(2026,9,20,8,0,0,DateTimeKind.Utc).AddSeconds(n*30).ToString("yyyy-MM-ddTHH:mm:ss",CultureInfo.InvariantCulture);

View file

@ -129,4 +129,5 @@ await ImageRegression.Run(Check);
QualityRegression.Run(Check);
OverlayRegression.Run(Check);
PreviewRegression.Run(Check);
StellarDetailRegression.Run(Check);
Console.WriteLine($"{passed} checks passed. Synthetic tests validate mechanics, not astrophotography stack quality.");

View file

@ -0,0 +1,51 @@
using AstroFrame.Engine;
using System.Security.Cryptography;
static class StellarDetailRegression
{
public static void Run(Action<bool,string> check)
{
double[] Gaussian(double major,double minor,double angle)=>Enumerable.Range(0,169).Select(i=>
{
double x=i%13-6,y=i/13-6,u=x*Math.Cos(angle)+y*Math.Sin(angle),v=-x*Math.Sin(angle)+y*Math.Cos(angle);
return 1000+3000*Math.Exp(-.5*(u*u/(major*major)+v*v/(minor*minor)));
}).ToArray();
var round=StellarDetail.Describe(Gaussian(1,1,0))!;
var stretched=StellarDetail.Describe(Gaussian(1.4,.7,.6))!;
check(round.Ellipticity<.001&&stretched.Ellipticity>.45&&Math.Abs(stretched.Angle-.6)<.03,"source-moment guides distinguish round stars from rotated elongation");
check(Math.Abs(stretched.X-6.5)<.01&&Math.Abs(stretched.Y-6.5)<.01,"shape guides remain centered on source pixel centers");
check(StellarDetail.Describe(Enumerable.Repeat(1000.0,169).ToArray())==null&&StellarDetail.Describe([double.NaN])==null,"empty or invalid stellar profiles do not invent shape guides");
string directory=Path.Combine(Path.GetTempPath(),"AstroFrame-stars-"+Guid.NewGuid());Directory.CreateDirectory(directory);
try
{
const int size=64;var positions=new[]{(X:14,Y:16),(X:40,Y:38),(X:18,Y:43)};List<Frame> frames=[];
for(int n=0;n<2;n++)
{
float[] pixels=Enumerable.Repeat(1000f,size*size).ToArray();
foreach(var p in positions)for(int y=0;y<size;y++)for(int x=0;x<size;x++)
{
double dx=x-p.X-(n==0?0:3),dy=y-p.Y+(n==0?0:2),u=dx*Math.Cos(.6)+dy*Math.Sin(.6),v=-dx*Math.Sin(.6)+dy*Math.Cos(.6),a=n==0?1.4:1,b=n==0?.7:1;
pixels[y*size+x]+=(float)(3000*Math.Exp(-.5*(u*u/(a*a)+v*v/(b*b))));
}
string path=Path.Combine(directory,$"star{n}.fit");ImageRegression.WriteFits(path,pixels,size,size,n);
var f=Fits.Inspect(path);f.Measured=true;f.Session="shared";f.Automatic=Verdict.Keep;f.MatchFraction=1;f.ReferenceId="reference";f.Alignment=[1,0,n==0?0:3.0/size,n==0?0:-2.0/size];
f.Stars=positions.Select(p=>new Star((double)p.X/size,(double)p.Y/size,100,3,n==0?.5:0)).ToList();frames.Add(f);
}
var project=new Project{Frames=frames};ProjectStore.Save(project,directory);
byte[] hash=SHA256.HashData(File.ReadAllBytes(frames[0].Path));
check(StellarDetail.Comparison(project,frames[0])==frames[1],"elongation inspector selects an aligned same-session KEEP comparison");
var detail=StellarDetail.Read(directory,frames[0],frames[1]);
check(detail.Stars.Count==3&&detail.Stars.All(s=>s.Selected.Shape!.Ellipticity>.45&&s.Comparison!.Shape!.Ellipticity<.01),"aligned shifted source crops compare the same elongated and round stars");
check(hash.SequenceEqual(SHA256.HashData(File.ReadAllBytes(frames[0].Path)))&&frames[0].Automatic==Verdict.Keep,"source inspection preserves FITS bytes and frame decisions");
frames[1].Override=Verdict.Reject;
check(StellarDetail.Comparison(project,frames[0])==null&&StellarDetail.Read(directory,frames[0],null).Stars.All(s=>s.Comparison==null),"source elongation remains inspectable without a suitable KEEP exposure");
frames[1].Override=null;frames[1].ReferenceId="different";
check(StellarDetail.Comparison(project,frames[0])==null,"unrelated reference alignments are excluded from star comparison");
using var cancel=new CancellationTokenSource();cancel.Cancel();bool cancelled=false;try{StellarDetail.Read(directory,frames[0],null,cancel.Token);}catch(OperationCanceledException){cancelled=true;}
check(cancelled,"source star inspection cancels during read");
frames[0].Modified--;bool refused=false;try{StellarDetail.Read(directory,frames[0],null);}catch(IOException){refused=true;}
check(refused,"changed sources are refused by the elongation inspector");
}
finally{Directory.Delete(directory,true);}
}
}