In [1]:
from lib import transient
from imp import reload
# reload(transient)

import os
import numpy as np

import matplotlib.pyplot as plt
import matplotlib.colors as colors
import matplotlib.colorbar as colorbar
import matplotlib.cm as cmx
from mpl_toolkits.axes_grid1 import make_axes_locatable


from scipy.optimize import curve_fit 

import pandas as pd

In [2]:
filepath = 'E:/data/RuCl3/mat/kerr_rotation/fluence_3.8K/'
files = os.listdir(filepath)

cutFreq = 0.01 # THz
t0 = 85
pump_spot = 80
probe_spot = 50

key_parameter = 'pump_energy'
description = ''

usebg = False
trs = []
k_parameters = []
data = {}
parameters = {}

if 'background.mat' in files:
    bg_trace = transient.Transient()
    bg_trace.import_file(filepath + 'background.mat', 
                           cleanData=False, 
                           key_parameter=key_parameter,description=description)
    files.remove('background.mat')
    bg_trace.crop_time_scale()
    bg_trace.shift_time(t0)
    bg_trace.filter_low_pass(cutFreq)
#     tr.flip_trace()
    bg_trace.remove_DC_offset()
    bg_trace.flip_time()
    usebg = True
    
for file in files:
    try:

        tr = transient.Transient()
        tr.import_file(filepath + file, 
                           cleanData=False, 
                           key_parameter=key_parameter,description=description)
        tr.pump_spot = pump_spot
        tr.probe_spot = probe_spot
        tr.calc_energy_densities()
        tr.crop_time_scale()
        tr.shift_time(t0)
        tr.filter_low_pass(cutFreq)
    #     tr.flip_trace()
        tr.remove_DC_offset()
        tr.flip_time()
        # save parameters
        trParameters = tr.get_metadata()
        for key, val in trParameters.items():
            try:
                parameters[key].append(val)
            except KeyError:
                parameters[key] = [val]
        analysis_log = parameters.pop('analysis_log')
        if usebg:
            tr.trace = tr.trace - bg_trace.trace
        k_parameters.append(float(getattr(tr,key_parameter)))

        data[getattr(tr,key_parameter)] = tr.trace       
    
#        tr.trace = np.divide(tr.trace,max(tr.trace))
    #     tr.trace = np.divide(tr.trace,tr.pump_power)
    except Exception as exc:
        print('skipped file: {0}\nerror: {1}'.format(file,exc))
data = pd.DataFrame(data,index=tr.time)
print(data)
parameter_dataframe = pd.DataFrame(parameters, index = k_parameters)
analysis_log_dataframe = pd.DataFrame(analysis_log, index = k_parameters)
print(parameter_dataframe)
# for key, val in parameters.items():
#     print(str(key) + ': ')
#     print(val)

print('Imported {0} scan(s) as {1} dependence'.format(len(trs),tr.key_parameter))
data.plot(colormap='rainbow')


background.mat
Ru3Cl-Pu-0.005-pr-0.2-1kAVG-T-3.8K-kerr.mat
0.001
0.072
Ru3Cl-Pu-0.01-pr-0.2-1kAVG-T-3.8K-kerr.mat
0.001
0.072
Ru3Cl-Pu-0.02-pr-0.2-1kAVG-T-3.8K-kerr.mat
0.003
0.072
Ru3Cl-Pu-0.04-pr-0.2-1kAVG-T-3.8K-kerr.mat
0.006
0.072
Ru3Cl-Pu-0.08-pr-0.2-1kAVG-T-3.8K-kerr.mat
0.011
0.072
Ru3Cl-Pu-0.16-pr-0.2-1kAVG-T-3.8K-kerr.mat
0.022
0.072
Ru3Cl-Pu-0.32-pr-0.2-1kAVG-T-3.8K-kerr.mat
0.045
0.072
Ru3Cl-Pu-0.64-pr-0.2-1kAVG-T-3.8K-kerr.mat
0.09
0.072
Ru3Cl-Pu-1.2-pr-0.2-1kAVG-T-3.8K-kerr.mat
0.169
0.072
Ru3Cl-Pu-2.4-pr-0.2-1kAVG-T-3.8K-kerr.mat
0.337
0.072
Ru3Cl-Pu-4.8-pr-0.2-1kAVG-T-3.8K-kerr.mat
0.675
0.072
                   0.001         0.003         0.006         0.011  \
