cheminfo / isotherm-analysis

JS tools to convert isotherms to jcamp and to analyze them
https://cheminfo.github.io/isotherm-analysis/
MIT License
0 stars 0 forks source link

implement dvs vacuum parser #11

Open kjappelbaum opened 4 years ago

kjappelbaum commented 4 years ago

DVS.zip

kjappelbaum commented 4 years ago

encoding of the files is unclear to me

kjappelbaum commented 4 years ago

chardet also couldn't find it, also uchardet couldn't find it. @lpatiny do you have an idea how we could figure this out?

kjappelbaum commented 4 years ago

according to https://wiki.bath.ac.uk/download/attachments/103682652/intrinsic%20.pdf?version=1&modificationDate=1513689161000&api=v2 it seems that users can probably also export the excel, now asked the student if they can export the excel and for an example

kjappelbaum commented 4 years ago

got the excel Archive.zip

kjappelbaum commented 4 years ago

actually they are more tricky as they are coadsorption

kjappelbaum commented 4 years ago

actually this instrument allows also for dynamic testing https://www.surfacemeasurementsystems.com/wp-content/uploads/2017/08/DVS_Vacuum.pdf.

The bigger issue though is that we do not know which gas is used and only have the mass

kjappelbaum commented 4 years ago

john gave me the following snippet which he uses to analyze the data

def pure_data(csvfile, Mw, adsorbent, gas, temp):
    csv_name = adsorbent + gas + '_' + str(temp) +'.csv'
    if os.path.isfile(csv_name):
        return pd.read_csv(csv_name)
    else:

        df_initial = pd.read_csv(csvfile, encoding='1250')
        sat_pressure = float(df_initial['Unnamed: 1'][14]) #in torr
        data_points = float(df_initial['Unnamed: 1'][19])
        header = float(df_initial['Unnamed: 1'][20]) - 2
        data_start = float(df_initial['Unnamed: 1'][20])
        isotherm_start = float(df_initial['Unnamed: 1'][22])
        initial_mass = float(df_initial['Unnamed: 1'][27]) #mg
        start = isotherm_start - data_start

        df_all = pd.read_csv(csvfile, encoding='1250', header=int(header))
        df_all.columns = df_all.columns.str.replace("�C", "\u00B0C")

        df_isotherm = df_all[int(start):]
        df_isotherm.reset_index(drop=True, inplace=True)

        def loading(mass, initial, M_weight):
            change = mass - initial
            mmol = change/(M_weight*1000)
            loading = mmol/(initial/1000)
            return loading

        def torr_to_bar(pressure_in_torr):
            return pressure_in_torr*0.00133322

        df_isotherm['Loading [mmol/g]'] = loading(df_isotherm['Mass [mg]'], initial_mass, Mw)
        df_isotherm['Pressure [bar]'] = torr_to_bar(df_isotherm['Actual Pressure [Torr]'])
        df_length = len(df_isotherm['Target Relative Pressure [%]'])-1

        for i in range(df_length):
            if df_isotherm['Target Relative Pressure [%]'][i] == df_isotherm['Target Relative Pressure [%]'][i+1]:
                df_isotherm.drop(i, inplace=True)
            percent_complete = (100*i)/df_length
            if percent_complete % 10 < 0.001:
                print(str(percent_complete) + '%' + ' complete for ' + csvfile)
        df_isotherm.reset_index(drop=True, inplace=True)

        df_length = len(df_isotherm['Target Relative Pressure [%]'])

        modelist = []
        for i in range(df_length):
            if i == 0:
                modelist.append('Adsorption')
            else:
                if df_isotherm['Target Relative Pressure [%]'][i - 1] < df_isotherm['Target Relative Pressure [%]'][i]:
                    modelist.append('Adsorption')  
                else:
                    modelist.append('Desorption')  

        df_final = pd.DataFrame()
        df_final['Pressure [bar]'] = df_isotherm['Pressure [bar]']
        df_final['Relative Pressure [%]'] = df_isotherm['Actual Relative Pressure [%]']
        df_final['Loading [mmol/g]'] = df_isotherm['Loading [mmol/g]']
        df_final['Temperature \u00B0C'] = df_isotherm['Actual Preheater Temperature [\u00B0C]'].mean()
        df_final['Gas'] = gas
        df_final['Adsorbent'] = adsorbent
        df_final['Mode'] = modelist
        df_final.to_csv(csv_name, index=False)

        return df_final

