Mercurial > repos > muon-spectroscopy-computational-project > larch_athena
comparison larch_athena.py @ 4:a0d3b0fe0fa3 draft
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_athena commit 3fe6078868efd0fcea0fb5eea8dcd4b152d9c0a8
author | muon-spectroscopy-computational-project |
---|---|
date | Thu, 11 Apr 2024 09:01:59 +0000 |
parents | 82e9dd980916 |
children | 27015eaf9a78 |
comparison
equal
deleted
inserted
replaced
3:82e9dd980916 | 4:a0d3b0fe0fa3 |
---|---|
259 do_calibrate: bool, | 259 do_calibrate: bool, |
260 calibrate_settings: dict, | 260 calibrate_settings: dict, |
261 do_rebin: bool, | 261 do_rebin: bool, |
262 do_pre_edge: bool, | 262 do_pre_edge: bool, |
263 pre_edge_settings: dict, | 263 pre_edge_settings: dict, |
264 ref_channel: str, | |
264 do_xftf: bool, | 265 do_xftf: bool, |
265 xftf_settings: dict, | 266 xftf_settings: dict, |
266 plot_graph: list, | 267 plot_graph: list, |
267 annotation: str, | 268 annotation: str, |
268 path_key: str = "out", | 269 path_key: str = "out", |
284 xas_data = xas_data.rebinned | 285 xas_data = xas_data.rebinned |
285 # After re-bin, will need to redo pre-edge | 286 # After re-bin, will need to redo pre-edge |
286 do_pre_edge = True | 287 do_pre_edge = True |
287 | 288 |
288 if do_pre_edge: | 289 if do_pre_edge: |
289 pre_edge_with_defaults(xas_data, pre_edge_settings) | 290 pre_edge_with_defaults(xas_data, pre_edge_settings, ref_channel) |
290 | 291 |
291 if do_xftf: | 292 if do_xftf: |
292 xftf_with_defaults(xas_data, xftf_settings) | 293 xftf_with_defaults(xas_data, xftf_settings) |
293 | 294 |
294 if plot_graph: | 295 if plot_graph: |
320 if "edge" in plot_keys: | 321 if "edge" in plot_keys: |
321 plt.subplot(nrows, 1, index) | 322 plt.subplot(nrows, 1, index) |
322 plt.plot(xas_data.energy, xas_data.pre_edge, "g", label="pre-edge") | 323 plt.plot(xas_data.energy, xas_data.pre_edge, "g", label="pre-edge") |
323 plt.plot(xas_data.energy, xas_data.post_edge, "r", label="post-edge") | 324 plt.plot(xas_data.energy, xas_data.post_edge, "r", label="post-edge") |
324 plt.plot(xas_data.energy, xas_data.mu, "b", label="fit data") | 325 plt.plot(xas_data.energy, xas_data.mu, "b", label="fit data") |
326 if hasattr(xas_data, "mu_std"): | |
327 plt.fill_between( | |
328 x=xas_data.energy, | |
329 y1=xas_data.mu - xas_data.mu_std, | |
330 y2=xas_data.mu + xas_data.mu_std, | |
331 alpha=0.2, | |
332 label="standard deviation", | |
333 ) | |
334 e0 = xas_data.e0 | |
335 plt.axvline(e0, color="m", label=f"edge energy = {e0}") | |
325 plt.grid(color="r", linestyle=":", linewidth=1) | 336 plt.grid(color="r", linestyle=":", linewidth=1) |
326 plt.xlabel("Energy (eV)") | 337 plt.xlabel("Energy (eV)") |
327 plt.ylabel("x$\mu$(E)") # noqa: W605 | 338 plt.ylabel("x$\mu$(E)") # noqa: W605 |
328 plt.title("Pre-edge and post_edge fitting to $\mu$") # noqa: W605 | 339 plt.title("Pre-edge and post_edge fitting to $\mu$") # noqa: W605 |
329 plt.legend() | 340 plt.legend() |
330 index += 1 | 341 index += 1 |
331 | 342 |
332 if "flat" in plot_keys: | 343 if "flat" in plot_keys: |
333 plt.subplot(nrows, 1, index) | 344 plt.subplot(nrows, 1, index) |
334 plt.plot(xas_data.energy, xas_data.flat) | 345 plt.plot(xas_data.energy, xas_data.flat, label="flattened signal") |
346 if hasattr(xas_data, "mu_std"): | |
347 mu_std_normalised = xas_data.mu_std / xas_data.edge_step | |
348 plt.fill_between( | |
349 x=xas_data.energy, | |
350 y1=xas_data.flat - mu_std_normalised, | |
351 y2=xas_data.flat + mu_std_normalised, | |
352 alpha=0.2, | |
353 label="standard deviation", | |
354 ) | |
355 plt.legend() | |
335 plt.grid(color="r", linestyle=":", linewidth=1) | 356 plt.grid(color="r", linestyle=":", linewidth=1) |
336 plt.xlabel("Energy (eV)") | 357 plt.xlabel("Energy (eV)") |
337 plt.ylabel("Flattened x$\mu$(E)") # noqa: W605 | 358 plt.ylabel("Flattened x$\mu$(E)") # noqa: W605 |
338 index += 1 | 359 index += 1 |
339 | 360 |
355 matplotlib.use("Agg") | 376 matplotlib.use("Agg") |
356 | 377 |
357 dat_file = sys.argv[1] | 378 dat_file = sys.argv[1] |
358 input_values = json.load(open(sys.argv[2], "r", encoding="utf-8")) | 379 input_values = json.load(open(sys.argv[2], "r", encoding="utf-8")) |
359 merge_inputs = input_values["merge_inputs"]["merge_inputs"] | 380 merge_inputs = input_values["merge_inputs"]["merge_inputs"] |
360 data_format = input_values["merge_inputs"]["format"]["format"] | 381 format_inputs = input_values["merge_inputs"]["format"] |
361 if "is_zipped" in input_values["merge_inputs"]["format"]: | 382 if "is_zipped" in format_inputs: |
362 is_zipped = bool( | 383 is_zipped = bool(format_inputs["is_zipped"]["is_zipped"]) |
363 input_values["merge_inputs"]["format"]["is_zipped"]["is_zipped"] | |
364 ) | |
365 else: | 384 else: |
366 is_zipped = False | 385 is_zipped = False |
367 | 386 |
368 extract_group = None | 387 extract_group = None |
369 if "extract_group" in input_values["merge_inputs"]["format"]: | 388 if "extract_group" in format_inputs: |
370 extract_group = input_values["merge_inputs"]["format"]["extract_group"] | 389 extract_group = format_inputs["extract_group"] |
371 | 390 |
372 energy_column = None | 391 if "energy_column" not in format_inputs: |
373 mu_column = None | 392 energy_column = None |
374 if "energy_column" in input_values["merge_inputs"]["format"]: | 393 else: |
375 energy_column = input_values["merge_inputs"]["format"]["energy_column"] | 394 energy_column = format_inputs["energy_column"]["energy_column"] |
376 if "mu_column" in input_values["merge_inputs"]["format"]: | 395 if energy_column == "auto": |
377 mu_column = input_values["merge_inputs"]["format"]["mu_column"] | 396 energy_column = None |
397 elif energy_column == "other": | |
398 energy_column_input = format_inputs["energy_column"] | |
399 energy_column = energy_column_input["energy_column_text"] | |
400 | |
401 if "mu_column" not in format_inputs: | |
402 mu_column = None | |
403 else: | |
404 mu_column = format_inputs["mu_column"]["mu_column"] | |
405 if mu_column == "auto": | |
406 mu_column = None | |
407 elif mu_column == "other": | |
408 mu_column = format_inputs["mu_column"]["mu_column_text"] | |
378 | 409 |
379 reader = Reader( | 410 reader = Reader( |
380 energy_column=energy_column, | 411 energy_column=energy_column, |
381 mu_column=mu_column, | 412 mu_column=mu_column, |
382 data_format=data_format, | 413 data_format=format_inputs["format"], |
383 extract_group=extract_group, | 414 extract_group=extract_group, |
384 ) | 415 ) |
385 keyed_data = reader.load_data( | 416 keyed_data = reader.load_data( |
386 dat_file=dat_file, | 417 dat_file=dat_file, |
387 merge_inputs=merge_inputs, | 418 merge_inputs=merge_inputs, |
394 | 425 |
395 do_rebin = input_values["processing"].pop("rebin") | 426 do_rebin = input_values["processing"].pop("rebin") |
396 | 427 |
397 pre_edge_items = input_values["processing"]["pre_edge"].items() | 428 pre_edge_items = input_values["processing"]["pre_edge"].items() |
398 pre_edge_settings = {k: v for k, v in pre_edge_items if v is not None} | 429 pre_edge_settings = {k: v for k, v in pre_edge_items if v is not None} |
399 do_pre_edge = pre_edge_settings.pop("pre_edge") == "true" | 430 do_pre_edge = bool(pre_edge_settings.pop("pre_edge")) |
431 | |
432 ref_channel = None | |
433 if "ref_channel" in pre_edge_settings: | |
434 ref_channel = pre_edge_settings.pop("ref_channel") | |
400 | 435 |
401 xftf_items = input_values["processing"]["xftf"].items() | 436 xftf_items = input_values["processing"]["xftf"].items() |
402 xftf_settings = {k: v for k, v in xftf_items if v is not None} | 437 xftf_settings = {k: v for k, v in xftf_items if v is not None} |
403 do_xftf = xftf_settings.pop("xftf") == "true" | 438 do_xftf = xftf_settings.pop("xftf") == "true" |
404 | 439 |
411 do_calibrate=do_calibrate, | 446 do_calibrate=do_calibrate, |
412 calibrate_settings=calibrate_settings, | 447 calibrate_settings=calibrate_settings, |
413 do_rebin=do_rebin, | 448 do_rebin=do_rebin, |
414 do_pre_edge=do_pre_edge, | 449 do_pre_edge=do_pre_edge, |
415 pre_edge_settings=pre_edge_settings, | 450 pre_edge_settings=pre_edge_settings, |
451 ref_channel=ref_channel, | |
416 do_xftf=do_xftf, | 452 do_xftf=do_xftf, |
417 xftf_settings=xftf_settings, | 453 xftf_settings=xftf_settings, |
418 plot_graph=plot_graph, | 454 plot_graph=plot_graph, |
419 annotation=annotation, | 455 annotation=annotation, |
420 path_key=key, | 456 path_key=key, |