-6.300199   3.073390e-06  1.333444e-06 -8.752352e-07 -2.021428e-06   
-6.300183   2.996535e-06  1.363688e-06 -8.637341e-07 -2.047098e-06   
-6.300157   2.857641e-06  1.403662e-06 -9.263910e-07 -2.116642e-06   
-6.300118   2.655707e-06  1.402789e-06 -1.105271e-06 -2.247647e-06   
-6.300069   2.456185e-06  1.357741e-06 -1.325792e-06 -2.351150e-06   
-6.300008   2.234746e-06  1.136935e-06 -1.585247e-06 -2.533800e-06   
-6.299936   1.923880e-06  7.661117e-07 -1.874191e-06 -2.878808e-06   
-6.299852   1.631408e-06  4.543740e-07 -2.031219e-06 -3.235262e-06   
-6.299757   1.463869e-06  2.616901e-07 -1.982017e-06 -3.424250e-06   
-6.299651   1.274178e-06  1.602839e-07 -1.858330e-06 -3.448460e-06   
-6.299533   9.108981e-07  1.139141e-07 -1.733651e-06 -3.367721e-06   
-6.299405   4.691837e-07  1.148497e-07 -1.628175e-06 -3.152260e-06   
-6.299264   1.410306e-07  1.521745e-07 -1.553547e-06 -2.799703e-06   
-6.299113  -3.123967e-08  1.115285e-07 -1.487249e-06 -2.389642e-06   
-6.298950  -1.874457e-07  6.016876e-08 -1.434510e-06 -2.021960e-06   
-6.298775  -2.875943e-07  1.660159e-07 -1.284493e-06 -1.698193e-06   
-6.298590  -2.150287e-07  3.900902e-07 -9.341708e-07 -1.328826e-06   
-6.298393  -1.217449e-07  6.533483e-07 -4.068166e-07 -8.930638e-07   
-6.298184  -9.321990e-08  8.480511e-07  2.342170e-07 -4.561661e-07   
-6.297965  -6.677524e-08  9.367300e-07  7.742917e-07 -1.010688e-07   
-6.297734  -3.907398e-08  1.015301e-06  1.116067e-06  2.253762e-07   
-6.297491  -1.172021e-07  9.895606e-07  1.368395e-06  5.855582e-07   
-6.297238  -4.042059e-07  8.351415e-07  1.539430e-06  8.548754e-07   
-6.296973  -6.324193e-07  7.110713e-07  1.688464e-06  1.038489e-06   
-6.296696  -6.170976e-07  5.767433e-07  1.843029e-06  1.267322e-06   
-6.296409  -6.341198e-07  4.087622e-07  1.911052e-06  1.554489e-06   
-6.296109  -7.252132e-07  3.138316e-07  1.912099e-06  1.841343e-06   
-6.295799  -7.402500e-07  3.152738e-07  1.878386e-06  2.093705e-06   
-6.295477  -6.558476e-07  3.486081e-07  1.862961e-06  2.407389e-06   
-6.295144  -5.612942e-07  2.488204e-07  1.851938e-06  2.759254e-06   
...                  ...           ...           ...           ...   
 85.803973  1.014874e-03  1.973478e-03  4.259659e-03  6.989322e-03   
 85.804291  1.015401e-03  1.973665e-03  4.259541e-03  6.989146e-03   
 85.804598  1.015747e-03  1.973836e-03  4.259366e-03  6.988806e-03   
 85.804893  1.015920e-03  1.973894e-03  4.259162e-03  6.988419e-03   
 85.805177  1.015951e-03  1.973914e-03  4.258928e-03  6.988127e-03   
 85.805450  1.015962e-03  1.973965e-03  4.258582e-03  6.987912e-03   
 85.805711  1.016130e-03  1.974152e-03  4.258221e-03  6.987839e-03   
 85.805961  1.016412e-03  1.974493e-03  4.258003e-03  6.987880e-03   
 85.806200  1.016607e-03  1.974839e-03  4.257878e-03  6.987880e-03   
 85.806427  1.016779e-03  1.975239e-03  4.257842e-03  6.987841e-03   
 85.806643  1.017007e-03  1.975754e-03  4.257966e-03  6.987789e-03   
 85.806848  1.017154e-03  1.976175e-03  4.258150e-03  6.987729e-03   
 85.807041  1.017110e-03  1.976422e-03  4.258313e-03  6.987673e-03   
 85.807223  1.016896e-03  1.976586e-03  4.258430e-03  6.987574e-03   
 85.807394  1.016659e-03  1.976718e-03  4.258500e-03  6.987458e-03   
 85.807553  1.016493e-03  1.976875e-03  4.258627e-03  6.987395e-03   
 85.807701  1.016343e-03  1.977021e-03  4.258872e-03  6.987353e-03   
 85.807837  1.016192e-03  1.977207e-03  4.259176e-03  6.987310e-03   
 85.807963  1.016100e-03  1.977424e-03  4.259387e-03  6.987211e-03   
 85.808076  1.016065e-03  1.977496e-03  4.259456e-03  6.987022e-03   
 85.808179  1.016010e-03  1.977518e-03  4.259496e-03  6.986844e-03   
 85.808270  1.015936e-03  1.977577e-03  4.259536e-03  6.986756e-03   
 85.808350  1.015857e-03  1.977643e-03  4.259524e-03  6.986753e-03   
 85.808419  1.015775e-03  1.977683e-03  4.259506e-03  6.986842e-03   
 85.808476  1.015765e-03  1.977606e-03  4.259559e-03  6.987009e-03   
 85.808522  1.015868e-03  1.977621e-03  4.259715e-03  6.987251e-03   
 85.808556  1.016053e-03  1.977847e-03  4.259956e-03  6.987588e-03   
 85.808579  1.016237e-03  1.978138e-03  4.260241e-03  6.988005e-03   
 85.808591  1.016351e-03  1.978479e-03  4.260547e-03  6.988408e-03   
 85.808591  1.016382e-03  1.978783e-03  4.260790e-03  6.988669e-03   

                   0.022         0.045         0.090         0.169  \
