-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates to functionality and to docstrings
- Loading branch information
1 parent
ce3e6dd
commit 09c3a84
Showing
5 changed files
with
122 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,90 @@ | ||
""" | ||
RegionGrid( | ||
geo :: GeoRegion, | ||
lon :: Array{<:Real,2}, | ||
lat :: Array{<:Real,2} | ||
) -> RegionGrid | ||
geo :: GeoRegion, | ||
pnts :: Array{Point2{FT}} | ||
) where FT <: Real -> gmsk :: RegionMask | ||
Creates a `RegionMask` type based on the following arguments. This method is more suitable for non-rectilinear grids of longitude and latitude points, such as in the output of WRF or CESM. | ||
Arguments | ||
========= | ||
- `geo` : A GeoRegion of interest | ||
- `lon` : An array containing the longitude points | ||
- `lat` : An array containing the latitude points | ||
- `pnts` : An array containing the longitude points | ||
Returns | ||
======= | ||
- `gmsk` : A `RegionMask` | ||
""" | ||
function RegionGrid( | ||
geo :: GeoRegion, | ||
lon :: Array{<:Real,2}, | ||
lat :: Array{<:Real,2} | ||
) | ||
geo :: GeoRegion, | ||
pnts :: Array{Point2{FT}} | ||
) where FT <: Real | ||
|
||
@info "$(modulelog()) - Creating a RegionMask for the $(geo.name) GeoRegion based on an array of longitude and latitude points" | ||
|
||
if eltype(lon) <: AbstractFloat | ||
FT = eltype(lon) | ||
end | ||
|
||
if size(lon) != size(lat) | ||
error("$(modulelog()) - The size of the longitude and latitude arrays are not the same.") | ||
end | ||
|
||
mask = zeros(size(lon)) | ||
wgts = zeros(size(lon)) | ||
npnt = size(pnts) | ||
mask = zeros(npnt) | ||
wgts = zeros(npnt) | ||
lon = zeros(npnt) | ||
lat = zeros(npnt) | ||
|
||
for ii in eachindex(lon) | ||
ipnt = Point2(lon[ii],lat[ii]) | ||
if in(ipnt,geo) | ||
mask[ii] = 1 | ||
wgts[ii] = cosd.(lat[ii]) | ||
else; mask[ii] = NaN | ||
wgts[ii] = 0 | ||
lon[ii] = pnts[ii][1] | ||
lat[ii] = pnts[ii][2] | ||
if in(pnts[ii],geo) | ||
mask[ii] = 1 | ||
wgts[ii] = cosd.(pnts[ii][2]) | ||
else | ||
mask[ii] = NaN | ||
wgts[ii] = 0 | ||
end | ||
end | ||
|
||
return RegionMask{FT}(lon,lat,mask,wgts) | ||
|
||
end | ||
|
||
function VectorGrid( | ||
geo :: GeoRegion, | ||
lon :: Vector{<:Real}, | ||
lat :: Vector{<:Real} | ||
) | ||
""" | ||
VectorGrid( | ||
geo :: GeoRegion, | ||
pnts :: Vector{Point2{FT}} | ||
) where FT <: Real -> gmsk :: VectorMask | ||
@info "$(modulelog()) - Creating a RegionMask for the $(geo.name) GeoRegion based on an array of longitude and latitude points" | ||
Creates a `VectorMask` type based on a vector of | ||
if eltype(lon) <: AbstractFloat | ||
FT = eltype(lon) | ||
end | ||
Arguments | ||
========= | ||
- `geo` : A GeoRegion of interest | ||
- `pnts` : A `Vector` of `Float` Types, containing the longitude points | ||
if length(lon) != length(lat) | ||
error("$(modulelog()) - The size of the longitude and latitude arrays are not the same.") | ||
end | ||
Returns | ||
======= | ||
- `gmsk` : A `VectorMask` | ||
""" | ||
function VectorGrid( | ||
geo :: GeoRegion, | ||
pnts :: Vector{Point2{FT}} | ||
) where FT <: Real | ||
|
||
mask = zeros(length(lon)) | ||
@info "$(modulelog()) - Creating a RegionMask for the $(geo.name) GeoRegion based on an array of longitude and latitude points" | ||
|
||
for ii in eachindex(lon) | ||
ipnt = Point2(lon[ii],lat[ii]) | ||
if in(ipnt,geo) | ||
npnt = length(pnts) | ||
mask = zeros(npnt) | ||
wgts = zeros(npnt) | ||
lon = zeros(npnt) | ||
lat = zeros(npnt) | ||
|
||
for ii in 1 : length(pnts) | ||
lon[ii] = pnts[ii][1] | ||
lat[ii] = pnts[ii][2] | ||
if in(pnts[ii],geo) | ||
mask[ii] = 1 | ||
wgts[ii] = cosd.(pnts[ii][2]) | ||
else; mask[ii] = NaN | ||
wgts[ii] = 0 | ||
end | ||
end | ||
jj = .!isnan.(mask) | ||
|
||
return VectorMask{FT}(lon,lat,mask,lon[jj],lat[jj]) | ||
return VectorMask{FT}(lon,lat,mask,wgts) | ||
|
||
end |
Oops, something went wrong.