Skip to content

Commit

Permalink
added quantiletransformer powerTransformer and robustScaler functions
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanho committed Sep 20, 2024
1 parent fae9174 commit a44b04e
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion src/ucar/unidata/idv/resources/python/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,4 +682,63 @@ def fillMinMaxScaler(gridFF,user_min,user_max):
scalerG.setSample(j,fillMinMaxScaler(grid.getSample(j),user_min,user_max))
return scalerG
else:
return fillMinMaxScaler(grid,user_min,user_max)
return fillMinMaxScaler(grid,user_min,user_max)

def gridQuantileTransform(grid):
""" Rescale the grid values individually to a common range [user_min, user_max] linearly using statistics and
it is also known as min-max normalization
"""
from visad import FlatField

def fillQuantileTransform(gridFF):

tempFF=GridMath.quantileTransformerFF(gridFF)#put units here
return tempFF

if GridUtil.isTimeSequence(grid):
scalerG=grid.clone()
for j,time in enumerate(grid.domainEnumeration()):
scalerG.setSample(j,fillQuantileTransform(grid.getSample(j)))
return scalerG
else:
return fillQuantileTransform(grid)

def gridPowerTransform(grid, user_lambda):
""" Rescale the grid values individually to a common range [user_min, user_max] linearly using statistics and
it is also known as min-max normalization
"""
from visad import FlatField

def fillPowerTransform(gridFF, user_lambda):
if user_lambda == None or user_lambda =="":
data = gridFF.getFloats()[0]
user_lambda = GridUtil.findOptimalLambda(data, -5, 5, 0.1)

tempFF=GridMath.powerTransformerFF(gridFF, user_lambda)#put units here
return tempFF

if GridUtil.isTimeSequence(grid):
scalerG=grid.clone()
for j,time in enumerate(grid.domainEnumeration()):
scalerG.setSample(j,fillPowerTransform(grid.getSample(j), user_lambda))
return scalerG
else:
return fillPowerTransform(grid, user_lambda)

def gridRobustScaler(grid):
""" Rescale the grid values individually to a common range [user_min, user_max] linearly using statistics and
it is also known as min-max normalization
"""
from visad import FlatField

def fillRobustScaler(gridFF):
tempFF=GridMath.robustScalerFF(gridFF)#put units here
return tempFF

if GridUtil.isTimeSequence(grid):
scalerG=grid.clone()
for j,time in enumerate(grid.domainEnumeration()):
scalerG.setSample(j,fillRobustScaler(grid.getSample(j)))
return scalerG
else:
return fillRobustScaler(grid)

0 comments on commit a44b04e

Please sign in to comment.