## Change data range and step¶

Original:(start,end, step), new:(start,end, step)

Ori(4.2,7.0, 0.1) -> new(4.2,6.2, 0.1)

Ori(4.2,7.0, 0.05) -> new(4.2,6.2, 0.05) If wf<6.2 Ori(4.2,7.0, 0.05) -> new(4.2,6.2, 0.1) If wf<6.2 Ori(4.2,7.0, 0.05) -> new(5.0,7.0, 0.05) If wf>5.0 Ori(4.2,7.0, 0.05) -> new(5.0,7.0, 0.1) If wf>5.0

Ori(4.2,6.2, 0.05) -> new(4.2,6.2, 0.1)

In [1]:

    import os
    # import time
    # from datetime import datetime
    # from pprint import pprint

    import pandas as pd
    from pandas import Series, DataFrame

    # import scipy as sp
    # from scipy.optimize import leastsq
    import numpy as np

    # import matplotlib.pyplot as plt
    # import seaborn as sns
    # sns.set_style('whitegrid')
    # %matplotlib inline

    # #高解像度の設定（きれいな図が出力されますがファイルサイズが大きくなります）
    # %config InlineBackend.figure_formats = {'png', 'retina'}

    # from sklearn.externals import joblib

In [2]:

    df_original= pd.read_excel('./validation_data_MDR.xlsx')

