diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
new file mode 100644
index 0000000..f3b528f
--- /dev/null
+++ b/.github/workflows/release.yaml
@@ -0,0 +1,26 @@
+name: release
+
+on:
+ push:
+ tags:
+ - "v[0-9]+.[0-9]+.[0-9]+"
+
+jobs:
+ goreleaser:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v2
+ with:
+ fetch-depth: 1
+ - name: Set up Go
+ uses: actions/setup-go@v2
+ with:
+ go-version: 1.18
+ # - name: Run GoReleaser
+ # uses: goreleaser/goreleaser-action@v2
+ # with:
+ # version: latest
+ # args: release --rm-dist
+ # env:
+ # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
\ No newline at end of file
diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml
new file mode 100644
index 0000000..c80757e
--- /dev/null
+++ b/.github/workflows/test.yaml
@@ -0,0 +1,33 @@
+name: test
+on:
+ push:
+ branches:
+ - main
+ paths-ignore:
+ - 'README.md'
+ - '.github/**'
+ pull_request:
+ paths-ignore:
+ - 'README.md'
+jobs:
+ test:
+ strategy:
+ matrix:
+ go-version: [1.17.x, 1.18.x]
+ os: [ubuntu-latest]
+ runs-on: ${{ matrix.os }}
+ steps:
+ - name: Install Go
+ uses: actions/setup-go@v2
+ with:
+ go-version: ${{ matrix.go-version }}
+ - name: Checkout code
+ uses: actions/checkout@v2
+ - name: Build
+ run: go mod tidy && make build
+ - uses: dominikh/staticcheck-action@v1.2.0
+ name: staticcheck
+ with:
+ install-go: false
+ - name: Test
+ run: make test
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index d00ba2c..1b5c3e1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,6 +15,7 @@
# vendor/
.idea
+.vscode
tempdata/
.temp/
diff --git a/.goreleaser.yaml b/.goreleaser.yaml
new file mode 100644
index 0000000..1eb9203
--- /dev/null
+++ b/.goreleaser.yaml
@@ -0,0 +1,61 @@
+project_name: ordinary-kriging-cli
+
+env:
+ - GO111MODULE=on
+
+before:
+ hooks:
+ - go mod tidy
+
+builds:
+ - main: ./cmd/ordinary-kriging-cli
+ binary: ordinary-kriging-cli
+ mod_timestamp: '{{ .CommitTimestamp }}'
+ goos:
+ - linux
+ - darwin
+ - windows
+ ldflags:
+ - -s -w
+ - -X main.version={{.Version}}
+ - -X main.commit={{.ShortCommit}}
+ - -X main.date={{.Date}}
+
+archives:
+ - replacements:
+ darwin: darwin
+ linux: linux
+ windows: windows
+ amd64: x86_64
+ format_overrides:
+ - goos: windows
+ format: zip
+ files:
+ - LICENSE
+ - README.md
+
+release:
+ prerelease: auto
+ footer: |
+ **Full Changelog**: https://github.com/lvisei/go-kriging/compare/{{ .PreviousTag }}...{{ .Tag }}
+
+changelog:
+ sort: asc
+ use: github
+ filters:
+ exclude:
+ - '^docs:'
+ - '^test:'
+ - '^chore:'
+ - Merge pull request
+ - Merge remote-tracking branch
+ - Merge branch
+ groups:
+ - title: 'New Features'
+ regexp: "^.*feat:+.*$"
+ order: 0
+ - title: 'Bug fixes'
+ regexp: "^.*fix:+.*$"
+ order: 10
+ - title: Other
+ order: 999
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
index ee733a2..bef0369 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2020 liuvigongzuoshi
+Copyright (c) 2020 lvisei
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..4af3ba4
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,16 @@
+GOCMD=go
+GOBUILD=$(GOCMD) build
+GOCLEAN=$(GOCMD) clean
+GOTEST=$(GOCMD) test
+BINARY_NAME=ordinary-kriging-cli
+
+all: build test
+build:
+ $(GOBUILD) -o $(BINARY_NAME) -v ./cmd/$(BINARY_NAME)
+test:
+ $(GOTEST) -v ./...
+gentest: build
+ $(GOTEST) -v ./... -gen_golden_files
+clean:
+ $(GOCLEAN)
+ rm -f $(BINARY_NAME)
\ No newline at end of file
diff --git a/README.md b/README.md
index 3b4133d..ccc1868 100644
--- a/README.md
+++ b/README.md
@@ -1,13 +1,15 @@
# go-kriging
-[](https://pkg.go.dev/github.com/liuvigongzuoshi/go-kriging)
+[](https://pkg.go.dev/github.com/lvisei/go-kriging)
+[](https://goreportcard.com/report/github.com/lvisei/go-kriging)
+[](https://opensource.org/licenses/MIT)
Golang Multi-Goroutine spatial interpolation algorithm library for geospatial prediction and mapping via ordinary kriging.
-Based on @oeo4b's [kriging.js](https://github.com/oeo4b/kriging.js) refactoring and optimized the algorithm and added some new features.
+Based on @oeo4b's [kriging.js](https://github.com/oeo4b/kriging.js) refactoring and optimized the algorithm and added some new features.
-

+
This is exponential grid output png examples.
@@ -15,15 +17,14 @@ Based on @oeo4b's [kriging.js](https://github.com/oeo4b/kriging.js) refactoring
The train method with the new ordinaryKriging fits your input to whatever variogram model you specify - gaussian, exponential or spherical - and returns a variogram variable.
-
```go
-import "github.com/liuvigongzuoshi/go-kriging/ordinarykriging"
+import "github.com/lvisei/go-kriging/ordinarykriging"
func main() {
sigma2 := 0
alpha := 100
ordinaryKriging := ordinarykriging.NewOrdinary(values, x, y)
- variogram = ordinaryKriging.Train(ordinarykriging.Spherical, sigma2, alpha)
+ variogram = ordinaryKriging.Train(ordinarykriging.Spherical, sigma2, alpha)
}
```
@@ -32,7 +33,7 @@ func main() {
Values can be predicted for new coordinate pairs by using the predict method with the new ordinaryKriging.
```go
-import "github.com/liuvigongzuoshi/go-kriging/ordinarykriging"
+import "github.com/lvisei/go-kriging/ordinarykriging"
func main() {
// ...
@@ -47,9 +48,9 @@ func main() {
According to [sakitam-gis](https://sakitam-gis.github.io/kriging.js/examples/world.html), the various variogram models can be interpreted as kernel functions for 2-dimensional coordinates a, b and parameters nugget, range, sill and A. Reparameterized as a linear function, with w = [nugget, (sill-nugget)/range], this becomes:
-- Gaussian: k(a,b) = w[0] + w[1] * ( 1 - exp{ -( ||a-b|| / range )2 / A } )
-- Exponential: k(a,b) = w[0] + w[1] * ( 1 - exp{ -( ||a-b|| / range ) / A } )
-- Spherical: k(a,b) = w[0] + w[1] * ( 1.5 * ( ||a-b|| / range ) - 0.5 * ( ||a-b|| / range )3 )
+- Gaussian: k(a,b) = w[0] + w[1] \* ( 1 - exp{ -( ||a-b|| / range )2 / A } )
+- Exponential: k(a,b) = w[0] + w[1] \* ( 1 - exp{ -( ||a-b|| / range ) / A } )
+- Spherical: k(a,b) = w[0] + w[1] _ ( 1.5 _ ( ||a-b|| / range ) - 0.5 \* ( ||a-b|| / range )3 )
The variance parameter α of the prior distribution for w should be manually set, according to:
@@ -62,14 +63,12 @@ Using the fitted kernel function hyperparameters and setting K as the Gram matri
The variance parameter σ2 of the likelihood reflects the error in the gaussian process and should be manually set.
-
## Other
-[kriging-wasm example](https://github.com/liuvigongzuoshi/kriging-wasm) - Test example used by wasm compiled with go-kriging algorithm code.
-
-[go-kriging-service](https://github.com/liuvigongzuoshi/go-kriging-service) - Call the REST service written by the go-kriging algorithm package, which supports concurrent calls by multiple users, and has a simple logging and fault-tolerant recovery mechanism.
+[kriging-wasm example](https://github.com/lvisei/kriging-wasm) - Test example used by wasm compiled with go-kriging algorithm code.
+[go-kriging-service](https://github.com/lvisei/go-kriging-service) - Call the REST service written by the go-kriging algorithm package, which supports concurrent calls by multiple users, and has a simple logging and fault-tolerant recovery mechanism.
## License
-This package implement @oeo4b's kriging.js, a JavaScript library that is also [MIT-licensed](https://en.wikipedia.org/wiki/MIT_License).
\ No newline at end of file
+This package implement @oeo4b's kriging.js, a JavaScript library that is also [MIT-licensed](https://en.wikipedia.org/wiki/MIT_License).
diff --git a/canvas/canvas.go b/canvas/canvas.go
index 72a2099..d782ac9 100644
--- a/canvas/canvas.go
+++ b/canvas/canvas.go
@@ -52,7 +52,7 @@ func NewCanvasWithImage(background image.Image) *Canvas {
return canvas
}
-// NewCanvasWithLocal 从本地图片创建新的画布
+// NewCanvasWithLocalImagePath 从本地图片创建新的画布
func NewCanvasWithLocalImagePath(imagePath string) (*Canvas, error) {
img, err := LoadLocalImage(imagePath)
if err != nil {
@@ -129,7 +129,7 @@ func (canvas *Canvas) Output() ([]byte, error) {
return buffer.Bytes(), nil
}
-// SavePNG
+// SavePNG 保存 PNG 图片
func (canvas *Canvas) SavePNG(path string) error {
if err := canvas.context.SavePNG(path); err != nil {
return err
diff --git a/cmd/ordinary-kriging-cli/main.go b/cmd/ordinary-kriging-cli/main.go
index 37a932e..55981a7 100644
--- a/cmd/ordinary-kriging-cli/main.go
+++ b/cmd/ordinary-kriging-cli/main.go
@@ -7,6 +7,15 @@ import (
"github.com/spf13/cobra"
)
+var (
+ // these are set in build step
+ version = "unversioned"
+ //lint:ignore U1000 embedded by goreleaser
+ commit = "?"
+ //lint:ignore U1000 embedded by goreleaser
+ date = "?"
+)
+
func main() {
execute()
@@ -16,9 +25,9 @@ var cmd = &cobra.Command{
Use: "go-kriging",
Short: "geospatial prediction and mapping via ordinary kriging",
Long: `Golang library for geospatial prediction and mapping via ordinary kriging.
- Complete documentation is available at https://github.com/liuvigongzuoshi/go-kriging`,
+ Complete documentation is available at https://github.com/lvisei/go-kriging`,
Run: func(cmd *cobra.Command, args []string) {
- fmt.Println("Go Kriging Version: v0.1.0")
+ fmt.Printf("Go Kriging Version: v%s \n", version)
// TODO:
},
}
diff --git a/examples/csv/main.go b/examples/csv/main.go
index fd72eeb..eb0df3e 100644
--- a/examples/csv/main.go
+++ b/examples/csv/main.go
@@ -13,9 +13,9 @@ import (
"strconv"
"time"
- "github.com/liuvigongzuoshi/go-kriging/canvas"
- "github.com/liuvigongzuoshi/go-kriging/ordinarykriging"
- "github.com/liuvigongzuoshi/go-kriging/pkg/json"
+ "github.com/lvisei/go-kriging/canvas"
+ "github.com/lvisei/go-kriging/ordinarykriging"
+ "github.com/lvisei/go-kriging/pkg/json"
)
const testDataDirPath = "testdata"
@@ -33,9 +33,9 @@ func main() {
// log.Fatal(err)
//}
//defer func() {
- //pprof.StopCPUProfile()
- //cpuProfile.Close()
- //memProfile.Close()
+ //pprof.StopCPUProfile()
+ //cpuProfile.Close()
+ //memProfile.Close()
//}()
data, err := readCsvFile("examples/csv/testdata/2045.csv")
diff --git a/examples/tinygo/main.go b/examples/tinygo/main.go
index e978b28..448cef7 100644
--- a/examples/tinygo/main.go
+++ b/examples/tinygo/main.go
@@ -1,8 +1,9 @@
package main
import (
- "github.com/liuvigongzuoshi/go-kriging/ordinarykriging"
"log"
+
+ "github.com/lvisei/go-kriging/ordinarykriging"
)
// tinygo build -o kriging.wasm -opt z -heap-size 2048M -target wasm ./main.go
diff --git a/examples/wasm/main.go b/examples/wasm/main.go
index 658909d..fed7b14 100644
--- a/examples/wasm/main.go
+++ b/examples/wasm/main.go
@@ -1,3 +1,6 @@
+//go:build js
+// +build js
+
package main
import (
@@ -7,7 +10,7 @@ import (
"syscall/js"
- "github.com/liuvigongzuoshi/go-kriging/ordinarykriging"
+ "github.com/lvisei/go-kriging/ordinarykriging"
)
// GOOS=js GOARCH=wasm go build -o kriging.wasm
diff --git a/go.mod b/go.mod
index 1041da5..41f36fa 100644
--- a/go.mod
+++ b/go.mod
@@ -1,4 +1,4 @@
-module github.com/liuvigongzuoshi/go-kriging
+module github.com/lvisei/go-kriging
go 1.15
diff --git a/ordinarykriging/example_test.go b/ordinarykriging/example_test.go
index 8616d70..460d6c2 100644
--- a/ordinarykriging/example_test.go
+++ b/ordinarykriging/example_test.go
@@ -3,7 +3,7 @@ package ordinarykriging_test
import (
"fmt"
- "github.com/liuvigongzuoshi/go-kriging/ordinarykriging"
+ "github.com/lvisei/go-kriging/ordinarykriging"
)
var (
diff --git a/ordinarykriging/matrix-inverse.go b/ordinarykriging/matrix-inverse.go
index 0c5dd01..d8e4973 100644
--- a/ordinarykriging/matrix-inverse.go
+++ b/ordinarykriging/matrix-inverse.go
@@ -1,8 +1,9 @@
package ordinarykriging
import (
- "gonum.org/v1/gonum/mat"
"math"
+
+ "gonum.org/v1/gonum/mat"
)
// gaussJordanInversion inversion via gauss-jordan elimination
@@ -123,7 +124,7 @@ func matrixInverseByCol(a [][]float64) ([][]float64, bool) {
var maxAbs = func(a []float64) (float64, int, bool) {
var sol float64
var ii int
- var err bool = false
+ var err = false
n := len(a)
ii = 0
@@ -150,6 +151,7 @@ func matrixInverseByCol(a [][]float64) ([][]float64, bool) {
return nil, false
}
+ //lint:ignore SA4006 for temp
temp1 := make([]float64, n)
//主元消去
diff --git a/ordinarykriging/ordinarykriging.go b/ordinarykriging/ordinarykriging.go
index 7a904d8..0f47147 100644
--- a/ordinarykriging/ordinarykriging.go
+++ b/ordinarykriging/ordinarykriging.go
@@ -6,12 +6,13 @@ package ordinarykriging
import (
"errors"
- "github.com/liuvigongzuoshi/go-kriging/canvas"
"image"
"image/color"
"math"
"sort"
"sync"
+
+ "github.com/lvisei/go-kriging/canvas"
)
// Variogram ordinary kriging variogram
@@ -73,21 +74,17 @@ func (variogram *Variogram) Train(model ModelType, sigma2 float64, alpha float64
switch model {
case Gaussian:
variogram.model = krigingVariogramGaussian
- break
case Exponential:
variogram.model = krigingVariogramExponential
- break
case Spherical:
variogram.model = krigingVariogramSpherical
- break
}
// Lag distance/semivariance
var i, j, k, l, n int
n = len(variogram.t)
- var distance DistanceList
- distance = make([][2]float64, (n*n-n)/2)
+ var distance DistanceList = make([][2]float64, (n*n-n)/2)
i = 0
k = 0
@@ -165,13 +162,10 @@ func (variogram *Variogram) Train(model ModelType, sigma2 float64, alpha float64
switch model {
case Gaussian:
X[i*2+1] = 1.0 - exp(-(1.0/A)*pow2(lag[i]/variogram.Range))
- break
case Exponential:
X[i*2+1] = 1.0 - exp(-(1.0/A)*lag[i]/variogram.Range)
- break
case Spherical:
X[i*2+1] = 1.5*(lag[i]/variogram.Range) - 0.5*pow3(lag[i]/variogram.Range)
- break
}
Y[i] = semi[i]
}
@@ -516,7 +510,7 @@ func (variogram *Variogram) Plot(gridMatrices *GridMatrices, width, height int,
return ctx
}
-// PlotRectangleGrid
+// PlotRectangleGrid plot to canvas
// 绘制矩形网格到数据 canvas 上
func (variogram *Variogram) PlotRectangleGrid(contourRectangle *ContourRectangle, width, height int, xlim, ylim [2]float64, colors []color.Color) *canvas.Canvas {
// Create canvas
@@ -550,7 +544,7 @@ func (variogram *Variogram) PlotRectangleGrid(contourRectangle *ContourRectangle
return ctx
}
-// PlotPng
+// PlotPng plot to png
func (variogram *Variogram) PlotPng(rectangleGrids *ContourRectangle) *image.RGBA {
contour := rectangleGrids.Contour
xWidth := rectangleGrids.XWidth
diff --git a/ordinarykriging/ordinarykriging_test.go b/ordinarykriging/ordinarykriging_test.go
index 3358023..f74c2fb 100644
--- a/ordinarykriging/ordinarykriging_test.go
+++ b/ordinarykriging/ordinarykriging_test.go
@@ -9,7 +9,7 @@ import (
"testing"
"time"
- "github.com/liuvigongzuoshi/go-kriging/ordinarykriging"
+ "github.com/lvisei/go-kriging/ordinarykriging"
)
const pngDirPath = "tempdata"
diff --git a/staticcheck.conf b/staticcheck.conf
new file mode 100644
index 0000000..990a025
--- /dev/null
+++ b/staticcheck.conf
@@ -0,0 +1 @@
+checks = ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-U1000"]
\ No newline at end of file