Also: - Add test for reading uv from tile coords - Build with nix - Pin nix with npins - Remove .config tools manifest - Remove preview flag
51 lines
1.5 KiB
Forth
51 lines
1.5 KiB
Forth
module Oceanbox.FvcomKit.NorShelf
|
|
|
|
open System
|
|
open Serilog
|
|
open FSharpPlus
|
|
open Thredds
|
|
open ROMS
|
|
|
|
let private getNorshelfUrl (threddsUrl: string) (kind: Kind) (mode: Mode) (date: DateTime) =
|
|
let fmt (d: DateTime) =
|
|
$"{d.Year}%02d{d.Month}%02d{d.Day}T00Z.nc"
|
|
let url = threddsUrl + "/sea_norshelf_files"
|
|
|
|
$"{url}/{date.Year}/%02d{date.Month}/norshelf_{kind}_{mode}_{fmt date}"
|
|
|
|
let private getArchiveUrls urlf (t: DateTime) =
|
|
let t = t.ToUniversalTime ()
|
|
let now = DateTime.Now.ToUniversalTime ()
|
|
let dDay = (now.Date - t.Date).Days
|
|
|
|
if dDay < -3 then // no data available
|
|
[]
|
|
elif dDay <= 0 then // forecast, count down from latest
|
|
dateRange now -1 |> List.map (urlf Forecast)
|
|
elif dDay > 1 then // use analyzed
|
|
[ urlf Analyzed t ]
|
|
else // limbo land
|
|
[ urlf Analyzed t; urlf Forecast (t.AddDays -1) ]
|
|
|
|
let tryGetArchive threddsUrl avg (t: DateTime) =
|
|
let kind = if avg then Avg else Qck
|
|
|
|
getArchiveUrls (getNorshelfUrl threddsUrl kind) t
|
|
|> tryOpenThredds
|
|
|> Option.bind (fun (fname, ds) -> tryGetTimeIndex ds t |> Option.map (fun idx -> (fname, ds, idx)))
|
|
|
|
let readArchive file reader =
|
|
tryOpenArchive file
|
|
|> Option.bind (fun nc ->
|
|
try
|
|
let data = reader nc
|
|
Log.Information $"Read NorShelf data from {file}"
|
|
Some data
|
|
with e ->
|
|
Log.Error e.Message
|
|
None)
|
|
|
|
let readRomsGrid fname = readArchive fname readGrid
|
|
|
|
let readRomsProps fname idx =
|
|
readArchive fname ((flip readProps) idx) |