Skip to content

Commit

Permalink
ci: add test&releaser action (#1)
Browse files Browse the repository at this point in the history
* ci: test&releaser action
  • Loading branch information
lvisei authored May 8, 2022
1 parent 0463f47 commit 6891b57
Show file tree
Hide file tree
Showing 18 changed files with 190 additions and 44 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
33 changes: 33 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
name: staticcheck
with:
install-go: false
- name: Test
run: make test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# vendor/

.idea
.vscode

tempdata/
.temp/
Expand Down
61 changes: 61 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)
29 changes: 14 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
# go-kriging

[![GoDoc](https://godoc.org/github.com/liuvigongzuoshi/go-kriging?status.svg)](https://pkg.go.dev/github.com/liuvigongzuoshi/go-kriging)
[![GoDoc](https://godoc.org/github.com/lvisei/go-kriging?status.svg)](https://pkg.go.dev/github.com/lvisei/go-kriging)
[![Go Report Card](https://goreportcard.com/badge/github.com/lvisei/go-kriging)](https://goreportcard.com/report/github.com/lvisei/go-kriging)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](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.

<div align="center">
<img src="https://raw.githubusercontent.com/liuvigongzuoshi/go-kriging/main/docs/grid-exponential.png" width="600">
<img src="https://raw.githubusercontent.com/lvisei/go-kriging/main/docs/grid-exponential.png" width="600">
<p>This is exponential grid output png examples.</p>
</div>

## Fitting a Model

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)
}
```

Expand All @@ -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() {
// ...
Expand All @@ -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:

Expand All @@ -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).
This package implement @oeo4b's kriging.js, a JavaScript library that is also [MIT-licensed](https://en.wikipedia.org/wiki/MIT_License).
4 changes: 2 additions & 2 deletions canvas/canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions cmd/ordinary-kriging-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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:
},
}
Expand Down
12 changes: 6 additions & 6 deletions examples/csv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion examples/tinygo/main.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 4 additions & 1 deletion examples/wasm/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build js
// +build js

package main

import (
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/liuvigongzuoshi/go-kriging
module github.com/lvisei/go-kriging

go 1.15

Expand Down
2 changes: 1 addition & 1 deletion ordinarykriging/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ordinarykriging_test
import (
"fmt"

"github.com/liuvigongzuoshi/go-kriging/ordinarykriging"
"github.com/lvisei/go-kriging/ordinarykriging"
)

var (
Expand Down
6 changes: 4 additions & 2 deletions ordinarykriging/matrix-inverse.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package ordinarykriging

import (
"gonum.org/v1/gonum/mat"
"math"

"gonum.org/v1/gonum/mat"
)

// gaussJordanInversion inversion via gauss-jordan elimination
Expand Down Expand Up @@ -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
Expand All @@ -150,6 +151,7 @@ func matrixInverseByCol(a [][]float64) ([][]float64, bool) {
return nil, false
}

//lint:ignore SA4006 for temp
temp1 := make([]float64, n)

//主元消去
Expand Down
Loading

0 comments on commit 6891b57

Please sign in to comment.