GithubHelp home page GithubHelp logo

oyvsyo / moed_task1 Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 59 KB

Phisical spectrum modulation program on python and ROOT

Home Page: https://oyvsyo.github.io/moed_task1/

License: GNU General Public License v3.0

Python 100.00%
peak spectrum simulation python fwhm peak-parameters

moed_task1's Introduction

Task1

Task1 is the open source project for spectrum modulation designed by Dvoiak Stepan,
Kiev National University student for MOED course.
This program can modulate peaks, compton and background by parameters.

The code and this instruction also available at project site

Getting Started

Clone this repo to your local machine:

$ git clone https://github.com/oyvsyo/moed_task1.git

To start nodulation jus run this command in terminal (bash shell or mac shell) in project directory:

$ python2 task1.py

You will see two windows (left - for config window, rigth - for drawing spectrums).
In config window you can set parameters of spectrums, load configurations, save configuration, save spectrums in txt file and eps pictures.

Default parameters

To draw simple default specters just press red button Draw.
You got spectrums on canvas (drawing window)
If you want to clear all entries - press pink button Clear All.
If you want to set defaul parameters again - press Default button.

Your own configuration

The best way to set you own spectrum parameters - it's change defaul!
All rules and sintaxys diclarated in next paragraf.

Also, you can write config file manualy (syntaxis - like json
or standart python dict)
To load your file - simply open menu File->Open config

The rules of config file

Concept of config file is python dict - structure of "key": "value"
pairs. There are 6 keys of parameters:

  • interval - the python list of two values: minimum and maximum
    of Energy range of investigated spectrum [Emin, Emax] (unsigned float)
  • num_bin - number channels (unsigned interer)
  • peaks - it's a python list of three dimentional lists with peaks
    parameters values [Intensity(1/s), Energy(keV), FWMH(keV)] (unsigned float)
  • opt1 - optional chose for FWHM simulation (integer 1 or 0), if 0 - FWHM gets
    from last peak parameters, if 1 - FWHM is calculated by formula: a0+a1*sqrt(E)
  • FWHM_pars - the parameters of FWHM formula [a0, a1] (float numbers)
  • background - parameters of background simulation formula:
    a*exp(b* E) + c+d* E (float numbers)

Notice! Its not recomendet to set num_bin parameter over 1000.
Calculating can take too much time (4 seconds on my computer).
Operations numbers increase like (num_bin)^2 times.

Also you can comment some text with "<" and ">" symbols like:
<comment here>.

Notice! You can't use "<" and ">" symbols inside comment.

An example of default confuguration file:

<spectrum simulation>
<config file example>
<after square brackets "[..]" always put ",">
<all parameters must be set>
{
    <Energy(keV) range - must be positive:>
    'interval': [50, 3000],
    <number of bins (put "," after bin number value):>
    <must be positive int number>
    'num_bin': 300,

    <peaks parameters sets in square brackets>
    <in defined order: [Intensity(1/s), Energy(keV), FWMH(keV)]>
    <peaks parameters must be positive>
    'peaks':[
        [15000, 2000.89, 150.8],
        [14000, 1400.5, 135.0],
        [13000, 1000, 131.0],
        [17000, 1200, 75.0],
        [12000, 2999, 50.0],
    ],

    <optional chose for FWMH simulation>
    < 0 - FWMH is set from peak parameters>
    < 1 - calculating by formula: FWHM = a0+a1*sqrt(E)>
    <after opt1 value put ",">
    "opt1": 1,

    <set the FWMH params for formula FWHM = a0+a1*sqrt(E)>
    <if opt1=1 [a0, a1]:>
    "FWHM_pars": [0.5, 1],

    <background parameters [a, b, c, d] : a*exp(b*E) + c+d*E>
    <parameter 'a' must be positive>
    'background': [40, -0.01, 50, -0.005],
}

Notice! The config file must have .txt exestention

Using GUI

The main logic based on config file syntax.
The simplest way - just edit default parameters!

To set parameters with GUI you need to know some rules:

  1. All entries are required.
  2. Enter the vaule of "key":"value" pairs from config file.
  3. If key value is list - write parameters in list format (like [a, b, c]).
  4. For FWMH simulation by formula: FWHM = a0+a1*sqrt(E) just check
    FWHM optin calculate checkbuttun
  5. Other parameters sets like vaule vor keys in config file dict.

Notice! GUI does not support comments.

Example for peak entry:

[[14000, 2700.89, 110.8]
 [16000, 700.5, 135.0]
 [17000, 1600, 75.0]]

Ntice: for peaks its not nessecery to write "," after "]"

To save your comfiguration press File->Save config as..
and enter name.

Saving results of simulation

To save a pictures and .txt files of simulated spectrum press
File->Save output to.. and write a path to directory that
will be created for yuor output files (dir name - name_out).
You can find 4 eps pictures and 4 txt spectrum files. (txt files - its two columns of float numbers - first - energy, second - counts).

Requirments

This software is require python 2.7* versions, some standart for ubuntu 14.04 python librarys:

  • math
  • re
  • os
  • ast
  • sys
  • Tkinter
  • tkFileDialog
  • tkMessageBox

There are one non standart library:

  • numpy 1.8.2

And tha main core of simulation - ROOT.

Notice! For using this program you must have ROOT classes avaliable in python scope. Read more about PyRoot

Notice! ROOT 5.* versions are required (probably must works on 6.* versions, but not tested)

Tested on ubuntu 14.04 whith python 2.7.6 and ROOT 5.34/36, gcc 4.8.4

Authors

Dvoiak Stepan - oyvsyo

License

This project is licensed under the GNU GENERAL PUBLIC LICENSE - see the LICENSE file for details

moed_task1's People

Contributors

oyvsyo avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.