Commit 813945c4 authored by Zolnierczuk, Piotr's avatar Zolnierczuk, Piotr
Browse files

transmission plot bugfix

parent f162deab
Loading
Loading
Loading
Loading
+44 −0
Original line number Diff line number Diff line
#!/usr/bin/env python

import sys
import os.path
import shutil
import h5py
import numpy as np

filename = sys.argv[1]
cut_index = int(sys.argv[2])
basename = os.path.join('.', os.path.basename(filename))
print(basename, cut_index)

shutil.copy(filename, basename)

hf = h5py.File(basename, mode='r+')

scan_index = hf['/entry/DASlogs/scan_index']
si_values = scan_index['value']
si_times  = scan_index['time']
#
si_ave     = scan_index['average_value']
si_ave_err = scan_index['average_value_error']
si_min     = scan_index['minimum_value']
si_max     = scan_index['maximum_value']

si_values[:cut_index]=0
si_times [:cut_index]=0
for i,(t,v) in enumerate(zip(si_times [cut_index-10:cut_index+10],
                             si_values[cut_index-10:cut_index+10])):
    print(f"{i:8d}, {t:8.2f}, {v:8d}")

si_ave = np.average(si_values)    

scan_index['average_value'][0]        = np.average(si_values)
scan_index['average_value_error'][0]  = np.std(si_values)
scan_index['minimum_value'][0]        = np.min(si_values)
scan_index['maximum_value'][0]        = np.max(si_values)
scan_index['value'][:] = si_values[:]
scan_index['time'][:]  = si_times[:]

hf.close()

+25 −0
Original line number Diff line number Diff line
#!/usr/bin/env python

import sys
import os.path
import shutil
import h5py
import numpy as np

filename  = sys.argv[1]
new_title = sys.argv[2]
basename = os.path.join('.', os.path.basename(filename))

shutil.copy(filename, basename)

hf = h5py.File(basename, mode='r+')

old_title = hf['/entry/title'][0].decode('ascii')
hf['/entry/title'][0] = new_title.encode('ascii')
print(basename)
print(old_title)
print(new_title)

hf.close()

+5 −5
Original line number Diff line number Diff line
@@ -432,7 +432,7 @@ def plot_transmission_single(axs, filename, **kwargs):
    counts  = np.asarray(data["detector array"])
    ecounts = sqrt(counts)
    lmax    = data['wavelength']/ANGSTROM
    sample  = data.get('sample', '')
    sample  = data.get('sample', '').lstrip('_') # remove leading '_'
    proposal = data.get('proposal')
    try:
        prop = proposal.split()
@@ -481,9 +481,9 @@ def plot_transmission(ax0, ax1, filenames, **kwargs):
    ax0.set_ylabel('Counts/PCharge')
    ax0.grid(True)
    if len(filenames)>5:
        ax0.legend(ncol=2)
        ax0.legend(ncol=2, loc=0)
    else:
        ax0.legend()
        ax0.legend(loc=0)

    if spectrum_only:
        ax0.set_xlabel(r'Neutron Wavelength [$\AA$]')
@@ -503,7 +503,7 @@ def plot_transmission(ax0, ax1, filenames, **kwargs):
        ax1.errorbar(w, tfac, yerr=efac, fmt='.', color=color, ms=0.01, lw=1.0)
        if polyfit is None:
            ax1.axhline(tavg, color=color, ls='--', lw=0.5)
            out.write("%-20.20s %.4g +/- %.4g\n" % (s, tavg, etavg))
            out.write("%-32.32s %.4g +/- %.4g\n" % (s, tavg, etavg))
        else:
            a = np.polyfit(w, tfac, deg=polyfit)
            ax1.plot(w, np.polyval(a,w), '--',lw=0.5, color=color)
@@ -636,7 +636,7 @@ def action_transmission(filenames, **kwargs):
                outfiles = convert_files(filename, outdir='.', converter='to_taco')
                new_filenames.extend(outfiles)
            elif filetype == 'application/taco-nse-transmission':
                new_filenames.append(outfiles)
                new_filenames.append(filename)
            else:
                log.warning("File %s is not a transmission file", filename)
                continue
+2 −2
Original line number Diff line number Diff line
@@ -3,8 +3,8 @@ PySEN revision module
"""
import sys
__version__  = "2.1"
__release__  = "b4"
__date__     = "Apr 2, 2025"
__release__  = "b5"
__date__     = "Apr 15, 2025"

def version(full=False):
    "get pysen version number"
+11395 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading