• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aburrell / pyValEIA / 20249760475

15 Dec 2025 10:29PM UTC coverage: 8.579%. First build
20249760475

push

github

web-flow
Merge pull request #28 from aburrell/rc_0.0.2

Release Candidate v0.0.2

237 of 2677 new or added lines in 24 files covered. (8.85%)

253 of 2949 relevant lines covered (8.58%)

0.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

33.33
/pyValEIA/utils/math.py
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
#
4
# DISTRIBUTION STATEMENT A: Approved for public release. Distribution is
5
# unlimited.
6
# ----------------------------------------------------------------------------
7
"""Functions that support mathematical calculations."""
8

9
import numpy as np
10✔
10

11

12
def get_exponent(number):
10✔
13
    """Calculate the exponent of number using base 10.
14

15
    Parameters
16
    ----------
17
    number : double
18
        Number for which the base-10 exponent will be calculated
19

20
    Returns
21
    -------
22
    exp_val : float
23
        Exponent of `number` as a whole value
24

25
    """
NEW
26
    if number == 0:
×
27
        # This is the same result, but without the RuntimeWarning
NEW
28
        exp_val = -np.inf
×
29
    else:
NEW
30
        exp_val = np.floor(np.log10(abs(number)))
×
31

NEW
32
    return exp_val
×
33

34

35
def base_round(xvals, base=5):
10✔
36
    """Round values to the nearest base.
37

38
    Parameters
39
    ----------
40
    xvals : array-like
41
        Values to be rounded
42
    base : int
43
        Base to be rounded to (default=5)
44

45
    Returns
46
    -------
47
    round_vals : array-like
48
        Values rounded to nearest base
49

50
    """
NEW
51
    round_vals = np.floor(base * np.round(np.asarray(xvals).astype(np.float64)
×
52
                                          / base))
53

NEW
54
    return round_vals
×
55

56

57
def unique_threshold(xvals, thresh=0.01):
10✔
58
    """Round values to the desired threshold and return a unique array.
59

60
    Parameters
61
    ----------
62
    xvals : array-like
63
        Values to be rounded
64
    thresh : float
65
        Threshold for uniqueness (default=0.01)
66

67
    Returns
68
    -------
69
    uvals : array-like
70
        Unique values at the desired threshold level
71

72
    """
73
    # Number of decimal places
NEW
74
    ndec = int(abs(np.log10(thresh)))
×
75

76
    # Threshold here is our base in rounding
NEW
77
    uvals = np.unique(np.round(xvals, ndec))
×
78

NEW
79
    return uvals
×
80

81

82
def set_dif_thresh(lat_span, percent=0.05):
10✔
83
    """Set a difference threshold.
84

85
    Parameters
86
    ----------
87
    lat_span: double
88
        span of latitude array e.g. max(latitude) - min(latitude)
89
    percent : kwarg double
90
        Percent as a decimal for difference  threshold from 0-1 (default=0.05)
91

92
    Returns
93
    -------
94
    float
95
        Percentage times the span
96

97
    Notes
98
    -----
99
    Set the threshold for what is different, input scale (if lat_span) = 50,
100
    then our max tec/ne is 50 so set thresh to 5 for 10%
101
    can also use this for maximum difference between peak and trough,
102
    so can use smaller threshold
103

104
    """
105

NEW
106
    return percent * lat_span
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc