Skip to content

Commit

Permalink
Add INMET.on (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm authored Sep 25, 2024
1 parent 33b8231 commit 9fb7f50
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "1.1.3"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
CoordRefSystems = "b46f11dc-f210-4604-bfba-323c1ec968cb"
Countries = "5bf49175-83fb-4b6d-82b5-d6ded85154ae"
DataDeps = "124859b0-ceae-595e-8997-d05f6a7a8dfe"
GeoIO = "f5a160d5-e41d-4189-8b61-d57781c419e3"
Expand All @@ -17,6 +18,7 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[compat]
CSV = "0.10"
CoordRefSystems = "0.14"
Countries = "0.3"
DataDeps = "0.7"
GeoIO = "1.16"
Expand Down
28 changes: 17 additions & 11 deletions src/inmet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
Provides functions to load data from the INMET API.
Please check their docstrings for more details:
- `INMET.stations`
* [`INMET.stations`](@ref)
* [`INMET.on`](@ref)
"""
module INMET

using Meshes
using Unitful
using GeoTables
using CoordRefSystems

import INMET as INMETData

Expand All @@ -23,16 +25,20 @@ Return INMET stations of given kind. There are two kinds of stations: `:automati
"""
function stations(kind=:automatic)
df = INMETData.stations(kind)
names = propertynames(df)
cnames = [:VL_LONGITUDE, :VL_LATITUDE, :VL_ALTITUDE]
fnames = setdiff(names, cnames)
feats = df[:, fnames]
coords = ustrip.(df[:, cnames])
points = map(eachrow(coords)) do row
x, y, z = row
Point(x, y, z)
end
georef(feats, PointSet(points))
georef(df, (:VL_LATITUDE, :VL_LONGITUDE, :VL_ALTITUDE), crs=LatLonAlt)
end

"""
on(time)
Return data for all automatic stations on a given `time`.
The time can be a `Date` or a `DateTime` object. In the
latter case, minutes and seconds are ignored while the
hour information is retained (data in hourly frequency).
"""
function on(time)
df = INMETData.on(time)
georef(df, (:VL_LATITUDE, :VL_LONGITUDE), crs=LatLon)
end

end

0 comments on commit 9fb7f50

Please sign in to comment.