-6.300199  -5.412746e-06  3.644082e-06 -4.106907e-06  3.986486e-06   
-6.300183  -5.304490e-06  3.671553e-06 -3.985785e-06  4.109303e-06   
-6.300157  -5.197042e-06  3.605153e-06 -3.993888e-06  4.185690e-06   
-6.300118  -5.177731e-06  3.414350e-06 -4.068363e-06  4.138432e-06   
-6.300069  -5.204743e-06  3.091837e-06 -4.116018e-06  3.999495e-06   
-6.300008  -5.212122e-06  2.708268e-06 -4.357330e-06  3.616368e-06   
-6.299936  -5.210905e-06  2.368274e-06 -4.711083e-06  3.053688e-06   
-6.299852  -5.124161e-06  2.053394e-06 -4.998700e-06  2.599042e-06   
-6.299757  -4.847424e-06  1.822338e-06 -5.132964e-06  2.317061e-06   
-6.299651  -4.490802e-06  1.641262e-06 -5.112912e-06  2.071121e-06   
-6.299533  -4.144590e-06  1.413458e-06 -5.098680e-06  1.738180e-06   
-6.299405  -3.770589e-06  1.209175e-06 -4.976449e-06  1.369311e-06   
-6.299264  -3.346833e-06  9.810739e-07 -4.629375e-06  1.076050e-06   
-6.299113  -2.828369e-06  7.248813e-07 -4.258772e-06  7.545203e-07   
-6.298950  -2.326853e-06  4.874246e-07 -3.972085e-06  3.745866e-07   
-6.298775  -1.891788e-06  2.209868e-07 -3.705060e-06  1.003979e-07   
-6.298590  -1.344923e-06  7.108937e-08 -3.256077e-06 -1.519713e-08   
-6.298393  -7.050284e-07  7.967008e-08 -2.543746e-06 -3.972591e-08   
-6.298184  -1.189073e-07  1.015050e-07 -1.777071e-06 -1.094348e-07   
-6.297965   3.554989e-07  6.707298e-08 -1.012193e-06 -1.936980e-07   
-6.297734   7.730734e-07 -8.744763e-08 -2.327678e-07 -1.976120e-07   
-6.297491   1.224731e-06 -3.099423e-07  4.696263e-07 -3.005681e-07   
-6.297238   1.630297e-06 -5.781794e-07  1.064852e-06 -5.695912e-07   
-6.296973   2.030366e-06 -8.860207e-07  1.602950e-06 -7.669995e-07   
-6.296696   2.546676e-06 -1.097604e-06  2.172877e-06 -8.005293e-07   
-6.296409   3.048085e-06 -1.266180e-06  2.722624e-06 -7.870550e-07   
-6.296109   3.456319e-06 -1.439813e-06  3.187642e-06 -8.051254e-07   
-6.295799   3.777231e-06 -1.565008e-06  3.685502e-06 -8.345718e-07   
-6.295477   4.061684e-06 -1.663663e-06  4.180309e-06 -9.010457e-07   
-6.295144   4.341628e-06 -1.735754e-06  4.532473e-06 -1.140610e-06   
...                  ...           ...           ...           ...   
 85.803973  8.630301e-03  8.741056e-03  2.195783e-04 -8.359020e-05   
 85.804291  8.630656e-03  8.741095e-03  2.194184e-04 -8.318087e-05   
 85.804598  8.630894e-03  8.740982e-03  2.191478e-04 -8.284953e-05   
 85.804893  8.631133e-03  8.740706e-03  2.189708e-04 -8.246675e-05   
 85.805177  8.631451e-03  8.740386e-03  2.189521e-04 -8.211571e-05   
 85.805450  8.631779e-03  8.740094e-03  2.188365e-04 -8.195088e-05   
 85.805711  8.632241e-03  8.739904e-03  2.187034e-04 -8.178777e-05   
 85.805961  8.632897e-03  8.739713e-03  2.186175e-04 -8.144029e-05   
 85.806200  8.633557e-03  8.739517e-03  2.184588e-04 -8.115311e-05   
 85.806427  8.634152e-03  8.739424e-03  2.182289e-04 -8.096277e-05   
 85.806643  8.634693e-03  8.739347e-03  2.179060e-04 -8.068629e-05   
 85.806848  8.635184e-03  8.739200e-03  2.175466e-04 -8.038345e-05   
 85.807041  8.635693e-03  8.738989e-03  2.171846e-04 -8.021427e-05   
 85.807223  8.636172e-03  8.738778e-03  2.166684e-04 -8.027817e-05   
 85.807394  8.636588e-03  8.738616e-03  2.160320e-04 -8.035046e-05   
 85.807553  8.637075e-03  8.738451e-03  2.154441e-04 -8.013939e-05   
 85.807701  8.637643e-03  8.738358e-03  2.149423e-04 -7.981722e-05   
 85.807837  8.638105e-03  8.738378e-03  2.145172e-04 -7.962257e-05   
 85.807963  8.638375e-03  8.738317e-03  2.140462e-04 -7.949111e-05   
 85.808076  8.638624e-03  8.738144e-03  2.135275e-04 -7.932357e-05   
 85.808179  8.638993e-03  8.738011e-03  2.130509e-04 -7.904141e-05   
 85.808270  8.639418e-03  8.738040e-03  2.125608e-04 -7.859944e-05   
 85.808350  8.639867e-03  8.738168e-03  2.121682e-04 -7.804183e-05   
 85.808419  8.640380e-03  8.738215e-03  2.119774e-04 -7.744339e-05   
 85.808476  8.640879e-03  8.738282e-03  2.118808e-04 -7.692860e-05   
 85.808522  8.641235e-03  8.738464e-03  2.118125e-04 -7.652439e-05   
 85.808556  8.641465e-03  8.738640e-03  2.117861e-04 -7.619766e-05   
 85.808579  8.641691e-03  8.738787e-03  2.119562e-04 -7.588369e-05   
 85.808591  8.641885e-03  8.738895e-03  2.123041e-04 -7.550518e-05   
 85.808591  8.641948e-03  8.738962e-03  2.124999e-04 -7.521428e-05   

                   0.337         0.675  
-6.300199  -1.344040e-06  9.411200e-07  
-6.300183  -1.219029e-06  1.053517e-06  
-6.300157  -1.307233e-06  1.127807e-06  
-6.300118  -1.547845e-06  1.117473e-06  
-6.300069  -1.714944e-06  1.090824e-06  
-6.300008  -1.943575e-06  9.260562e-07  
-6.299936  -2.372120e-06  5.307418e-07  
-6.299852  -2.825814e-06  2.797790e-07  
-6.299757  -3.011468e-06  3.699935e-07  
-6.299651  -2.967286e-06  4.777539e-07  
-6.299533  -2.976612e-06  4.417936e-07  
-6.299405  -3.020575e-06  3.477009e-07  
-6.299264  -2.935372e-06  2.998722e-07  
-6.299113  -2.717775e-06  2.375286e-07  
-6.298950  -2.501178e-06 -9.515957e-09  
-6.298775  -2.282265e-06 -2.778665e-07  
-6.298590  -1.879050e-06 -3.661565e-07  
-6.298393  -1.380402e-06 -3.569773e-07  
-6.298184  -9.880990e-07 -3.671330e-07  
-6.297965  -6.603455e-07 -4.426592e-07  
-6.297734  -2.734582e-07 -5.134401e-07  
-6.297491   1.391042e-07 -6.337051e-07  
-6.297238   4.327720e-07 -9.050680e-07  
-6.296973   6.580288e-07 -1.073652e-06  
-6.296696   1.015968e-06 -9.745730e-07  
-6.296409   1.482670e-06 -7.650072e-07  
-6.296109   1.878968e-06 -5.610933e-07  
-6.295799   2.230175e-06 -3.969902e-07  
-6.295477   2.608280e-06 -2.205317e-07  
-6.295144   2.890189e-06 -1.026189e-07  
...                  ...           ...  
 85.803973  9.077022e-04  1.846246e-03  
 85.804291  9.076799e-04  1.845841e-03  
 85.804598  9.075388e-04  1.845302e-03  
 85.804893  9.074560e-04  1.844958e-03  
 85.805177  9.074560e-04  1.844830e-03  
 85.805450  9.073425e-04  1.844735e-03  
 85.805711  9.071917e-04  1.844710e-03  
 85.805961  9.071968e-04  1.844810e-03  
 85.806200  9.072536e-04  1.844869e-03  
 85.806427  9.072597e-04  1.844766e-03  
 85.806643  9.072033e-04  1.844612e-03  
 85.806848  9.071729e-04  1.844524e-03  
 85.807041  9.072276e-04  1.844403e-03  
 85.807223  9.071752e-04  1.844085e-03  
 85.807394  9.070114e-04  1.843715e-03  
 85.807553  9.069665e-04  1.843521e-03  
 85.807701  9.069910e-04  1.843367e-03  
 85.807837  9.069154e-04  1.843052e-03  
 85.807963  9.067464e-04  1.842702e-03  
 85.808076  9.066060e-04  1.842471e-03  
 85.808179  9.065197e-04  1.842344e-03  
 85.808270  9.063755e-04  1.842269e-03  
 85.808350  9.062741e-04  1.842207e-03  
 85.808419  9.063934e-04  1.842243e-03  
 85.808476  9.066280e-04  1.842360e-03  
 85.808522  9.068430e-04  1.842369e-03  
 85.808556  9.070207e-04  1.842301e-03  
 85.808579  9.072518e-04  1.842345e-03  
 85.808591  9.075741e-04  1.842504e-03  
 85.808591  9.077710e-04  1.842620e-03  

