fix: fix xgrid projection and stuff

This commit is contained in:
2025-03-07 09:27:15 +01:00
parent 4fec8d12c0
commit ad74f0246b
8 changed files with 56 additions and 111 deletions

View File

@@ -1,78 +0,0 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2005
MinimumVisualStudioVersion = 15.0.26124.0
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C3B6A214-CE4D-4ED1-9DCA-C689AA48ECF5}"
ProjectSection(SolutionItems) = preProject
README.md = README.md
LICENSE = LICENSE
Dockerfile = Dockerfile
.gitlab-ci.yml = .gitlab-ci.yml
EndProjectSection
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Build", "Build.fsproj", "{CBD855E6-8E30-4B99-B715-845F9CB5BA7F}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "src", "src/Excavator.fsproj", "{5599F868-EC40-4BEE-8295-7A2A41BEF741}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "test", "test\Tests.fsproj", "{0184583E-99DB-473B-BBCD-C07A1AC4FF65}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CBD855E6-8E30-4B99-B715-845F9CB5BA7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CBD855E6-8E30-4B99-B715-845F9CB5BA7F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CBD855E6-8E30-4B99-B715-845F9CB5BA7F}.Debug|x64.ActiveCfg = Debug|Any CPU
{CBD855E6-8E30-4B99-B715-845F9CB5BA7F}.Debug|x64.Build.0 = Debug|Any CPU
{CBD855E6-8E30-4B99-B715-845F9CB5BA7F}.Debug|x86.ActiveCfg = Debug|Any CPU
{CBD855E6-8E30-4B99-B715-845F9CB5BA7F}.Debug|x86.Build.0 = Debug|Any CPU
{CBD855E6-8E30-4B99-B715-845F9CB5BA7F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CBD855E6-8E30-4B99-B715-845F9CB5BA7F}.Release|Any CPU.Build.0 = Release|Any CPU
{CBD855E6-8E30-4B99-B715-845F9CB5BA7F}.Release|x64.ActiveCfg = Release|Any CPU
{CBD855E6-8E30-4B99-B715-845F9CB5BA7F}.Release|x64.Build.0 = Release|Any CPU
{CBD855E6-8E30-4B99-B715-845F9CB5BA7F}.Release|x86.ActiveCfg = Release|Any CPU
{CBD855E6-8E30-4B99-B715-845F9CB5BA7F}.Release|x86.Build.0 = Release|Any CPU
{5599F868-EC40-4BEE-8295-7A2A41BEF741}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5599F868-EC40-4BEE-8295-7A2A41BEF741}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5599F868-EC40-4BEE-8295-7A2A41BEF741}.Debug|x64.ActiveCfg = Debug|Any CPU
{5599F868-EC40-4BEE-8295-7A2A41BEF741}.Debug|x64.Build.0 = Debug|Any CPU
{5599F868-EC40-4BEE-8295-7A2A41BEF741}.Debug|x86.ActiveCfg = Debug|Any CPU
{5599F868-EC40-4BEE-8295-7A2A41BEF741}.Debug|x86.Build.0 = Debug|Any CPU
{5599F868-EC40-4BEE-8295-7A2A41BEF741}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5599F868-EC40-4BEE-8295-7A2A41BEF741}.Release|Any CPU.Build.0 = Release|Any CPU
{5599F868-EC40-4BEE-8295-7A2A41BEF741}.Release|x64.ActiveCfg = Release|Any CPU
{5599F868-EC40-4BEE-8295-7A2A41BEF741}.Release|x64.Build.0 = Release|Any CPU
{5599F868-EC40-4BEE-8295-7A2A41BEF741}.Release|x86.ActiveCfg = Release|Any CPU
{5599F868-EC40-4BEE-8295-7A2A41BEF741}.Release|x86.Build.0 = Release|Any CPU
{0184583E-99DB-473B-BBCD-C07A1AC4FF65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0184583E-99DB-473B-BBCD-C07A1AC4FF65}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0184583E-99DB-473B-BBCD-C07A1AC4FF65}.Debug|x64.ActiveCfg = Debug|Any CPU
{0184583E-99DB-473B-BBCD-C07A1AC4FF65}.Debug|x64.Build.0 = Debug|Any CPU
{0184583E-99DB-473B-BBCD-C07A1AC4FF65}.Debug|x86.ActiveCfg = Debug|Any CPU
{0184583E-99DB-473B-BBCD-C07A1AC4FF65}.Debug|x86.Build.0 = Debug|Any CPU
{0184583E-99DB-473B-BBCD-C07A1AC4FF65}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0184583E-99DB-473B-BBCD-C07A1AC4FF65}.Release|Any CPU.Build.0 = Release|Any CPU
{0184583E-99DB-473B-BBCD-C07A1AC4FF65}.Release|x64.ActiveCfg = Release|Any CPU
{0184583E-99DB-473B-BBCD-C07A1AC4FF65}.Release|x64.Build.0 = Release|Any CPU
{0184583E-99DB-473B-BBCD-C07A1AC4FF65}.Release|x86.ActiveCfg = Release|Any CPU
{0184583E-99DB-473B-BBCD-C07A1AC4FF65}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {03BBFC03-A554-4604-A4F9-E9C1275410E2}
EndGlobalSection
EndGlobal

