In [9]:
import pandas as pd
import numpy as np
from glob import glob
import os

In [10]:
paths_t = glob('C:\\Users\\jlandman\\Desktop\\newData\\CH_Huss-Fischer\\GlaThiDa2.0_UFR\\results\\*_T.dat')

In [11]:
# not needed, new IDs are already prescribed in 
"""
# new GTD IDs
new_ids= {}
begin = 2091
ct=0
for path in paths_t:
    new_ids[os.path.split(path)[-1].split('.')[0]] = begin + ct
    ct+=1
"""


Out[11]:
"\n# new GTD IDs\nnew_ids= {}\nbegin = 2091\nct=0\nfor path in paths_t:\n    new_ids[os.path.split(path)[-1].split('.')[0]] = begin + ct\n    ct+=1\n"

In [13]:
for path_t in paths_t:
    t_dat = pd.read_csv(path_t, header=None, sep=': ')
    tt_path = os.path.join(os.path.dirname(path_t),os.path.split(path_t)[1].split('.')[0]+'T.dat')
    tt_dat = pd.read_csv(tt_path, header=None, sep=': ')
    ttt_path = os.path.join(os.path.dirname(path_t),os.path.split(path_t)[1].split('.')[0]+'TT.dat')
    ttt_dat = pd.read_csv(ttt_path, header=None, delim_whitespace=True)

    excel = pd.DataFrame([], [0])
    excel.loc[excel.index==0, 'GlaThiDa_ID'] = np.nan # has to be inserted manually in the Excel sheet, later on
    excel.loc[excel.index==0, 'POLITICAL_UNIT'] = 'CH'
    excel.loc[excel.index==0, 'GLACIER_NAME'] = t_dat[t_dat[0] == 'Glacier name'][1].iloc[0].upper().strip()
    excel.loc[excel.index==0, 'SOURCE_ID'] = np.nan
    excel.loc[excel.index==0, 'GLACIER_ID'] = np.nan
    excel.loc[excel.index==0, 'LAT'] = float(t_dat[t_dat[0] == 'lat'][1].iloc[0])
    excel.loc[excel.index==0, 'LON'] = float(t_dat[t_dat[0] == 'lon'][1].iloc[0])
    excel.loc[excel.index==0, 'SURVEY_DATE'] = int(t_dat[t_dat[0] == 'Survey Date'][1].iloc[0])
    excel.loc[excel.index==0, 'DEM_DATE'] = int(t_dat[t_dat[0] == 'DEM Date'][1].iloc[0])
    excel.loc[excel.index==0, 'AREA'] = float(t_dat[t_dat[0] == 'Area'][1].iloc[0])
    excel.loc[excel.index==0, 'MEAN_SLOPE'] = float(t_dat[t_dat[0] == 'Mean slope'][1].iloc[0])
    excel.loc[excel.index==0, 'MEAN_THICKNESS'] = float(t_dat[t_dat[0] == 'Mean thickness'][1].iloc[0])
    excel.loc[excel.index==0, 'MEAN_THICKNESS_UNCERTAINTY'] = float(t_dat[t_dat[0] == 'Mean thickness uncertainty'][1].iloc[0])
    excel.loc[excel.index==0, 'MAXIMUM_THICKNESS'] = float(t_dat[t_dat[0] == 'Max thickness'][1].iloc[0])
    excel.loc[excel.index==0, 'MAX_THICKNESS_UNCERTAINTY'] = float(t_dat[t_dat[0] == 'Max thickness uncertainty'][1].iloc[0])
    excel.loc[excel.index==0, 'SURVEY_METHOD'] = t_dat[t_dat[0] == 'Method'][1].iloc[0].strip()
    excel.loc[excel.index==0, 'SURVEY_METHOD_DETAILS'] = t_dat[t_dat[0] == 'Method details'][1].iloc[0].strip()
    excel.loc[excel.index==0, 'NUMBER_OF_SURVEY_POINTS']= int(t_dat[t_dat[0] == 'Survey points'][1].iloc[0])
    excel.loc[excel.index==0, 'NUMBER_OF_SURVEY_PROFILES'] = np.nan
    excel.loc[excel.index==0, 'TOTAL_LENGTH_OF_SURVEY_PROFILES'] = np.nan
    excel.loc[excel.index==0, 'INTERPOLATION_METHOD'] = ''
    excel.loc[excel.index==0, 'INVESTIGATOR'] = t_dat[t_dat[0] == 'Investigator'][1].iloc[0].strip()
    excel.loc[excel.index==0, 'SPONSORING_AGENCY'] = t_dat[t_dat[0] == 'Sponsor'][1].iloc[0].strip()
    excel.loc[excel.index==0, 'REFERENCES'] = t_dat[t_dat[0] == 'Reference'][1].iloc[0].strip()
    excel.loc[excel.index==0, 'DATA_FLAG'] = np.nan
    excel.loc[excel.index==0, 'REMARKS'] = ''
    
    
    """excel_tt = pd.DataFrame([], range(len(tt_dat)))
    for k, row in excel_tt.iterrows():
        excel_tt.loc[excel_tt.index==k, 'GlaThiDa_ID'] = np.nan
        excel_tt.loc[excel_tt.index==k, 'POLITICAL_UNIT'] = 'CH'
        excel_tt.loc[excel_tt.index==k, 'GLACIER_NAME'] = t_dat[t_dat[0] == 'Glacier name'][1].iloc[0].upper()
        excel_tt.loc[excel_tt.index==k, 'SURVEY_DATE'] = t_dat[t_dat[0] == 'Survey Date'][1].iloc[0]
        excel_tt.loc[excel_tt.index==k, 'LOWER_BOUND'] = pd.Series([i.split(' - ')[0] for i in tt_dat[0].values])
        excel_tt.loc[excel_tt.index==k, 'UPPER_BOUND'] = pd.Series([i.split('-')[1] for i in tt_dat[0].values])
        excel_tt.loc[excel_tt.index==k, 'AREA'] = pd.Series([i.split(';')[0] for i in tt_dat[2].values])
        excel_tt.loc[excel_tt.index==k, 'MEAN_SLOPE'] = np.nan
        excel_tt.loc[excel_tt.index==k, 'MEAN_THICKNESS'] = pd.Series([i.split('; ')[0] for i in tt_dat[4].values])
        excel_tt.loc[excel_tt.index==k, 'MEAN_THICKNESS_UNCERTAINTY'] = np.nan
        excel_tt.loc[excel_tt.index==k, 'MAXIMUM_THICKNESS'] = tt_dat[5]
        excel_tt.loc[excel_tt.index==k, 'MAXIMUM_THICKNESS_UNCERTAINTY'] = np.nan
        excel_tt.loc[excel_tt.index==k, 'DATA_FLAG'] = np.nan
        excel_tt.loc[excel_tt.index==k, 'REMARKS'] = ''
    
    
    excel_ttt = pd.DataFrame([], range(len(ttt_dat)))
    print(ttt_path, len(excel_ttt), excel_ttt)
    for k, row in excel_ttt.iterrows():
        excel_ttt.loc[excel_ttt.index==k, 'GlaThiDa_ID'] = np.nan
        excel_ttt.loc[excel_ttt.index==k, 'POLITICAL_UNIT'] = 'CH'
        excel_ttt.loc[excel_ttt.index==k, 'GLACIER_NAME'] = t_dat[t_dat[0] == 'Glacier name'][1].iloc[0].upper()
        excel_ttt.loc[excel_ttt.index==k, 'SURVEY_DATE'] = t_dat[t_dat[0] == 'Survey Date'][1].iloc[0]
        excel_ttt.loc[excel_ttt.index==k, 'POINT_ID'] = ttt_dat[ttt_dat.index==k][0].iloc[0]
        excel_ttt.loc[excel_ttt.index==k, 'POINT_LAT'] = ttt_dat[ttt_dat.index==k][2].iloc[0]
        excel_ttt.loc[excel_ttt.index==k, 'POINT_LON'] = ttt_dat[ttt_dat.index==k][1].iloc[0]
        excel_ttt.loc[excel_ttt.index==k, 'ELEVATION'] = round(ttt_dat[ttt_dat.index==k][3].iloc[0])
        excel_ttt.loc[excel_ttt.index==k, 'THICKNESS'] = round(ttt_dat[ttt_dat.index==k][4].iloc[0],1)
        
        excel_ttt.loc[excel_ttt.index==k, 'THICKNESS_UNCERTAINTY'] = np.nan
        excel_ttt.loc[excel_ttt.index==k, 'DATA_FLAG'] = np.nan
        excel_ttt.loc[excel_ttt.index==k, 'REMARKS'] = ''"""

    excel.to_excel(path_t[:-4]+'.xlsx', index=False)
    """excel_tt.to_excel(tt_path[:-4]+'.xlsx', index=False)
    excel_ttt.to_excel(ttt_path[:-4]+'.xlsx', index=False)"""


C:\Users\jlandman\Anaconda3\lib\site-packages\ipykernel\__main__.py:2: ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support regex separators; you can avoid this warning by specifying engine='python'.
  from ipykernel import kernelapp as app
C:\Users\jlandman\Anaconda3\lib\site-packages\ipykernel\__main__.py:4: ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support regex separators; you can avoid this warning by specifying engine='python'.