Skip to content

Commit 71ac786

Browse files
committed
Fix root image path setting when there are multiple satellite definitions for a given satellite
1 parent d574f15 commit 71ac786

8 files changed

Lines changed: 59 additions & 15 deletions

File tree

Sanchez.Processing/Services/SatelliteRegistry.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class SatelliteRegistry(
2323
public async Task InitialiseAsync()
2424
{
2525
logger.LogInformation("Initialising satellite registry from {DefinitionsPath}", options.DefinitionsPath);
26-
26+
2727
var json = await File.ReadAllTextAsync(options.DefinitionsPath);
2828
var definitions = JsonConvert.DeserializeObject<List<SatelliteConfiguration>>(json);
2929

@@ -55,7 +55,7 @@ private async Task InitializeImagePathsAsync()
5555
ArgumentNullException.ThrowIfNull(_definitions);
5656

5757
if (options.ImagePaths == null) return;
58-
58+
5959
logger.LogInformation("Initialising image paths from {ImagePaths}", options.ImagePaths);
6060
var json = await File.ReadAllTextAsync(options.ImagePaths);
6161

@@ -64,14 +64,17 @@ private async Task InitializeImagePathsAsync()
6464
foreach (var path in paths)
6565
{
6666
// Validate satellite definition exists
67-
var definition = _definitions.Find(d => d.DisplayName == path.Satellite);
68-
if (definition == null)
67+
var definitions = _definitions.Where(d => d.DisplayName == path.Satellite).ToList();
68+
if (definitions.Count == 0)
6969
{
7070
logger.LogWarning("Unable to find satellite definition for {Satellite}; ignoring image path", path.Satellite);
7171
continue;
7272
}
7373

74-
definition.RootDirectory = Path.GetFullPath(path.Directory);
74+
foreach (var definition in definitions)
75+
{
76+
definition.RootDirectory = Path.GetFullPath(path.Directory);
77+
}
7578
}
7679
}
7780

@@ -91,7 +94,7 @@ private async Task InitializeImagePathsAsync()
9194
logger.LogTrace(
9295
"Skipping {Definition} handler for {Filename} as it is not under the root directory {RootDirectory}",
9396
definition.DisplayName, filename, definition.RootDirectory);
94-
97+
9598
continue;
9699
}
97100

Sanchez.sln.DotSettings.user

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
22
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFileSystem_002EWindows_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003Fmatt_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003Fd6b0a348da189959c7eaf7be7f5b52ab59881ae6e7301778edba2ba2f6d46d3_003FFileSystem_002EWindows_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
3+
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ALateBoundTestFramework_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003Fmatt_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003F74ffbd432d65ff1251694d2f6af3ebabfc09bd714d0aa751f5cfd61dd9_003FLateBoundTestFramework_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
34
<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue">&lt;AssemblyExplorer&gt;&#xD;
45
&lt;Assembly Path="C:\code\sanchez\Tests\Sanchez.Processing.Test\bin\Debug\netcoreapp3.1\Sanchez.Processing.dll" /&gt;&#xD;
56
&lt;/AssemblyExplorer&gt;</s:String>

Sanchez/Models/CommandLine/CommandLineOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public abstract record CommandLineOptions
5353
[Option('n', HelpText = "Don't add gaussian noise to output image", Required = false)]
5454
public bool NoNoise { get; set; }
5555

56-
[Option('p', "imagepaths", HelpText = "Path to image path JSON file", Required = false)]
57-
public string? ImagePaths { get; set; }
56+
[Option('p', "imagepaths", HelpText = "Path to image root path JSON file", Required = false)]
57+
public string? ImageRootPaths { get; set; }
5858

5959
[Option('q', "quiet", HelpText = "Don't perform console output", Required = false, Default = false)]
6060
public bool Quiet { get; set; }

Sanchez/Services/OptionsParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private static RenderOptions ProcessBaseOptions(CommandLineOptions options)
6969

7070
if (options.UnderlayPath != null) renderOptions.UnderlayPath = options.UnderlayPath;
7171
if (options.DefinitionsPath != null) renderOptions.DefinitionsPath = options.DefinitionsPath;
72-
if (options.ImagePaths != null) renderOptions.ImagePaths = options.ImagePaths;
72+
if (options.ImageRootPaths != null) renderOptions.ImagePaths = options.ImageRootPaths;
7373

7474
SetOverlayOptions(options, renderOptions);
7575

Tests/Sanchez.Processing.Test/Services/SatelliteRegistryTests.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,39 @@ public void HimawariMatched()
7575
}
7676

