Skip to content

Commit

Permalink
fix: grid no data value
Browse files Browse the repository at this point in the history
  • Loading branch information
lvisei committed Dec 22, 2020
1 parent 6c4d755 commit 5adb5ea
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
18 changes: 8 additions & 10 deletions examples/csv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"strconv"
"time"

"runtime/pprof"

"github.com/liuvigongzuoshi/go-kriging/canvas"
"github.com/liuvigongzuoshi/go-kriging/ordinarykriging"
"github.com/liuvigongzuoshi/go-kriging/pkg/json"
Expand All @@ -26,19 +24,19 @@ const cpuProfileFilePath = tempDataDirPath + "/cpu_profile"
const memProfileFilePath = tempDataDirPath + "/mem_profile"

func main() {
cpuProfile, _ := os.Create(cpuProfileFilePath)
if err := pprof.StartCPUProfile(cpuProfile); err != nil {
log.Fatal(err)
}
//cpuProfile, _ := os.Create(cpuProfileFilePath)
//if err := pprof.StartCPUProfile(cpuProfile); err != nil {
// log.Fatal(err)
//}
//memProfile, _ := os.Create(memProfileFilePath)
//if err := pprof.WriteHeapProfile(memProfile); err != nil {
// log.Fatal(err)
//}
defer func() {
pprof.StopCPUProfile()
cpuProfile.Close()
//defer func() {
//pprof.StopCPUProfile()
//cpuProfile.Close()
//memProfile.Close()
}()
//}()

data, err := readCsvFile("examples/csv/testdata/2045.csv")
if err != nil {
Expand Down
15 changes: 10 additions & 5 deletions ordinarykriging/ordinarykriging.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ func (variogram *Variogram) Grid(polygon PolygonCoordinates, width float64) *Gri
return &GridMatrices{}
}

var nodataValue float64 = -9999

// Boundaries of polygon space
xlim := [2]float64{polygon[0][0][0], polygon[0][0][0]}
ylim := [2]float64{polygon[0][0][1], polygon[0][0][1]}
Expand Down Expand Up @@ -349,6 +351,8 @@ func (variogram *Variogram) Grid(polygon PolygonCoordinates, width float64) *Gri
if pipFloat64(currentPolygon, xTarget, yTarget) {
wg.Add(1)
go parallelPredict(j, k, currentPolygon, xTarget, yTarget)
} else {
A[j][k] = nodataValue
}
//if pipFloat64(currentPolygon, xTarget, yTarget) {
// A[j][k] = variogram.Predict(xTarget,
Expand All @@ -374,11 +378,12 @@ func (variogram *Variogram) Grid(polygon PolygonCoordinates, width float64) *Gri
}

gridMatrices := &GridMatrices{
Xlim: xlim,
Ylim: ylim,
Zlim: [2]float64{minFloat64(variogram.t), maxFloat64(variogram.t)},
Width: width,
Data: A,
Xlim: xlim,
Ylim: ylim,
Zlim: [2]float64{minFloat64(variogram.t), maxFloat64(variogram.t)},
Width: width,
Data: A,
NodataValue: nodataValue,
}
return gridMatrices
}
Expand Down
11 changes: 6 additions & 5 deletions ordinarykriging/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ func (t DistanceList) Swap(i, j int) {
}

type GridMatrices struct {
Data [][]float64 `json:"data"`
Width float64 `json:"width"`
Xlim [2]float64 `json:"xLim"`
Ylim [2]float64 `json:"yLim"`
Zlim [2]float64 `json:"zLim"`
Data [][]float64 `json:"data"`
Width float64 `json:"width"`
Xlim [2]float64 `json:"xLim"`
Ylim [2]float64 `json:"yLim"`
Zlim [2]float64 `json:"zLim"`
NodataValue float64 `json:"nodataValue"`
}

type ContourRectangle struct {
Expand Down

0 comments on commit 5adb5ea

Please sign in to comment.