[6331 rows x 10 columns]
        R0                 date description key_parameter material  \
0.001  1.0  2016-12-06-18.30.00               pump_energy    Ru3Cl   
0.001  1.0  2016-12-06-18.32.38               pump_energy    Ru3Cl   
0.003  1.0  2016-12-06-18.35.10               pump_energy    Ru3Cl   
0.006  1.0  2016-12-06-18.37.50               pump_energy    Ru3Cl   
0.011  1.0  2016-12-06-18.40.40               pump_energy    Ru3Cl   
0.022  1.0  2016-12-06-18.43.26               pump_energy    Ru3Cl   
0.045  1.0  2016-12-06-18.45.50               pump_energy    Ru3Cl   
0.090  1.0  2016-12-06-18.48.28               pump_energy    Ru3Cl   
0.169  1.0  2016-12-06-18.51.30               pump_energy    Ru3Cl   
0.337  1.0  2016-12-06-18.55.48               pump_energy    Ru3Cl   
0.675  1.0  2016-12-06-18.58.26               pump_energy    Ru3Cl   

                      name                            original_filepath  \
0.001  Ru3Cl__None_mJ/cm^2  Ru3Cl-Pu-0.005-pr-0.2-1kAVG-T-3.8K-kerr.mat   
0.001  Ru3Cl__None_mJ/cm^2   Ru3Cl-Pu-0.01-pr-0.2-1kAVG-T-3.8K-kerr.mat   
0.003  Ru3Cl__None_mJ/cm^2   Ru3Cl-Pu-0.02-pr-0.2-1kAVG-T-3.8K-kerr.mat   
0.006  Ru3Cl__None_mJ/cm^2   Ru3Cl-Pu-0.04-pr-0.2-1kAVG-T-3.8K-kerr.mat   
0.011  Ru3Cl__None_mJ/cm^2   Ru3Cl-Pu-0.08-pr-0.2-1kAVG-T-3.8K-kerr.mat   
0.022  Ru3Cl__None_mJ/cm^2   Ru3Cl-Pu-0.16-pr-0.2-1kAVG-T-3.8K-kerr.mat   
0.045  Ru3Cl__None_mJ/cm^2   Ru3Cl-Pu-0.32-pr-0.2-1kAVG-T-3.8K-kerr.mat   
0.090  Ru3Cl__None_mJ/cm^2   Ru3Cl-Pu-0.64-pr-0.2-1kAVG-T-3.8K-kerr.mat   
0.169  Ru3Cl__None_mJ/cm^2    Ru3Cl-Pu-1.2-pr-0.2-1kAVG-T-3.8K-kerr.mat   
0.337  Ru3Cl__None_mJ/cm^2    Ru3Cl-Pu-2.4-pr-0.2-1kAVG-T-3.8K-kerr.mat   
0.675  Ru3Cl__None_mJ/cm^2    Ru3Cl-Pu-4.8-pr-0.2-1kAVG-T-3.8K-kerr.mat   

               other  probe_energy  probe_power  probe_spot  pump_energy  \
0.001  [1kavg, kerr]         0.072          0.2        50.0        0.001   
0.001  [1kavg, kerr]         0.072          0.2        50.0        0.001   
0.003  [1kavg, kerr]         0.072          0.2        50.0        0.003   
0.006  [1kavg, kerr]         0.072          0.2        50.0        0.006   
0.011  [1kavg, kerr]         0.072          0.2        50.0        0.011   
0.022  [1kavg, kerr]         0.072          0.2        50.0        0.022   
0.045  [1kavg, kerr]         0.072          0.2        50.0        0.045   
0.090  [1kavg, kerr]         0.072          0.2        50.0        0.090   
0.169  [1kavg, kerr]         0.072          0.2        50.0        0.169   
0.337  [1kavg, kerr]         0.072          0.2        50.0        0.337   
0.675  [1kavg, kerr]         0.072          0.2        50.0        0.675   

       pump_power  pump_spot  temperature  
0.001       0.005       80.0          3.8  
0.001       0.010       80.0          3.8  
0.003       0.020       80.0          3.8  
0.006       0.040       80.0          3.8  
0.011       0.080       80.0          3.8  
0.022       0.160       80.0          3.8  
0.045       0.320       80.0          3.8  
0.090       0.640       80.0          3.8  
0.169       1.200       80.0          3.8  
0.337       2.400       80.0          3.8  
0.675       4.800       80.0          3.8  
Imported 0 scan(s) as pump_energy dependence
Out[2]:
<matplotlib.axes._subplots.AxesSubplot at 0x22fa4c80438>

