Analysis of many nmr data files using nmrglue

I am trying to create a python script with the ability to analyze individual NMR data and produce a set of analysis output back into each folder, but with just one python script. Here is the script I have for analyzing the individual NMR experiments:

import math 
import numpy as np
from numpy import *
import scipy
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
import matplotlib.cm as cm
import nmrglue as ng
import sys
from mpl_toolkits.mplot3d import Axes3D
import csv

def exp(x, a, b, c):
    d=1/b 
    return a+c*np.exp(-b*x) 

out=open(f'Okuno Lab Python Work/Okuno Test 1/okuno1output.txt', 'w')#ZY
out=open(f'Okuno Lab Python Work/Okuno Test 1/okuno1output.txt', 'a')#ZY

List_area=[]
List_noise=[]
List_inten=[]

with open(f'Okuno Lab Python Work/Okuno Test 1/okuno1tau.csv', 'r') as d:
    reader = csv.reader(d)
    pretauList = list(reader)
    tauList = np.array(pretauList)

data=open(f'Okuno Lab Python Work/Okuno Test 1/okuno1noise.txt', 'r+')#ZY
lines=data.readlines()
for line in lines:
    fields=line.split()
    noise=float(fields[0])

for i in range(0, len(tauList), 1):
    List_noise.append(noise)

dic,data = ng.pipe.read(str(f'Okuno Lab Python Work/Okuno Test 1/test036.ft1'))#ZY

udic = ng.pipe.guess_udic(dic,data)
uc = ng.fileiobase.uc_from_udic(udic)
ppm_1H = uc.ppm_scale()
uc0 = ng.pipe.make_uc(dic,data,dim=0)
ub=uc0("6.5ppm")
lb=uc0("8.2ppm")

ppm = ppm_1H[lb:ub]
inten = data[lb:ub]
maxvalue=max(inten.real)
pt=np.where(data.real==maxvalue)
intensity=data[pt]
maxpt=uc0.ppm(float(pt[0]))
    
display(uc0.ppm(float(pt[0])))
off=0
count=0
for i in range(1, len(tauList)+1, 1):
    
    off=off+500
    count=count+1
    try:
        dic,data = ng.pipe.read(str(f'Okuno Lab Python Work/Okuno Test 1/test00{str(i)}.ft1'))#ZY
    except IOError:
        dic,data = ng.pipe.read(str(f'Okuno Lab Python Work/Okuno Test 1/test0{str(i)}.ft1'))#ZY
    
    ppm = ppm_1H[lb:ub]
    inten = data[lb:ub]
    intensity=data[pt]
 
    area=inten.sum()
    List_area.append(float(area.real))    
    List_inten.append(float(intensity.real))

    colors = cm.gist_heat(np.linspace(0, 1, len(tauList)+1))
    plt.xlim([6.5, 9.5])
    plt.plot(ppm, inten.real, color=colors[count]) 

x=array(tauList)
y=array(List_inten)
plt.show()

try:
    #initial guesses
    guessB=2/max(x)
    guessA=max(y)
    guess=(guessA,  guessB, -guessA)
    popt, pcov = curve_fit(exp, x, y, guess)
    #get the errors
    errors=np.sqrt(pcov.diagonal())
    print ('rate', popt[1], '+/-', errors[1] )   
    print(out,'rate', popt[1], '+/-', errors[1])  
    
except RuntimeError:
     print("@@@@@@@@@@@@@@@@@@@@@@@@")
     print("Error - curve_fit failed")
     print("@@@@@@@@@@@@@@@@@@@@@@@@") 

xaxis=np.arange(0,tauList[-1], 0.0001)

rate_fig = plt.figure(1)#ZY
plt.plot(tauList, List_inten, marker='o', markersize=10, linestyle='None')
plt.plot(xaxis, exp(xaxis, *popt), marker='None', linestyle='-', linewidth=2, color='r')
plt.savefig(f'rates{ZY_i}.ps', transparent=True)
plt.show()

And here is the script for trying to analyze all NMR files instead of just one:

rawdata_folder = str(Path.cwd())
scripts_folder = rawdata_folder + '/analyze'

scripts_folder

col = ['ppm','rate','rate_error']
logs = pd.DataFrame()
all_rate_figs = []

for ZY_i in range(1,16):
    currentdata_path = Path(f'{rawdata_folder}/{ZY_i}')
    print('Current folder: ')
    print(currentdata_path)
    this_script = f'{scripts_folder}/Rcalc{ZY_i}.ipynb'
    %run {this_script}
    
    #extract 'folder' , 'ppm','rate' and 'rate_error'
    this_data = {'ppm':uc0.ppm(float(pt[0])),'rate':popt[1],'rate_error':errors[1]}
    logs = logs.append(this_data,ignore_index=True)
    all_rate_figs.append(rate_fig)

for r in range(len(all_rate_figs)):
    print('Rate Figure ' + str(r+1))
    display(all_rate_figs[r])

Essentially, I have a large number of NMR data files and am hoping to be able to analyze all of them and create files with my desired output using just one python script. Does anyone have any ideas or tips? Thankyou!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật