Release 1.0.2 with localized sky overlay and cloud-resistant display fit
All checks were successful
Release AstroFrame / packages (push) Successful in 1m1s
All checks were successful
Release AstroFrame / packages (push) Successful in 1m1s
This commit is contained in:
parent
1e8e8c88fe
commit
6b56c0b122
16 changed files with 227 additions and 24 deletions
|
|
@ -1,6 +1,6 @@
|
|||
<Project>
|
||||
<PropertyGroup>
|
||||
<Version>1.0.1</Version>
|
||||
<Version>1.0.2</Version>
|
||||
<Authors>Elijah Kuntz</Authors>
|
||||
<Product>AstroFrame</Product>
|
||||
</PropertyGroup>
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ Exports include `accepted.txt` with accepted output paths and `decisions.csv` wi
|
|||
|
||||
## Build and validate
|
||||
|
||||
The [server release workflow](.forgejo/workflows/release.yml) builds and publishes both platforms when a stable version tag such as `v1.0.2` is pushed. Set the matching version with `./packaging/Set-Version.ps1 -Version 1.0.2`, commit/push the source, then push the tag. It uses the existing Docker runner and automatically supplied Forgejo token. Pushes and manual Actions runs on `main` check the build without publishing. Version [1.0.1 is published](https://git.elijahkuntz.com/Elijah/AstroFrame/releases/tag/v1.0.1). See [automatic releases](docs/releases.md#automatic-server-releases).
|
||||
The [server release workflow](.forgejo/workflows/release.yml) builds and publishes both platforms when a stable version tag such as `v1.0.3` is pushed. Set the matching version with `./packaging/Set-Version.ps1 -Version 1.0.3`, commit/push the source, then push the tag. It uses the existing Docker runner and automatically supplied Forgejo token. Pushes and manual Actions runs on `main` check the build without publishing. Version 1.0.2 fixes the spatial preview overlay; see [release notes](docs/release-notes/1.0.2.md) and [automatic releases](docs/releases.md#automatic-server-releases).
|
||||
|
||||
Requires a .NET 8 SDK. `Build.ps1` uses the workspace-local SDK if present, otherwise `dotnet` from PATH:
|
||||
|
||||
|
|
|
|||
9
docs/release-notes/1.0.2.md
Normal file
9
docs/release-notes/1.0.2.md
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
AstroFrame 1.0.2 fixes the spatial preview overlay.
|
||||
|
||||
- Pink now highlights positive sky structure relative to the clean session reference, rather than both brighter and darker differences.
|
||||
- A cloud-resistant background fit removes offset and gradient without creating false highlights in clear corners.
|
||||
- Strong and moderately bright cloud patches remain visible; weak background residuals are excluded.
|
||||
- A legend explains the pink fill and the regional stellar-flux grid.
|
||||
- Existing projects reconstruct the corrected display from cached measurements without requiring a full reanalysis. Classification metrics, decisions, notes and source images are preserved.
|
||||
|
||||
Verified on the reported NGC 1432 exposures ending in 235115, 235146 and 235248, with regressions for visible cloud cores, dark comparison regions and read-only project reconstruction.
|
||||
|
|
@ -40,6 +40,8 @@ To uninstall a script-installed Linux copy, close AstroFrame and remove only `~/
|
|||
|
||||
## Settings and updates
|
||||
|
||||
Version **1.0.2** corrects the spatial preview overlay. Pink shows the strongest positive sky structure against the clean session reference; the display fit resists bright cloud contamination, and weak background residuals are suppressed. Both bright and moderately bright cloud patches remain visible. The grid shows regional stellar flux. This is supporting evidence rather than an exact cloud boundary. Existing saved projects reconstruct the display from cached catalogs without changing classification metrics or human decisions. See [1.0.2 release notes](release-notes/1.0.2.md).
|
||||
|
||||
Open **Settings → Updates** for the installed version, update status, last successful check, automatic-check preference, and **Check for updates**. The sidebar and independent settings store leave room for future categories.
|
||||
|
||||
Installed packages check on launch and every six hours while running. A persistent **Settings · Update available** indicator appears when a newer stable version is found. **Install update and restart** downloads the update, validates its package checksum, saves the project and restarts. Analysis, export and saving block installation; if work starts during download, the package remains ready for a later restart. Projects and settings survive updates. Failed checks display an error rather than claiming the app is up to date. Source-tree builds explain that installing a package enables updates.
|
||||
|
|
@ -59,12 +61,12 @@ Once this workflow is committed and pushed, enable Actions for the AstroFrame re
|
|||
To release a new version:
|
||||
|
||||
```powershell
|
||||
./packaging/Set-Version.ps1 -Version 1.0.2
|
||||
./packaging/Set-Version.ps1 -Version 1.0.3
|
||||
git add Directory.Build.props
|
||||
git commit -m "Release 1.0.2"
|
||||
git commit -m "Release 1.0.3"
|
||||
git push origin main
|
||||
git tag v1.0.2
|
||||
git push origin v1.0.2
|
||||
git tag v1.0.3
|
||||
git push origin v1.0.3
|
||||
```
|
||||
|
||||
Include all intended source changes in the release commit before tagging. The pushed tag is the publication trigger; ordinary commits to `main` run the build and checks without publishing. The version in `Directory.Build.props` must exactly match the tag. Version `v1.0.1` is published; `v1.0.0` remains an unpublished tag from the first failed publishing attempt. Choose a new version for each later release.
|
||||
|
|
@ -89,7 +91,7 @@ The Windows script cross-packages both platforms. Results appear in `artifacts/r
|
|||
On Linux with a .NET 10 SDK:
|
||||
|
||||
```sh
|
||||
bash packaging/release.sh 1.0.1
|
||||
bash packaging/release.sh 1.0.2
|
||||
```
|
||||
|
||||
That script builds the Linux channel. The tool manifest pins Velopack CLI 1.2.161, matching the application's SDK dependency. Building on Windows is enough to create both packages, but compatibility should still be checked on target Linux desktops.
|
||||
|
|
|
|||
|
|
@ -55,7 +55,9 @@ try { $release = Invoke-RestMethod "$api/releases/tags/$tag" -Headers $headers }
|
|||
catch { if ([int]$_.Exception.Response.StatusCode -ne 404) { throw } }
|
||||
if ($release -and !$release.draft) { throw "$tag is already published. Release assets are immutable; build a new version." }
|
||||
if (!$release) {
|
||||
$body = @{ tag_name=$tag; target_commitish=$commit; name="AstroFrame $Version"; body="AstroFrame $Version for Windows and Linux. See the repository README for installation and update instructions."; draft=$true; prerelease=$false } | ConvertTo-Json
|
||||
$notesPath = Join-Path 'docs/release-notes' "$Version.md"
|
||||
$notes = if (Test-Path -LiteralPath $notesPath) { Get-Content -LiteralPath $notesPath -Raw } else { "AstroFrame $Version for Windows and Linux. See the repository README for installation and update instructions." }
|
||||
$body = @{ tag_name=$tag; target_commitish=$commit; name="AstroFrame $Version"; body=$notes; draft=$true; prerelease=$false } | ConvertTo-Json
|
||||
$release = Invoke-RestMethod "$api/releases" -Method Post -Headers $headers -ContentType 'application/json' -Body $body
|
||||
}
|
||||
$attached = @(Invoke-RestMethod "$api/releases/$($release.id)/assets" -Headers $headers)
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@ public sealed partial class MainWindow:Window
|
|||
filter.SelectionChanged+=(_,_)=>{if(!refreshing)RefreshFrames();};sort.SelectionChanged+=(_,_)=>{if(!refreshing)RefreshFrames();};metric.SelectionChanged+=(_,_)=>{chart.Metric=QualityChart.Metrics[Math.Max(0,metric.SelectedIndex)];chart.InvalidateVisual();};
|
||||
chart.FrameClicked+=f=>{if(!visible.Contains(f))filter.SelectedIndex=0;frames.SelectedItem=f;frames.ScrollIntoView(f);Select(f);};
|
||||
spatial.IsCheckedChanged+=(_,_)=>{preview.Spatial=spatial.IsChecked==true;preview.InvalidateVisual();};compare.IsCheckedChanged+=(_,_)=>UpdateComparison();
|
||||
ToolTip.SetTip(spatial,"Pink shows the strongest excess sky brightness against the clean session reference, excluding weak background residuals. Grid colors show regional stellar flux. This is supporting evidence, not an exact cloud boundary.");
|
||||
KeyDown+=async(_,e)=>
|
||||
{
|
||||
if(busy||updates.Applying||e.Source is TextBox)return;
|
||||
|
|
@ -205,7 +206,7 @@ public sealed partial class MainWindow:Window
|
|||
{
|
||||
selected=f;chart.Selected=f;chart.InvalidateVisual();details.IsVisible=true;inspector.Children.Clear();
|
||||
position.Text=$"{visible.IndexOf(f)+1:N0} / {visible.Count:N0}";
|
||||
preview.Load(projectDirectory,f);preview.Spatial=spatial.IsChecked==true;UpdateComparison();
|
||||
preview.Load(projectDirectory,f,project?.Frames);preview.Spatial=spatial.IsChecked==true;UpdateComparison();
|
||||
exposureName.Text=f.Name;ToolTip.SetTip(exposureName,f.Name);exposureStatus.Text=f.Status+" · "+f.Time+" UTC"+(f.Override.HasValue?" · Manual":"");exposureStatus.Foreground=Palette.Verdict(f.Effective);
|
||||
inspector.Children.Add(Palette.Label("DECISION EVIDENCE",10,Palette.Muted));
|
||||
inspector.Children.Add(new TextBlock{Text=f.Cause,FontSize=14,Foreground=Palette.Text,TextWrapping=TextWrapping.Wrap});
|
||||
|
|
@ -227,7 +228,7 @@ public sealed partial class MainWindow:Window
|
|||
bool show=compare.IsChecked==true;comparisonBorder.IsVisible=show;previewWorkspace.ColumnDefinitions[1].Width=show?new GridLength(1,GridUnitType.Star):new GridLength(0);previewPanel.Margin=show?new(0,0,6,0):new(0);
|
||||
preview.Caption=show?"Selected":"";comparison.Caption=show?"Nearby":"";preview.InvalidateVisual();
|
||||
if(selected==null||project==null||!show){comparison.Load(projectDirectory,null);return;}
|
||||
var nearby=project.Frames.Where(f=>f.Session==selected.Session&&f.Id!=selected.Id&&f.Timestamp.HasValue&&selected.Timestamp.HasValue&&f.Error=="").OrderBy(f=>Math.Abs((f.Timestamp!.Value-selected.Timestamp!.Value).TotalSeconds)).FirstOrDefault();comparison.Load(projectDirectory,nearby);ToolTip.SetTip(comparisonBorder,nearby==null?"No comparable nearby exposure":"Nearby · "+nearby.Time+" · "+nearby.Status);
|
||||
var nearby=project.Frames.Where(f=>f.Session==selected.Session&&f.Id!=selected.Id&&f.Timestamp.HasValue&&selected.Timestamp.HasValue&&f.Error=="").OrderBy(f=>Math.Abs((f.Timestamp!.Value-selected.Timestamp!.Value).TotalSeconds)).FirstOrDefault();comparison.Load(projectDirectory,nearby,project.Frames);ToolTip.SetTip(comparisonBorder,nearby==null?"No comparable nearby exposure":"Nearby · "+nearby.Time+" · "+nearby.Status);
|
||||
}
|
||||
void Move(int step){if(visible.Count==0)return;int index=selected==null?0:visible.IndexOf(selected);var f=visible[Math.Clamp(index+step,0,visible.Count-1)];frames.SelectedItem=f;frames.ScrollIntoView(f);}
|
||||
async Task Override(Verdict? verdict,bool advance=true)
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ public sealed class ExposureView:Control,IDisposable
|
|||
static readonly SemaphoreSlim LoadGate=new(1);
|
||||
WriteableBitmap? bitmap;
|
||||
PreviewDisplay? frameDisplay,nebulaDisplay;
|
||||
byte[] overlayMask=[];
|
||||
CancellationTokenSource? request;
|
||||
string message="Select an exposure";
|
||||
public Task Loading {get;private set;}=Task.CompletedTask;
|
||||
|
|
@ -85,18 +86,18 @@ public sealed class ExposureView:Control,IDisposable
|
|||
public double Stretch {get;set;}=.18;
|
||||
public string Caption {get;set;}="";
|
||||
public ExposureView(){RenderOptions.SetBitmapInterpolationMode(this,BitmapInterpolationMode.HighQuality);}
|
||||
public void Load(string projectDirectory,Frame? f)
|
||||
public void Load(string projectDirectory,Frame? f,IReadOnlyList<Frame>? frames=null)
|
||||
{
|
||||
Dispose();Frame=f;message=f==null?"Select an exposure":"Loading preview…";InvalidateVisual();
|
||||
if(f==null){Loading=Task.CompletedTask;return;}
|
||||
request=new();Loading=LoadCore(projectDirectory,f,request.Token);
|
||||
request=new();Loading=LoadCore(projectDirectory,f,frames??[],request.Token);
|
||||
}
|
||||
async Task LoadCore(string directory,Frame f,CancellationToken token)
|
||||
async Task LoadCore(string directory,Frame f,IReadOnlyList<Frame> frames,CancellationToken token)
|
||||
{
|
||||
try
|
||||
{
|
||||
await LoadGate.WaitAsync(token);
|
||||
(PreviewDisplay Frame,PreviewDisplay Nebula) prepared;
|
||||
(PreviewDisplay Frame,PreviewDisplay Nebula,byte[] Overlay) prepared;
|
||||
try
|
||||
{
|
||||
prepared=await Task.Run(async()=>
|
||||
|
|
@ -109,11 +110,11 @@ public sealed class ExposureView:Control,IDisposable
|
|||
await ResourcePolicy.WaitForHeadroom(ResourcePolicy.EstimateFrameBytes(f.Width,f.Height,f.Bayer!=""?2:1),token);
|
||||
var image=Fits.Read(f.Path,token);token.ThrowIfCancellationRequested();Fits.Preview(image,path,f);plane=PreviewRenderer.Read(path,f);
|
||||
}
|
||||
token.ThrowIfCancellationRequested();return(PreviewRenderer.Prepare(plane),PreviewRenderer.Prepare(plane,true));
|
||||
token.ThrowIfCancellationRequested();return(PreviewRenderer.Prepare(plane),PreviewRenderer.Prepare(plane,true),SkyOverlay.LoadMask(directory,f,frames,token));
|
||||
},token);
|
||||
}
|
||||
finally{LoadGate.Release();}
|
||||
token.ThrowIfCancellationRequested();frameDisplay=prepared.Frame;nebulaDisplay=prepared.Nebula;RefreshDisplay();
|
||||
token.ThrowIfCancellationRequested();frameDisplay=prepared.Frame;nebulaDisplay=prepared.Nebula;overlayMask=prepared.Overlay;RefreshDisplay();
|
||||
}
|
||||
catch(OperationCanceledException){}
|
||||
catch(Exception e){if(!token.IsCancellationRequested){message="Preview unavailable: "+e.Message;InvalidateVisual();}}
|
||||
|
|
@ -129,8 +130,9 @@ public sealed class ExposureView:Control,IDisposable
|
|||
{
|
||||
base.Render(c);c.FillRectangle(Palette.Background,new Rect(Bounds.Size));
|
||||
if(bitmap==null){c.DrawText(new FormattedText(message,System.Globalization.CultureInfo.CurrentCulture,FlowDirection.LeftToRight,new Typeface("Inter"),13,Palette.Muted){MaxTextWidth=Math.Max(100,Bounds.Width-32)},new(16,20));return;}
|
||||
double header=Caption!=""?26:0;
|
||||
if(header>0)c.DrawText(new FormattedText(Caption+" · "+Frame?.Time,System.Globalization.CultureInfo.CurrentCulture,FlowDirection.LeftToRight,new Typeface("Inter"),10,Palette.Muted),new(8,7));
|
||||
double captionHeight=Caption!=""?26:0,header=captionHeight+(Spatial?22:0);
|
||||
if(captionHeight>0)c.DrawText(new FormattedText(Caption+" · "+Frame?.Time,System.Globalization.CultureInfo.CurrentCulture,FlowDirection.LeftToRight,new Typeface("Inter"),10,Palette.Muted),new(8,7));
|
||||
if(Spatial)c.DrawText(new FormattedText(overlayMask.Length==SkyModel.Count?"Pink: excess sky · Grid: stellar flux":"Sky overlay unavailable · cached reference required",System.Globalization.CultureInfo.CurrentCulture,FlowDirection.LeftToRight,new Typeface("Inter"),10,Palette.Muted){MaxTextWidth=Math.Max(1,Bounds.Width-16)},new(8,captionHeight+5));
|
||||
double scale=Math.Min(Bounds.Width/bitmap.PixelSize.Width,Math.Max(1,Bounds.Height-header)/bitmap.PixelSize.Height),w=bitmap.PixelSize.Width*scale,h=bitmap.PixelSize.Height*scale;var rect=new Rect((Bounds.Width-w)/2,header+(Bounds.Height-header-h)/2,w,h);c.DrawImage(bitmap,new Rect(bitmap.Size),rect);
|
||||
if(Spatial&&Frame!=null&&Frame.Alignment.Length==4)
|
||||
{
|
||||
|
|
@ -140,8 +142,8 @@ public sealed class ExposureView:Control,IDisposable
|
|||
{
|
||||
StreamGeometry Cell(double x,double y,double dx,double dy)
|
||||
{var geometry=new StreamGeometry();using(var g=geometry.Open()){g.BeginFigure(Map(x,y),true);g.LineTo(Map(x+dx,y));g.LineTo(Map(x+dx,y+dy));g.LineTo(Map(x,y+dy));g.EndFigure(true);}return geometry;}
|
||||
if(f.CloudMask.Length==SkyModel.Count)for(int i=0;i<SkyModel.Count;i++)if(f.CloudMask[i]>0)
|
||||
c.DrawGeometry(new SolidColorBrush(Color.FromArgb(85,245,142,155)),null,Cell((double)(i%SkyModel.Columns)/SkyModel.Columns,(double)(i/SkyModel.Columns)/SkyModel.Rows,1.0/SkyModel.Columns,1.0/SkyModel.Rows));
|
||||
if(overlayMask.Length==SkyModel.Count)for(int i=0;i<SkyModel.Count;i++)if(overlayMask[i]>0)
|
||||
c.DrawGeometry(new SolidColorBrush(Color.FromArgb((byte)Math.Round(105*overlayMask[i]/255.0),245,142,155)),null,Cell((double)(i%SkyModel.Columns)/SkyModel.Columns,(double)(i/SkyModel.Columns)/SkyModel.Rows,1.0/SkyModel.Columns,1.0/SkyModel.Rows));
|
||||
for(int i=0;i<12;i++)
|
||||
{
|
||||
double baseline=f.Baselines.GetValueOrDefault($"Region {i+1}"),ratio=baseline>0?f.RegionFlux[i]/baseline:1;
|
||||
|
|
@ -151,5 +153,5 @@ public sealed class ExposureView:Control,IDisposable
|
|||
}
|
||||
}
|
||||
}
|
||||
public void Dispose(){request?.Cancel();request?.Dispose();request=null;bitmap?.Dispose();bitmap=null;frameDisplay=nebulaDisplay=null;}
|
||||
public void Dispose(){request?.Cancel();request?.Dispose();request=null;bitmap?.Dispose();bitmap=null;frameDisplay=nebulaDisplay=null;overlayMask=[];}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ public sealed class Frame
|
|||
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;}=[];
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@ public static class SkyModel
|
|||
int col=Math.Min((int)u,Columns-2),row=Math.Min((int)v,Rows-2);double dx=u-col,dy=v-row;
|
||||
return (map[row*Columns+col]*(1-dx)+map[row*Columns+col+1]*dx)*(1-dy)+(map[(row+1)*Columns+col]*(1-dx)+map[(row+1)*Columns+col+1]*dx)*dy;
|
||||
}
|
||||
public static double[] Aligned(Frame f)
|
||||
public static double[] Aligned(Frame f)=>Detrend(AlignedBackground(f));
|
||||
public static double[] AlignedBackground(Frame f)
|
||||
{
|
||||
double[] map=Enumerable.Repeat(double.NaN,Count).ToArray();if(f.Alignment.Length!=4||f.SkyMap.Length!=Count)return map;
|
||||
var a=f.Alignment;double aspect=(double)f.Height/f.Width;
|
||||
|
|
@ -35,7 +36,7 @@ public static class SkyModel
|
|||
double u=a[0]*x-a[1]*y*aspect+a[2],v=(a[1]*x+a[0]*y*aspect+a[3])/aspect;
|
||||
if(u>.025&&u<.975&&v>.025&&v<.975)map[i]=Sample(f.SkyMap,u,v);
|
||||
}
|
||||
return Detrend(map);
|
||||
return map;
|
||||
}
|
||||
public static double[] Detrend(double[] values)
|
||||
{
|
||||
|
|
@ -56,7 +57,7 @@ public static class SkyModel
|
|||
}
|
||||
return residual;
|
||||
}
|
||||
static double[] Solve(double[,] m)
|
||||
internal static double[] Solve(double[,] m)
|
||||
{
|
||||
for(int k=0;k<3;k++)
|
||||
{
|
||||
|
|
|
|||
88
src/AstroFrame.Engine/SkyOverlay.cs
Normal file
88
src/AstroFrame.Engine/SkyOverlay.cs
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
namespace AstroFrame.Engine;
|
||||
|
||||
/// <summary>Display excess sky brightness without calling darker residuals cloud glow.</summary>
|
||||
public static class SkyOverlay
|
||||
{
|
||||
public sealed class Reference(double[] background,double[] scatter,double noise)
|
||||
{
|
||||
public byte[] Measure(Frame frame)=>ExcessMask(Residual(SkyModel.AlignedBackground(frame).Select((v,j)=>v-background[j]).ToArray(),noise),scatter);
|
||||
}
|
||||
|
||||
// Cloud glow is one-sided contamination of the local sky. An asymmetric fit
|
||||
// gives clear cells more influence than bright patches when removing the
|
||||
// offset/gradient, instead of introducing positive residuals in dark corners.
|
||||
static double[] Residual(double[] values,double noise)
|
||||
{
|
||||
if(values.Count(double.IsFinite)<12)return Enumerable.Repeat(double.NaN,SkyModel.Count).ToArray();
|
||||
double[] coefficients=[Robust.Median(values),0,0];noise=Math.Max(.1,noise);
|
||||
for(int iteration=0;iteration<80;iteration++)
|
||||
{
|
||||
double[,] system=new double[3,4];
|
||||
for(int i=0;i<SkyModel.Count;i++)if(double.IsFinite(values[i]))
|
||||
{
|
||||
double[] v=[1,(i%SkyModel.Columns+.5)/SkyModel.Columns-.5,(i/SkyModel.Columns+.5)/SkyModel.Rows-.5];
|
||||
double residual=values[i]-v[0]*coefficients[0]-v[1]*coefficients[1]-v[2]*coefficients[2];
|
||||
double weight=(residual>=0?.15:.85)/Math.Max(noise,Math.Abs(residual));
|
||||
for(int r=0;r<3;r++){for(int c=0;c<3;c++)system[r,c]+=weight*v[r]*v[c];system[r,3]+=weight*v[r]*values[i];}
|
||||
}
|
||||
var fitted=SkyModel.Solve(system);double change=fitted.Zip(coefficients,(a,b)=>Math.Abs(a-b)).Max();coefficients=fitted;
|
||||
if(change<.01)break;
|
||||
}
|
||||
return values.Select((v,i)=>v-coefficients[0]-coefficients[1]*((i%SkyModel.Columns+.5)/SkyModel.Columns-.5)-coefficients[2]*((i/SkyModel.Columns+.5)/SkyModel.Rows-.5)).ToArray();
|
||||
}
|
||||
|
||||
public static Reference? CreateReference(IEnumerable<Frame> frames,CancellationToken ct)
|
||||
{
|
||||
var clean=frames.ToArray();if(clean.Length==0)return null;
|
||||
List<double[]> maps=[];foreach(var f in clean){ct.ThrowIfCancellationRequested();maps.Add(SkyModel.AlignedBackground(f));}
|
||||
double[] median=Enumerable.Range(0,SkyModel.Count).Select(j=>maps.Any(m=>double.IsFinite(m[j]))?Robust.Median(maps.Select(m=>m[j])):double.NaN).ToArray();
|
||||
double floor=Math.Max(.1,Robust.Median(clean.Select(f=>f.Noise))*.08);
|
||||
List<double[]> residuals=[];foreach(var map in maps){ct.ThrowIfCancellationRequested();residuals.Add(Residual(map.Select((v,j)=>v-median[j]).ToArray(),floor));}
|
||||
double[] scatter=Enumerable.Range(0,SkyModel.Count).Select(j=>Math.Max(floor,Robust.Mad(residuals.Select(m=>m[j])))).ToArray();
|
||||
return new(median,scatter,floor);
|
||||
}
|
||||
|
||||
public static byte[] ExcessMask(double[] residual,double[] scatter)
|
||||
{
|
||||
if(residual.Length!=SkyModel.Count||scatter.Length!=SkyModel.Count)return [];
|
||||
// Use both reference scatter and the structure's dynamic range to exclude
|
||||
// weak background-fit residuals. Saturate locally significant structure
|
||||
// quickly so a bright cloud cannot wash out a second, fainter cloud.
|
||||
double scale=Math.Max(.1,Robust.Quantile(residual.Where(v=>v>0),.95));
|
||||
return residual.Select((v,j)=>
|
||||
{
|
||||
double threshold=Math.Max(5*scatter[j],scale*.15);
|
||||
if(!double.IsFinite(v)||!double.IsFinite(threshold)||threshold<=0||v<=threshold)return (byte)0;
|
||||
double strength=v/(2*threshold);
|
||||
return (byte)Math.Clamp(Math.Round(255*strength),1,255);
|
||||
}).ToArray();
|
||||
}
|
||||
|
||||
// Older projects have only the two-sided classification mask. Reconstruct the
|
||||
// display from their catalogs without saving or changing any measurements.
|
||||
public static byte[] LoadMask(string directory,Frame frame,IReadOnlyList<Frame> frames,CancellationToken ct)
|
||||
{
|
||||
if(frame.ExcessSkyMask.Length==SkyModel.Count)return frame.ExcessSkyMask;
|
||||
if(frame.Alignment.Length!=4)return [];
|
||||
Frame? Read(Frame source)
|
||||
{
|
||||
ct.ThrowIfCancellationRequested();
|
||||
var copy=new Frame{Id=source.Id,Length=source.Length,Modified=source.Modified,Width=source.Width,Height=source.Height,Alignment=source.Alignment,Noise=source.Noise};
|
||||
return ProjectStore.LoadCatalog(directory,copy)&©.SkyMap.Length==SkyModel.Count?copy:null;
|
||||
}
|
||||
var selected=Read(frame);if(selected==null)return [];
|
||||
var clean=frames.Where(f=>f.Session==frame.Session&&f.Measured&&f.Error==""&&f.Alignment.Length==4&&f.AdditionalMeasurements.GetValueOrDefault("Clear reference member")>0).ToArray();
|
||||
if(clean.Length==0)return [];
|
||||
List<Frame> references=[];
|
||||
foreach(var referenceFrame in clean)
|
||||
{
|
||||
var reference=Read(referenceFrame);
|
||||
// An incomplete reference would produce a different mask; show unavailable instead.
|
||||
if(reference==null)return [];
|
||||
references.Add(reference);
|
||||
}
|
||||
ct.ThrowIfCancellationRequested();
|
||||
var overlay=CreateReference(references,ct);
|
||||
ct.ThrowIfCancellationRequested();return overlay?.Measure(selected)??[];
|
||||
}
|
||||
}
|
||||
|
|
@ -62,10 +62,14 @@ public static class SpatialReference
|
|||
double stability=Math.Min(1,referenceNoise*.5/Math.Max(referenceResidual,.1));
|
||||
double floor=Math.Max(.1,referenceNoise*.08);
|
||||
double[] scatter=Enumerable.Range(0,SkyModel.Count).Select(j=>Math.Max(floor,Robust.Mad(residuals.Select(m=>m[j])))).ToArray();
|
||||
var overlay=SkyOverlay.CreateReference(clean.Select(i=>a[i]),ct);
|
||||
for(int i=0;i<a.Length;i++)
|
||||
{
|
||||
ct.ThrowIfCancellationRequested();var f=a[i];var residual=Difference(maps[i],reference);int valid=residual.Count(double.IsFinite);
|
||||
var z=residual.Select((v,j)=>Math.Abs(v)/scatter[j]).ToArray();bool[] mask=z.Select(v=>double.IsFinite(v)&&v>5).ToArray();
|
||||
// The two-sided residual remains classification evidence. Pink display
|
||||
// cells identify excess sky brightness, not the compensating dark residual.
|
||||
f.ExcessSkyMask=overlay?.Measure(f)??[];
|
||||
f.CloudMask=mask.Select(v=>(byte)(v?1:0)).ToArray();f.CloudCoverage=(double)mask.Count(v=>v)/Math.Max(valid,1);f.CloudSignificance=Robust.Quantile(z,.95);
|
||||
f.ReferenceConfidence=stability*Math.Min(1,clean.Length/20.0)*(double)valid/SkyModel.Count;
|
||||
f.AdditionalMeasurements["Cloud connected coverage"]=(double)SkyModel.LargestComponent(mask)/Math.Max(valid,1);
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Update="Fixtures/*.json" CopyToOutputDirectory="PreserveNewest" />
|
||||
<ProjectReference Include="../../src/AstroFrame.Engine/AstroFrame.Engine.csproj" />
|
||||
<RuntimeHostConfigurationOption Include="System.GC.HeapHardLimit" Value="3221225472" />
|
||||
<RuntimeHostConfigurationOption Include="System.GC.Server" Value="false" />
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -38,6 +38,18 @@ static class ImageRegression
|
|||
check(clear.All(f=>f.Automatic==Verdict.Keep),"persistent nebulosity and gradual sky/flux trends remain KEEP in image pipeline");
|
||||
check(cloud.All(f=>f.Automatic==Verdict.Reject),"prolonged moving cloud does not become the local baseline");
|
||||
check(cloud.All(f=>f.CloudMask.Any(v=>v>0)&&f.Evidence.Any(e=>e.Metric=="Cloud structure")),"cloud masks and spatial explanations survive the full image pipeline");
|
||||
bool Localized(Frame f)
|
||||
{
|
||||
int n=frames.IndexOf(f);double center=.22+(n%9)*.045,aspect=(double)f.Height/f.Width;var a=f.Alignment;
|
||||
var cells=Enumerable.Range(0,SkyModel.Count).Select(i=>
|
||||
{
|
||||
double x=(i%SkyModel.Columns+.5)/SkyModel.Columns,y=(i/SkyModel.Columns+.5)/SkyModel.Rows;
|
||||
return(i,Y:(a[1]*x+a[0]*y*aspect+a[3])/aspect);
|
||||
}).Where(c=>c.Y>.05&&c.Y<.95).ToArray();
|
||||
var core=cells.Where(c=>Math.Abs(c.Y-center)<.05).ToArray();var clearSky=cells.Where(c=>Math.Abs(c.Y-center)>.24).ToArray();
|
||||
return f.ExcessSkyMask.Length==SkyModel.Count&&core.Length>0&&core.Count(c=>f.ExcessSkyMask[c.i]>=128)>=core.Length*.85&&clearSky.Length>0&&clearSky.Count(c=>f.ExcessSkyMask[c.i]>0)<=clearSky.Length*.1;
|
||||
}
|
||||
check(cloud.All(Localized),"image pipeline highlights physical cloud cores while leaving distant clear sky unshaded");
|
||||
check(frames[18].Automatic==Verdict.Review,"modest transient sky structure without stellar loss routes to REVIEW, preserving conservative rejection");
|
||||
var reference=frames.First(f=>f.Id==cloud[0].ReferenceId);var image=Fits.Read(cloud[0].Path);
|
||||
var vanished=reference.Stars[0] with{Flux=1};reference.Stars=[vanished];var forced=Matching.ForcedFlux(reference,cloud[0],image);
|
||||
|
|
|
|||
77
tests/AstroFrame.Validation/OverlayRegression.cs
Normal file
77
tests/AstroFrame.Validation/OverlayRegression.cs
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
using AstroFrame.Engine;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.Json;
|
||||
|
||||
static class OverlayRegression
|
||||
{
|
||||
public static void Run(Action<bool,string> check)
|
||||
{
|
||||
var residual=new double[SkyModel.Count];var scatter=Enumerable.Repeat(2.0,SkyModel.Count).ToArray();
|
||||
for(int i=0;i<100;i++)residual[i]=500;
|
||||
residual[100]=100;residual[101]=-500;residual[102]=9;residual[103]=double.NaN;residual[104]=50;
|
||||
var strengths=SkyOverlay.ExcessMask(residual,scatter);
|
||||
check(strengths[0]==255&&strengths[100]>=128&&strengths[101]==0&&strengths[102]==0&&strengths[103]==0&&strengths[104]==0,"fainter cloud structure stays visible while weak, dark and invalid residuals are unshaded");
|
||||
RealFrames(check);
|
||||
string directory=Path.Combine(Path.GetTempPath(),"AstroFrame-overlay-"+Guid.NewGuid());
|
||||
try
|
||||
{
|
||||
float[] Map(bool cloud)=>Enumerable.Range(0,SkyModel.Count).Select(i=>
|
||||
{
|
||||
double x=(i%SkyModel.Columns+.5)/SkyModel.Columns,y=(i/SkyModel.Columns+.5)/SkyModel.Rows;
|
||||
double nebula=80*Math.Exp(-((x-.45)*(x-.45)+(y-.55)*(y-.55))*35);
|
||||
double glow=cloud?450*Math.Exp(-Math.Pow(y/.18,2))+400*Math.Exp(-Math.Pow((x-.25)/.23,2)-Math.Pow((y-.42)/.16,2)):0;
|
||||
return (float)(1000+75*x+30*y+nebula+glow);
|
||||
}).ToArray();
|
||||
Frame Make(int n,bool cloud=false)=>new()
|
||||
{
|
||||
Id=n.ToString(),Length=100,Modified=200,Width=240,Height=400,Session="same night",Measured=true,
|
||||
SkyMap=Map(cloud),SkyNoise=Enumerable.Repeat(20f,SkyModel.Count).ToArray(),Noise=20,Alignment=[1,0,0,0],
|
||||
Stars=[new(.4,.5,1000,3,.1)],AdditionalMeasurements=new(){{"Clear reference member",cloud?0:1}}
|
||||
};
|
||||
var frames=Enumerable.Range(0,30).Select(n=>Make(n)).ToList();var selected=Make(30,true);
|
||||
selected.CloudMask=Enumerable.Repeat((byte)1,SkyModel.Count).ToArray();selected.CloudCoverage=.9;selected.Automatic=Verdict.Reject;selected.Override=Verdict.Keep;selected.Note="Human decision";
|
||||
frames.Add(selected);
|
||||
// Other sessions must not contribute to the reference, even without a readable catalog.
|
||||
frames.Add(new(){Id="other",Session="other night",Measured=true,Alignment=[1,0,0,0],AdditionalMeasurements=new(){{"Clear reference member",1}}});
|
||||
var project=new Project{Frames=frames,Complete=true};ProjectStore.Save(project,directory);
|
||||
var files=Directory.GetFiles(directory,"*",SearchOption.AllDirectories);
|
||||
string Hash(string path)=>Convert.ToHexString(SHA256.HashData(File.ReadAllBytes(path)));
|
||||
var before=files.ToDictionary(path=>path,Hash);
|
||||
var restored=ProjectStore.Load(directory);selected=restored.Frames.Single(f=>f.Id=="30");
|
||||
var mask=SkyOverlay.LoadMask(directory,selected,restored.Frames,CancellationToken.None);
|
||||
var clear=Enumerable.Range(0,SkyModel.Count).Where(i=>(i%SkyModel.Columns+.5)/SkyModel.Columns>.7&&(i/SkyModel.Columns+.5)/SkyModel.Rows>.35&&(i/SkyModel.Columns+.5)/SkyModel.Rows<.6).ToArray();
|
||||
var core=Enumerable.Range(0,SkyModel.Count).Where(i=>(i%SkyModel.Columns+.5)/SkyModel.Columns>.15&&(i%SkyModel.Columns+.5)/SkyModel.Columns<.35&&(i/SkyModel.Columns+.5)/SkyModel.Rows>.35&&(i/SkyModel.Columns+.5)/SkyModel.Rows<.45).ToArray();
|
||||
check(mask.Length==SkyModel.Count&&clear.All(i=>mask[i]==0)&&core.All(i=>mask[i]>0),"legacy overlay follows localized cloud glow instead of the compensating dark sky");
|
||||
check(selected.CloudMask.All(v=>v==1)&&selected.CloudCoverage==.9&&selected.Automatic==Verdict.Reject&&selected.Override==Verdict.Keep&&selected.Note=="Human decision","overlay reconstruction preserves classification evidence and human decisions");
|
||||
check(files.All(path=>before[path]==Hash(path)),"legacy overlay reconstruction leaves the saved project and catalogs byte-identical");
|
||||
selected.ExcessSkyMask=mask;
|
||||
check(SkyOverlay.LoadMask("missing directory",selected,[],CancellationToken.None).SequenceEqual(mask),"newly measured overlays display without reopening reference catalogs");
|
||||
selected.ExcessSkyMask=[];
|
||||
File.Delete(Path.Combine(directory,"catalogs","0-v2.bin"));
|
||||
check(SkyOverlay.LoadMask(directory,selected,restored.Frames,CancellationToken.None).Length==0,"incomplete legacy references never fall back to the misleading two-sided mask");
|
||||
}
|
||||
finally{if(Directory.Exists(directory))Directory.Delete(directory,true);}
|
||||
}
|
||||
|
||||
sealed record Sample(string Name,int Width,int Height,double[] Alignment,float[] SkyMap,double[][] CloudRegions,double[][] ClearRegions);
|
||||
sealed record Fixture(double?[] ReferenceBackground,double[] ReferenceScatter,double Noise,Sample[] Samples);
|
||||
static void RealFrames(Action<bool,string> check)
|
||||
{
|
||||
var fixture=JsonSerializer.Deserialize<Fixture>(File.ReadAllText(Path.Combine(AppContext.BaseDirectory,"Fixtures","overlay-backgrounds.json")))!;
|
||||
var reference=new SkyOverlay.Reference(fixture.ReferenceBackground.Select(v=>v??double.NaN).ToArray(),fixture.ReferenceScatter,fixture.Noise);
|
||||
foreach(var sample in fixture.Samples)
|
||||
{
|
||||
var frame=new Frame{Width=sample.Width,Height=sample.Height,Alignment=sample.Alignment,SkyMap=sample.SkyMap};
|
||||
var mask=reference.Measure(frame);var a=sample.Alignment;double aspect=(double)sample.Height/sample.Width;
|
||||
int[] Cells(double[] region)=>Enumerable.Range(0,SkyModel.Count).Where(i=>
|
||||
{
|
||||
double x=(i%SkyModel.Columns+.5)/SkyModel.Columns,y=(i/SkyModel.Columns+.5)/SkyModel.Rows;
|
||||
double u=a[0]*x-a[1]*y*aspect+a[2],v=(a[1]*x+a[0]*y*aspect+a[3])/aspect;
|
||||
return u>region[0]&&u<region[1]&&v>region[2]&&v<region[3];
|
||||
}).ToArray();
|
||||
var clouds=sample.CloudRegions.Select(Cells).ToArray();var clear=sample.ClearRegions.Select(Cells).ToArray();
|
||||
check(clouds.All(cells=>cells.Length>0&&cells.Count(i=>mask[i]>=128)>=cells.Length*.85&&cells.Average(i=>(double)mask[i])>180),$"{sample.Name}: each reported cloud core has clearly visible overlay strength");
|
||||
check(clear.All(cells=>cells.Length>0&&cells.Count(i=>mask[i]>0)<=cells.Length*.1),$"{sample.Name}: dark comparison regions avoid the false corner overlay");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -105,5 +105,6 @@ try
|
|||
}
|
||||
finally{Directory.Delete(temp,true);}
|
||||
await ImageRegression.Run(Check);
|
||||
OverlayRegression.Run(Check);
|
||||
PreviewRegression.Run(Check);
|
||||
Console.WriteLine($"{passed} checks passed. Synthetic tests validate mechanics, not astrophotography stack quality.");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue