Source code for haslib.elas_class

# -*- coding: utf-8 -*-
# elas_class.py
#
# Class definition for an object that should hold all information of an
# elastic measurement run
#
# Patrick Kraus
# 29.2.2012

import matplotlib.pyplot as plt
from io import StringIO
import numpy as np


[docs]class Elastics(object): # ----------------------------------------------------------------- # ---------------------- INITIALROUTINE --------------------------- # ----------------------------------------------------------------- def __init__(self, G1, G2, DATA, TN=75.0, specpos=None, scandir=1): """ Elastics Object - storing the full information of an elastic measurement run Start parameters: G1, G2 ... reciprocal direction of the Measurement DATA ... Name and adress of the outputfile TN ... Default Nozzle Tenmperature (old-style files), default 75.0 K specpos ... define position of specular by hand; default: Max is set to specular pos scandir ... def. of incident angle, Cambridge apparatus: 1 (default), Graz apparatus: -1 """ # Storage of the initial Parameters self.G = np.array([G1, G2]) # Reading the handed file self.file = DATA # Variable Declaration self.angtot = None self.angsteps = None self.thet_start = None self.stepT = None self.TN = None self.TS = None MEAS = np.array([0, 0, 0, 0]) # Variablemap dictionary variable_dict = {'measurement angle': 'angtot', 'number of total steps': 'angsteps', 'startposition of thetastepper': 'thet_start', 'meas-time per point': 'stepT', 'nozzle temperature in K': 'TN', 'sample temperature in °C': 'TS'} # First read the Haeder HEAD = True with open(self.file, encoding='utf-8') as myfile: for line in myfile: if HEAD: arg = line[line.find('[') + 1:line.find(']')] if line.find('[') >= 0: if arg in variable_dict: setattr(self, variable_dict[arg], float(line[line.find(']') + 1:-1])) if arg == "EOH": # Reached end of Header, set flag HEAD = False else: MEAS = np.vstack([MEAS, np.loadtxt(StringIO(line))]) # Eliminate first row MEAS = MEAS[1::] # Split the data stored in MEAS self.counts = MEAS[:, 0] self.time = MEAS[:, 1] self.cps = MEAS[:, 2] self.theta_orig = MEAS[:, 3] # Auto-correct apparative errors # abst = self.theta_orig[1] - self.theta_orig[0] # if int(abst) == 0: # abst = self.theta_orig[2] - self.theta_orig[1] # self.theta_orig = self.theta_orig[0] + # abst * arange(self.theta_orig.size) # Determine if TN is set now, setting default value if self.TN is None: print("WARNING! No Nozzle Temperature information - set to 75.0 K") self.TN = TN # recalculate the angle if specpos is None: dummy = self.theta_orig[self.cps.argmax()] else: dummy = specpos # defnition of theta_i according to the apparatus angle # scandir = -1 for the Graz machine and +1 for the Cambridge machine self.theta = scandir*np.array(self.theta_orig - dummy) # ----------------------------------------------------------------- # ----------------------------------------------------------------- # ----------------------------------------------------------------- # ----------------------------------------------------------------- # ---------------------- ACCESS ROUTINES -------------------------- # -----------------------------------------------------------------
[docs] def plotit(self, zoom=1.0): elasfig = plt.figure() elasax = elasfig.add_subplot(111) elasax.semilogy(self.theta, self.cps / zoom, 'k') plt.title(self.file) elasax.set_xlabel('Incident Angle relative to specular / Degrees') elasax.set_ylabel('Measured Intensity / cps') elasax.set_xlim([self.theta.min(), self.theta.max()]) plt.grid(True) plt.show() return elasfig
[docs] def corr_TN(self, Tnew): self.TN = Tnew
# ----------------------------------------------------------------- # ----------------------------------------------------------------- # -----------------------------------------------------------------