Last active
March 14, 2020 17:14
-
-
Save AntoineLu/a149120115192a00665acf54138f2303 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#%% Import des packages | |
import numpy as np | |
import pandas as pd | |
from uncertainties import ufloat | |
from uncertainties import unumpy | |
#%% Définition des différentes fonctions | |
def couplingCalculator(file, couplage = '', write = ''): | |
try: | |
dataFrame = pd.read_csv(file, skiprows=0, error_bad_lines=False) | |
dataFrame = conv_pdToUfloat(dataFrame) | |
dataFrame['QL'] = dataFrame['f (MHz)']/dataFrame['Delta f (MHz)'] | |
# if couplage == '': | |
# couplage = dataFrame['couplage'] | |
if couplage == 'sur': | |
dataFrame['Qi'] = 2*dataFrame['QL']/(1+10**(dataFrame['S11 (dB)']/20)) | |
dataFrame['Qt'] = 2*dataFrame['QL']*10**(-dataFrame['S21 (dB)']/10)*(1+10**(dataFrame['S11 (dB)']/20)) | |
elif couplage == 'sous': | |
dataFrame['Qi'] = 2*dataFrame['QL']/(1-10**(dataFrame['S11 (dB)']/20)) | |
dataFrame['Qt'] = 2*dataFrame['QL']*10**(-dataFrame['S21 (dB)']/10)*(1-10**(dataFrame['S11 (dB)']/20)) | |
else: | |
print("ERREUR. couplage prend la valeur 'sous' ou 'sur'") | |
sigma = 6.93e6 #conductivité Nb à 300 K | |
# sigma = 5.8e7 #conductivité Cu à 300 K | |
mu0 = 4*np.pi*1e-7 | |
dataFrame['R_s Nb 300K'] = (2*np.pi*dataFrame["f (MHz)"]*1e6*mu0/sigma)**.5 | |
dataFrame['G'] = dataFrame['R_s Nb 300K'] / (1/dataFrame['QL'] - 1/dataFrame['Qi'] - 1/dataFrame['Qt']) | |
if write != '': | |
dataFrame2 = unumpy.nominal_values(dataFrame) | |
dataFrame2.to_csv(write,index = False) | |
return(dataFrame) | |
except: | |
print("Les noms des en-têtes du fichier CSV sont probablement mal définis. Consultez la documentation help(couplingCalculator)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment