Skip to content

Commit

Permalink
optionally remove NaN from field
Browse files Browse the repository at this point in the history
  • Loading branch information
boriskaus committed Feb 25, 2024
1 parent f8e1389 commit e28d748
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions ext/GMT_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ ImportTopo(; lat=[37,49], lon=[4,20], file::String="@earth_relief_01m.grd") = Im


"""
data_GMT = ImportGeoTIFF(fname::String; fieldname=:layer1, negative=false, iskm=true, NorthernHemisphere=true, constantDepth=false)
data_GMT = ImportGeoTIFF(fname::String; fieldname=:layer1, negative=false, iskm=true, NorthernHemisphere=true, constantDepth=false, removeNaN_z=false, removeNaN_field=false)
This imports a GeoTIFF dataset (usually containing a surface of some sort) using GMT.
The file should either have `UTM` coordinates of `longlat` coordinates. If it doesn't, you can
Expand All @@ -119,9 +119,9 @@ Optional keywords:
- `iskm` : if true, the depth is multiplied by 1e-3 (default=true)
- `NorthernHemisphere`: if true, the UTM zone is set to be in the northern hemisphere (default=true); only relevant if the data uses UTM projection
- `constantDepth`: if true we will not warp the surface by z-values, but use a constant value instead
- `removeNaN` : if true, we will remove NaN values from the dataset
- `removeNaN_z` : if true, we will remove NaN values from the z-dataset
"""
function ImportGeoTIFF(fname::String; fieldname=:layer1, negative=false, iskm=true, NorthernHemisphere=true, constantDepth=false, removeNaN=false)
function ImportGeoTIFF(fname::String; fieldname=:layer1, negative=false, iskm=true, NorthernHemisphere=true, constantDepth=false, removeNaN_z=false, removeNaN_field=false)
G = gmtread(fname);

# Transfer to GeoData
Expand Down Expand Up @@ -150,16 +150,19 @@ function ImportGeoTIFF(fname::String; fieldname=:layer1, negative=false, iskm=tr
end

end

if removeNaN_z
remove_NaN_Surface!(Depth, Lon, Lat)
end
if removeNaN_field
remove_NaN_Surface!(data, Lon, Lat)
end
data_field = NamedTuple{(fieldname,)}((data,));

if constantDepth
Depth = zero(Lon)
end

if removeNaN
remove_NaN_Surface!(Depth, Lon, Lat)
end

if contains(G.proj4,"utm")
zone = parse(Int64,split.(split(G.proj4,"zone=")[2]," ")[1]); # retrieve UTM zone
data_GMT = UTMData(Lon, Lat, Depth, zone, NorthernHemisphere, data_field)
Expand Down

2 comments on commit e28d748

@boriskaus
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/101638

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.9 -m "<description of version>" e28d748c5ad8e9bf71bc0f1d722ec6332c0fc97c
git push origin v0.5.9

Please sign in to comment.