Commit 79faa039 authored by Zolnierczuk, Piotr's avatar Zolnierczuk, Piotr
Browse files

changed default normalization type for diffrun

now default is pcharge, one can select from pcharge, power and none
parent b022b990
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -99,7 +99,10 @@ PROTON_CHARGE_UNIT = 1e-7 # 0.1 micro Coulomb (NSE control program unit
DEFAULT_ACCELERATOR_FREQ   =   60.0 # Hz
DEFAULT_ACCELERATOR_POWER  =    1.4 # MW
DEFAULT_PROTON_ENERGY      = 1000.0 # MeV
PCHARGE_PER_SECOND        = DEFAULT_ACCELERATOR_POWER/DEFAULT_PROTON_ENERGY/PROTON_CHARGE_UNIT
DEFAULT_PCHARGE_PER_SECOND = DEFAULT_ACCELERATOR_POWER/DEFAULT_PROTON_ENERGY/PROTON_CHARGE_UNIT

def pcharge_per_second(power=DEFAULT_ACCELERATOR_POWER, energy=DEFAULT_PROTON_ENERGY):
    return power/energy/PROTON_CHARGE_UNIT

def tau_limits(lmax, mode='standard'):
    """ get instrument Fourier time limits in [ns]"""
+3 −1
Original line number Diff line number Diff line
@@ -373,7 +373,7 @@ def add_diffrun_options(subparser, parents=None):
                      aliases=['df',],
                      help='diffrun plot (diffraction scans)',
                      description='create diffraction scan plot(s)')
    pars.set_defaults(selection=None, power=DEFAULT_ACCELERATOR_POWER)
    pars.set_defaults(selection=None, power=DEFAULT_ACCELERATOR_POWER, norm_type='pcharge')
    pars.add_argument('file', metavar='filename', help='file to process', nargs='+')
    pars.add_argument('--up',      '-u', dest='selection', action='append_const', const='up',
                       help="plot 'up' counts")
@@ -393,6 +393,8 @@ def add_diffrun_options(subparser, parents=None):
                       help="plot in semilogy")
    pars.add_argument('--att', '-A', dest='att_table', action='store_true',
                       help="use attenuation table")
    pars.add_argument('--norm-type', dest='norm_type', choices=['pcharge', 'power', 'none'],
                       help='select normalization type (default: %(default)s)')

def add_transmission_options(subparser, parents=None):
    "transition options"
+17 −4
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ from matplotlib.colors import LogNorm
from scipy.spatial import ConvexHull

from ..constants import ANGSTROM
from ..config import PCHARGE_PER_SECOND, wavelength_bandwitdh
from ..config import pcharge_per_second, wavelength_bandwitdh
from ..inout  import read_datfile, read_diffrun, read_transmission, read_datreat


@@ -273,12 +273,18 @@ def plot_diffrun(axis, filenames, **kwargs):
    output    = kwargs.pop('output', None)
    power     = kwargs.pop('power',  1.4)
    use_att   = kwargs.pop('att_table', False)
    norm_type = kwargs.pop('norm_type', 'pcharge')

    log = logging.getLogger()

    title  = 'Diffraction Run Plot'
    out    = None
    cmap   = mpl.colormaps.get_cmap('hsv')
    default_ylabel = {'proton_charge'     : 'Count Rate [counts/pcharge]',
                      'pcharge'           : 'Count Rate [counts/pcharge]',
                      'accelerator_power' : 'Count Rate [counts/s] at %.1f MW' % power,
                      'power'             : 'Count Rate [counts/s] at %.1f MW' % power,
                     }.get(norm_type, 'Counts')

    if output:
        out = open(output, 'wb') #pylint: disable=consider-using-with
@@ -319,8 +325,14 @@ def plot_diffrun(axis, filenames, **kwargs):
        att1   = result[1::2, 4]*1.0 if use_att else np.ones_like(pc1)
        cnt1   = cnt[1::2]
        #
        fup  = att0/pc0*PCHARGE_PER_SECOND
        fdn  = att1/pc1*PCHARGE_PER_SECOND
        fup = 1.0
        fdn = 1.0
        if norm_type in ('power', 'accelerator_power'):
            fup  = att0/pc0*pcharge_per_second(power=power)
            fdn  = att1/pc1*pcharge_per_second(power=power)
        if norm_type in ('pcharge', 'proton_charge'):
            fup  = att0/pc0
            fdn  = att1/pc1
        cup  = cnt0*fup
        cdn  = cnt1*fdn
        ecup = sqrt(cnt0)*fup
@@ -386,7 +398,8 @@ def plot_diffrun(axis, filenames, **kwargs):
    if ylabel:
        axis.set_ylabel(ylabel)
    else:
        axis.set_ylabel('Count Rate [counts/s] at %.1f MW' % power)
        axis.set_ylabel(default_ylabel)

    #if axis1 is not None:
    #    axis1.set_yscale('log' if logscale else 'linear')
    #    axis1.legend(loc='best')
+2 −2
Original line number Diff line number Diff line
@@ -3,8 +3,8 @@ PySEN revision module
"""
import sys
__version__  = "1.3"
__release__  = "a4"
__date__     = "June 2, 2023"
__release__  = "b1"
__date__     = "June 20, 2023"

def version(full=False):
    "get pysen version number"