Repository navigation
Expand file tree
/
Copy pathQuickStartHttp.cs
More file actions
70 lines (57 loc) · 2.98 KB
/
Copy pathQuickStartHttp.cs
File metadata and controls
70 lines (57 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using ZarrNET.Core.Helpers;
using ZarrNET;
using ZarrNET.Core;
using ZarrNET.Core.OmeZarr;
namespace ZarrNET
{
public static class QuickStartHttp
{
public async static void Starts(string source)
{
// =============================================================================
// Quick Start - Reading from HTTP/S3
// =============================================================================
// Works with any URL - local paths, HTTP, S3, Azure, GCS
var dataSource = source;
if (source == null)
{
dataSource = "https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0062A/6001240.zarr";
}
// Or your local file:
// var dataSource = @"C:\data\image.zarr";
Console.WriteLine($"Opening: {dataSource}\n");
await using var reader = await OmeZarrReader.OpenAsync(dataSource);
// Auto-detect what kind of dataset this is
Console.WriteLine($"Dataset type: {reader.RootNodeType}");
// Open as multiscale image
var image = reader.AsMultiscaleImage();
var multiscale = image.Multiscales[0];
Console.WriteLine($"Image: {multiscale.Name ?? "(unnamed)"}");
Console.WriteLine($"Axes: {string.Join(", ", multiscale.Axes.Select(a => $"{a.Name}[{a.Unit}]"))}");
Console.WriteLine($"Resolution levels: {multiscale.Datasets.Length}\n");
// Open the lowest resolution level for fast preview
var lastLevel = multiscale.Datasets.Length - 1;
var thumbnail = await image.OpenResolutionLevelAsync(lastLevel);
Console.WriteLine($"Thumbnail level {lastLevel}:");
Console.WriteLine($" Shape: [{string.Join(", ", thumbnail.Shape)}]");
Console.WriteLine($" Pixel size: {string.Join(" x ", thumbnail.GetPixelSize().Select(p => $"{p:G4}"))}\n");
// Read a plane
var plane = await thumbnail.ReadPlaneAsync(t: 0, c: 0, z: 0);
Console.WriteLine($"Loaded plane: {plane}");
// Extract as typed array
var pixels = plane.As1DArray<ushort>();
Console.WriteLine($"Pixel stats:");
Console.WriteLine($" Min: {pixels.Min()}");
Console.WriteLine($" Max: {pixels.Max()}");
Console.WriteLine($" Mean: {pixels.Average(p => (double)p):F1}");
// Now load full resolution
Console.WriteLine("\nLoading full resolution...");
var fullRes = await image.OpenResolutionLevelAsync(0);
Console.WriteLine($"Full res shape: [{string.Join(", ", fullRes.Shape)}]");
// Read a small region from full res
var fullResPlane = await fullRes.ReadPlaneAsync(t: 0, c: 0, z: 0);
Console.WriteLine($"Full res plane: {fullResPlane.Width}x{fullResPlane.Height}");
Console.WriteLine("\n✓ Successfully read from remote OME-Zarr dataset!");
}
}
}