Skip to content

Latest commit

History

34 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

pyplotfit

dependencies / used modules

  • matplotlib.pyplot
  • matplotlib.patches
  • numpy
  • math
  • scipy
  • inspect

HOW-TO

read datas

First of all reading your Dataset. According to our experiment, we designed a method for reading the output file of an Gamma-Ray-Detektor. Feel free to add or change other reading functions in datasetfunctions.py.

dataset=datasetfunctions.readfile("EU152.Spe")

The output of readfile(filename) is an dictionary.

dataset= { 'name': filename.split('.')[0], 'time': int(measuretime), 'channel': channel, 'counts': counts }

realize plot

In the next step you are able to create an Plot()-, Scatter()- or Errorbar()-Object. The only required parameters are the datas for x and y. For example:

plot=plot.Errorbar(X, Y)

All other parameters are not required or there are default settings. In depends on the chosen plot style you are able to set ... (with default values)

Plot(
x: list (required)
y: list (required)
dataLabel=None: straxisLabel=None: listxAxis=None: listlineType="--": strlineColor="blue": strgrid=True: boolextraLegendComponent=None: str
)
Scatter(
x: list (required)
y: list (required)
dataLabel=None: straxisLabel=None: listxAxis=None: listlineType="--": strlineColor="blue": strgrid=True: boolextraLegendComponent=None: strmarker=None: stredgecolors=None: strlinewidths=None: str
)
Errorbar(
x: list (required)
y: list (required)
dataLabel=None: straxisLabel=None: listxAxis=None: listlineType="--": strlineColor="blue": strgrid=True: boolextraLegendComponent=None: stryerr=None: list (samedimensionlikeyrequired)
xerr=None: list (samedimensionlikexrequired) elinewidth=1.5: floatmarkersize=5: floatecolor="lightgray": strfmt="x": str
)

add fits

If you want, you can add fits to an specific area. Therefore you create an fit() object.

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.

Listofallkeynumbersofavailablefits:
1: doublegaussianwithlinearunderground2: exp3: gaussianwithlinearunderground4: 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

importsrc.datasetfunctionsasdsfimportsrc.fitasfitimportsrc.plotasplotif__name__=='__main__':
# read your file and set x and ydataset=dsf.readSpeFile("Sichel-Tanne.Spe")
X, Y=dataset["channel"], dataset["counts"]
# change scale and calculate statistical errorX=dsf.calibrate_dataSets(X, [0.39, 18.62])
yerr=dsf.calculatestatisticalerrors(Y)
# create plot objectplot=plot.Errorbar(X, Y, xAxis=[625, 700], axisLabel=["Ereignisse N", "Energie E [keV]"], ecolor="grey")
plot.setDataLabel("Energiekalibrierung")
# create fit objectGaussFit=fit.Fit(plot, X, Y, 3, upperLimit=670, lowerLimit=650, initialGuesses=[1000, 660, 1, 1, 1])
# show everything you doneplot.showPlot()

exampleFit Console output:

Calculatedfit-params:
c1=1012.3287915580813withstandarddeviation+/-8.20387656143891mu1=661.0887096784303withstandarddeviation+/-0.011160440691047291sigma1=1.2134294338415335withstandarddeviation+/-0.011929200090804748a=-0.2220767579949974withstandarddeviation+/-0.3694342003581278b=155.6003162319009withstandarddeviation+/-243.63893229660619

About

A small Python script that allows easy display of measurement data. Furthermore, with predefined objects and fit functions, it is possible to fit selected value ranges with the help of functions. The design is based on the fact that the project can easily be supplemented with further fit functions and various methods for reading in data sets.

Topics

Resources

Security policy

Stars

1 star

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages