<commit_before>package maths.interpolation

import grizzled.slf4j.Logging
import locals.InterpolationType._
import maths.interpolation.cubic.BicubicInterpolation
import maths.interpolation.linear.BilinearInterpolation
import physical.flow.FlowGridWrapper
import physical.{GeoCoordinate, Velocity}

class Interpolation extends Logging {


  val bicubicInterpolation = new BicubicInterpolation()
  val bilinearInterpolation = new BilinearInterpolation()
  //TODO: Get dimensions from flow grid
  def apply(coordinate: GeoCoordinate, grid: FlowGridWrapper, index: Array[Int]): Option[Velocity] = {
    //debug("Interpolating the coordinate " + coordinate)
    val centroid = grid.getCentroid(index)
    //debug("Retrieved the polygon " + polygon.id)
    val latitudeDisplacement = (coordinate.latitude - centroid.latitude) * (1.0 / 0.1) + 1.0
    val longitudeDisplacement = (coordinate.longitude - centroid.longitude) * (1.0 / 0.1) + 1.0
    //debug("Latitude displacement = " + latitudeDisplacement + ", longitude displacement = " + longitudeDisplacement)

    //val bicubicInterpolation = new BicubicInterpolation()
    //val bilinearInterpolation = new BilinearInterpolation()

    val neighbourhood = grid.getInterpolationValues(coordinate, Bicubic)
    if (neighbourhood.isDefined) {
      Some(interpolate(Bicubic, neighbourhood.get, longitudeDisplacement, latitudeDisplacement))
    } else {
      val neighbourhood = grid.getInterpolationValues(coordinate, Bilinear)
      if (neighbourhood.isDefined) {
        Some(interpolate(Bilinear, neighbourhood.get, longitudeDisplacement, latitudeDisplacement))
      } else {
        grid.getVelocity(index).get
      }
    }
  }

  private def interpolate(interpolation: InterpolationType, neighbourhood: Array[Array[Velocity]],
                          long: Double, lat: Double): Velocity = interpolation match {
    case Bicubic => bicubicInterpolation(neighbourhood, long, lat)
    case Bilinear => bilinearInterpolation(neighbourhood, long, lat)
    case _ => throw new RuntimeException("Undefined interpolation method")
  }

  private def nextInterpolationStep(interpolation: Interpolation): InterpolationType = interpolation match {
    case Bicubic => Bilinear
    case Tricubic => TriLinear
    case _ => throw new RuntimeException("Undefined interpolation method")
  }
}


<commit_msg>Working on unit tests for case classes<commit_after>package maths.interpolation

import grizzled.slf4j.Logging
import locals.InterpolationType._
import maths.interpolation.cubic.BicubicInterpolation
import maths.interpolation.linear.BilinearInterpolation
import physical.flow.FlowGridWrapper
import physical.{GeoCoordinate, Velocity}

class Interpolation extends Logging {


  val bicubicInterpolation = new BicubicInterpolation()
  val bilinearInterpolation = new BilinearInterpolation()
  //TODO: Get dimensions from flow grid
  def apply(coordinate: GeoCoordinate, grid: FlowGridWrapper, index: Array[Int]): Option[Velocity] = {
    //debug("Interpolating the coordinate " + coordinate)
    val centroid = grid.getCentroid(index)
    //debug("Retrieved the polygon " + polygon.id)
    val latitudeDisplacement = (coordinate.latitude - centroid.latitude) * (1.0 / 0.1) + 1.0
    val longitudeDisplacement = (coordinate.longitude - centroid.longitude) * (1.0 / 0.1) + 1.0
    //debug("Latitude displacement = " + latitudeDisplacement + ", longitude displacement = " + longitudeDisplacement)

    //val bicubicInterpolation = new BicubicInterpolation()
    //val bilinearInterpolation = new BilinearInterpolation()

    val neighbourhood = grid.getInterpolationValues(coordinate, Bicubic)
    if (neighbourhood.isDefined) {
      Some(interpolate(Bicubic, neighbourhood.get, longitudeDisplacement, latitudeDisplacement))
    } else {
      val neighbourhood = grid.getInterpolationValues(coordinate, Bilinear)
      if (neighbourhood.isDefined) {
        Some(interpolate(Bilinear, neighbourhood.get, longitudeDisplacement, latitudeDisplacement))
      } else {
        grid.getVelocity(index)
      }
    }
  }

  private def interpolate(interpolation: InterpolationType, neighbourhood: Array[Array[Velocity]],
                          long: Double, lat: Double): Velocity = interpolation match {
    case Bicubic => bicubicInterpolation(neighbourhood, long, lat)
    case Bilinear => bilinearInterpolation(neighbourhood, long, lat)
    case _ => throw new RuntimeException("Undefined interpolation method")
  }

  private def nextInterpolationStep(interpolation: Interpolation): InterpolationType = interpolation match {
    case Bicubic => Bilinear
    case Tricubic => TriLinear
    case _ => throw new RuntimeException("Undefined interpolation method")
  }
}



{'fraction_non_alphanumeric': 0.09017610863568852, 'fraction_numerical': 0.00551665605771271, 'mean_word_length': 4.456018518518518, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6812074', 'n_tokens_mistral': 1411, 'n_tokens_neox': 1344, 'n_words': 308}