7777
[Test]
78-
public void ElectroMatched()
78+
public void ElectroN2Matched()
7979
{
8080
// Verify 4-9 definition
81-
var (definition, timestamp) = SatelliteRegistry.Locate("c:/images/200830_0230_6.jpg");
81+
var (definition, timestamp) = SatelliteRegistry.Locate("c:/satellite/electro-l-n2/200830_0230_6.jpg");
8282
definition.Should().NotBeNull("satellite definition should have been found");
8383
timestamp.Should().NotBeNull("timestamp should have been extracted");
84+
definition.DisplayName.Should().Be("Electro-L N2");
8485

8586
definition!.FilenameParserType.Should().Be(FilenameParserType.Electro);
8687
timestamp.Should().Be(new DateTime(2020, 08, 29, 23, 30, 0));
8788

8889
// Verify 1-3 definition
89-
(definition, _) = SatelliteRegistry.Locate("c:/images/200830_0230_1.jpg");
90+
(definition, _) = SatelliteRegistry.Locate("c:/satellite/electro-l-n2/200830_0230_1.jpg");
9091
definition.Should().NotBeNull("satellite definition should have been found");
92+
definition.DisplayName.Should().Be("Electro-L N2");
93+
}
94+
95+
[Test]
96+
public void ElectroN3Matched_ImageRootPath()
97+
{
98+
// Verify 4-9 definition, with a base path matching the test image root
99+
var (definition, timestamp) = SatelliteRegistry.Locate("c:/satellite/electro-l-n3/200830_0230_6.jpg");
100+
definition.Should().NotBeNull("satellite definition should have been found");
101+
timestamp.Should().NotBeNull("timestamp should have been extracted");
102+
definition.DisplayName.Should().Be("Electro-L N3");
103+
104+
definition!.FilenameParserType.Should().Be(FilenameParserType.Electro);
105+
timestamp.Should().Be(new DateTime(2020, 08, 29, 23, 30, 0));
106+
107+
// Verify 1-3 definition
108+
(definition, _) = SatelliteRegistry.Locate("c:/satellite/electro-l-n3/200830_0230_1.jpg");
109+
definition.Should().NotBeNull("satellite definition should have been found");
110+
definition.DisplayName.Should().Be("Electro-L N3");
91111
}
92112

93113
[Test]

Tests/Sanchez.Test.Common/AbstractTests.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Sanchez.Services;
1111
using SixLabors.ImageSharp;
1212
using SixLabors.ImageSharp.PixelFormats;
13+
using Sanchez.Processing.Helpers;
1314

1415
namespace Sanchez.Test.Common;
1516

@@ -24,13 +25,15 @@ public abstract class AbstractTests
2425
protected const string Goes16Filename = "GOES17_FD_CH13_20200830T033031Z.jpg";
2526

2627
private static string DefinitionsPath => Path.Combine(TestContext.CurrentContext.TestDirectory, Constants.DefaultDefinitionsPath);
28+
private static string ImageRootPath => Path.Combine(TestContext.CurrentContext.TestDirectory, PathHelper.ResourcePath("ImagePaths.json"));
29+
2730
protected RenderOptions RenderOptions => GetService<RenderOptions>();
2831

2932
protected ISatelliteRegistry SatelliteRegistry => GetService<ISatelliteRegistry>();
3033
private IUnderlayCacheRepository UnderlayCacheRepository => GetService<IUnderlayCacheRepository>();
3134

32-
private ServiceProvider ServiceProvider { get; set; }
33-
protected FileState State { get; set; }
35+
private ServiceProvider ServiceProvider { get; set; } = null!;
36+
protected FileState State { get; private set; } = null!;
3437

3538
[SetUp]
3639
public virtual void SetUp() => State = new FileState();
@@ -47,7 +50,8 @@ public void OneTimeSetUp()
4750
InterpolationType = InterpolationOptions.B,
4851
SpatialResolution = Constants.Satellite.SpatialResolution.TwoKm,
4952
DefinitionsPath = DefinitionsPath,
50-
AtmosphereAmount = 1.0f
53+
AtmosphereAmount = 1.0f,
54+
ImageRootPaths = ImageRootPath
5155
});
5256

5357
// Build DI container
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"Satellite": "Electro-L N2",
4+
"Directory": "c:/satellite/electro-l-n2"
5+
},
6+
{
7+
"Satellite": "Electro-L N3",
8+
"Directory": "c:/satellite/electro-l-n3"
9+
}
10+
]

Tests/Sanchez.Test.Common/Sanchez.Test.Common.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@
1111
<PackageReference Include="Microsoft.NET.Test.Sdk" />
1212
</ItemGroup>
1313

14+
<ItemGroup>
15+
<None Update="Resources\ImagePaths.json">
16+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
17+
</None>
18+
</ItemGroup>
19+
1420
</Project>

0 commit comments

Comments
 (0)