@@ -6,9 +6,11 @@ def __init__(self, array, out_dtype=None)
6
6
7
7
and methods
8
8
9
+ * scaling_needed() - returns True if array requires scaling for write
10
+ *.finite_range() - returns min, max of self.array
9
11
* to_fileobj(fileobj, offset=None, order='F')
10
12
11
- They do have attributes:
13
+ They have attributes:
12
14
13
15
* array
14
16
* out_dtype
@@ -178,6 +180,20 @@ def to_fileobj(self, fileobj, order='F', nan2zero=True):
178
180
179
181
180
182
class SlopeArrayWriter (ArrayWriter ):
183
+ """ ArrayWriter that can use scalefactor for writing arrays
184
+
185
+ The scalefactor allows the array writer to write floats to int output types,
186
+ and rescale larger ints to smaller. It can therefore lose precision.
187
+
188
+ It extends the ArrayWriter class with attribute:
189
+
190
+ * slope
191
+
192
+ and methods:
193
+
194
+ * reset() - reset slope to default (not adapted to self.array)
195
+ * calc_scale() - calculate slope to best write self.array
196
+ """
181
197
182
198
def __init__ (self , array , out_dtype = None , calc_scale = True ,
183
199
scaler_dtype = np .float32 ):
@@ -339,6 +355,22 @@ def _range_scale(self):
339
355
340
356
341
357
class SlopeInterArrayWriter (SlopeArrayWriter ):
358
+ """ Array writer that can use slope and intercept to scale array
359
+
360
+ The writer can subtract an intercept, and divided by a slope, in order to
361
+ be able to convert floating point values into a (u)int range, or to convert
362
+ larger (u)ints to smaller.
363
+
364
+ It extends the ArrayWriter class with attributes:
365
+
366
+ * inter
367
+ * slope
368
+
369
+ and methods:
370
+
371
+ * reset() - reset inter, slope to default (not adapted to self.array)
372
+ * calc_scale() - calculate inter, slope to best write self.array
373
+ """
342
374
343
375
def __init__ (self , array , out_dtype = None , calc_scale = True ,
344
376
scaler_dtype = np .float32 ):
@@ -357,7 +389,7 @@ def __init__(self, array, out_dtype=None, calc_scale=True,
357
389
If False, then you can calculate this scaling with
358
390
``obj.calc_scale()`` - see examples
359
391
scaler_dtype : dtype-like, optional
360
- specifier for numpy dtype for scaling
392
+ specifier for numpy dtype for slope, intercept
361
393
362
394
Examples
363
395
--------
@@ -480,6 +512,16 @@ def get_slope_inter(writer):
480
512
slope in `writer` or 1.0 if not present
481
513
inter : scalar
482
514
intercept in `writer` or 0.0 if not present
515
+
516
+ Examples
517
+ --------
518
+ >>> arr = np.arange(10)
519
+ >>> get_slope_inter(ArrayWriter(arr))
520
+ (1.0, 0.0)
521
+ >>> get_slope_inter(SlopeArrayWriter(arr))
522
+ (1.0, 0.0)
523
+ >>> get_slope_inter(SlopeInterArrayWriter(arr))
524
+ (1.0, 0.0)
483
525
"""
484
526
try :
485
527
slope = writer .slope
@@ -514,6 +556,18 @@ def make_array_writer(data, out_type, has_intercept=True, has_slope=True,
514
556
writer : arraywriter instance
515
557
Instance of array writer, with class adapted to `has_intercept` and
516
558
`has_slope`.
559
+
560
+ Examples
561
+ --------
562
+ >>> aw = make_array_writer(np.arange(10), np.uint8, True, True)
563
+ >>> type(aw) == SlopeInterArrayWriter
564
+ True
565
+ >>> aw = make_array_writer(np.arange(10), np.uint8, False, True)
566
+ >>> type(aw) == SlopeArrayWriter
567
+ True
568
+ >>> aw = make_array_writer(np.arange(10), np.uint8, False, False)
569
+ >>> type(aw) == ArrayWriter
570
+ True
517
571
"""
518
572
data = np .asarray (data )
519
573
if has_intercept == True and has_slope == False :
0 commit comments