Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .circleci/README.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class RasterRefBench extends SparkEnv with LazyLogging {
val r2 = RFRasterSource(remoteCOGSingleband2)

singleDF = Seq((r1, r2)).toDF("B1", "B2")
.select(RasterRefToTile(RasterSourceToRasterRefs(Some(r1.dimensions), Seq(0), $"B1", $"B2")))
.select(RasterRefToTile(RasterSourceToRasterRefs(Some(r1.dimensions), Seq(0), 0.toShort, $"B1", $"B2")))

expandedDF = Seq((r1, r2)).toDF("B1", "B2")
.select(RasterRefToTile(RasterSourceToRasterRefs($"B1", $"B2")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class TileEncodeBench extends SparkEnv {
case "rasterRef" ⇒
val baseCOG = "https://s3-us-west-2.amazonaws.com/landsat-pds/c1/L8/149/039/LC08_L1TP_149039_20170411_20170415_01_T1/LC08_L1TP_149039_20170411_20170415_01_T1_B1.TIF"
val extent = Extent(253785.0, 3235185.0, 485115.0, 3471015.0)
tile = RasterRefTile(RasterRef(RFRasterSource(URI.create(baseCOG)), 0, Some(extent), None))
tile = RasterRefTile(RasterRef(RFRasterSource(URI.create(baseCOG)), 0, Some(extent), None, 0.toShort))
case _ ⇒
tile = randomTile(tileSize, tileSize, cellTypeName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class RasterRefIT extends TestEnvironment {
// [west, south, east, north]
val area = Extent(31.115, 29.963, 31.148, 29.99).reproject(LatLng, redScene.crs)

val red = RasterRef(redScene, 0, Some(area), None)
val green = RasterRef(RFRasterSource(scene(3)), 0, Some(area), None)
val blue = RasterRef(RFRasterSource(scene(2)), 0, Some(area), None)
val red = RasterRef(redScene, 0, Some(area), None, 0)
val green = RasterRef(RFRasterSource(scene(3)), 0, Some(area), None, 0)
val blue = RasterRef(RFRasterSource(scene(2)), 0, Some(area), None, 0)

val rf = Seq((red, green, blue)).toDF("red", "green", "blue")
val df = rf.select(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import org.apache.spark.sql.catalyst.expressions.UnaryExpression
import org.locationtech.rasterframes.model.TileContext

/** Boilerplate for expressions operating on a single Tile-like . */
trait UnaryRasterOp extends UnaryExpression {
trait UnaryRasterFunction extends UnaryExpression {
override def checkInputDataTypes(): TypeCheckResult = {
if (!tileExtractor.isDefinedAt(child.dataType)) {
TypeCheckFailure(s"Input type '${child.dataType}' does not conform to a raster type.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,26 @@ package org.locationtech.rasterframes.expressions

import com.typesafe.scalalogging.Logger
import geotrellis.raster.Tile
import org.apache.spark.sql.catalyst.analysis.TypeCheckResult
import org.apache.spark.sql.catalyst.analysis.TypeCheckResult.{TypeCheckFailure, TypeCheckSuccess}
import org.apache.spark.sql.catalyst.expressions.UnaryExpression
import org.apache.spark.sql.rf.TileUDT
import org.apache.spark.sql.types.DataType
import org.locationtech.rasterframes.encoders.CatalystSerializer._
import org.locationtech.rasterframes.expressions.DynamicExtractors._
import org.locationtech.rasterframes.model.TileContext
import org.slf4j.LoggerFactory

/** Operation on a tile returning a tile. */
trait UnaryLocalRasterOp extends UnaryExpression {
trait UnaryRasterOperator extends UnaryRasterFunction {
@transient protected lazy val logger = Logger(LoggerFactory.getLogger(getClass.getName))

override def dataType: DataType = child.dataType

override def checkInputDataTypes(): TypeCheckResult = {
if (!tileExtractor.isDefinedAt(child.dataType)) {
TypeCheckFailure(s"Input type '${child.dataType}' does not conform to a raster type.")
}
else TypeCheckSuccess
}

override protected def nullSafeEval(input: Any): Any = {
override protected def eval(tile: Tile, ctx: Option[TileContext]): Any = {
implicit val tileSer = TileUDT.tileSerializer
val (childTile, childCtx) = tileExtractor(child.dataType)(row(input))

childCtx match {
case Some(ctx) => ctx.toProjectRasterTile(op(childTile)).toInternalRow
case None => op(childTile).toInternalRow
ctx match {
case Some(ctx) => ctx.toProjectRasterTile(op(tile)).toInternalRow
case None => op(tile).toInternalRow
}
}

protected def op(child: Tile): Tile
}

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
package org.locationtech.rasterframes.expressions.accessors

import org.locationtech.rasterframes.encoders.CatalystSerializer._
import org.locationtech.rasterframes.expressions.UnaryRasterOp
import org.locationtech.rasterframes.expressions.UnaryRasterFunction
import org.locationtech.rasterframes.tiles.ProjectedRasterTile.ConcreteProjectedRasterTile
import geotrellis.raster.Tile
import org.apache.spark.sql.catalyst.expressions.Expression
Expand All @@ -35,7 +35,7 @@ import org.locationtech.rasterframes.tiles.InternalRowTile
import org.locationtech.rasterframes._

/** Expression to extract at tile from several types that contain tiles.*/
case class ExtractTile(child: Expression) extends UnaryRasterOp with CodegenFallback {
case class ExtractTile(child: Expression) extends UnaryRasterFunction with CodegenFallback {
override def dataType: DataType = TileType

override def nodeName: String = "rf_extract_tile"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
package org.locationtech.rasterframes.expressions.accessors

import org.locationtech.rasterframes.encoders.CatalystSerializer._
import org.locationtech.rasterframes.expressions.UnaryRasterOp
import org.locationtech.rasterframes.expressions.UnaryRasterFunction
import geotrellis.raster.Tile
import org.apache.spark.sql.catalyst.expressions.Expression
import org.apache.spark.sql.catalyst.expressions.codegen.CodegenFallback
import org.apache.spark.sql.types.DataType
import org.apache.spark.sql.{Column, TypedColumn}
import org.locationtech.rasterframes.expressions.UnaryRasterOp
import org.locationtech.rasterframes.expressions.UnaryRasterFunction
import org.locationtech.rasterframes.model.TileContext

case class GetTileContext(child: Expression) extends UnaryRasterOp with CodegenFallback {
case class GetTileContext(child: Expression) extends UnaryRasterFunction with CodegenFallback {
override def dataType: DataType = schemaOf[TileContext]

override def nodeName: String = "get_tile_context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ case class RealizeTile(child: Expression) extends UnaryExpression with CodegenFa
override protected def nullSafeEval(input: Any): Any = {
val in = row(input)
val tile = tileableExtractor(child.dataType)(in)
// TODO: This operation might be more efficient if we bypass toArrayTile and copy directly into Tungsten.
(tile.toArrayTile(): Tile).toInternalRow
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* This software is licensed under the Apache 2 license, quoted below.
*
* Copyright 2020 Astraea, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* [http://www.apache.org/licenses/LICENSE-2.0]
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/

package org.locationtech.rasterframes.expressions.focalops
import geotrellis.raster.Tile
import geotrellis.raster.mapalgebra.focal.Kernel
import org.apache.spark.sql.Column
import org.apache.spark.sql.catalyst.expressions.Expression
import org.apache.spark.sql.catalyst.expressions.codegen.CodegenFallback
import org.locationtech.rasterframes.expressions.{NullToValue, UnaryRasterOperator}

case class Convolve(child: Expression, kernel: Kernel) extends UnaryRasterOperator with NullToValue with CodegenFallback {
override def nodeName: String = "rf_convolve"
override def na: Any = null
override protected def op(t: Tile): Tile = t.convolve(kernel)
}

object Convolve {
def apply(tile: Column, kernel: Kernel): Column = new Column(Convolve(tile.expr, kernel))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This software is licensed under the Apache 2 license, quoted below.
*
* Copyright 2020 Astraea, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* [http://www.apache.org/licenses/LICENSE-2.0]
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/

package org.locationtech.rasterframes.expressions.focalops

import geotrellis.raster.Tile
import geotrellis.raster.mapalgebra.focal.Neighborhood
import org.apache.spark.sql.Column
import org.apache.spark.sql.catalyst.expressions.Expression

case class FocalMax(child: Expression, neighborhood: Neighborhood) extends FocalNeighborhoodOperator {
override def nodeName: String = "rf_focal_max"
override protected def op(t: Tile): Tile = t.focalMax(neighborhood)
}

object FocalMax {
def apply(tile: Column, neighborhood: Neighborhood): Column = new Column(FocalMax(tile.expr, neighborhood))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This software is licensed under the Apache 2 license, quoted below.
*
* Copyright 2020 Astraea, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* [http://www.apache.org/licenses/LICENSE-2.0]
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/

package org.locationtech.rasterframes.expressions.focalops

import geotrellis.raster.Tile
import geotrellis.raster.mapalgebra.focal.Neighborhood
import org.apache.spark.sql.Column
import org.apache.spark.sql.catalyst.expressions.Expression

case class FocalMean(child: Expression, neighborhood: Neighborhood) extends FocalNeighborhoodOperator {
override def nodeName: String = "rf_focal_mean"
override protected def op(t: Tile): Tile = t.focalMean(neighborhood)
}

object FocalMean {
def apply(tile: Column, neighborhood: Neighborhood): Column = new Column(FocalMean(tile.expr, neighborhood))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* This software is licensed under the Apache 2 license, quoted below.
*
* Copyright 2020 Astraea, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* [http://www.apache.org/licenses/LICENSE-2.0]
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/

package org.locationtech.rasterframes.expressions.focalops

import geotrellis.raster.Tile
import geotrellis.raster.mapalgebra.focal.Neighborhood
import org.apache.spark.sql.Column
import org.apache.spark.sql.catalyst.expressions.Expression

case class FocalMedian(child: Expression, neighborhood: Neighborhood) extends FocalNeighborhoodOperator {
override def nodeName: String = "rf_focal_median"
override protected def op(t: Tile): Tile = t.focalMedian(neighborhood)
}

object FocalMedian {
def apply(tile: Column, neighborhood: Neighborhood): Column = new Column(FocalMedian(tile.expr, neighborhood))
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* This software is licensed under the Apache 2 license, quoted below.
*
* Copyright 2020 Astraea, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* [http://www.apache.org/licenses/LICENSE-2.0]
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/

package org.locationtech.rasterframes.expressions.focalops
import geotrellis.raster.Tile
import geotrellis.raster.mapalgebra.focal.Neighborhood
import org.apache.spark.sql.Column
import org.apache.spark.sql.catalyst.expressions.Expression

case class FocalMin(child: Expression, neighborhood: Neighborhood) extends FocalNeighborhoodOperator {
override def nodeName: String = "rf_focal_min"
override protected def op(t: Tile): Tile = t.focalMin(neighborhood)
}

object FocalMin {
def apply(tile: Column, neighborhood: Neighborhood): Column = new Column(FocalMin(tile.expr, neighborhood))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* This software is licensed under the Apache 2 license, quoted below.
*
* Copyright 2020 Astraea, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* [http://www.apache.org/licenses/LICENSE-2.0]
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/

package org.locationtech.rasterframes.expressions.focalops

import geotrellis.raster.Tile
import geotrellis.raster.mapalgebra.focal.Neighborhood
import org.apache.spark.sql.Column
import org.apache.spark.sql.catalyst.expressions.Expression

case class FocalMode(child: Expression, neighborhood: Neighborhood) extends FocalNeighborhoodOperator {
override def nodeName: String = "rf_focal_mode"
override protected def op(t: Tile): Tile = t.focalMode(neighborhood)
}

object FocalMode {
def apply(tile: Column, neighborhood: Neighborhood): Column = new Column(FocalMode(tile.expr, neighborhood))
}


Loading