Skip to content

Commit

Permalink
added support for wps pixel fractions (#347)
Browse files Browse the repository at this point in the history
  • Loading branch information
edisonguo authored Sep 27, 2019
1 parent b7cb193 commit f7acc3a
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 61 deletions.
4 changes: 2 additions & 2 deletions processor/drill_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewDrillGRPC(ctx context.Context, serverAddress []string, errChan chan erro
}
}

func (gi *GeoDrillGRPC) Run(bandStrides int, decileCount int, verbose bool) {
func (gi *GeoDrillGRPC) Run(bandStrides int, decileCount int, pixelCount int, verbose bool) {
defer close(gi.Out)
start := time.Now()

Expand Down Expand Up @@ -141,7 +141,7 @@ func (gi *GeoDrillGRPC) Run(bandStrides int, decileCount int, verbose bool) {
c := pb.NewGDALClient(conns[(iTile+workerStart)%len(conns)])
bands, err := getBands(g.TimeStamps)

granule := &pb.GeoRPCGranule{Operation: "drill", Path: g.Path, Geometry: g.Geometry, Bands: bands, BandStrides: int32(bandStrides), DrillDecileCount: int32(decileCount), ClipUpper: gran.ClipUpper, ClipLower: gran.ClipLower}
granule := &pb.GeoRPCGranule{Operation: "drill", Path: g.Path, Geometry: g.Geometry, Bands: bands, BandStrides: int32(bandStrides), DrillDecileCount: int32(decileCount), ClipUpper: gran.ClipUpper, ClipLower: gran.ClipLower, PixelCount: int32(pixelCount)}
r, err := c.Process(gi.Context, granule)
if err != nil {
gi.Error <- err
Expand Down
7 changes: 6 additions & 1 deletion processor/drill_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func InitDrillPipeline(ctx context.Context, apiAddr string, rpcAddrs []string, i
func (dp *DrillPipeline) Process(geoReq GeoDrillRequest, suffix string, templateFileName string, bandStrides int, approx bool, drillAlgorithm string, verbose bool) chan string {
const DefaultDecileAnchorPoints = 9
decileCount := 0
pixelCount := 0
if len(drillAlgorithm) > 0 {
drillAlgos := strings.Split(drillAlgorithm, ",")
for _, algo := range drillAlgos {
Expand All @@ -42,6 +43,10 @@ func (dp *DrillPipeline) Process(geoReq GeoDrillRequest, suffix string, template
if algo == "deciles" {
decileCount = DefaultDecileAnchorPoints
}

if algo == "pixel_count" {
pixelCount = 1
}
}

}
Expand All @@ -62,7 +67,7 @@ func (dp *DrillPipeline) Process(geoReq GeoDrillRequest, suffix string, template
dm.In = grpcDriller.Out

go i.Run(verbose)
go grpcDriller.Run(bandStrides, decileCount, verbose)
go grpcDriller.Run(bandStrides, decileCount, pixelCount, verbose)

nCols := decileCount + 1
var namespaces []string
Expand Down
10 changes: 10 additions & 0 deletions templates/WPS_Outputs/geometryDrill/geoglam_pixel_fraction.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<wps:Output>
<ows:Identifier>veg_cover</ows:Identifier>
<ows:Title>Vegetation Cover</ows:Title>
<ows:Abstract>Time series data for Geoglam Fractional Cover.</ows:Abstract>
<wps:Data>
<wps:ComplexData mimeType="application/vnd.terriajs.catalog-member+json" schema="https://tools.ietf.org/html/rfc7159">
<![CDATA[{ "data": "date,pixel_frac\n{{ . }}", "isEnabled": true, "type": "csv", "name": "%s", "tableStyle": { "columns": { "pixel_frac": { "units": "%%", "chartLineColor": "#FFFFFF", "yAxisMin": 0, "yAxisMax": 1, "active": true } } } }]]>
</wps:ComplexData>
</wps:Data>
</wps:Output>
16 changes: 12 additions & 4 deletions worker/gdalprocess/drill.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ func DrillDataset(in *pb.GeoRPCGranule) *pb.Result {

C.OGR_G_AssignSpatialReference(geom, selSRS)

res := readData(ds, in.Bands, geom, int(in.BandStrides), int(in.DrillDecileCount), in.ClipUpper, in.ClipLower)
res := readData(ds, in.Bands, geom, int(in.BandStrides), int(in.DrillDecileCount), int(in.PixelCount), in.ClipUpper, in.ClipLower)
C.OGR_G_DestroyGeometry(geom)
return res
}

func readData(ds C.GDALDatasetH, bands []int32, geom C.OGRGeometryH, bandStrides int, decileCount int, clipUpper float32, clipLower float32) *pb.Result {
func readData(ds C.GDALDatasetH, bands []int32, geom C.OGRGeometryH, bandStrides int, decileCount int, pixelCount int, clipUpper float32, clipLower float32) *pb.Result {
nCols := 1 + decileCount

avgs := []*pb.TimeSeries{}
Expand Down Expand Up @@ -141,11 +141,19 @@ func readData(ds C.GDALDatasetH, bands []int32, geom C.OGRGeometryH, bandStrides
for i := 0; i < bandSize; i++ {
if dsDscr.Mask.Pix[i] == 255 && dataBuf[i+bandOffset] != nodata {
val := dataBuf[i+bandOffset]
if pixelCount != 0 {
total++
}

if val < clipLower || val > clipUpper {
continue
}
sum += val
total++
if pixelCount == 0 {
sum += val
total++
} else {
sum += 1.0
}
}
}

Expand Down
117 changes: 63 additions & 54 deletions worker/gdalservice/gdalservice.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions worker/gdalservice/gdalservice.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ message GeoRPCGranule {
float clipUpper = 14;
float clipLower = 15;
int32 sRSCf = 16;
int32 pixelCount = 17;
}

message Raster {
Expand Down

0 comments on commit f7acc3a

Please sign in to comment.