def coads_data(csvfile, Mw_gas, Mw_solvent, adsorbent, gas, solvent, temp, RH):
    csv_name = adsorbent + gas + solvent + 'coadsorption_' + RH + str(temp) +'.csv'
    if os.path.isfile(csv_name):
        return pd.read_csv(csv_name)
    else:

        df_initial = pd.read_csv(csvfile, encoding='1250')
        sat_pressure = float(df_initial['Unnamed: 1'][14]) #in torr
        data_points = float(df_initial['Unnamed: 1'][19])
        header = float(df_initial['Unnamed: 1'][20]) - 2
        data_start = float(df_initial['Unnamed: 1'][20])
        isotherm_start = float(df_initial['Unnamed: 1'][22])
        initial_mass = float(df_initial['Unnamed: 1'][27]) #mg
        start = isotherm_start - data_start

        df_all = pd.read_csv(csvfile, encoding='1250', header=int(header))
        df_all.columns = df_all.columns.str.replace("�C", "\u00B0C")

        df_isotherm = df_all[int(start):]
        df_isotherm.reset_index(drop=True, inplace=True)

        def loading(mass, initial, M_weight, initial_mass):
            change = mass - initial
            mmol = change/(M_weight*1000)
            loading = mmol/(initial_mass/1000)
            return loading

        def torr_to_bar(pressure_in_torr):
            return pressure_in_torr*0.00133322

        df_length = len(df_isotherm['Target Relative Pressure [%]']) -1

        for i in range(df_length):
            if df_isotherm['Target Relative Pressure [%]'][i] == df_isotherm['Target Relative Pressure [%]'][i+1]:
                df_isotherm.drop(i, inplace=True)
            percent_complete = (100*i)/df_length
            if percent_complete % 10 < 0.001:
                print(str(percent_complete) + '%' + ' complete for ' + csvfile)
        df_isotherm.reset_index(drop=True, inplace=True)
        df_isotherm['Loading [mmol/g]'] = 0
        new_header = solvent + ' Loading [mmol/g]'
        df_isotherm[new_header] = loading(df_isotherm['Mass [mg]'][0], initial_mass, Mw_solvent, initial_mass)
        df_isotherm['Loading [mmol/g]'][1:] = loading(df_isotherm['Mass [mg]'][1:], df_isotherm['Mass [mg]'][0], Mw_gas, initial_mass)

        df_isotherm['Pressure [bar]'] = torr_to_bar(df_isotherm['Actual Pressure [Torr]'])
        df_length = len(df_isotherm['Target Relative Pressure [%]'])

        modelist = []
        for i in range(df_length):
            if i == 0:
                modelist.append('Adsorption')
            else:
                if df_isotherm['Target Relative Pressure [%]'][i - 1] < df_isotherm['Target Relative Pressure [%]'][i]:
                    modelist.append('Adsorption')  
                else:
                    modelist.append('Desorption')  

        df_final = pd.DataFrame()
        df_final['Pressure [bar]'] = df_isotherm['Pressure [bar]'] - df_isotherm['Pressure [bar]'][0]
        df_final['Loading [mmol/g]'] = df_isotherm['Loading [mmol/g]']
        df_final['Temperature \u00B0C'] = df_isotherm['Actual Preheater Temperature [\u00B0C]'].mean()
        df_final[new_header] = df_isotherm[new_header]
        df_final['Gas'] = gas
        df_final['Adsorbent'] = adsorbent
        df_final['Mode'] = modelist
        df_final.to_csv(csv_name, index=False)

        return df_final