Skip to content

Commit

Permalink
finalize praktikum
Browse files Browse the repository at this point in the history
  • Loading branch information
binkertpat committed Feb 17, 2022
1 parent 711fa70 commit 2c6cbde
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 87 deletions.

This file was deleted.

This file was deleted.

33 changes: 15 additions & 18 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 49 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,54 @@ Errorbar(
```
### add fits

If you want, you can add fits to an specific area. Therefore you create an <code>fit()</code> object.
```python
GaussFit = fit.Fit(plot, X, Y, 3, upperLimit=670, lowerLimit=650, initialGuesses=[1000, 660, 1, 1, 1])
```
Required Arguments are the plot object, the x- and y-datas and the fit index. All avaible fits will be printed in the console with the current index.
```python
List of all key numbers of available fits:
1: doublegaussianwithlinearunderground
2: exp
3: gaussianwithlinearunderground
4: linear
```
Not required arguments are upper- and lower limits for the fit area and the initial guesses. But maybe the fit wont show if you dont set them.

# Example
```python
import src.datasetfunctions as dsf
import src.fit as fit
import src.plot as plot

if __name__ == '__main__':

# read your file and set x and y
dataset = dsf.readSpeFile("Sichel-Tanne.Spe")
X, Y = dataset["channel"], dataset["counts"]

# change scale and calculate statistical error
X = dsf.calibrate_dataSets(X, [0.39, 18.62])
yerr = dsf.calculatestatisticalerrors(Y)

# create plot object
plot = plot.Errorbar(X, Y, xAxis=[625, 700], axisLabel=["Ereignisse N", "Energie E [keV]"], ecolor="grey")
plot.setDataLabel("Energiekalibrierung")

# create fit object
GaussFit = fit.Fit(plot, X, Y, 3, upperLimit=670, lowerLimit=650, initialGuesses=[1000, 660, 1, 1, 1])

# show everything you done
plot.showPlot()
```
![exampleFit](img/examplefit.png)
Console output:
```python
Calculated fit-params:
c1 = 1012.3287915580813 with standard deviation +/- 8.20387656143891
mu1 = 661.0887096784303 with standard deviation +/- 0.011160440691047291
sigma1 = 1.2134294338415335 with standard deviation +/- 0.011929200090804748
a = -0.2220767579949974 with standard deviation +/- 0.3694342003581278
b = 155.6003162319009 with standard deviation +/- 243.63893229660619
```

## open TODOs
- Update functioncollection for more fit functions
- function for find index in sorted array for nearest given value
Binary file added img/energiekalibrierung_umgedreht.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/examplefit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 6 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

if __name__ == '__main__':

#dataset = dsf.readcvsv("energiekalibrierung.CSV")
#Y, X = dataset["x"], dataset["y"]

# read your file and set x and y
dataset = dsf.readSpeFile("Sichel-Tanne.Spe")
X, Y = dataset["channel"], dataset["counts"]
Expand All @@ -13,12 +16,11 @@
yerr = dsf.calculatestatisticalerrors(Y)

# create plot object
plot = plot.Errorbar(X, Y, xAxis=[2555, 2570], axisLabel=["Energie E [keV]", "Ereignisse N"], ecolor="grey",
yerr=yerr, extraLegendComponent="Messzeit: "+str(dataset["time"])+"s")
plot.setDataLabel("Sichel-Tanne")
plot = plot.Errorbar(X, Y, xAxis=[625, 700], axisLabel=["Ereignisse N", "Energie E [keV]"], ecolor="grey")
plot.setDataLabel("Energiekalibrierung")

# create fit object
GaussFit = fit.Fit(plot, X, Y, 3, initialGuesses=[12, 2562, 4, 1, 1], lowerLimit=2556, upperLimit=2568)
GaussFit = fit.Fit(plot, X, Y, 3, upperLimit=670, lowerLimit=650, initialGuesses=[1000, 660, 1, 1, 1])

# show everything you done
plot.showPlot()
4 changes: 2 additions & 2 deletions src/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ def getExtraLegendComponent(self):

def calculateYAxis(self):
"""scale y-axis according to max y-datas"""
self.yAxis["min"] = np.min(self.getyDatas()[datasetfunctions.getArrayIndexForNearestValue(self.getxDatas(), self.getxAxis()["min"]):datasetfunctions.getArrayIndexForNearestValue(self.getxDatas(), self.getxAxis()["max"])])
self.yAxis["max"] = np.max(self.getyDatas()[datasetfunctions.getArrayIndexForNearestValue(self.getxDatas(), self.getxAxis()["min"]):datasetfunctions.getArrayIndexForNearestValue(self.getxDatas(), self.getxAxis()["max"])]) * 1.1
self.yAxis["min"] = 0
self.yAxis["max"] = 1500

def generateAxisDefinition(self):
"""generate new axis-definition"""
Expand Down

0 comments on commit 2c6cbde

Please sign in to comment.