modified gr2sq.py for output png and xlsx
This commit is contained in:
@@ -13,6 +13,8 @@ par.add_argument('-q', '--qrange', nargs=2, default=None, type=float)
|
|||||||
par.add_argument('-t', '--trange', nargs=2, default=[10, 120], type=float)
|
par.add_argument('-t', '--trange', nargs=2, default=[10, 120], type=float)
|
||||||
par.add_argument('--pnt', default=1001, type=int)
|
par.add_argument('--pnt', default=1001, type=int)
|
||||||
par.add_argument('--lmd', default=1.54183, type=float)
|
par.add_argument('--lmd', default=1.54183, type=float)
|
||||||
|
par.add_argument('-p', '--plot', default=False, action='store_true')
|
||||||
|
|
||||||
args = par.parse_args()
|
args = par.parse_args()
|
||||||
|
|
||||||
|
|
||||||
@@ -1092,7 +1094,7 @@ class Data():
|
|||||||
self.pairs = self.gr.columns[1:-1]
|
self.pairs = self.gr.columns[1:-1]
|
||||||
|
|
||||||
def CalSq(self):
|
def CalSq(self):
|
||||||
columns = np.append(["Q"], self.pairs)
|
columns = np.append(["Q", "2theta"], self.pairs)
|
||||||
self.sq = pd.DataFrame(columns=columns)
|
self.sq = pd.DataFrame(columns=columns)
|
||||||
if args.qrange is None:
|
if args.qrange is None:
|
||||||
tmin, tmax = sorted(args.trange)
|
tmin, tmax = sorted(args.trange)
|
||||||
@@ -1152,7 +1154,7 @@ class Data():
|
|||||||
c_nd = n * ci * cj * Ncoe[a] * Ncoe[b] / Ncoe["cf"]**2
|
c_nd = n * ci * cj * Ncoe[a] * Ncoe[b] / Ncoe["cf"]**2
|
||||||
self.sq["ND"] += c_nd * self.sq[pair]
|
self.sq["ND"] += c_nd * self.sq[pair]
|
||||||
|
|
||||||
def PlotSq(self):
|
def OutputSq(self):
|
||||||
fig, ax = plt.subplots()
|
fig, ax = plt.subplots()
|
||||||
if args.qrange is None:
|
if args.qrange is None:
|
||||||
x = 2*np.arcsin(args.lmd / 4 / np.pi * self.sq["Q"])*180/np.pi
|
x = 2*np.arcsin(args.lmd / 4 / np.pi * self.sq["Q"])*180/np.pi
|
||||||
@@ -1162,9 +1164,15 @@ class Data():
|
|||||||
label = "$Q/{\\rm \\AA^{-1}}$"
|
label = "$Q/{\\rm \\AA^{-1}}$"
|
||||||
ax.plot(x, self.sq["XRD"])
|
ax.plot(x, self.sq["XRD"])
|
||||||
ax.set_xlabel(label)
|
ax.set_xlabel(label)
|
||||||
|
base, _ = os.path.splitext(self.grfile)
|
||||||
|
fig.savefig(f"{base}.png")
|
||||||
|
print(f"{base}.png was created.")
|
||||||
|
with pd.ExcelWriter(f"{base}.xlsx") as o:
|
||||||
|
self.sq.to_excel(o, sheet_name="S(Q)", index=False)
|
||||||
|
print(f"{base}.xlsx was created.")
|
||||||
|
if args.plot is True:
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
d = Data(args.grfile)
|
d = Data(args.grfile)
|
||||||
|
d.OutputSq()
|
||||||
d.PlotSq()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user