In [8]:
data.to_csv('e:/data/RuCl3/csv/low_temp_low_fluence.csv')

In [33]:
savepath = 'E:/data/RuCl3/HDF5/'
name = 'kerr_4K_fluence_dependence'
data.to_hdf(savepath + name + '.hdf5', 'data', mode="w")
parameter_dataframe.to_hdf(savepath + name + '.hdf5', 'parameters', mode='a')
# analysis_log_dataframe.to_hdf(savepath + name + '.hdf5', 'analysis_log', mode='a')
data.to_csv(savepath + name + '.csv')


C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\generic.py:1138: PerformanceWarning: 
your performance may suffer as PyTables will pickle object types that it cannot
map directly to c-types [inferred_type->mixed,key->block1_values] [items->['date', 'description', 'key_parameter', 'material', 'name', 'original_filepath', 'other']]

  return pytables.to_hdf(path_or_buf, key, self, **kwargs)

In [29]:
data1 = pd.DataFrame()

In [75]:
data1 = pd.read_hdf(savepath + name + '.hdf5', 'data')

In [147]:
data1 = data[data.columns[0:6]]
data2 = data[data.columns[6:12]]
data1.plot()
data2.plot()


Out[147]:
<matplotlib.axes._subplots.AxesSubplot at 0x26f542042b0>

In [231]:
data.plot(colormap='jet')


Out[231]:
<matplotlib.axes._subplots.AxesSubplot at 0x26f54089160>

In [47]:
trace=trace1[1]
    Time=trace1[0]
    guess=( 0.01,1.68,0.1,0.4,-0.27,0.2)
    #       t,taupulse,taudecay,linearconst,A,C,t_zero
    plt.plot(Time,trace)
    popt, pcov = sp.optimize.curve_fit(fitFunction,Time,trace,p0=guess)
    popt=1
    #fig=plt.figure('fittings')
    #plt.clf()
    #plt.plot(Time,fitFunction(Time, *popt))
    #plt.plot(trace[1],fitFunction(trace[1], 0.16,1.63,0.0011,0.4,-0.27,0.2))
    #plt.plot(Time,trace - fitFunction(Time,  *popt))
    #plt.show()
    return(popt)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-47-e315f32ac52d> in <module>()
----> 1 trace=trace1[1]
      2 Time=trace1[0]
      3 guess=( 0.01,1.68,0.1,0.4,-0.27,0.2)
      4 #       t,taupulse,taudecay,linearconst,A,C,t_zero
      5 plt.plot(Time,trace)

NameError: name 'trace1' is not defined

In [102]:
def expfunc_const(x, A, t0, c):
    labels = ['A', 't0', 'c']
    func = A * (1 - np.exp(- x / t0)) + c
    return func

In [122]:
def double_exponential_pos_neg(x, A1, t1, A2, t2, d):
    labels = ['A1', 't1', 'A2', 't2', 'c', 'd']
    func = A1 * (1 - np.exp(- x / t1)) + A2 * (1 - np.exp(- x / t2)) + d
    return func

In [149]:
def expFunc_lin_const(x, A, t0, c, d):
    labels = ['A', 't0', 'c', 'd']
    func = A * (1 - np.exp(- x / t0)) + c * x + d
    return func, labels

In [117]:
xdata = data1.index.tolist()
popts={}
pcovs={}
fig = plt.figure(figsize=(12,9))
fits = {}
substr = {}
for column in data1:
    ydata = data1.loc[0:xdata[-1],column].tolist()
    print(len(ydata))
    x = np.array(xdata[-len(ydata)-1:-1])
    y = np.array(ydata)
    plt.plot(x,y)
    
    popt, pcov = curve_fit(expfunc_const,x,y) #,p0=guess
    popts[column] = popt
    pcovs[column] = pcov
    fits[column] = expfunc_const(x, *popt)
    substr[column] = fits[column] - y
    plt.plot(x, expfunc_const(x, *popt), '-')
    
    
fig2 = plt.figure(figsize=(12,9))
for key,val in substr.items():
    plt.plot(x,val,label=key)
for key,val in popts.items():
    print(key,val,pcov[key])


5265
5265
5265
5265
5265
5265
0.001 [  1.17371267e-03   1.85213950e+01  -1.28340284e-04] [  1.07765182e-10  -1.29505644e-07  -1.06089726e-10]
0.003 [  2.27835821e-03   1.85127230e+01  -2.63923800e-04] [  1.07765182e-10  -1.29505644e-07  -1.06089726e-10]
0.006 [  4.73021685e-03   2.23915565e+01  -3.76634946e-04] [  1.07765182e-10  -1.29505644e-07  -1.06089726e-10]
0.011 [  7.67969463e-03   2.10194676e+01  -5.43127342e-04] [  1.07765182e-10  -1.29505644e-07  -1.06089726e-10]
0.022 [  9.43646531e-03   1.89305618e+01  -7.19213405e-04] [  1.07765182e-10  -1.29505644e-07  -1.06089726e-10]
0.045 [  9.83679429e-03   1.12689093e+01  -1.07126153e-03] [  1.07765182e-10  -1.29505644e-07  -1.06089726e-10]
C:\ProgramData\Anaconda3\lib\site-packages\ipykernel\__main__.py:26: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future

using double_exponential_pos_neg


In [145]:
xdata = data1.index.tolist()
popts={}
pcovs={}
fig = plt.figure(figsize=(12,9))
fits = {}
substr = {}
labels=['A1', 't1', 'A2', 't2', 'd']
for column in data1:
    ydata = data1.loc[0:xdata[-1],column].tolist()
    print(len(ydata))
    x = np.array(xdata[-len(ydata)-1:-1])
    y = np.array(ydata)
    plt.plot(x,y)
    
    popt, pcov = curve_fit(double_exponential_pos_neg,x,y,p0=(0.001,20,0,0.001,1)) #,p0=guess
    popts[column] = popt
    pcovs[column] = pcov
    fits[column] = double_exponential_pos_neg(x, *popt)
    substr[column] = fits[column] - y
    plt.plot(x, double_exponential_pos_neg(x, *popt), '-',)
    labels.append(column)
    
