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

timcera / pyslice / 12340932278

15 Dec 2024 05:42PM CUT coverage: 45.447%. Remained the same
12340932278

Pull #4

github

web-flow
Merge d90cfa984 into 2ffee6f33
Pull Request #4: build(deps): bump actions/setup-python from 4 to 5

529 of 1164 relevant lines covered (45.45%)

2.27 hits per line

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

17.65
/src/pyslice/pyslice_lib/PySPG/Load.py
1
import math
5✔
2
import os
5✔
3
import sys
5✔
4

5
import numpy as np
5✔
6

7

8
def loadData(s):
5✔
9
    with open(s) as fIn:
×
10
        return [
×
11
            list(map(float, strLine.replace("D", "E").strip().split()))
12
            for strLine in fIn.readlines()
13
            if strLine.find("nan") == -1
14
            and strLine.strip() != ""
15
            and strLine.find("inf") == -1
16
        ]
17

18

19
def dumpData(s, data):
5✔
20
    with open(s, "w") as fout:
×
21
        for line in data:
×
22
            fout.write("\t".join([str(i) for i in line]) + "\n")
×
23

24

25
def loadXY(s, xCol=0, yCol=1):
5✔
26
    data = loadData(s)
×
27
    out = []
×
28
    for line in data:
×
29
        try:
×
30
            out.append([line[xCol], line[yCol]])
×
31
        except Exception:
×
32
            sys.stderr.write("skipping line %d, wrong size\n" % (data.index(line)))
×
33
    return out
×
34

35

36
#    return [
37
#           [line[xCol],line[yCol] ]
38
#           for line in data
39
#         ]
40
#  except:
41
#    sys.stderr.write("error!!! in file: %s...\n"%s)
42
#    sys.stderr.write("not enough columns, or inconsistent datafile. asked for columns %d and %d, where there are only %d..\n"%(xCol,yCol,len(data[0])))
43
#    sys.stderr.write("not enough columns, or inconsistent datafile. asked for columns %d and %d, where there are only %d..\n"%(xCol,yCol,len(data[-1])))
44
#    sys.stderr.write("gracefully quitting...\n")
45
#    sys.exit()
46

47
# try: #
48
#    return [
49
#           [line[xCol],line[yCol] ]
50
#           for line in data
51
#         ]
52
#  except:
53
#    sys.stderr.write("error!!! in file: %s...\n"%s)
54
#    sys.stderr.write("not enough columns, or inconsistent datafile. asked for columns %d and %d, where there are only %d..\n"%(xCol,yCol,len(data[0])))
55
#    sys.stderr.write("not enough columns, or inconsistent datafile. asked for columns %d and %d, where there are only %d..\n"%(xCol,yCol,len(data[-1])))
56
#    sys.stderr.write("gracefully quitting...\n")
57
#    sys.exit()
58

59

60
def loadXYZ(s, xCol=0, yCol=1, zCol=2):
5✔
61
    return [[line[xCol], line[yCol], line[zCol]] for line in loadData(s)]
×
62

63

64
def loadY(s, yCol=1):
5✔
65
    with open(s) as fIn:
×
66
        lines = fIn.readlines()
×
67

68
    try:
×
69
        return [float(line.strip().split()[yCol]) for line in lines if len(line) > 1]
×
70
    except Exception:
×
71
        sys.stderr.write(
×
72
            " ... error reading file: %s, %d\n"
73
            % (os.path.realpath(s), os.path.isfile(s))
74
        )
75
        return [0]
×
76

77

78
def transformXY(ls, xFormula="x", yFormula="y"):
5✔
79
    xf = xFormula.replace("x", "(x)")
×
80
    xf = xf.replace("y", "(y)")
×
81
    yf = yFormula.replace("x", "(x)")
×
82
    yf = yf.replace("y", "(y)")
×
83

84
    lsOut = []
×
85

86
    for line in ls:
×
87
        try:
×
88
            lsOut.append(
×
89
                [
90
                    eval(xf.replace("x", str(line[0])).replace("y", str(line[1]))),
91
                    eval(yf.replace("y", str(line[1])).replace("x", str(line[0]))),
92
                ]
93
            )
94

95
        except Exception:
×
96
            sys.stderr.write(f"skipping line: {str(line)}" + "\n")
×
97
    return lsOut
×
98

99

100
def transformXYZ(ls, xFormula="x", yFormula="y", zFormula="z"):
5✔
101
    xf = xFormula.replace("x", "(x)")
×
102
    yf = yFormula.replace("y", "(y)")
×
103
    zf = zFormula.replace("z", "(z)")
×
104

105
    return [
×
106
        [
107
            eval(xf.replace("x", str(line[0]))),
108
            eval(yf.replace("y", str(line[1]))),
109
            eval(zf.replace("z", str(line[2]))),
110
        ]
111
        for line in ls
112
    ]
113

114

115
def histogram(data, nbins, maxboxsize=10000, minx=-1e64, maxx=1e64):
5✔
116
    #
117
    # pythonize this code!!!!!!
118
    #
119
    if len(data) == 0:
×
120
        data = [0]
×
121

122
    mina = max(min(data), minx)
×
123
    maxa = min(max(data), maxx)
×
124
    boxsize = min(maxboxsize, ((maxa - mina) // nbins))
×
125
    out = [0] * int(math.ceil((maxa - mina) // boxsize))
×
126

127
    for idata in data:
×
128
        try:
×
129
            pos = int(math.floor((idata - mina) // boxsize))
×
130
            if pos == len(out):
×
131
                pos = len(out) - 1
×
132
            sys.stderr.write("%d\n" % pos)
×
133
            out[pos] += 1
×
134
        except Exception:
×
135
            sys.stderr.write(f"histogram error!!! len(data) = {len(out)} \n")
×
136
            sys.stderr.write(
×
137
                "\n".join(
138
                    [
139
                        f"{str(k)} = {str(locals()[k])}"
140
                        for k in list(locals().keys())
141
                        if k != "data"
142
                    ]
143
                )
144
                + "\n"
145
            )
146

147
            sys.exit()
×
148
    suma = np.sum(out)
×
149

150
    out3 = [(x // suma) for x in out]
×
151
    return [
×
152
        [float(i) / float(nbins) * (maxa - mina) + mina, out3[i]] for i in range(nbins)
153
    ]
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

© 2025 Coveralls, Inc