def loadData(filePath=None):
    '''
    #====================================================================
    in:
    read measured raw data file,
    search the line ['    Field       Remanence  '] in measured data file,
    skip all the rows above and the last line,
    otherwise, load data as two columns.
    #
    out:
    rawDf,fitDf are the pandas dataframe of measured raw data, and the
    log10 interploted data
    #====================================================================
    '''
    skip_from = '    Field       Remanence  '
    with open(filePath,'rb') as fr:
        #f = fr.read()
        for i,line in enumerate(fr,1):
            #print(line)
            if skip_from in str(line):
                skiprows=i+2
                break
            else:
                skiprows=None
    skiprows = skiprows if isinstance(skiprows,int) else 1
    rawDf = pd.read_csv(filePath, sep='\s+', delimiter=',', names=['field','remanance'],
                        dtype=np.float64, skiprows=skiprows, skipfooter=1,engine='python')
    rawDf = rawDf[(rawDf['field']>0)]
    rawDf = rawDf.sort_values(by=['field'])
    rawDf['field'] = rawDf['field']*10**3 # mT to # T
    y_measure=rawDf['remanance']
    rawDf = rawDf[(rawDf['field']>=2)]
    rawDf['field_log'] = np.log10(rawDf['field'])
    rawDf['rem_gradient'] = np.gradient(rawDf['remanance'])
    rawDf['rem_grad_norm'] = rawDf['rem_gradient']/rawDf['rem_gradient'].max()
    field_fit = np.linspace(np.log10(rawDf['field'].min()),
                            np.log10(rawDf['field'].max()), 100)
    y_gradient = interpolate.splev(field_fit,
                                   interpolate.splrep(np.log10(rawDf['field']),
                                   np.gradient(rawDf['remanance'])))
    fitDf = pd.DataFrame({'field':field_fit,'remanance':y_gradient})
    fitDf.remanance[fitDf.remanance<=0] = 10**-15
    return rawDf,fitDf
def loadData ( filePath = None ) : skip_from = '    Field       Remanence  ' with open ( filePath , 'rb' ) as fr : for i , line in enumerate ( fr , 1 ) : if skip_from in str ( line ) : skiprows = i + 2 break else : skiprows = None skiprows = skiprows if isinstance ( skiprows , int ) else 1 rawDf = pd . read_csv ( filePath , sep = '\s+' , delimiter = ',' , names = [ 'field' , 'remanance' ] , dtype = np . float64 , skiprows = skiprows , skipfooter = 1 , engine = 'python' ) rawDf = rawDf [ ( rawDf [ 'field' ] > 0 ) ] rawDf = rawDf . sort_values ( by = [ 'field' ] ) rawDf [ 'field' ] = rawDf [ 'field' ] * 10 ** 3 y_measure = rawDf [ 'remanance' ] rawDf = rawDf [ ( rawDf [ 'field' ] >= 2 ) ] rawDf [ 'field_log' ] = np . log10 ( rawDf [ 'field' ] ) rawDf [ 'rem_gradient' ] = np . gradient ( rawDf [ 'remanance' ] ) rawDf [ 'rem_grad_norm' ] = rawDf [ 'rem_gradient' ] / rawDf [ 'rem_gradient' ] . max ( ) field_fit = np . linspace ( np . log10 ( rawDf [ 'field' ] . min ( ) ) , np . log10 ( rawDf [ 'field' ] . max ( ) ) , 100 ) y_gradient = interpolate . splev ( field_fit , interpolate . splrep ( np . log10 ( rawDf [ 'field' ] ) , np . gradient ( rawDf [ 'remanance' ] ) ) ) fitDf = pd . DataFrame ( { 'field' : field_fit , 'remanance' : y_gradient } ) fitDf . remanance [ fitDf . remanance <= 0 ] = 10 ** - 15 return rawDf , fitDf
#====================================================================
    in:
    read measured raw data file,
    search the line ['    Field       Remanence  '] in measured data file,
    skip all the rows above and the last line,
    otherwise, load data as two columns.
    #
    out:
    rawDf,fitDf are the pandas dataframe of measured raw data, and the
    log10 interploted data
    #====================================================================