fig2 = plt.figure(figsize=(12,9))

for key,val in substr.items():
    plt.plot(x,val,label=key)
poptsdf = pd.DataFrame(popts).transpose()
poptsdf.columns = ['A1', 't1', 'A2', 't2', 'd']

print(poptsdf)
fig3 = plt.figure()
for column in poptsdf[:,'A1':'t2']:
    poptsdf[column].plot()


# for key,val in popts.items():
#     print(key,val,pcov[key])


5265
5265
5265
5265
5265
5265
             A1             t1        A2         t2         d
0.001  0.001485      14.530739 -0.000483   3.838586  0.000024
0.003  0.002991      14.563470 -0.000939   5.280026 -0.000071
0.006  0.004991      20.488110 -0.000694   2.263541  0.000009
0.011  0.007983      19.722849 -0.000958   1.703150  0.000059
0.022  0.009893      17.658319 -0.001309   1.702298  0.000076
0.045  1.440849 -669106.733946  0.009951  11.599819 -0.001033
C:\ProgramData\Anaconda3\lib\site-packages\ipykernel\__main__.py:3: RuntimeWarning: overflow encountered in exp
  app.launch_new_instance()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-145-8eebabb9e087> in <module>()
     30 print(poptsdf)
     31 fig3 = plt.figure()
---> 32 for column in poptsdf[:,'A1':'t2']:
     33     poptsdf[column].plot()
     34 

C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py in __getitem__(self, key)
   2057             return self._getitem_multilevel(key)
   2058         else:
-> 2059             return self._getitem_column(key)
   2060 
   2061     def _getitem_column(self, key):

C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py in _getitem_column(self, key)
   2064         # get column
   2065         if self.columns.is_unique:
-> 2066             return self._get_item_cache(key)
   2067 
   2068         # duplicate columns & possible reduce dimensionality

C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\generic.py in _get_item_cache(self, item)
   1382         """Return the cached item, item represents a label indexer."""
   1383         cache = self._item_cache
-> 1384         res = cache.get(item)
   1385         if res is None:
   1386             values = self._data.get(item)

TypeError: unhashable type: 'slice'
<matplotlib.figure.Figure at 0x26f541febe0>

fit function for electronic stuff


In [158]:
def negexpfunc_const(x, A, t0, c):
    labels = ['A', 't0', 'c']
    func = - A * (np.exp(- x / t0)) + c
    return func

In [193]:
usedata = data[data.columns[0:5]]
fitfunction = double_exponential_pos_neg
fitlabels=['A1', 't1', 'A2', 't2', 'd']
guess = (0.001,20,0,0.001,1)

##############
xdata = usedata.index.tolist()
popts={}
pcovs={}
fig = plt.figure(figsize=(12,9))
fits = {}
substr = {}

for column in usedata:
    ydata = usedata.loc[0:xdata[-1],column].tolist()
    x = np.array(xdata[-len(ydata)-1:-1])
    y = np.array(ydata)
    plt.plot(x,y)
    
    popt, pcov = curve_fit(fitfunction,x,y,p0=guess) #,p0=guess
    popts[column] = popt
    pcovs[column] = pcov
    fits[column] = fitfunction(x, *popt)
    substr[column] = fits[column] - y
    plt.plot(x, fitfunction(x, *popt), '-',)
    labels.append(column)
    
fig2 = plt.figure(figsize=(12,9))

for key,val in substr.items():
    plt.plot(x,val,label=key)
poptsdf = pd.DataFrame(popts).transpose()
poptsdf.columns = fitlabels

print(poptsdf)
for column in poptsdf:
    plt.figure()    
    poptsdf[column].plot(title=column)


C:\ProgramData\Anaconda3\lib\site-packages\ipykernel\__main__.py:3: RuntimeWarning: overflow encountered in exp
  app.launch_new_instance()
             A1         t1        A2        t2         d
0.001  0.001485  14.530739 -0.000483  3.838586  0.000024
0.003  0.002991  14.563470 -0.000939  5.280026 -0.000071
0.006  0.004991  20.488110 -0.000694  2.263541  0.000009
0.011  0.007983  19.722849 -0.000958  1.703150  0.000059
0.022  0.009893  17.658319 -0.001309  1.702298  0.000076

single exponential fit


In [244]:
usedata = data[data.columns[0:6]]

def fitfunction(x, A, t0, c):
    return  A * (1 - np.exp(- x / t0)) + c

fitlabels=['A1', 't1', 'd']
guess = (0.001,20,0)
# def fitfunction(x, A, t0, tau):
#     return  A * (1 - np.exp(- (x-t0) / tau)) 

# fitlabels=['A1', 't1', 'tau']
# guess = (0.001,1,20)

##############
xdata = usedata.index.tolist()
popts={}
pcovs={}
# fig = plt.figure(figsize=(12,6))
# ax1 = fig.add_subplot(1,2,1)
# ax2 = fig.add_subplot(1,2,2)
fits = {}
substr = {}

# figsize = layout.figaspect()
fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(12,6))
color_idx = np.linspace(0, 1, len(usedata.columns))

for i, column in zip(color_idx, usedata):
    
    ydata = usedata.loc[0:xdata[-1],column].tolist()
    x = np.array(xdata[-len(ydata)-1:-1])
    y = np.array(ydata)
    ax1.plot(x,y,color=plt.cm.jet(i),)
    
    popt, pcov = curve_fit(fitfunction,x,y,p0=guess) #,p0=guess
    popts[column] = popt
    pcovs[column] = pcov
    fits[column] = fitfunction(x, *popt)
    substr[column] =y - fits[column] 
    ax1.plot(x, fitfunction(x, *popt), '--',color=plt.cm.jet(i))
    labels.append(column)
    

for i, key in zip(color_idx, substr):
    ax2.plot(x,substr[key],label=key,color=plt.cm.jet(i))
poptsdf = pd.DataFrame(popts).transpose()
poptsdf.columns = fitlabels

print(poptsdf)
# fig = plt.figure()    
# nfigs = len(poptsdf.columns)
# print(nfigs)
x = poptsdf.index.tolist()

