You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/domain/create_domain.jl
+72-55Lines changed: 72 additions & 55 deletions
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,6 @@ Domain{T, N, M}
5
5
6
6
Data structure describing the computational domain for the simulation.
7
7
8
-
$(FIELDS)
9
8
"""
10
9
struct Domain{T, N, M}
11
10
# The mask describing where the points are located on the grid.
@@ -27,56 +26,78 @@ struct Domain{T, N, M}
27
26
end
28
27
29
28
"""
30
-
Construct a Domain using vectors of longitudes and latitudes, a land_area_fraction array and a surface class mapping. The shape of the longitudes by latitudes should match the trailing dimensions of the land_area_fraction array. This signature is used for gridded domains.
29
+
Construct a Domain using vectors of longitudes and latitudes, a vegetation_area_fraction array and a surface class mapping. The shape of the longitudes by latitudes should match the trailing dimensions of the vegetation_area_fraction array. This signature is used for gridded domains.
31
30
32
31
If the lon_bnds and lat_bnds are not supplied, then they are inferred from the passed latitudes and longitudes. If `normalise` is true, the sum of fractions in a grid cell is normalised to 1.
# First validate the land area fraction. This includes checking the mapping is workable
37
36
# with the passed land fractions i.e. the user hasn't denoted a tile index greater than
38
37
# the number of slices in the array
39
-
@assert(size(land_area_fraction, 2), size(land_area_fraction, 3))==(length(lons), length(lats)),"The size of the land_area_fraction and the supplied longitudes and latitudes are not compatible. Size of land_area_fraction: $(size(land_area_fraction)), with lons: $(length(lons)) and lats: $(length(lats))"
38
+
@assertsize(vegetation_area_fraction, 1) ==length(lons) &&size(vegetation_area_fraction, 2)==length(lats) "The size of the vegetation_area_fraction and the supplied longitudes and latitudes are not compatible. Size of vegetation_area_fraction: $(size(vegetation_area_fraction)), with lons: $(length(lons)) and lats: $(length(lats))"
40
39
41
40
# Convert the mapping values to vectors for consistent handling and array accessing,
42
41
# then validate
43
42
mapping =Dict(surface => inds isa Vector ? inds : [inds] for (surface, inds) in mapping)
@assertsize(mask) == (size(vegetation_area_fraction, 1), size(vegetation_area_fraction, 2)), "Supplied mask does not match the shape of the land area fractions."
68
+
end
54
69
55
-
#Now we have handled everything that is specific to the gridded domains- reshape the
56
-
# data so that it can be treated in the same way as site runs.
57
-
# This means that the land_area_fraction should represent spatial points in a single
58
-
# dimension, and the mask should be a vector (if supplied)
Construct a Domain using vectors of x and y coordinates (typically latitude and longitude), a land_area_fraction array and a surface class mapping. The longitudes and latitudes are paired, representing specific locations. This signature is used for site domains, and for processing of gridded domains after some preprocessing.
92
+
Construct a Domain using vectors of x and y coordinates (typically latitude and longitude), a vegetation_area_fraction array and a surface class mapping. The longitudes and latitudes are paired, representing specific locations. This signature is used for site domains, and for processing of gridded domains after some preprocessing.
75
93
76
94
If the lon_bnds and lat_bnds are not supplied, then it is assumed that the coordinates represent longitudes and latitudes, and the size of the grid cells is assumed to be 0.01 degrees.
functionDomain(lons, lats, vegetation_area_fraction::Matrix{T}, mapping; lon_bnds=nothing, lat_bnds=nothing, mask=nothing, normalise=false) where {T}
98
+
99
+
# Check that the lons and lats are valid
100
+
@assertlength(lons) ==length(lats) ==size(vegetation_area_fraction, 2) "The longitudes, latitudes and number of columns in the vegetation_area_fraction array must be the same."
Ensure that the specified mapping is valid with the given land area fractions. The only condition is that the mapping doesn't contain any indices outside the range available in the land area fractions i.e. 1 <= indx <= size(land_area_fraction, 1)
150
+
Ensure that the specified mapping is valid with the given land area fractions. The only condition is that the mapping doesn't contain any indices outside the range available in the land area fractions i.e. 1 <= indx <= size(vegetation_area_fraction, 1)
@@ -224,15 +253,3 @@ function define_on_domain(vars, domain::Domain{T}, dims=()) where {T}
224
253
225
254
which_domain, ComponentVector(t)
226
255
end
227
-
228
-
functioncheck_land_domain(domain::Domain, data::Array{T, 3}) where {T}
229
-
for i =1:size(data, 3)
230
-
@assertall(domain.mask .== .!(ismissing.(@view(data[:, :, i])))), "Supplied data is expected to be on the same grid as the land mask, but it is not."
231
-
end
232
-
end
233
-
234
-
functioncheck_land_domain(domain::Domain, data::Array{T, 4}) where {T}
235
-
for i =1:size(data, 3), j =1:size(data, 4)
236
-
@assertall(domain.mask .== .!(ismissing.(@view(data[:, :, i, j])))), "Supplied data is expected to be on the same grid as the land mask, but it is not."
0 commit comments