16
Excavator.slnx Normal file
View File

@@ -0,0 +1,16 @@
<Solution>
<Configurations>
<Platform Name="Any CPU" />
<Platform Name="x64" />
<Platform Name="x86" />
</Configurations>
<Folder Name="/Solution Items/">
<File Path=".gitlab-ci.yml" />
<File Path="Dockerfile" />
<File Path="LICENSE" />
<File Path="README.md" />
</Folder>
<Project Path="Build.fsproj" />
<Project Path="src/Excavator.fsproj" />
<Project Path="test/Tests.fsproj" />
</Solution>

View File

@@ -19,7 +19,7 @@
<PackageReference Include="FSharp.Data" Version="6.4.1" />
<PackageReference Include="FSharpPlus" Version="1.7.0" />
<PackageReference Include="MessagePack" Version="3.1.3" />
<PackageReference Include="Oceanbox.FvcomKit" Version="5.7.0" />
<PackageReference Include="Oceanbox.FvcomKit" Version="5.12.0" />
<PackageReference Include="sdslite-o" Version="2.7.2" />
<PackageReference Include="Serilog" Version="4.2.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />

View File

@@ -7,6 +7,7 @@ open Oceanbox.FvcomKit
open KdTree
open MessagePack
open Serilog
open Serilog.Events
let utm2ll = makeTransform Settings.projection CoordSys.WGS84
let ll2utm = makeTransform CoordSys.WGS84 Settings.projection
@@ -301,12 +302,23 @@ type BinGrid = {
[<Key(2)>] cells : (int * int * int)[]
}
let extractGrid (ncfile: string) outfile =
let private toLonLat proj (g: Fvcom.FvcomGrid) =
Transformations.stringToTransformation proj
|> Option.defaultWith (fun () ->
failwith $"toLonLat: failed to get projecton coordsys for {proj}")
|> fun coordsys -> Grid.toLonLat coordsys { Nodes = g.Nodes; Elem = g.Elem; BBox = g.BBox }
let extractGrid (proj: string) (ncfile: string) outfile =
Log.Information("Extracting grid from {nc}", ncfile)
try
let ds =
NetCDFDataSet.Open (ncfile, openMode = Microsoft.Research.Science.Data.ResourceOpenMode.ReadOnly)
let g = Fvcom.getGridLonLat ds
let g: Grid.Grid =
if proj = "WGS84" then
Fvcom.getGridLonLat ds
|> fun g -> { Nodes = g.Nodes; Elem = g.Elem; BBox = g.BBox }
else
Fvcom.getGrid ds |> toLonLat proj
let bg : BinGrid = {
hash = [||]
vertices = g.Nodes
@@ -320,5 +332,9 @@ let extractGrid (ncfile: string) outfile =
let bytes' = MessagePackSerializer.Serialize(bg')
Log.Debug $"Writing binary grid to {outfile}"
IO.File.WriteAllBytes(outfile, bytes')
if Log.IsEnabled(LogEventLevel.Debug) then
let bg'' = MessagePackSerializer.Deserialize<BinGrid>(bytes')
printfn $"%A{bg''.vertices}"
printfn $"%A{bg''.hash |> Convert.ToHexStringLower}"
with exn ->
Log.Error $"{exn}"

View File

@@ -9,19 +9,17 @@ open FileList
open Grid
open NetCDF
open Stats
open ProjNet.FSharp
open Oceanbox.FvcomKit
open Settings
let configureSerilog level =
let n =
match level with
| 0 -> LogEventLevel.Error
| 1 -> LogEventLevel.Warning
| 0 -> LogEventLevel.Verbose
| 1 -> LogEventLevel.Debug
| 2 -> LogEventLevel.Information
| 3 -> LogEventLevel.Debug
| _ -> LogEventLevel.Verbose
| 3 -> LogEventLevel.Warning
| _ -> LogEventLevel.Error
LoggerConfiguration()
.MinimumLevel.Is(n)
.WriteTo.Console(standardErrorFromLevel = LogEventLevel.Verbose)
@@ -153,7 +151,7 @@ type GridFormat =
| MsgPack
type ExtractArgs =
| Out of string: string
| [<AltCommandLine("-o")>] Out of string: string
| Proj of string: string
// | Format of fmt: GridFormat
| [<MainCommand; ExactlyOnce; Last>] NcFile of file: string
@@ -161,11 +159,12 @@ type ExtractArgs =
member this.Usage =
match this with
| Out _ -> "Output file"
| Proj _ -> "Output projection"
| Proj _ -> "Input grid projection"
// | Format _ -> "Output format (plain or msgpack)"
| NcFile _ -> "NetCDF input"
type Arguments =
| Log_level of int
| [<CliPrefix(CliPrefix.None)>] ST of ParseResults<StationsArgs>
| [<CliPrefix(CliPrefix.None)>] A of ParseResults<AreaArgs>
| [<CliPrefix(CliPrefix.None)>] R of ParseResults<RadiusArgs>
@@ -176,6 +175,7 @@ type Arguments =
interface IArgParserTemplate with
member this.Usage =
match this with
| Log_level _ -> "Log level (0 = Verbose, 4 = Error)"
| ST _ -> "Export stations to nc"
| A _ -> "Export area to nc"
| R _ -> "Export area inside radius to nc"
@@ -190,7 +190,8 @@ let main argv =
let parser =
ArgumentParser.Create<Arguments> (programName = "Excavator", errorHandler = errorHandler)
let args = parser.Parse argv
Log.Logger <- configureSerilog 3
let loglevel = args.GetResult(Arguments.Log_level, 2)
Log.Logger <- configureSerilog loglevel
if args.Contains ST then
let aArgs = args.GetResult ST
@@ -370,6 +371,6 @@ let main argv =
let out = args'.GetResult(ExtractArgs.Out, defaultValue="grid.bin")
let proj = args'.GetResult(ExtractArgs.Proj, defaultValue="WGS84")
// let fmt = args'.GetResult(ExtractArgs.Format, defaultValue=GridFormat.MsgPack)
Excavator.Grid.extractGrid ncfile out
extractGrid proj ncfile out
0

View File

@@ -1,7 +1,6 @@
module Settings
open System.IO
open Thoth.Json.Net
open Serilog
type Settings = { Setting: string }
@@ -13,13 +12,6 @@ let tryGetEnv =
| "" -> None
| x -> Some x
let readAppsettings () =
let settings = System.IO.File.ReadAllText "appsettings.json"
match Decode.Auto.fromString<Settings> settings with
| Ok s -> s
| Error e -> failwith e
let mutable projection = CoordSys.UTMn 33
// let appsettings = readAppsettings ()

View File

@@ -1,3 +0,0 @@
{
"Setting" : "example setting"
}

View File

@@ -14,7 +14,7 @@
},
"FSharp.Core": {
"type": "Direct",
"requested": "[9.0.200, )",
"requested": "[9.0.201, )",
"resolved": "9.0.201",
"contentHash": "Ozq4T0ISTkqTYJ035XW/JkdDDaXofbykvfyVwkjLSqaDZ/4uNXfpf92cjcMI9lf9CxWqmlWHScViPh/4AvnWcw=="
},
@@ -56,21 +56,22 @@
},
"Oceanbox.FvcomKit": {
"type": "Direct",
"requested": "[5.7.0, )",
"resolved": "5.7.0",
"contentHash": "mHtxBOj5WAymHmILwhkCu6gdHhSx0DccQGoNiDQFnkfuicai2UHVwRdkSlMQmlgr2kR1Ikprb4aNuWJn9oQtkg==",
"requested": "[5.12.0, )",
"resolved": "5.12.0",
"contentHash": "78qkFpO2819Ddg6hYqRKXwCj2/ZBqrNKJ3536Q9R+4lx7dfMox97VPcpHviPRb/NsFG1M60TaYpm2DxuZclPaA==",
"dependencies": {
"FSharp.Core": "9.0.100",
"FSharp.Data": "6.4.0",
"FSharpPlus": "1.6.1",
"FSharp.Core": "9.0.201",
"FSharp.Data": "6.4.1",
"FSharpPlus": "1.7.0",
"FsPickler": "5.3.2",
"KDTree": "1.4.1",
"MathNet.Numerics.FSharp": "5.0.0",
"MessagePack": "3.1.3",
"ProjNet.FSharp": "5.2.0",
"SDSlite.Oceanbox": "2.7.3",
"Serilog": "4.1.0",
"Serilog": "4.2.0",
"Serilog.Sinks.Console": "6.0.0",
"Serilog.Sinks.Seq": "8.0.0",
"Serilog.Sinks.Seq": "9.0.0",
"Thoth.Json.Net": "12.0.0"
}
},