In [7]:

    def modify_range(df):
        """
        df:dataframe

        1: 分割数を少なくする
        2,3：分析範囲を小さくする

        """
        df_new=df.copy()

        for i in df.index:
            start = eval(df["energy_range"][i])[0]
            end = eval(df["energy_range"][i])[1]
            step = eval(df["energy_range"][i])[2]
            est_wf = df["estimate_wf"][i]
            data_= np.array(eval(df["n_pys"][i])).flatten()
            ene_= np.array(eval(df["ene"][i])).flatten()
            sample_name_=df["Sample_name"][i]
            power_=df["photon_power"][i]

            #print('energy range:',start,end,step)

            if start == 4 and end == 7 and step == 0.05:

                  #0.1eV
                temp_data=data_[::2].flatten()
                temp_ene=ene_[::2].flatten()
                temp_enerange=(4,7,0.1)
                temp_dic={"ene":temp_ene.tolist(),"n_pys":temp_data.tolist(),"energy_range":temp_enerange,
                            "Sample_name":sample_name_+'_s',"estimate_wf":est_wf,"photon_power":power_}
                temp_se = pd.Series(temp_dic)
                df_new=df_new.append(temp_se, ignore_index=True)

                if 4.2 < est_wf < 6.2:

                    end_ind=np.where(ene_==6.2)[0][0]
                    start_ind=np.where(ene_==4.2)[0][0]
                    temp_data=data_[start_ind:end_ind+1:1].flatten()
                    temp_ene=ene_[start_ind:end_ind+1:1].flatten()
                    temp_enerange=(4.2,6.2,0.05)
                    temp_dic={"ene":temp_ene.tolist(),"n_pys":temp_data.tolist(),"energy_range":temp_enerange,
                              "Sample_name":sample_name_+'_r',"estimate_wf":est_wf,"photon_power":power_}
                    temp_se = pd.Series(temp_dic)
                    df_new=df_new.append(temp_se, ignore_index=True)

                    #0.1eV
                    temp_data=data_[start_ind:end_ind+1:2].flatten()
                    temp_ene=ene_[start_ind:end_ind+1:2].flatten()
                    temp_enerange=(4.2,6.2,0.1)
                    temp_dic={"ene":temp_ene.tolist(),"n_pys":temp_data.tolist(),"energy_range":temp_enerange,
                              "Sample_name":sample_name_+'_rs',"estimate_wf":est_wf,"photon_power":power_}
                    temp_se = pd.Series(temp_dic)
                    df_new=df_new.append(temp_se, ignore_index=True)

                    if est_wf > 5.0:
                        end_ind=np.where(ene_==7.0)[0][0]
                        start_ind=np.where(ene_==5.0)[0][0]
                        temp_data=data_[start_ind:end_ind+1:1].flatten()
                        temp_ene=ene_[start_ind:end_ind+1:1].flatten()
                        temp_enerange=(5.0,7.0,0.05)
                        temp_dic={"ene":temp_ene.tolist(),"n_pys":temp_data.tolist(),"energy_range":temp_enerange,
                                  "Sample_name":sample_name_+'_hr',"estimate_wf":est_wf,"photon_power":power_}
                        temp_se = pd.Series(temp_dic)
                        df_new=df_new.append(temp_se, ignore_index=True)

                        #0.1eV
                        temp_data=data_[start_ind:end_ind+1:2].flatten()
                        temp_ene=ene_[start_ind:end_ind+1:2].flatten()
                        temp_enerange=(5.0,7.0,0.1)
                        temp_dic={"ene":temp_ene.tolist(),"n_pys":temp_data.tolist(),"energy_range":temp_enerange,
                                  "Sample_name":sample_name_+'_hrs',"estimate_wf":est_wf,"photon_power":power_}
                        temp_se = pd.Series(temp_dic)
                        df_new=df_new.append(temp_se, ignore_index=True)

            elif start == 4 and end == 7 and step == 0.1 :

                if 4.2 < est_wf < 6.2:
                    end_ind=np.where(ene_==6.2)[0][0]
                    start_ind=np.where(ene_==4.2)[0][0]
                    temp_data=data_[start_ind:end_ind+1:1].flatten()
                    temp_ene=ene_[start_ind:end_ind+1:1].flatten()
                    temp_enerange=(4.2,6.2,0.1)
                    temp_dic={"ene":temp_ene.tolist(),"n_pys":temp_data.tolist(),"energy_range":temp_enerange,
                              "Sample_name":sample_name_+'_r',"estimate_wf":est_wf,"photon_power":power_}
                    temp_se = pd.Series(temp_dic)
                    df_new=df_new.append(temp_se, ignore_index=True)

                    if est_wf > 5.0:
                        end_ind=np.where(ene_==7.0)[0][0]
                        start_ind=np.where(ene_==5.0)[0][0]
                        temp_data=data_[start_ind:end_ind+1:1].flatten()
                        temp_ene=ene_[start_ind:end_ind+1:1].flatten()
                        temp_enerange=(5.0,7.0,0.1)
                        temp_dic={"ene":temp_ene.tolist(),"n_pys":temp_data.tolist(),"energy_range":temp_enerange,
                                  "Sample_name":sample_name_+'_hr',"estimate_wf":est_wf,"photon_power":power_}
                        temp_se = pd.Series(temp_dic)
                        df_new=df_new.append(temp_se, ignore_index=True)

                else:
                    pass

            elif start == 4.2 and end == 6.2 and step == 0.05:
                   #0.1eV
                end_ind=np.where(ene_==6.2)[0][0]
                start_ind=np.where(ene_==4.2)[0][0]
                temp_data=data_[start_ind:end_ind+1:2].flatten()
                temp_ene=ene_[start_ind:end_ind+1:2].flatten()
                temp_enerange=(4.2,6.2,0.1)
                temp_dic={"ene":temp_ene.tolist(),"n_pys":temp_data.tolist(),"energy_range":temp_enerange,
                          "Sample_name":sample_name_+'_s',"estimate_wf":est_wf,"photon_power":power_}
                temp_se = pd.Series(temp_dic)
                df_new=df_new.append(temp_se, ignore_index=True)

            elif start == 4.2 and end == 7.0 and step == 0.1:
               #0.1eV
                end_ind=np.where(ene_==6.2)[0][0]
                start_ind=np.where(ene_==4.2)[0][0]
                temp_data=data_[start_ind:end_ind+1:1].flatten()
                temp_ene=ene_[start_ind:end_ind+1:1].flatten()
                temp_enerange=(4.2,6.2,0.1)
                temp_dic={"ene":temp_ene.tolist(),"n_pys":temp_data.tolist(),"energy_range":temp_enerange,
                          "Sample_name":sample_name_+'_r',"estimate_wf":est_wf,"photon_power":power_}
                temp_se = pd.Series(temp_dic)
                df_new=df_new.append(temp_se, ignore_index=True)

            else:
                pass

        return df_new

In [8]:

    df_new=modify_range(df_original)

In [10]:

    #df_new.to_csv('./validation_data_MDR_modify.csv', index=False)
    df_new.to_excel('./validation_data_MDR_modify.xlsx')