1+ using SentinelDataSource
2+ using YAXArrays
3+ using Distances
4+ using DimensionalData
5+ using AWS
6+
7+ struct AnonymousGCS <: AbstractAWSConfig end
8+ struct NoCredentials end
9+ AWS. region (aws:: AnonymousGCS ) = " " # No region
10+ AWS. credentials (aws:: AnonymousGCS ) = NoCredentials () # No credentials
11+ AWS. check_credentials (c:: NoCredentials ) = c # Skip credentials check
12+ AWS. sign! (aws:: AnonymousGCS , :: AWS.Request ) = nothing # Don't sign request
13+ function AWS. generate_service_url (aws:: AnonymousGCS , service:: String , resource:: String )
14+ service == " s3" || throw (ArgumentError (" Can only handle s3 requests to GCS" ))
15+ awsurl = string (" https://objects.eodc.eu:2222" , resource)
16+ return awsurl
17+ end
18+ AWS. global_aws_config (AnonymousGCS ())
19+ path = " s3://e05ab01a9d56408d82ac32d69a5aae2a:sample-data/tutorial_data/cpm_v253/S2A_MSIL2A_20180601T102021_N0500_R065_T32UPC_20230902T045008.zarr/measurements/reflectance/r20m"
20+
21+ pathbase = " s3://e05ab01a9d56408d82ac32d69a5aae2a:sample-data/eopf-sample-output/"
22+ zopen (path)
23+ c = Cube (open_dataset (zopen (path)))
24+ yax = YAXArray ((Dim {:x} (1 : 500 ), Dim {:y} (500 : - 1 : 1 ), Dim {:Variables} (1 : 10 )), rand (500 ,500 ,10 ))
25+ c = yax
26+ function spectraldiversity (c)
27+ dlat = dims (c, :x )
28+ dlon = dims (c, :y )
29+ dband = dims (c, :Variables )
30+ # This needs a better interface for within index space
31+ latinterval = MovingIntervals (center= dlat. val, width= 3 * step (dlat), n= length (dlat)- 1 , step= step (dlat))
32+ loninterval = MovingIntervals (center= dlon. val, width= - 3 * step (dlon), n= length (dlon)- 1 , step= - step (dlon))
33+ bandinterval = MovingIntervals (:closed , :closed , left= first (dband. val), right= last (dband. val), n= 1 )
34+ meanwindows = windows (c, :y => loninterval, :Variables => Whole ())
35+ @show meanwindows[10 ,10 ,1 ]
36+ @time xmap (innerdiversity, meanwindows)
37+ end
38+ spectraldiversity (c)
39+ function innerdiversity (xout, arr)
40+ winsize = prod (size (arr)) ÷ size (arr,3 )
41+ arrreshaped = reshape (arr, (winsize, size (arr,3 )))
42+ tslist = eachrow (arrreshaped)
43+ dists = pairwise (Euclidean (), tslist) .* 2 ./ winsize .^ 4
44+ xout .= sum (dists) ./ 2
45+ end
46+
47+ spectraldiversity (c)
0 commit comments