def parfitfunc(x, A, t0, c):
    return  A * (1 - np.exp(- x / t0)) + c
fig = plt.figure()
y= poptsdf['A1'].tolist()
print(len(x),len(y))
plt.plot(x,y,'o')
popt,pcov = curve_fit(parfitfunc,x,y,p0=(0.01,0.02,0))
xfit = np.arange(x[0],x[-1],(x[-1]-x[0])/100)
plt.plot(xfit,parfitfunc(xfit, *popt))
plt.title('fit of exponential amplitude')
print(popt)

def parfitfunc(x, A, b):
    return  A * x + b
plt.figure()
y= poptsdf['t1'].tolist()
print(len(x),len(y))
plt.plot(x,y,'o')
popt,pcov = curve_fit(parfitfunc,x,y,p0=(-200, 1))
xfit = np.arange(x[0],x[-1],(x[-1]-x[0])/100)
plt.plot(xfit,parfitfunc(xfit, *popt))
plt.title('fit of tau')
print(popt)


             A1         t1         d
0.001  0.001174  18.521397 -0.000128
0.003  0.002278  18.512714 -0.000264
0.006  0.004730  22.391563 -0.000377
0.011  0.007680  21.019466 -0.000543
0.022  0.009436  18.930558 -0.000719
0.045  0.009837  11.268903 -0.001071
6 6
[ 0.01045759  0.0083734  -0.000383  ]
6 6
[-187.38559679   21.18908884]

In [207]:
usedata = data[data.columns[0:6]]

# def fitfunction(x, A, t0, c):
#     return  A * (1 - np.exp(- x / t0)) + c

# fitlabels=['A1', 't1', 'd']
# guess = (0.001,20,0)
def fitfunction(x, A, t0, tau):
    return  A * (1 - np.exp(- (x-t0) / tau)) 

fitlabels=['A1', 't1', 'tau']
guess = (0.001,1,20)

##############
xdata = usedata.index.tolist()
popts={}
pcovs={}
fig = plt.figure(figsize=(12,6))
ax1 = fig.add_subplot(1,2,1)
ax2 = fig.add_subplot(1,2,2)
fits = {}
substr = {}

for column in usedata:
    ydata = usedata.loc[0:xdata[-1],column].tolist()
    x = np.array(xdata[-len(ydata)-1:-1])
    y = np.array(ydata)
    ax1.plot(x,y)
    
    popt, pcov = curve_fit(fitfunction,x,y,p0=guess) #,p0=guess
    popts[column] = popt
    pcovs[column] = pcov
    fits[column] = fitfunction(x, *popt)
    substr[column] =y - fits[column] 
    ax1.plot(x, fitfunction(x, *popt), '-',)
    labels.append(column)
    

for key,val in substr.items():
    ax2.plot(x,val,label=key)
poptsdf = pd.DataFrame(popts).transpose()
poptsdf.columns = fitlabels

print(poptsdf)
# fig = plt.figure()    
# nfigs = len(poptsdf.columns)
# print(nfigs)
for column in poptsdf:
    plt.figure()    
    poptsdf[column].plot(title=column)


             A1        t1        tau
0.001  0.001045  2.144767  18.521336
0.003  0.002014  2.279229  18.512697
0.006  0.004354  1.857874  22.391560
0.011  0.007137  1.541734  21.019467
0.022  0.008717  1.500767  18.930559
0.045  0.008766  1.299335  11.268907

New analysis: setting up for simple import of datasets


In [ ]:
filepath = 'E:/data/RuCl3/mat/kerr_rotation/fluence_3.8K/'

cutFreq = 0.01 # THz
t0 = 85
pump_spot = 80
probe_spot = 50

key_parameter = 'pump_energy'
description = ''

files = os.listdir(filepath)
usebg = False
trs = []
k_parameters = []
data = {}
parameters = {}



if 'background.mat' in files:
    bg_trace = transient.Transient()
    bg_trace.import_file(filepath + 'background.mat', 
                           cleanData=False, 
                           key_parameter=key_parameter,description=description)
    files.remove('background.mat')
    bg_trace.crop_time_scale()
    bg_trace.shift_time(t0)
    bg_trace.filter_low_pass(cutFreq)
#     tr.flip_trace()
    bg_trace.remove_DC_offset()
    bg_trace.flip_time()
    usebg = True
    
for file in files:
    try:

        tr = transient.Transient()
        tr.import_file(filepath + file, 
                           cleanData=False, 
                           key_parameter=key_parameter,description=description)
        tr.pump_spot = pump_spot
        tr.probe_spot = probe_spot
        tr.calc_energy_densities()
        tr.crop_time_scale()
        tr.shift_time(t0)
        tr.filter_low_pass(cutFreq)
    #     tr.flip_trace()
        tr.remove_DC_offset()
        tr.flip_time()
        # save parameters
        trParameters = tr.get_metadata()
        for key, val in trParameters.items():
            try:
                parameters[key].append(val)
            except KeyError:
                parameters[key] = [val]
        analysis_log = parameters.pop('analysis_log')
        if usebg:
            tr.trace = tr.trace - bg_trace.trace
        k_parameters.append(float(getattr(tr,key_parameter)))

        data[getattr(tr,key_parameter)] = tr.trace       
    
#        tr.trace = np.divide(tr.trace,max(tr.trace))
    #     tr.trace = np.divide(tr.trace,tr.pump_power)
    except Exception as exc:
        print('skipped file: {0}\nerror: {1}'.format(file,exc))
data = pd.DataFrame(data,index=tr.time)
print(data)
parameter_dataframe = pd.DataFrame(parameters, index = k_parameters)
analysis_log_dataframe = pd.DataFrame(analysis_log, index = k_parameters)
print(parameter_dataframe)
# for key, val in parameters.items():
#     print(str(key) + ': ')
#     print(val)

print('Imported {0} scan(s) as {1} dependence'.format(len(trs),tr.key_parameter))
data.plot(colormap='rainbow')

In [2]:
if asd:
    print(True)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-2-987b46f7c25c> in <module>()
----> 1 if asd:
      2     print(True)

NameError: name 'asd' is not defined

