|
| 1 | +/* |
| 2 | + * This software is licensed under the Apache 2 license, quoted below. |
| 3 | + * |
| 4 | + * Copyright 2019 Astraea, Inc. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 7 | + * use this file except in compliance with the License. You may obtain a copy of |
| 8 | + * the License at |
| 9 | + * |
| 10 | + * [http://www.apache.org/licenses/LICENSE-2.0] |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | + * License for the specific language governing permissions and limitations under |
| 16 | + * the License. |
| 17 | + * |
| 18 | + * SPDX-License-Identifier: Apache-2.0 |
| 19 | + * |
| 20 | + */ |
| 21 | + |
| 22 | +package astraea.spark.rasterframes.expressions.localops |
| 23 | + |
| 24 | +import astraea.spark.rasterframes._ |
| 25 | +import astraea.spark.rasterframes.expressions.{UnaryLocalRasterOp, fpTile} |
| 26 | +import geotrellis.raster.Tile |
| 27 | +import org.apache.spark.sql.catalyst.expressions.{Expression, ExpressionDescription} |
| 28 | +import org.apache.spark.sql.catalyst.expressions.codegen.CodegenFallback |
| 29 | +import org.apache.spark.sql.types.DataType |
| 30 | +import org.apache.spark.sql.{Column, TypedColumn} |
| 31 | + |
| 32 | + |
| 33 | +@ExpressionDescription( |
| 34 | + usage = "_FUNC_(tile) - Performs cell-wise exponential.", |
| 35 | + arguments = """ |
| 36 | + Arguments: |
| 37 | + * tile - input tile""", |
| 38 | + examples = """ |
| 39 | + Examples: |
| 40 | + > SELECT _FUNC_(tile); |
| 41 | + ...""" |
| 42 | +) |
| 43 | +case class Exp(child: Expression) extends UnaryLocalRasterOp with CodegenFallback { |
| 44 | + override val nodeName: String = "exp" |
| 45 | + |
| 46 | + override protected def op(tile: Tile): Tile = fpTile(tile).localPowValue(math.E) |
| 47 | + |
| 48 | + override def dataType: DataType = child.dataType |
| 49 | +} |
| 50 | +object Exp { |
| 51 | + def apply(tile: Column): TypedColumn[Any, Tile] = |
| 52 | + new Column(Exp(tile.expr)).as[Tile] |
| 53 | +} |
| 54 | + |
| 55 | +@ExpressionDescription( |
| 56 | + usage = "_FUNC_(tile) - Compute 10 to the power of cell values.", |
| 57 | + arguments = """ |
| 58 | + Arguments: |
| 59 | + * tile - input tile""", |
| 60 | + examples = """ |
| 61 | + Examples: |
| 62 | + > SELECT _FUNC_(tile); |
| 63 | + ...""" |
| 64 | +) |
| 65 | +case class Exp10(child: Expression) extends UnaryLocalRasterOp with CodegenFallback { |
| 66 | + override val nodeName: String = "log10" |
| 67 | + |
| 68 | + override protected def op(tile: Tile): Tile = fpTile(tile).localPowValue(10.0) |
| 69 | + |
| 70 | + override def dataType: DataType = child.dataType |
| 71 | +} |
| 72 | +object Exp10 { |
| 73 | + def apply(tile: Column): TypedColumn[Any, Tile] = new Column(Exp10(tile.expr)).as[Tile] |
| 74 | +} |
| 75 | + |
| 76 | +@ExpressionDescription( |
| 77 | + usage = "_FUNC_(tile) - Compute 2 to the power of cell values.", |
| 78 | + arguments = """ |
| 79 | + Arguments: |
| 80 | + * tile - input tile""", |
| 81 | + examples = """ |
| 82 | + Examples: |
| 83 | + > SELECT _FUNC_(tile); |
| 84 | + ...""" |
| 85 | +) |
| 86 | +case class Exp2(child: Expression) extends UnaryLocalRasterOp with CodegenFallback { |
| 87 | + override val nodeName: String = "exp2" |
| 88 | + |
| 89 | + override protected def op(tile: Tile): Tile = fpTile(tile).localPowValue(2.0) |
| 90 | + |
| 91 | + override def dataType: DataType = child.dataType |
| 92 | +} |
| 93 | +object Exp2{ |
| 94 | + def apply(tile: Column): TypedColumn[Any, Tile] = new Column(Exp2(tile.expr)).as[Tile] |
| 95 | +} |
| 96 | + |
| 97 | +@ExpressionDescription( |
| 98 | + usage = "_FUNC_(tile) - Performs cell-wise exponential, then subtract one.", |
| 99 | + arguments = """ |
| 100 | + Arguments: |
| 101 | + * tile - input tile""", |
| 102 | + examples = """ |
| 103 | + Examples: |
| 104 | + > SELECT _FUNC_(tile); |
| 105 | + ...""" |
| 106 | +) |
| 107 | +case class ExpM1(child: Expression) extends UnaryLocalRasterOp with CodegenFallback { |
| 108 | + override val nodeName: String = "expm1" |
| 109 | + |
| 110 | + override protected def op(tile: Tile): Tile = fpTile(tile).localPowValue(math.E).localSubtract(1.0) |
| 111 | + |
| 112 | + override def dataType: DataType = child.dataType |
| 113 | +} |
| 114 | +object ExpM1{ |
| 115 | + def apply(tile: Column): TypedColumn[Any, Tile] = new Column(ExpM1(tile.expr)).as[Tile] |
| 116 | +} |
0 commit comments