Class ArrayHelper

java.lang.Object
net.simplace.sim.components.util.helper.ArrayHelper

public class ArrayHelper extends Object
Methods for dealing with arrays of layers WIKI_START Includes methods for resampling layers of different vertical resolution. WIKI_END
Author:
Gunther Krauss
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Resample modes - CENTER - takes the value of the source layer that hits the center of target layer - FIRST - takes the value of the first source layer that overlaps with the target layer - LAST - takes the value of the last source layer that overlaps with the target layer - AVG - takes the weighted average of the overlapping source layers - SUM - takes the sum of overlapping source layers, multiplied by the proportion of their overlap
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Double[]
    averagedLayerProportions(Double[] layervalues, Double[] depthOfLayers, double maxdepth)
     
    static double
    averageOfLayerMasses(Double[] layervalues, Double[] depthOfLayers, double maxdepth)
     
    static double
    averageOfLayerProportions(Double[] layervalues, Double[] depthOfLayers, double maxdepth)
     
    static Double[]
    coverageOfLayers(Double[] depthOfLayers, double maxdepth)
     
    static double
    depth(Double[] depths, int layernr)
    Returns the depth of the bottom border of a layer Deals also with layernr that are out of the layers bounds.
    static Double[]
    depthOfLayers(Double[] thicknessOfLayers)
    Calculates depths of layer from given thickness per layer
    static Double[]
    depthOfLayers(Double[] thicknessOfLayers, double maxdepth)
    Calculates the depth of layers from thickness of each layer up to maxdepth Once maxdepth is reached, all following layer depths are set to maxdepth
    static double
    maxLayerDepth(Double[] depthOfLayers, double maxdepth)
    Calculates the minimum of layer depth and a given maxdepth
    static int
    maxLayerIndex(Double[] depthOfLayers, double maxdepth)
    Calculates the array index (layernr) of the depth array that coresponds to the maxdepth
    static double
    overlap(Double[] depths1, int layernr1, Double[] depths2, int layernr2)
    Returns the overlap of two layers from different resolutions.
    static Double[]
    partialAveragedLayerAmounts(Double[] layervalues, Double[] depthOfLayers, double maxdepth, double part)
     
    static Double[]
    partialAveragedLayerProportions(Double[] layervalues, Double[] depthOfLayers, double maxdepth, double part)
     
    static <T> T[]
    redistributeLayersCenter(Double[] sourceDepths, Double[] targetDepths, T[] sourceValues, T[] targetValues)
    Resamples layer values from one resolution to another by taking the value of the source layer hitting the center of target layer Values have to be proportions (e.g. water content in mm or volumetric water content in mm^3/mm^3)
    static <T> T[]
    redistributeLayersFirst(Double[] sourceDepths, Double[] targetDepths, T[] sourceValues, T[] targetValues)
    Resamples layer values from one resolution to another by taking the value of first overlapping layer Values have to be proportions (e.g. water content in mm or volumetric water content in mm^3/mm^3)
    static <T> T[]
    redistributeLayersLast(Double[] sourceDepths, Double[] targetDepths, T[] sourceValues, T[] targetValues)
    Resamples layer values from one resolution to another by taking the value of last overlapping layer Values have to be proportions (e.g. water content in mm or volumetric water content in mm^3/mm^3)
    static Double[]
    resampleLayerAmounts(Double[] sourceDepths, Double[] targetDepths, Double[] sourceValues)
    Resamples layer values from one resolution to another by summing up Values have to be amounts (e.g. water content in mm)
    static Double[]
    resampleLayerProportions(Double[] sourceDepths, Double[] targetDepths, Double[] sourceValues)
    Resamples layer values from one resolution to another by averaging Values have to be proportions (e.g. water content in mm or volumetric water content in mm^3/mm^3)
    static Double[]
    resampleLayers(Double[] sourceDepths, Double[] targetDepths, Double[] sourceValues, boolean proportional)
    Resamples layer values from one resolution to another One has to specify, whether the values are amounts or proportions (e.g. water content in mm or volumetric water content in mm^3/mm^3)
    static Double[]
    resampleLayers(Double[] sourceDepths, Double[] targetDepths, Double[] sourceValues, ArrayHelper.RESAMPLE_MODE mode)
    Resamples numeric layer values from one resolution to another The target value of each layer is calculated from the overlapping source layers, depending on the mode: - AVG - average of source values weighted by the overlap proportion - SUM - sum of source values multiplied by the overlap proportion - FIRST - value of first source layer that overlaps with the target layer - LAST - value of last source layer that overlaps with the target layer - CENTER - value of the source layer that overlaps the center of the target layer
    static String[]
    resampleLayers(Double[] sourceDepths, Double[] targetDepths, String[] sourceValues, ArrayHelper.RESAMPLE_MODE mode)
    Resamples string layer values from one resolution to another
    static double
    sumOfLayers(Double[] layervalues, Double[] depthOfLayers, double maxdepth)
     
    static double
    thickness(Double[] depths, int layernr)
    Returns the thickness of a layer Deals also with layernr that are out of the layer bounds.
    static Double[]
    thicknessOfLayers(Double[] depthOfLayers)
    Calculates the thickness of layers from given depths
    static Double[]
    thicknessOfLayers(Double[] depthOfLayers, double maxdepth)
    Calculates the thickness of layers from given depths up to a maximum depth Thickness of layers beyond maxdepth are set to 0.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ArrayHelper

      public ArrayHelper()
  • Method Details

    • depth

      public static double depth(Double[] depths, int layernr)
      Returns the depth of the bottom border of a layer Deals also with layernr that are out of the layers bounds. If layernr is smaller than 0 return 0, if layernr is bigger than the maximal layer number, return the depth of last layer.
      Parameters:
      depths - Bottom border depth of each layer
      layernr - layer number (0 based)
      Returns:
      depth of layer
    • thickness

      public static double thickness(Double[] depths, int layernr)
      Returns the thickness of a layer Deals also with layernr that are out of the layer bounds. If layernr is smaller than 0 or bigger then maximal layernr then return 0.
      Parameters:
      depths - Bottom border depth of each layer
      layernr - layer number (0 based)
      Returns:
      thickness of layer
    • overlap

      public static double overlap(Double[] depths1, int layernr1, Double[] depths2, int layernr2)
      Returns the overlap of two layers from different resolutions. If the two layers do not overlap, 0 is returned.
      Parameters:
      depths1 - Bottom border depth of each layer of resolution 1
      layernr1 - layer number in resolution 1
      depths2 - Bottom border depth of each layer of resolution 2
      layernr2 - layer number in resolution 1
      Returns:
      thicknes of overlap of the two layers
    • resampleLayers

      public static Double[] resampleLayers(Double[] sourceDepths, Double[] targetDepths, Double[] sourceValues, boolean proportional)
      Resamples layer values from one resolution to another One has to specify, whether the values are amounts or proportions (e.g. water content in mm or volumetric water content in mm^3/mm^3)
      Parameters:
      sourceDepths - Bottom border depth of each layer of source resolution
      targetDepths - Bottom border depth of each layer of target resolution
      sourceValues - Layer values of source resolution
      proportional - Whether values are amounts or proportions
      Returns:
      Layer values of target resolution
    • resampleLayerAmounts

      public static Double[] resampleLayerAmounts(Double[] sourceDepths, Double[] targetDepths, Double[] sourceValues)
      Resamples layer values from one resolution to another by summing up Values have to be amounts (e.g. water content in mm)
      Parameters:
      sourceDepths - Bottom border depth of each layer of source resolution
      targetDepths - Bottom border depth of each layer of target resolution
      sourceValues - Layer values of source resolution
      Returns:
      Layer values of target resolution
    • resampleLayerProportions

      public static Double[] resampleLayerProportions(Double[] sourceDepths, Double[] targetDepths, Double[] sourceValues)
      Resamples layer values from one resolution to another by averaging Values have to be proportions (e.g. water content in mm or volumetric water content in mm^3/mm^3)
      Parameters:
      sourceDepths - Bottom border depth of each layer of source resolution
      targetDepths - Bottom border depth of each layer of target resolution
      sourceValues - Layer values of source resolution
      Returns:
      Layer values of target resolution
    • redistributeLayersFirst

      public static <T> T[] redistributeLayersFirst(Double[] sourceDepths, Double[] targetDepths, T[] sourceValues, T[] targetValues)
      Resamples layer values from one resolution to another by taking the value of first overlapping layer Values have to be proportions (e.g. water content in mm or volumetric water content in mm^3/mm^3)
      Parameters:
      sourceDepths - Bottom border depth of each layer of source resolution
      targetDepths - Bottom border depth of each layer of target resolution
      sourceValues - Layer values of source resolution
      targetValues - Layer to be filled with the resampled values
      Returns:
      Layer values of target resolution
    • redistributeLayersLast

      public static <T> T[] redistributeLayersLast(Double[] sourceDepths, Double[] targetDepths, T[] sourceValues, T[] targetValues)
      Resamples layer values from one resolution to another by taking the value of last overlapping layer Values have to be proportions (e.g. water content in mm or volumetric water content in mm^3/mm^3)
      Parameters:
      sourceDepths - Bottom border depth of each layer of source resolution
      targetDepths - Bottom border depth of each layer of target resolution
      sourceValues - Layer values of source resolution
      targetValues - Layer to be filled with the resampled values
      Returns:
      Layer values of target resolution
    • redistributeLayersCenter

      public static <T> T[] redistributeLayersCenter(Double[] sourceDepths, Double[] targetDepths, T[] sourceValues, T[] targetValues)
      Resamples layer values from one resolution to another by taking the value of the source layer hitting the center of target layer Values have to be proportions (e.g. water content in mm or volumetric water content in mm^3/mm^3)
      Parameters:
      sourceDepths - Bottom border depth of each layer of source resolution
      targetDepths - Bottom border depth of each layer of target resolution
      sourceValues - Layer values of source resolution
      targetValues - Layer to be filled with the resampled values
      Returns:
      Layer values of target resolution
    • resampleLayers

      public static Double[] resampleLayers(Double[] sourceDepths, Double[] targetDepths, Double[] sourceValues, ArrayHelper.RESAMPLE_MODE mode)
      Resamples numeric layer values from one resolution to another The target value of each layer is calculated from the overlapping source layers, depending on the mode: - AVG - average of source values weighted by the overlap proportion - SUM - sum of source values multiplied by the overlap proportion - FIRST - value of first source layer that overlaps with the target layer - LAST - value of last source layer that overlaps with the target layer - CENTER - value of the source layer that overlaps the center of the target layer
      Parameters:
      sourceDepths - Bottom border depth of each layer of source resolution
      targetDepths - Bottom border depth of each layer of target resolution
      sourceValues - Layer values of source resolution
      mode - Sampling method
      Returns:
      Layer values of target resolution
    • resampleLayers

      public static String[] resampleLayers(Double[] sourceDepths, Double[] targetDepths, String[] sourceValues, ArrayHelper.RESAMPLE_MODE mode)
      Resamples string layer values from one resolution to another
      Parameters:
      sourceDepths - Bottom border depth of each layer of source resolution
      targetDepths - Bottom border depth of each layer of target resolution
      sourceValues - Layer values of source resolution
      mode - Sampling method
      Returns:
      Layer values of target resolution The target value of each layer is calculated from the overlapping source layers, depending on the mode: - FIRST - value of first source layer that overlaps with the target layer - LAST - value of last source layer that overlaps with the target layer - CENTER - value of the source layer that overlaps the center of the target layer
    • maxLayerDepth

      public static double maxLayerDepth(Double[] depthOfLayers, double maxdepth)
      Calculates the minimum of layer depth and a given maxdepth
      Parameters:
      depthOfLayers - array with layer depths
      maxdepth - maximum depth
      Returns:
      minimum of maxdepth and depth of last layer
    • maxLayerIndex

      public static int maxLayerIndex(Double[] depthOfLayers, double maxdepth)
      Calculates the array index (layernr) of the depth array that coresponds to the maxdepth
      Parameters:
      depthOfLayers - array with layer depths
      maxdepth - maximum depth
      Returns:
      highest layer nr where maxdepth falls in
    • thicknessOfLayers

      public static Double[] thicknessOfLayers(Double[] depthOfLayers, double maxdepth)
      Calculates the thickness of layers from given depths up to a maximum depth Thickness of layers beyond maxdepth are set to 0.
      Parameters:
      depthOfLayers - array with layer depths
      maxdepth - maximum depth
      Returns:
      thickness of layers
    • thicknessOfLayers

      public static Double[] thicknessOfLayers(Double[] depthOfLayers)
      Calculates the thickness of layers from given depths
      Parameters:
      depthOfLayers -
      Returns:
      thickness of layers
    • depthOfLayers

      public static Double[] depthOfLayers(Double[] thicknessOfLayers, double maxdepth)
      Calculates the depth of layers from thickness of each layer up to maxdepth Once maxdepth is reached, all following layer depths are set to maxdepth
      Parameters:
      thicknessOfLayers - thickness per layer
      maxdepth - maximum depth
      Returns:
      bottom depths of layers
    • depthOfLayers

      public static Double[] depthOfLayers(Double[] thicknessOfLayers)
      Calculates depths of layer from given thickness per layer
      Parameters:
      thicknessOfLayers - thickness per layers
      Returns:
      bottom depths of layers
    • coverageOfLayers

      public static Double[] coverageOfLayers(Double[] depthOfLayers, double maxdepth)
    • sumOfLayers

      public static double sumOfLayers(Double[] layervalues, Double[] depthOfLayers, double maxdepth)
    • averageOfLayerProportions

      public static double averageOfLayerProportions(Double[] layervalues, Double[] depthOfLayers, double maxdepth)
    • averageOfLayerMasses

      public static double averageOfLayerMasses(Double[] layervalues, Double[] depthOfLayers, double maxdepth)
    • averagedLayerProportions

      public static Double[] averagedLayerProportions(Double[] layervalues, Double[] depthOfLayers, double maxdepth)
    • partialAveragedLayerProportions

      public static Double[] partialAveragedLayerProportions(Double[] layervalues, Double[] depthOfLayers, double maxdepth, double part)
    • partialAveragedLayerAmounts

      public static Double[] partialAveragedLayerAmounts(Double[] layervalues, Double[] depthOfLayers, double maxdepth, double part)