In [3]:
pd.DataFrame([1,2,3], index=['a','b','c'])


Out[3]:
0
a 1
b 2
c 3

In [4]:
data


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-4-6137cde4893c> in <module>()
----> 1 data

NameError: name 'data' is not defined

In [5]:
filepath = 'E:/data/RuCl3/mat/2018-03-08/'
files = os.listdir(filepath)

cutFreq = 0.01 # THz
t0 = 85
pump_spot = 80
probe_spot = 50

key_parameter = 'pump_energy'
description = ''

usebg = False
trs = []
k_parameters = []
data = {}
parameters = {}

if 'background.mat' in files:
    bg_trace = transient.Transient()
    bg_trace.import_file(filepath + 'background.mat', 
                           cleanData=False, 
                           key_parameter=key_parameter,description=description)
    files.remove('background.mat')
    bg_trace.crop_time_scale()
    bg_trace.shift_time(t0)
    bg_trace.filter_low_pass(cutFreq)
#     tr.flip_trace()
    bg_trace.remove_DC_offset()
    bg_trace.flip_time()
    usebg = True
    
for file in files:
    try:

        tr = transient.Transient()
        tr.import_file(filepath + file, 
                           cleanData=False, 
                           key_parameter=key_parameter,description=description)
        tr.pump_spot = pump_spot
        tr.probe_spot = probe_spot
        tr.calc_energy_densities()
        tr.crop_time_scale()
        tr.shift_time(t0)
        tr.filter_low_pass(cutFreq)
    #     tr.flip_trace()
        tr.remove_DC_offset()
        tr.flip_time()
        # save parameters
        trParameters = tr.get_metadata()
        for key, val in trParameters.items():
            try:
                parameters[key].append(val)
            except KeyError:
                parameters[key] = [val]
        analysis_log = parameters.pop('analysis_log')
        if usebg:
            tr.trace = tr.trace - bg_trace.trace
        k_parameters.append(float(getattr(tr,key_parameter)))

        data[getattr(tr,key_parameter)] = tr.trace       
    
#        tr.trace = np.divide(tr.trace,max(tr.trace))
    #     tr.trace = np.divide(tr.trace,tr.pump_power)
    except Exception as exc:
        print('skipped file: {0}\nerror: {1}'.format(file,exc))
data = pd.DataFrame(data,index=tr.time)
print(data)
parameter_dataframe = pd.DataFrame(parameters, index = k_parameters)
analysis_log_dataframe = pd.DataFrame(analysis_log, index = k_parameters)
print(parameter_dataframe)
# for key, val in parameters.items():
#     print(str(key) + ': ')
#     print(val)

print('Imported {0} scan(s) as {1} dependence'.format(len(trs),tr.key_parameter))
data.plot(colormap='rainbow')


background.mat
RuCl3-pr-0.2-T-3.85k-pu-0.05-mW-10000-AVG.mat
0.007
0.072
RuCl3-pr-0.2-T-3.85k-pu-0.1-mW-10000-AVG.mat
0.014
0.072
RuCl3-pr-0.2-T-3.85k-pu-0.2-mW-5000-AVG.mat
0.028
0.072
RuCl3-pr-0.2-T-3.85k-pu-0.5-mW-1000-AVG.mat
0.07
0.072
t-cal.mat
skipped file: t-cal.mat
error: index 2 is out of bounds for axis 0 with size 2
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\internals.py in create_block_manager_from_arrays(arrays, names, axes)
   4262         blocks = form_blocks(arrays, names, axes)
-> 4263         mgr = BlockManager(blocks, axes)
   4264         mgr._consolidate_inplace()

C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\internals.py in __init__(self, blocks, axes, do_integrity_check, fastpath)
   2760         if do_integrity_check:
-> 2761             self._verify_integrity()
   2762 

C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\internals.py in _verify_integrity(self)
   2970             if block._verify_integrity and block.shape[1:] != mgr_shape[1:]:
-> 2971                 construction_error(tot_items, block.shape[1:], self.axes)
   2972         if len(self.items) != tot_items:

C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\internals.py in construction_error(tot_items, block_shape, axes, e)
   4232     raise ValueError("Shape of passed values is {0}, indices imply {1}".format(
-> 4233         passed, implied))
   4234 

ValueError: Shape of passed values is (4, 6468), indices imply (4, 0)

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-5-891081b7e61e> in <module>()
     64     except Exception as exc:
     65         print('skipped file: {0}\nerror: {1}'.format(file,exc))
---> 66 data = pd.DataFrame(data,index=tr.time)
     67 print(data)
     68 parameter_dataframe = pd.DataFrame(parameters, index = k_parameters)

C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py in __init__(self, data, index, columns, dtype, copy)
    264                                  dtype=dtype, copy=copy)
    265         elif isinstance(data, dict):
--> 266             mgr = self._init_dict(data, index, columns, dtype=dtype)
    267         elif isinstance(data, ma.MaskedArray):
    268             import numpy.ma.mrecords as mrecords

C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py in _init_dict(self, data, index, columns, dtype)
    400             arrays = [data[k] for k in keys]
    401 
--> 402         return _arrays_to_mgr(arrays, data_names, index, columns, dtype=dtype)
    403 
    404     def _init_ndarray(self, values, index, columns, dtype=None, copy=False):

C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py in _arrays_to_mgr(arrays, arr_names, index, columns, dtype)
   5406     axes = [_ensure_index(columns), _ensure_index(index)]
   5407 
-> 5408     return create_block_manager_from_arrays(arrays, arr_names, axes)
   5409 
   5410 

C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\internals.py in create_block_manager_from_arrays(arrays, names, axes)
   4265         return mgr
   4266     except ValueError as e:
-> 4267         construction_error(len(arrays), arrays[0].shape, axes, e)
   4268 
   4269 

C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\internals.py in construction_error(tot_items, block_shape, axes, e)
   4231         raise ValueError("Empty data passed with indices specified.")
   4232     raise ValueError("Shape of passed values is {0}, indices imply {1}".format(
-> 4233         passed, implied))
   4234 
   4235 

ValueError: Shape of passed values is (4, 6468), indices imply (4, 0)

In [ ]: