@@ -312,58 +312,56 @@ class SymmetricalLogScale(ScaleBase):
312
312
name = 'symlog'
313
313
314
314
class SymmetricalLogTransform (Transform ):
315
+ input_dims = 1
316
+ output_dims = 1
317
+ is_separable = True
318
+
319
+ def __init__ (self , base , linthresh ):
320
+ Transform .__init__ (self )
321
+ self .base = base
322
+ self .linthresh = linthresh
323
+ self ._log_base = np .log (base )
324
+ self ._linadjust = (np .log (linthresh ) / self ._log_base ) / linthresh
325
+
326
+ def transform (self , a ):
327
+ a = np .asarray (a )
328
+ sign = np .sign (a )
329
+ masked = ma .masked_inside (a , - self .linthresh , self .linthresh , copy = False )
330
+ log = sign * self .linthresh * (1 + ma .log (np .abs (masked ) / self .linthresh ))
331
+ if masked .mask .any ():
332
+ return np .asarray (ma .where (masked .mask ,
333
+ a ,
334
+ log ))
335
+ else :
336
+ return np .asarray (log )
337
+
338
+ def inverted (self ):
339
+ return SymmetricalLogScale .InvertedSymmetricalLogTransform (self .base , self .linthresh )
340
+
341
+ class InvertedSymmetricalLogTransform (Transform ):
315
342
input_dims = 1
316
343
output_dims = 1
317
344
is_separable = True
318
345
319
346
def __init__ (self , base , linthresh ):
320
347
Transform .__init__ (self )
321
348
self .base = base
322
- self .linthresh = abs ( linthresh )
349
+ self .linthresh = linthresh
323
350
self ._log_base = np .log (base )
324
- logb_linthresh = np .log (linthresh ) / self ._log_base
325
- self ._linadjust = 1.0 - logb_linthresh
326
- self ._linscale = 1.0 / linthresh
351
+ self ._log_linthresh = np .log (linthresh ) / self ._log_base
352
+ self ._linadjust = linthresh / (np .log (linthresh ) / self ._log_base )
327
353
328
354
def transform (self , a ):
329
355
a = np .asarray (a )
330
356
sign = np .sign (a )
331
357
masked = ma .masked_inside (a , - self .linthresh , self .linthresh , copy = False )
358
+ exp = sign * self .linthresh * ma .exp (sign * masked / self .linthresh - 1 )
332
359
if masked .mask .any ():
333
- log = sign * (ma .log (np .abs (masked )) / self ._log_base + self ._linadjust )
334
- return np .asarray (ma .where (masked .mask , a * self ._linscale , log ))
360
+ return np .asarray (ma .where (masked .mask ,
361
+ a ,
362
+ exp ))
335
363
else :
336
- return sign * (np .log (np .abs (a )) / self ._log_base + self ._linadjust )
337
-
338
- def inverted (self ):
339
- return SymmetricalLogScale .InvertedSymmetricalLogTransform (
340
- self .base , self .linthresh )
341
-
342
- class InvertedSymmetricalLogTransform (Transform ):
343
- input_dims = 1
344
- output_dims = 1
345
- is_separable = True
346
-
347
- def __init__ (self , base , linthresh ):
348
- Transform .__init__ (self )
349
- self .base = base
350
- self .linthresh = linthresh
351
- log_base = np .log (base )
352
- logb_linthresh = np .log (linthresh ) / log_base
353
- self ._linadjust = 1.0 - logb_linthresh
354
-
355
- def transform (self , a ):
356
- a = np .asarray (a )
357
- sign = np .sign (a )
358
- masked = ma .masked_inside (a , - 1.0 , 1.0 , copy = False )
359
- result = np .where ((a >= - 1.0 ) & (a <= 1.0 ),
360
- a * self .linthresh ,
361
- sign * np .power (self .base , np .abs (a - sign * self ._linadjust )))
362
- return result
363
-
364
- def inverted (self ):
365
- return SymmetricalLogScale .SymmetricalLogTransform (
366
- self .base , self .linthresh )
364
+ return np .asarray (exp )
367
365
368
366
def __init__ (self , axis , ** kwargs ):
369
367
"""
0 commit comments