diff --git a/Directory.Build.props b/Directory.Build.props index 5b66f18..76657f4 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 1.1.4 + 1.1.7 Elijah Kuntz AstroFrame diff --git a/README.md b/README.md index 54f694c..2bf5f5c 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ To analyze another dataset, choose **Analyze lights**, select the folder contain - Press **1**, **2**, **3** for KEEP, REVIEW, REJECT. Decisions save and advance. **J/K** navigates. **Reset** restores the automatic decision. **Ctrl+Z** undoes a manual decision. - Decision evidence and measurements remain visible below the quality graph. Hover over an evidence line to read its full technical detail, and scroll the panel for additional measurements. Preview stretch and manual decisions sit below the image. Existing notes remain in saved projects and exports; the note editor has been removed. Automatic decisions and human overrides remain separate. -KEEP means consistent measurements; it does not certify a perfect frame. REVIEW means a substantial deviation or measurement uncertainty. REJECT requires strong, coherent transient sky structure, agreement between cloud/flux/star-loss measurements, severe combined morphology degradation, or catastrophic star disappearance. Small ellipticity variations alone do not trigger review. +KEEP means consistent measurements; it does not certify a perfect frame. REVIEW means a substantial deviation or measurement uncertainty. REJECT requires strong, coherent transient sky structure, agreement between cloud/flux/star-loss measurements, thin cloud texture on an already-flagged frame that dims the stars beneath it relative to the rest of the exposure, severe combined morphology degradation, stellar elongation confirmed on the same matched reference stars (the roundness outliers stacking filters discard), or catastrophic star disappearance. Small ellipticity variations alone do not trigger review. The earlier engine missed obvious clouds and falsely reviewed a clear frame. Its rolling background baselines and detection-only flux measurements have been replaced. Analysis-version changes request reanalysis while preserving manual decisions. Display changes have their own cache version, so preview upgrades do not invalidate quality measurements. diff --git a/docs/analysis-design.md b/docs/analysis-design.md index f6c4364..8d076df 100644 --- a/docs/analysis-design.md +++ b/docs/analysis-design.md @@ -6,7 +6,7 @@ The supplied 1,920 originals cover four targets and five sessions, with 2160×38 The first algorithm failed real owner-reviewed examples: cloud structure inflated detected-star counts; flux only sampled surviving detections; rolling baselines absorbed prolonged cloud; a small ellipticity deviation reviewed a clear image. The v2 design replaces the cloud measurements, reference construction and classification policy. Rejection counts are not a target or a validation criterion. -Version 1.1.1 refines this policy with geometric fit diagnostics, local cloud-aperture corroboration, and matched-star morphology checks. The original v2 results remain a baseline; see [the 1.1.1 comparison](algorithm-1.1.1-validation.md) for the measurements and limits of the new validation. +Version 1.1.1 refines this policy with geometric fit diagnostics, local cloud-aperture corroboration, and matched-star morphology checks. Version 1.1.6 adds thin-cloud texture with same-exposure differential photometry; 1.1.7 adds moderate-cloud corroboration and confirmed-elongation rejection. The original v2 results remain a baseline; see [the 1.1.1 comparison](algorithm-1.1.1-validation.md) for the measurements and limits of the new validation. ## Components @@ -24,6 +24,7 @@ Additional detectors can add measurements independently. A future AI reviewer ca 4. Robustly remove each map's additive offset and planar gradient. Form an aligned median background map, measure transient residuals, and rebuild three times from the least transient 40% of exposures. This fraction constructs a reference; it is **not** a rejection quota. Persistent target nebulosity belongs to the reference. Smooth sky gradients and offsets are removed rather than interpreted as cloud. 5. Read each exposure once more, sequentially, for signed aperture photometry at up to 600 reference coordinates. A local annulus subtracts sky. Reference brightness establishes aperture eligibility; a star need not be detected in the tested exposure. Median fluxes from reference exposures normalize global and 3×4 regional transparency. This addresses survivor bias. Saturated apertures and positions outside the field are excluded explicitly. 6. Compare 960 aligned sky cells with the reference. Cell scatter comes from reference-frame residual MAD with a floor relative to measured image noise. Store a mask above five times that scatter, affected overlap fraction, largest connected component, 95th-percentile significance, residual ADU, aperture counts and reference overlap. These are named evidence, not an opaque combined score. +7. Measure thin-cloud texture separately. Remove a robust quadratic surface, not only a plane, from each aligned residual, then average each cell with its 3×3 neighbors. Divide by the per-cell scatter that reference exposures show for the same smoothed statistic; the floor is half the median of those scatters. Cells above four times scatter form a texture mask. Store the 98th-percentile texture significance, affected and largest connected fraction. Compare the median forced flux of reference apertures inside the mask with apertures in clear cells (below twice scatter) of the same exposure. Normalize that inside/outside ratio by the same apertures in the nearest 40 reference exposures and divide its loss by their MAD, with a 1% floor. Global transparency, seeing and airmass changes cancel in this differential ratio; a sky-only gradient leaves it near one. Grid background estimation and local aperture subtraction are standard image-analysis techniques; see [Photutils background documentation](https://photutils.readthedocs.io/en/stable/api/photutils.background.Background2D.html). This implementation is independent C#, using the supplied data to establish its comparison distributions. @@ -36,8 +37,11 @@ REJECT evidence routes are explicit: - Strong spatial structure: at least 25× reference scatter at the 95th percentile, at least 8% affected overlap and a connected area of at least 3.5%. A lone sky signal must be overwhelming before discarding integration; weaker coherent structure needs stellar corroboration or routes to REVIEW. - Moderate coherent spatial structure plus substantial global flux loss, regional forced-flux loss or detected-star loss. - Coherent structure at least 8× reference scatter, at least 8% affected overlap, and a connected anomalous area of at least 3.5%, corroborated by positive excess-sky coverage of at least 8% and a positive connected area of at least 3.5%. At least 20 reference apertures in two regions inside that excess sky must show below 90% of nearby same-aperture flux, with at least three times the larger of reference scatter, a 3% floor, and propagated local photometry uncertainty. Affected-aperture comparisons use the nearest 40 reference members, excluding the tested exposure, and require at least 12 valid comparison frames. +- Thin cloud on an exposure already routed to REVIEW by another measurement: texture significance at least 10, a connected textured area of at least 5%, at least 20 apertures both inside and outside the texture, and stars inside at most 98% of their clear-cell flux with a loss of at least 2.5 times nearby reference scatter. Applying real cloud masks to clear exposures put 0.4–0.6% of differential deviations at or above 2.5, and clear exposures do not reach the texture prerequisite. This route never rejects an otherwise clean KEEP. +- Moderate thin cloud on an exposure the planar structure detector already flags (at least 5× scatter over 2% of the overlap): texture significance at least 20 with the same connectivity and aperture requirements, inside/outside dimming of at least 1.5% and 1.5 times scatter, and independently at least 20 excess-sky apertures in two regions at or below 93% of nearby same-aperture flux with at least 2.5 times scatter. - Severe global flux loss (below 60% of clear-frame baseline) with substantial detected-star loss. - Severe combined stellar width and ellipticity degradation, or almost complete star disappearance relative to a rich reference field. +- Confirmed elongation: an existing elongation flag (at least four scatters and 0.15 above the nearby ellipticity baseline) that the same matched reference stars confirm. This requires at least 50 matched stars and 12 nearby reference frames, uncertainty at most 0.025, and a median change whose lower three-standard-error bound is at least 0.10, the same limit below which a flag is dismissed. Changes between the two limits stay REVIEW. Stacking workflows discard such roundness outliers; for example, Siril's Seestar script applies `-filter-round=2.5k`. On both supplied NGC 1432 nights, 22 of 38 confirmed frames fall below Siril's own roundness cutoff and the rest lie near it. Every confirmed frame exceeds an eccentricity-equivalent of 0.6. Unconfirmed or imprecise flags remain REVIEW. Automatic rejection requires enough comparable frames, valid time and adequate aligned overlap. Ordinary spatial rejection also requires verified geometry: at least 20 tight correspondences, at least 80% of correspondences within the width-scaled tight tolerance, three regions with at least three tight matches each, and a spread of at least 15% of the image width and height. The median residual must be at most the larger of 0.5 original pixels and 0.2× reference width; the 95th percentile must be at most the larger of one original pixel and 0.5× reference width. Transform scale must remain between 0.975 and 1.025. Missing stars alone no longer veto a cloud rejection when geometry and aperture coverage are verified; low star survival still cannot certify KEEP. Catalog-only classification retains its previous match-fraction safeguard. @@ -47,7 +51,7 @@ These significance and effect-size limits are **engineering policy, not calibrat ## Limits that need validation -A wholly uniform, cloudy session may lack any internally observable clear reference. Clouds that resemble a smooth gradient and have little detectable attenuation are difficult. Dense nebulosity, alignment failures, crowded fields, large drift/rotation and changing PSFs can bias maps or fixed-aperture flux. The current model removes only a planar sky trend; a legitimate time-varying nonlinear sky pattern can require review. The red overlay identifies anomalous sky structure, not a pixel-accurate physical cloud segmentation. +A wholly uniform, cloudy session may lack any internally observable clear reference. Clouds that resemble a smooth gradient and have little detectable attenuation are difficult. Dense nebulosity, alignment failures, crowded fields, large drift/rotation and changing PSFs can bias maps or fixed-aperture flux. The main structure model removes only a planar sky trend; a legitimate time-varying nonlinear sky pattern can require review. The thin-cloud texture also removes quadratic curvature, but requires stellar dimming beneath it before rejecting. Faint cirrus on an otherwise clean exposure remains KEEP: its effect on a stack has not been validated. The red overlay identifies anomalous sky structure, not a pixel-accurate physical cloud segmentation. Small sessions and unreliable references cannot automatically reject. Reference stability also checks reference-map residuals against measured pixel noise; a wholly unstable comparison population routes to REVIEW. This does not detect a perfectly uniform, consistently attenuated session. Human overrides remain separate from automatic results. Do not claim the method matches manual Siril selection until independently processed stacks support that claim. diff --git a/docs/release-notes/1.1.5.md b/docs/release-notes/1.1.5.md new file mode 100644 index 0000000..4b20039 --- /dev/null +++ b/docs/release-notes/1.1.5.md @@ -0,0 +1,9 @@ +# AstroFrame 1.1.5 + +- Choose what **Compare** shows: **Nearby frame**, the exposure closest in capture time, or **Best frame**, the strongest kept exposure in the selected exposure's session. The dropdown appears next to Compare while comparison is on. +- Best frame picks the highest quality score among kept, measured exposures, then the sharpest stars (lowest FWHM), then the strongest stellar flux. If the selected exposure is itself the best, the next best is shown. The pane caption reads **Best**, and its tooltip lists the score and FWHM. +- Nearby frame is the default, and each launch starts on Nearby. Overlay, Denoised, stretch, zoom and pan apply to both choices. + +Comparison choice is display-only: it never changes measurements, classifications or manual decisions. + +Validation: 95 engine, 23 updater, 10 mocked publisher and 77 isolated Windows interaction checks (including 11 new comparison checks), with rendering at 96 and 144 DPI on a copied workspace fixture. Verification leaves the installed app untouched. The server workflow builds Windows and Linux packages and checks the packaged Linux settings page. diff --git a/docs/release-notes/1.1.6.md b/docs/release-notes/1.1.6.md new file mode 100644 index 0000000..9b0c8cc --- /dev/null +++ b/docs/release-notes/1.1.6.md @@ -0,0 +1,11 @@ +# AstroFrame 1.1.6 + +Resolves more thin-cloud exposures automatically instead of leaving them for manual review. + +- Adds a thin-cloud texture measurement. Each aligned sky map has smooth curvature removed, neighboring cells averaged, and the result compared with the scatter of clear reference exposures. Faint cloud bands that previously fell below the sky-structure threshold now stand out clearly. +- Corroborates that texture with the stars beneath it. Forced photometry inside the texture is compared with clear parts of the same exposure and then with the same apertures in nearby clear frames. Global transparency, seeing and airmass changes cancel out; a sky gradient alone does not dim stars and cannot trigger rejection. +- An exposure already flagged for Review becomes Reject only when both measurements agree. The new route never rejects an exposure that would otherwise be Keep, and it adds no new Review triggers. Decision evidence explains the texture coverage and the measured dimming. + +In the supplied 1,053-frame NGC 1432 project, Review decreases from 48 to 36 and Reject increases from 100 to 112. All 12 changed exposures show visible cloud bands. Every Keep is unchanged. Replays of eleven other saved projects (about 5,000 exposures, including the M31 sessions with manual decisions) changed 15 more Review exposures to Reject. All were inspected: cloud passages, plus one dawn-twilight exposure next to frames the existing rules already reject. No Keep and no manually labeled exposure changed. The remaining NGC 1432 Reviews are mostly stellar-elongation flags, which this release does not change. + +Analysis time and memory use are essentially unchanged. Old automatic measurements require reanalysis; manual decisions are retained. Engine (100) and updater (23) checks pass on the versioned source. Windows and Linux update channels are included. diff --git a/docs/release-notes/1.1.7.md b/docs/release-notes/1.1.7.md new file mode 100644 index 0000000..2f04ae2 --- /dev/null +++ b/docs/release-notes/1.1.7.md @@ -0,0 +1,10 @@ +# AstroFrame 1.1.7 + +Resolves the remaining moderately clouded exposures and trailed-star exposures automatically, so very few frames are left for manual review. + +- **Moderate thin cloud.** An exposure the sky-structure detector already flags becomes Reject when strong cloud texture is backed by two independent, moderate signs of dimming: stars inside the texture are fainter than stars in clear parts of the same exposure, and the excess-sky apertures are fainter than in nearby frames. A light flash or other sky-only artifact that dims no stars still stays Review. +- **Confirmed star elongation.** Elongation is now rejected when the same matched reference stars confirm it well beyond measurement uncertainty. This follows common stacking practice: Siril's Seestar preprocessing script discards roundness outliers (`-filter-round=2.5k`), and PixInsight users commonly treat eccentricity above 0.6 as unusable. On both supplied NGC 1432 nights, 22 of 38 confirmed frames fall below Siril's own roundness cutoff and the rest sit near it; all exceed an eccentricity-equivalent of 0.6. Elongation that is imprecise or only marginally confirmed still stays Review. + +In the supplied 1,053-frame NGC 1432 project, Review decreases from 36 (1.1.6) to 1, an exposure with a full-width light flash, and from 48 in 1.1.5. Reject increases to 147. Every Keep is unchanged. Across eleven other saved projects (about 5,000 exposures), Review decreases from 337 to 153; every change is Review to Reject, and no Keep changed. Changed frames were checked against previews and matched star crops. Most of the remaining Reviews in one M33 session are high-background (twilight or moonlit) exposures, which this release does not change. + +Analysis time and memory use are unchanged. Old automatic measurements require reanalysis; manual decisions are retained. Engine (102) and updater (23) checks pass on the versioned source. Windows and Linux update channels are included. diff --git a/src/AstroFrame.Desktop/MainWindow.Verification.cs b/src/AstroFrame.Desktop/MainWindow.Verification.cs index 770abeb..c2783f2 100644 --- a/src/AstroFrame.Desktop/MainWindow.Verification.cs +++ b/src/AstroFrame.Desktop/MainWindow.Verification.cs @@ -21,6 +21,7 @@ public sealed partial class MainWindow bitmap.Render(this);bitmap.Save(System.IO.Path.Combine(output,name+".png")); } Check(project==null&&selected==null&&visible.Count==0,"ordinary startup starts a fresh session"); + Check(compareTarget.SelectedIndex==0&&!compareTarget.IsVisible,"each launch starts comparing against the nearby exposure"); Check(!memoryUsage.IsVisible&&!memoryTimer.IsEnabled&&!progress.IsVisible&&!inspectElongation.IsEnabled,"idle startup hides processing stats and disables star inspection"); Check(Background==Palette.Background&&TransparencyBackgroundFallback==Palette.Background&&NativeWindowBackground.IsApplied(this),"managed and native startup backgrounds match the application grey"); Capture("fresh-session"); @@ -55,6 +56,22 @@ public sealed partial class MainWindow spatial.IsChecked=true;compare.IsChecked=false;compare.IsChecked=true;Select(visible[0]);await WaitForPreviews();await Task.Delay(150); Check(preview.Spatial&&comparison.Spatial&&comparison.HasImage,"Overlay persists on both panes after toggling comparison and changing frame"); Capture("comparison-fit",144); + Check(compareTarget.IsVisible&&compareTarget.Items.Cast().SequenceEqual(new[]{"Nearby frame","Best frame"})&&compareTarget.SelectedIndex==0&&comparison.Caption=="Nearby","comparison target offers Nearby and Best and defaults to Nearby"); + var nearest=project!.Frames.Where(f=>f.Session==selected!.Session&&f.Id!=selected.Id&&f.Timestamp.HasValue&&f.Error=="").MinBy(f=>Math.Abs((f.Timestamp!.Value-selected!.Timestamp!.Value).TotalSeconds)); + Check(comparison.Frame==nearest,"Nearby compares the exposure closest in capture time"); + compareTarget.SelectedIndex=1;await WaitForPreviews();await Task.Delay(150);var bestFrame=comparison.Frame; + var kept=project.Frames.Where(f=>f.Session==selected!.Session&&f.Id!=selected.Id&&f.Error==""&&f.Measured&&f.Effective==AstroFrame.Engine.Verdict.Keep&&f.Fwhm>0).ToArray(); + Check(bestFrame!=null&&comparison.Caption=="Best","Best selects a comparison exposure ("+kept.Length+" kept candidates)"); + Check(comparison.HasImage,"Best comparison preview loads"); + Check(kept.Contains(bestFrame!)&&!kept.Any(f=>f.Score>bestFrame!.Score||f.Score==bestFrame!.Score&&f.Fwhm=0&&targetBounds.X+compareTarget.Bounds.Width<=Bounds.Width&&compareTarget.Bounds.Width>0,"comparison target dropdown stays visible at minimum window width");Capture("best-comparison-minimum",144); + Select(bestFrame!);await WaitForPreviews();Check(comparison.Frame!=null&&comparison.Frame!=selected&&comparison.Caption=="Best","selecting the best exposure compares the next best instead of itself"); + compare.IsChecked=false;Check(!compareTarget.IsVisible,"comparison target hides with Compare");compare.IsChecked=true; + Check(compareTarget.SelectedIndex==1&&comparison.Caption=="Best","comparison target persists while toggling Compare in a session"); + compareTarget.SelectedIndex=0;Select(visible[0]);await WaitForPreviews();Check(comparison.Caption=="Nearby"&&comparison.Frame!=null&&comparison.Frame.Session==selected!.Session,"switching back restores the nearby comparison"); Check(previewMode.Items.Cast().SequenceEqual(new[]{"Frame view","Denoised"}),"preview dropdown contains only Frame view and Denoised"); Check(preview.HasDenoised&&comparison.HasDenoised&&preview.Mode==AstroFrame.Engine.PreviewMode.Denoised&&comparison.Mode==preview.Mode,"Denoised applies to both comparison panes");Capture("denoised-comparison",144); double retainedZoom=viewport.Zoom;var retainedPan=viewport.Pan;previewMode.SelectedIndex=0;previewMode.SelectedIndex=1;await WaitForPreviews(); diff --git a/src/AstroFrame.Desktop/MainWindow.cs b/src/AstroFrame.Desktop/MainWindow.cs index f5a9561..0c7c054 100644 --- a/src/AstroFrame.Desktop/MainWindow.cs +++ b/src/AstroFrame.Desktop/MainWindow.cs @@ -45,6 +45,8 @@ public sealed partial class MainWindow:Window readonly ProgressBar progress=new(){Height=5,Minimum=0,Maximum=100,IsVisible=false,Foreground=Palette.Progress,Background=Palette.Line}; readonly Button analyze=Button("Analyze lights",true),export=Button("Export accepted"),stop=Button("Cancel"); readonly CheckBox spatial=new(){Content="Spatial overlay",FontSize=12},compare=new(){Content="Compare nearby",FontSize=12}; + // Not persisted: each launch starts comparing against the nearby exposure. + readonly ComboBox compareTarget=new(){ItemsSource=new[]{"Nearby frame","Best frame"},SelectedIndex=0,MinWidth=120,FontSize=11,IsVisible=false,Margin=new(10,0,0,0)}; Frame? selected;List visible=[]; readonly Stack<(Frame Frame,Verdict? Verdict,string Note,DateTime? At)> undo=[]; public MainWindow() @@ -93,7 +95,7 @@ public sealed partial class MainWindow:Window var previewActions=new WrapPanel{Margin=new(0,8,0,0)}; resetView.Padding=new(9,5);resetView.FontSize=11;resetView.Click+=(_,_)=>viewport.Reset();ToolTip.SetTip(resetView,"Reset image zoom and position");previewActions.Children.Add(resetView); inspectElongation.Padding=new(9,5);inspectElongation.FontSize=11;inspectElongation.Margin=new(8,0,0,0);inspectElongation.IsEnabled=false;inspectElongation.Click+=(_,_)=>ShowElongation();ToolTip.SetTip(inspectElongation,"Enlarge source stars and highlight their shape, with a matched KEEP frame when available");previewActions.Children.Add(inspectElongation);Grid.SetRow(previewActions,1);Grid.SetColumnSpan(previewActions,2);previewHeading.Children.Add(previewActions);center.Children.Add(previewHeading); - var viewRow=new Grid{ColumnDefinitions=new("Auto,*,Auto")};previewMode.MinWidth=125;previewMode.FontSize=11;viewRow.Children.Add(previewMode);var switches=new StackPanel{Orientation=Orientation.Horizontal,VerticalAlignment=VerticalAlignment.Center};spatial.Content="Overlay";compare.Content="Compare";spatial.Margin=new(0,0,12,0);switches.Children.Add(spatial);switches.Children.Add(compare);Grid.SetColumn(switches,2);viewRow.Children.Add(switches);Grid.SetRow(viewRow,1);center.Children.Add(viewRow); + var viewRow=new Grid{ColumnDefinitions=new("Auto,*,Auto")};previewMode.MinWidth=125;previewMode.FontSize=11;viewRow.Children.Add(previewMode);var switches=new StackPanel{Orientation=Orientation.Horizontal,VerticalAlignment=VerticalAlignment.Center};spatial.Content="Overlay";compare.Content="Compare";spatial.Margin=new(0,0,12,0);switches.Children.Add(spatial);switches.Children.Add(compare);switches.Children.Add(compareTarget);Grid.SetColumn(switches,2);viewRow.Children.Add(switches);Grid.SetRow(viewRow,1);center.Children.Add(viewRow); previewWorkspace.Children.Add(previewPanel);Grid.SetColumn(comparisonBorder,1);previewWorkspace.Children.Add(comparisonBorder);comparisonBorder.IsVisible=false;Grid.SetRow(previewWorkspace,2);center.Children.Add(previewWorkspace); Grid.SetRow(previewControls,3);center.Children.Add(previewControls); var caption=new StackPanel{Spacing=4,Margin=new(0,0,0,12)};exposureName.TextTrimming=TextTrimming.CharacterEllipsis;caption.Children.Add(exposureName);caption.Children.Add(exposureStatus);Grid.SetRow(caption,4);center.Children.Add(caption); @@ -107,7 +109,7 @@ public sealed partial class MainWindow:Window analyze.Click+=async(_,_)=>await Analyze();export.Click+=async(_,_)=>await ExportAccepted();stop.Click+=(_,_)=>cancellation?.Cancel(); 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=comparison.Spatial=spatial.IsChecked==true;preview.InvalidateVisual();comparison.InvalidateVisual();};compare.IsCheckedChanged+=(_,_)=>UpdateComparison(); + spatial.IsCheckedChanged+=(_,_)=>{preview.Spatial=comparison.Spatial=spatial.IsChecked==true;preview.InvalidateVisual();comparison.InvalidateVisual();};compare.IsCheckedChanged+=(_,_)=>UpdateComparison();compareTarget.SelectionChanged+=(_,_)=>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)=> { @@ -243,10 +245,18 @@ public sealed partial class MainWindow:Window void UpdateComparison() { 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(); + bool best=compareTarget.SelectedIndex==1;compareTarget.IsVisible=show; + preview.Caption=show?"Selected":"";comparison.Caption=show?best?"Best":"Nearby":"";preview.InvalidateVisual(); comparison.Spatial=spatial.IsChecked==true; 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,project.Frames);ToolTip.SetTip(comparisonBorder,nearby==null?"No comparable nearby exposure":"Nearby · "+nearby.Time+" · "+nearby.Status); + var other=best?BestFrame(project.Frames,selected):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,other,project.Frames);ToolTip.SetTip(comparisonBorder,other==null?best?"No other kept, measured exposure in this session":"No comparable nearby exposure":(best?"Best":"Nearby")+" · "+other.Time+" · "+other.Status+(best?$" · score {other.Score:0} · FWHM {other.Fwhm:0.00}":"")); + } + // Best kept exposure in the same session: highest quality score, then sharpest stars, then strongest stellar flux. + static Frame? BestFrame(IEnumerable frames,Frame selected) + { + return frames.Where(f=>f.Session==selected.Session&&f.Id!=selected.Id&&f.Error==""&&f.Measured&&f.Effective==Verdict.Keep&&f.Fwhm>0) + .OrderByDescending(f=>f.Score).ThenBy(f=>f.Fwhm).ThenByDescending(f=>f.Transparency).ThenBy(f=>f.Timestamp).FirstOrDefault(); } 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) diff --git a/src/AstroFrame.Engine/Classification.cs b/src/AstroFrame.Engine/Classification.cs index 7e488f0..ad0d684 100644 --- a/src/AstroFrame.Engine/Classification.cs +++ b/src/AstroFrame.Engine/Classification.cs @@ -40,6 +40,7 @@ public static class Classification double countZ=Metric("Star count",x=>x.StarCount,true,.10),fluxZ=Metric("Stellar flux",x=>x.Transparency,true,.06),widthZ=Metric("FWHM",x=>x.Fwhm,false,.08),shapeZ=Metric("Ellipticity",x=>x.Ellipticity,false,.15),bgZ=Metric("Background",x=>x.Background,false,.06),noiseZ=Metric("Noise",x=>x.Noise,false,.08); Metric("Background variation",x=>x.BackgroundVariation,false,.20); double Ratio(string key,double value)=>value/Math.Max(f.Baselines.GetValueOrDefault(key),.00001); + double Measured(string key)=>f.AdditionalMeasurements.GetValueOrDefault(key); double countRatio=Ratio("Star count",f.StarCount),fluxRatio=Ratio("Stellar flux",f.Transparency),widthRatio=Ratio("FWHM",f.Fwhm); double connected=f.AdditionalMeasurements.GetValueOrDefault("Cloud connected coverage"); // A single sky detector must be overwhelming to discard integration on its own. @@ -88,7 +89,15 @@ public static class Classification } if(widthBad)f.Evidence.Add(new("FWHM",f.Fwhm,f.Baselines["FWHM"],widthZ,$"Stellar width {widthRatio:0.00} × clear-frame baseline")); if(shapeBad)f.Evidence.Add(new("Ellipticity",f.Ellipticity,f.Baselines["Ellipticity"],shapeZ,$"Substantial stellar elongation ({f.Ellipticity:0.00} vs {f.Baselines["Ellipticity"]:0.00})")); - bool optics=widthBad&&shapeBad&&widthRatio>1.65; + // Stacking workflows such as Siril's Seestar script discard roundness outliers rather than + // averaging trailed stars into the result. Reject elongation that the same matched reference + // stars confirm well beyond their measurement uncertainty; unconfirmed flags stay REVIEW. + bool confirmedElongation=shapeBad&&Measured("Matched shape samples")>=50&&Measured("Matched shape reference frames")>=12&& + Measured("Matched shape uncertainty")>0&&Measured("Matched shape uncertainty")<=.025&& + Measured("Matched shape change")-3*Measured("Matched shape uncertainty")>=.10; + if(confirmedElongation)f.Evidence.Add(new("Matched stellar shape",Measured("Matched shape change"),0,Measured("Matched shape change")/Measured("Matched shape uncertainty"), + $"The same {Measured("Matched shape samples"):0} reference stars are {Measured("Matched shape change"):0.00} more elongated than in nearby clear frames (±{Measured("Matched shape uncertainty"):0.000}); a roundness outlier that stacking filters discard")); + bool optics=widthBad&&shapeBad&&widthRatio>1.65||confirmedElongation; bool catastrophic=f.StarCount<3&&f.Baselines["Star count"]>50; bool cloud=strongStructure||moderateStructure&&(fluxLoss||regionLoss||starLoss)||strongFlux||localCloudLoss; bool lowMatches=f.MatchFraction<.35; @@ -97,6 +106,22 @@ public static class Classification bool skyNoise=bgZ>5&&noiseZ>4&&Ratio("Background",f.Background)>1.4; if(skyNoise)f.Evidence.Add(new("Sky noise",f.Noise,f.Baselines["Noise"],noiseZ,"Background and sky noise are substantially above the clear-frame baseline")); bool suspicious=moderateStructure||fluxLoss||regionLoss||widthBad||shapeBad||skyNoise||starLoss||lowMatches; + // Thin cloud adds little residual glow, but it is coherent after smooth curvature is + // removed and dims the stars beneath it relative to clear parts of the same exposure. + // Requiring both keeps sky-only changes, such as gradients, out of this route. It only + // resolves frames other measurements already flag; it never rejects an otherwise clean KEEP. + bool texture=suspicious&&spatial&&Measured("Cloud texture significance")>=10&&Measured("Cloud texture connected coverage")>=.05&& + Measured("Cloud texture differential samples")>=20&&Measured("Cloud texture differential flux ratio")>0; + // Moderate dimming suffices when the plane-detrended structure detector also flags the frame, + // the texture is strong, and the excess-sky apertures independently lose flux against nearby frames. + bool thinCloud=texture&&(Measured("Cloud texture differential flux ratio")<=.98&&Measured("Cloud texture differential flux deviation")>=2.5|| + moderateStructure&&Measured("Cloud texture significance")>=20&& + Measured("Cloud texture differential flux ratio")<=.985&&Measured("Cloud texture differential flux deviation")>=1.5&& + Measured("Cloud aperture samples")>=20&&Measured("Cloud aperture regions")>=2&& + Measured("Cloud aperture flux ratio")>0&&Measured("Cloud aperture flux ratio")<=.93&&Measured("Cloud aperture flux deviation")>=2.5); + if(thinCloud)f.Evidence.Add(new("Cloud texture",Measured("Cloud texture differential flux ratio"),1,Measured("Cloud texture differential flux deviation"), + $"Thin cloud texture covers {Measured("Cloud texture coverage"):P0} of the aligned overlap (largest connected area {Measured("Cloud texture connected coverage"):P0}, {Measured("Cloud texture significance"):0.0} × clear-frame scatter); stars beneath it are {1-Measured("Cloud texture differential flux ratio"):P1} fainter relative to clear parts of the same exposure ({Measured("Cloud texture differential flux deviation"):0.0} × nearby clear-frame scatter, {Measured("Cloud texture differential samples"):0} apertures)")); + cloud|=thinCloud; f.Automatic=reliable&&(catastrophic||!weak&&(cloud||optics))?Verdict.Reject:!reliable||weak||suspicious||f.Warning!=""?Verdict.Review:Verdict.Keep; f.Cause=!reliable?"Insufficient reliable session reference":catastrophic?"Severe disappearance of reference stars":weak?"Uncertain alignment / reference photometry":cloud?"Likely cloud / transparency loss":optics?"Likely tracking or focus failure":suspicious?"Quality change needs review":"Consistent with the clean session reference"; if(!reliable)f.Evidence.Add(new("Reference",local.Length,12,0,"Automatic rejection disabled: insufficient clear comparison frames, timestamp or aligned overlap")); diff --git a/src/AstroFrame.Engine/Models.cs b/src/AstroFrame.Engine/Models.cs index 6aeb0ac..f081510 100644 --- a/src/AstroFrame.Engine/Models.cs +++ b/src/AstroFrame.Engine/Models.cs @@ -70,7 +70,7 @@ public sealed class Frame } public sealed class Project { - public const string EngineVersion="0.2.1-spatial-reference-2"; + public const string EngineVersion="0.2.3-spatial-reference-4"; public string Version {get;set;}=EngineVersion; public string Name {get;set;}="Untitled"; public string Source {get;set;}=""; diff --git a/src/AstroFrame.Engine/SkyModel.cs b/src/AstroFrame.Engine/SkyModel.cs index 5ac1210..86c2acb 100644 --- a/src/AstroFrame.Engine/SkyModel.cs +++ b/src/AstroFrame.Engine/SkyModel.cs @@ -38,36 +38,59 @@ public static class SkyModel } return map; } - public static double[] Detrend(double[] values) + public static double[] Detrend(double[] values)=>Detrend(values,false); + // Robust offset and gradient removal; quadratic terms also absorb smooth sky curvature. + public static double[] Detrend(double[] values,bool quadratic) { + int terms=quadratic?6:3; bool[] good=values.Select(double.IsFinite).ToArray();double[] residual=(double[])values.Clone(); if(good.Count(v=>v)<12)return residual; for(int iteration=0;iteration<5;iteration++) { - double[,] system=new double[3,4]; + double[,] system=new double[terms,terms+1]; for(int i=0;igood[i])),sigma=Math.Max(1,Robust.Mad(residual.Where((_,i)=>good[i]))); for(int i=0;iv)<12)break; } return residual; } + static double[] Basis(int i,bool quadratic) + { + double x=(i%Columns+.5)/Columns-.5,y=(i/Columns+.5)/Rows-.5; + return quadratic?[1,x,y,x*x,x*y,y*y]:[1,x,y]; + } + /// Mean of each finite cell and its finite 3-by-3 neighbors. + public static double[] Smooth(double[] values) + { + double[] output=Enumerable.Repeat(double.NaN,Count).ToArray(); + for(int row=0;row=0&&r=0&&c=3)output[row*Columns+col]=sum/n; + } + return output; + } internal static double[] Solve(double[,] m) { - for(int k=0;k<3;k++) + int n=m.GetLength(0); + for(int k=0;kMath.Abs(m[pivot,k]))pivot=r; - if(Math.Abs(m[pivot,k])<1e-8)return [Robust.Median([m[0,3]/Math.Max(m[0,0],1)]),0,0]; - for(int c=k;c<4;c++)(m[k,c],m[pivot,c])=(m[pivot,c],m[k,c]); - double divisor=m[k,k];for(int c=k;c<4;c++)m[k,c]/=divisor; - for(int r=0;r<3;r++)if(r!=k){double factor=m[r,k];for(int c=k;c<4;c++)m[r,c]-=factor*m[k,c];} + int pivot=k;for(int r=k+1;rMath.Abs(m[pivot,k]))pivot=r; + if(Math.Abs(m[pivot,k])<1e-8){double[] offset=new double[n];offset[0]=Robust.Median([m[0,n]/Math.Max(m[0,0],1)]);return offset;} + for(int c=k;c<=n;c++)(m[k,c],m[pivot,c])=(m[pivot,c],m[k,c]); + double divisor=m[k,k];for(int c=k;c<=n;c++)m[k,c]/=divisor; + for(int r=0;rm[r,n]).ToArray(); } public static int LargestComponent(bool[] mask) { diff --git a/src/AstroFrame.Engine/SpatialReference.cs b/src/AstroFrame.Engine/SpatialReference.cs index acd878b..9db033d 100644 --- a/src/AstroFrame.Engine/SpatialReference.cs +++ b/src/AstroFrame.Engine/SpatialReference.cs @@ -75,6 +75,13 @@ public static class SpatialReference 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); + // Thin cloud can add only a few ADU of coherent glow per cell: below the + // fractional-noise floor above, but far above clear-frame scatter once smooth + // curvature is removed and neighboring cells are averaged. Scale that smoothed + // texture by the scatter clear reference frames show for the same statistic. + var textures=maps.Select(m=>SkyModel.Smooth(SkyModel.Detrend(m.Select((v,j)=>v-reference[j]).ToArray(),true))).ToArray(); + double[] textureScatter=Enumerable.Range(0,SkyModel.Count).Select(j=>Robust.Mad(clean.Select(i=>textures[i][j]))).ToArray(); + double textureFloor=Math.Max(Math.Max(referenceNoise*.002,1e-6),.5*Robust.Median(textureScatter.Where(v=>v>0))); for(int i=0;iv>=128).ToArray(); f.AdditionalMeasurements["Cloud positive coverage"]=positive.Length==SkyModel.Count?(double)positive.Count(v=>v)/Math.Max(valid,1):0; f.AdditionalMeasurements["Cloud positive connected coverage"]=positive.Length==SkyModel.Count?(double)SkyModel.LargestComponent(positive)/Math.Max(valid,1):0; - MeasureCloudApertures(f,anchor,a,clean,normal,positive); + MeasureCloudApertures(f,anchor,a,clean,normal,positive,"Cloud aperture"); + double[] texture=textures[i].Select((v,j)=>v/Math.Max(textureFloor,textureScatter[j])).ToArray(); + bool[] textured=texture.Select(v=>v>4).ToArray();int textureValid=texture.Count(double.IsFinite); + f.AdditionalMeasurements["Cloud texture significance"]=Robust.Quantile(texture,.98); + f.AdditionalMeasurements["Cloud texture coverage"]=(double)textured.Count(v=>v)/Math.Max(textureValid,1); + f.AdditionalMeasurements["Cloud texture connected coverage"]=(double)SkyModel.LargestComponent(textured)/Math.Max(textureValid,1); + MeasureCloudApertures(f,anchor,a,clean,normal,textured,"Cloud texture aperture"); + MeasureDifferentialApertures(f,anchor,a,clean,normal,textured,texture.Select(v=>double.IsFinite(v)&&v<2).ToArray()); 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); @@ -97,14 +111,14 @@ public static class SpatialReference } } } - static void MeasureCloudApertures(Frame frame,Frame anchor,Frame[] frames,int[] clean,double[] normal,bool[] positive) + static void MeasureCloudApertures(Frame frame,Frame anchor,Frame[] frames,int[] clean,double[] normal,bool[] positive,string name) { var indices=Enumerable.Range(0,normal.Length).Where(j=>positive.Length==SkyModel.Count&& positive[Math.Clamp((int)(anchor.Stars[j].Y*SkyModel.Rows),0,SkyModel.Rows-1)*SkyModel.Columns+Math.Clamp((int)(anchor.Stars[j].X*SkyModel.Columns),0,SkyModel.Columns-1)]&& normal[j]*anchor.Exposure>=30*anchor.Noise&&frame.ForcedFlux.Length==normal.Length&&double.IsFinite(frame.ForcedFlux[j])).ToArray(); - frame.AdditionalMeasurements["Cloud aperture samples"]=indices.Length; - frame.AdditionalMeasurements["Cloud aperture regions"]=indices.Select(j=>Math.Clamp((int)(anchor.Stars[j].Y*4),0,3)*3+Math.Clamp((int)(anchor.Stars[j].X*3),0,2)).Distinct().Count(); - frame.AdditionalMeasurements["Cloud aperture flux ratio"]=0;frame.AdditionalMeasurements["Cloud aperture flux deviation"]=0; + frame.AdditionalMeasurements[name+" samples"]=indices.Length; + frame.AdditionalMeasurements[name+" regions"]=indices.Select(j=>Math.Clamp((int)(anchor.Stars[j].Y*4),0,3)*3+Math.Clamp((int)(anchor.Stars[j].X*3),0,2)).Distinct().Count(); + frame.AdditionalMeasurements[name+" flux ratio"]=0;frame.AdditionalMeasurements[name+" flux deviation"]=0; if(indices.Length<20)return; double Flux(Frame f)=>Robust.Median(indices.Where(j=>f.ForcedFlux.Length==normal.Length&&double.IsFinite(f.ForcedFlux[j])).Select(j=>f.ForcedFlux[j]/normal[j])); var comparisons=Nearby(frames,clean,frame).Where(f=>f.ForcedFlux.Length==normal.Length&&indices.Count(j=>double.IsFinite(f.ForcedFlux[j]))>=indices.Length*.8).Select(Flux).ToArray(); @@ -123,9 +137,28 @@ public static class SpatialReference double uncertainty=1.253*Math.Sqrt(indices.Sum(j=>Math.Pow(LocalNoise(j)*Math.Sqrt(varianceFactor)/Math.Max(1,frame.Exposure)/normal[j],2)))/indices.Length; double spread=Math.Max(baseline*.03,Math.Max(Robust.Mad(comparisons),uncertainty)); double measured=Flux(frame); - frame.AdditionalMeasurements["Cloud aperture flux ratio"]=measured/baseline; - frame.AdditionalMeasurements["Cloud aperture flux deviation"]=(baseline-measured)/spread; - frame.AdditionalMeasurements["Cloud aperture flux uncertainty"]=uncertainty/baseline; + frame.AdditionalMeasurements[name+" flux ratio"]=measured/baseline; + frame.AdditionalMeasurements[name+" flux deviation"]=(baseline-measured)/spread; + frame.AdditionalMeasurements[name+" flux uncertainty"]=uncertainty/baseline; + } + // Stars away from the texture share global transparency, seeing and airmass changes. + // Compare the inside/outside flux ratio with the same apertures in nearby clear frames. + static void MeasureDifferentialApertures(Frame frame,Frame anchor,Frame[] frames,int[] clean,double[] normal,bool[] inside,bool[] outside) + { + int[] Select(bool[] mask)=>Enumerable.Range(0,normal.Length).Where(j=>mask[Math.Clamp((int)(anchor.Stars[j].Y*SkyModel.Rows),0,SkyModel.Rows-1)*SkyModel.Columns+Math.Clamp((int)(anchor.Stars[j].X*SkyModel.Columns),0,SkyModel.Columns-1)]&& + normal[j]*anchor.Exposure>=30*anchor.Noise&&frame.ForcedFlux.Length==normal.Length&&double.IsFinite(frame.ForcedFlux[j])).ToArray(); + int[] a=Select(inside),b=Select(outside); + frame.AdditionalMeasurements["Cloud texture differential samples"]=Math.Min(a.Length,b.Length); + frame.AdditionalMeasurements["Cloud texture differential flux ratio"]=0;frame.AdditionalMeasurements["Cloud texture differential flux deviation"]=0; + if(a.Length<20||b.Length<20)return; + double Flux(Frame f,int[] indices)=>Robust.Median(indices.Where(j=>double.IsFinite(f.ForcedFlux[j])).Select(j=>f.ForcedFlux[j]/normal[j])); + double Ratio(Frame f)=>Flux(f,a)/Math.Max(Flux(f,b),1e-9); + var comparisons=Nearby(frames,clean,frame).Where(f=>f.ForcedFlux.Length==normal.Length&&a.Count(j=>double.IsFinite(f.ForcedFlux[j]))>=a.Length*.8&&b.Count(j=>double.IsFinite(f.ForcedFlux[j]))>=b.Length*.8).Select(Ratio).ToArray(); + double baseline=Robust.Median(comparisons);if(comparisons.Length<12||baseline<=0)return; + double measured=Ratio(frame),spread=Math.Max(baseline*.01,Robust.Mad(comparisons)); + frame.AdditionalMeasurements["Cloud texture differential flux ratio"]=measured/baseline; + frame.AdditionalMeasurements["Cloud texture differential flux deviation"]=(baseline-measured)/spread; + frame.AdditionalMeasurements["Cloud texture differential flux scatter"]=spread/baseline; } static IEnumerable Nearby(Frame[] frames,int[] clean,Frame selected)=>clean.Select(i=>frames[i]).Where(f=>f.Id!=selected.Id) .OrderBy(f=>Math.Abs((f.Timestamp.GetValueOrDefault()-selected.Timestamp.GetValueOrDefault()).TotalSeconds)).Take(40); diff --git a/tests/AstroFrame.Validation/QualityRegression.cs b/tests/AstroFrame.Validation/QualityRegression.cs index 0d5bf78..96c2671 100644 --- a/tests/AstroFrame.Validation/QualityRegression.cs +++ b/tests/AstroFrame.Validation/QualityRegression.cs @@ -16,7 +16,8 @@ static class QualityRegression 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]); + var thinFlagged=Make(49);var thinUndimmed=Make(50);var thinClean=Make(51);var unconfirmedShape=Make(52);var moderateCloud=Make(53); + frames.AddRange([opaque,broad,gradient,uncertain,cohort,trailing,subtleShape,insufficient,noisyFlux,thinFlagged,thinUndimmed,thinClean,unconfirmedShape,moderateCloud]); 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(); @@ -42,15 +43,40 @@ static class QualityRegression 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; + subtleShape.AdditionalMeasurements["Matched shape change"]=.10;subtleShape.AdditionalMeasurements["Matched shape uncertainty"]=.005; + void Texture(Frame f,double ratio,double deviation,bool flagged) + { + f.AdditionalMeasurements["Clear reference member"]=0; + f.AdditionalMeasurements["Cloud texture significance"]=20;f.AdditionalMeasurements["Cloud texture coverage"]=.15; + f.AdditionalMeasurements["Cloud texture connected coverage"]=.10;f.AdditionalMeasurements["Cloud texture differential samples"]=60; + f.AdditionalMeasurements["Cloud texture differential flux ratio"]=ratio;f.AdditionalMeasurements["Cloud texture differential flux deviation"]=deviation; + if(!flagged)return; + // Weak, uncorroborated planar structure routes the frame to REVIEW. + Cloud(f,6,.05,1); + } + Texture(thinFlagged,.96,4,true);Texture(thinUndimmed,1,.3,true);Texture(thinClean,.96,4,false); + unconfirmedShape.Ellipticity=.3;unconfirmedShape.AdditionalMeasurements["Matched shape samples"]=30; + unconfirmedShape.AdditionalMeasurements["Matched shape change"]=.2;unconfirmedShape.AdditionalMeasurements["Matched shape uncertainty"]=.01; + // Flagged sky structure, strong texture, and two moderate, independent dimming measurements. + Texture(moderateCloud,.98,2,false);Cloud(moderateCloud,8,.10,.91);moderateCloud.AdditionalMeasurements["Cloud aperture flux deviation"]=2.9; + moderateCloud.AdditionalMeasurements["Cloud texture significance"]=30;moderateCloud.Transparency=1; Classification.Run(frames); + check(thinFlagged.Automatic==Verdict.Reject&&thinFlagged.Evidence.Any(e=>e.Metric=="Cloud texture"),"flagged frame with thin cloud texture that dims stars beneath it rejects"); + check(thinUndimmed.Automatic==Verdict.Review,"thin texture without differential stellar dimming stays REVIEW"); + check(thinClean.Automatic==Verdict.Keep,"thin cloud texture alone never rejects an otherwise clean KEEP"); + check(moderateCloud.Automatic==Verdict.Reject&&moderateCloud.Evidence.Any(e=>e.Metric=="Cloud texture"),"flagged sky structure with strong texture and two moderate dimming measurements rejects"); + double[] curved=Enumerable.Range(0,SkyModel.Count).Select(i=>{double x=(i%SkyModel.Columns+.5)/SkyModel.Columns-.5,y=(i/SkyModel.Columns+.5)/SkyModel.Rows-.5;return 1000+40*x-30*y+200*x*x-150*x*y+120*y*y;}).ToArray(); + check(SkyModel.Detrend(curved,true).All(v=>Math.Abs(v)<.01)&&SkyModel.Detrend(curved).Max(Math.Abs)>5,"quadratic detrending removes smooth sky curvature that a plane leaves behind"); + double[] spike=new double[SkyModel.Count];spike[10*SkyModel.Columns+10]=9;var smoothed=SkyModel.Smooth(spike); + check(Math.Abs(smoothed[10*SkyModel.Columns+10]-1)<1e-9&&Math.Abs(smoothed[11*SkyModel.Columns+11]-1)<1e-9&&smoothed[12*SkyModel.Columns+12]==0,"texture smoothing averages each cell with its 3x3 neighbors"); 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(trailing.Automatic==Verdict.Reject&&trailing.Cause=="Likely tracking or focus failure","elongation confirmed by the same matched reference stars rejects as a roundness outlier"); + check(unconfirmedShape.Automatic==Verdict.Review,"elongation without enough matched reference stars stays REVIEW"); + check(subtleShape.Automatic==Verdict.Review,"matched elongation between the dismissal and rejection limits stays REVIEW"); 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()}};