Skip to content

Commit 61d9c5b

Browse files
committed
update code
1 parent c1d2a83 commit 61d9c5b

File tree

5 files changed

+41
-3
lines changed

5 files changed

+41
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ share/python-wheels/
2525
*.egg-info/
2626
.installed.cfg
2727
*.egg
28+
*.dat
2829
MANIFEST
2930

3031
# PyInstaller

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ include LICENSE README.md
22
include tests/test*.py
33
exclude environment.yml _config.yml
44
recursive-exclude .github/
5+
recursive-exclude .dat
56
recursive-include pygrc/*.py
67
include setup.cfg
78
include setup.py

pygrc/fit.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,18 @@ def __init__(
2727
data_y (tuple): input data on y axis
2828
*args (float): Takes initial parameter values
2929
30+
3031
"""
3132
self.args = args
32-
self.data_x = data_x.to_numpy()
33-
self.data_y = data_y.to_numpy()
33+
print(type(data_x))
34+
if 'numpy' not in str(type(data_x)):
35+
self.data_x = data_x.to_numpy()
36+
else:
37+
self.data_x = data_x
38+
if 'numpy' not in str(type(data_y)):
39+
self.data_y = data_y.to_numpy()
40+
else:
41+
self.data_y = data_y
3442

3543
def fit_lsq(
3644
self,
@@ -49,6 +57,15 @@ def fit_lsq(
4957
Returns:
5058
iminuit object
5159
60+
Example:
61+
62+
```python
63+
pygrc.Fit(x, y, 1,1).fit_lsq(function,[(-1,10),(-2,10)],.1)
64+
```
65+
here we have two variables and two parameters (initial values of parameters is 1.)
66+
where [..] are the limits for the two parameter and .1 is the error.
67+
68+
5269
"""
5370
least_square = LeastSquares(self.data_x, self.data_y, err, function)
5471
m = Minuit(least_square, *self.args)

pygrc/reader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def read(
4646
rawdata = np.loadtxt(filepath)
4747
data = pd.DataFrame(rawdata, columns=columns)
4848
return data
49-
elif pathlib.PurePosixPath(filepath).suffix == "csv":
49+
elif pathlib.PurePosixPath(filepath).suffix == ".csv":
5050
data = pd.read_csv(filepath)
5151
return data
5252
else:

tests/test_fit.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import pygrc
2+
import numpy as np
3+
import random
4+
import math
5+
6+
def function(x, *args):
7+
return args[0]*x + args[1]
8+
9+
# this will the least square against two numpy arrays
10+
def test_fit_lsq():
11+
x = np.linspace(0,10,10)
12+
y = np.zeros(10)
13+
for i in range(len(y)):
14+
y[i] = 2*x[i] + 2*random.random()
15+
m=pygrc.Fit(x, y, 1,1).fit_lsq(function,[(-1,10),(-2,10)],.1)
16+
assert math.fabs(m.values["x0"]-2.0) < 0.1, \
17+
"Least Square x0 parameter does not converge to true value"
18+
assert math.fabs(m.values["x1"]-1.0) < 1., \
19+
"Least Square x1 parameter does not converge to true value"

0 commit comments

Comments
 (0)