Commit ea737a5e authored by Jean-Eric Campagne's avatar Jean-Eric Campagne
Browse files

cmd line arg for phase.py

parent 5305e393
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
import getopt, sys
def pcubic(x,a,b,c,d):
return a*x**3 + b*x**2 + c*x + d
......@@ -43,7 +45,7 @@ def FitPolynomial(x,y,degMax=30,iqrMax=0.005):
return rc, xmean, polDeg, coeff, residuals, iqrn
def FitPolar(data):
def FitPolar(data, src, polar):
fig, axs = plt.subplots(2*(data.shape[1]-1),1,sharey=False,sharex=True,figsize=(7,7))
freq = data[:,0]
infos_list = []
......@@ -83,22 +85,46 @@ def FitPolar(data):
###
rootdir = './CasA/'
src='hv_A00_17juil18'
polars = ['H','V']
for idx, polar in enumerate(polars):
data = LoadPlotData(rootdir, src, polar)
infos = FitPolar(data)
filename = 'PhaseParam-'+src+'-'+polar+'.txt'
with open(filename,"w") as f:
f.write("\n".join(" ".join(map(str,x)) for x in infos))
#for bookkeeping
plt.savefig(src+'-'+polar+'-fit.pdf',bbox_inches = 'tight')
def main():
rootdir = './CasA/'
src='hv_A00_17juil18'
polars = ['H','V']
try:
opts, args = getopt.getopt(sys.argv[1:],"hr:s:p:",
["rootdir=","src=","polars="])
except getopt.GetoptError as err:
print(str(err))
print('phase.py -r <rootdir> -s <source> -p <polar as H or V or H,V>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print('phase.py -r <rootdir> -s <source> -p <polar as H or V or H,V>')
sys.exit()
elif opt in ("-r", "--rootdir"):
rootdir = arg
elif opt in ("-s", "--src"):
src = arg
elif opt in ("-p","--polars"):
polars = arg.split(",")
print('rootdir =<',rootdir,'>',' src = <',src,'>',' polars = <',polars,'>')
for idx, polar in enumerate(polars):
data = LoadPlotData(rootdir, src, polar)
infos = FitPolar(data, src, polar)
filename = 'PhaseParam-'+src+'-'+polar+'.txt'
with open(filename,"w") as f:
f.write("\n".join(" ".join(map(str,x)) for x in infos))
plt.savefig(src+'-'+polar+'-fit.pdf',bbox_inches = 'tight')
###########################
if __name__ == "__main__":
main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment