From d94fe40b9c3e7d336836aa5dab1d34904a7d0095 Mon Sep 17 00:00:00 2001 From: Chris S W Davis Date: Wed, 15 Nov 2023 14:04:57 +0000 Subject: [PATCH] added some exceptions to help users deal with failed magnetocosmics running --- AsympDirsCalculator/AsympDirsTools.py | 6 ++++++ AsympDirsCalculator/MAGNETOCOSMICSrun.py | 6 +++++- .../magcos_running_scripts/runNoRewriteMAGCOSsimulation.sh | 2 ++ setup.py | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/AsympDirsCalculator/AsympDirsTools.py b/AsympDirsCalculator/AsympDirsTools.py index f5a68fd..be660d8 100644 --- a/AsympDirsCalculator/AsympDirsTools.py +++ b/AsympDirsCalculator/AsympDirsTools.py @@ -1,6 +1,12 @@ import numpy as np import pandas as pd import datetime as dt +import shutil + +try: + assert not (shutil.which("magnetocosmics") is None) +except AssertionError: + raise Exception("ERROR: AsympDirsCalculator currently requires magnetocosmics to be installed, such that the command 'magnetocosmics' can be run in terminal. If you have installed a copy of magnetocosmics, please check to see ensure that your paths have been set correctly, and that magneto-env.sh has been sourced correctly. If you are having issues or suspect there might be a bug, please feel free to report it at https://github.com/ssc-maire/AsymptoticDirectionsCalculator-public/issues , and I will try to respond to your issue as soon as I'm able to.") from .MAGNETOCOSMICSrunManager import MAGNETOCOSMICSrunManager diff --git a/AsympDirsCalculator/MAGNETOCOSMICSrun.py b/AsympDirsCalculator/MAGNETOCOSMICSrun.py index a30808e..182ea3d 100644 --- a/AsympDirsCalculator/MAGNETOCOSMICSrun.py +++ b/AsympDirsCalculator/MAGNETOCOSMICSrun.py @@ -48,7 +48,11 @@ def __init__(self, macroFileGenerator.generateMacro(array_of_lats_and_longs, array_of_zeniths_and_azimuths) - subprocess.run(_magnetocosmicsShellScriptPath) + try: + magnetocosmics_subprocess_run = subprocess.run(_magnetocosmicsShellScriptPath) + assert magnetocosmics_subprocess_run.returncode == 0 + except: + raise Exception("ERROR: running magnetocosmics and processing output files failed, please check the above error messages to debug what might have gone wrong.") os.chdir(originalDirectory) diff --git a/AsympDirsCalculator/magcos_running_scripts/runNoRewriteMAGCOSsimulation.sh b/AsympDirsCalculator/magcos_running_scripts/runNoRewriteMAGCOSsimulation.sh index 289b63b..87dbd95 100755 --- a/AsympDirsCalculator/magcos_running_scripts/runNoRewriteMAGCOSsimulation.sh +++ b/AsympDirsCalculator/magcos_running_scripts/runNoRewriteMAGCOSsimulation.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + time magnetocosmics runningAsymptoticDirection.g4mac mv AsymptoticDirection*.out outputFiles diff --git a/setup.py b/setup.py index eb93c07..98ebe64 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ package_data={"AsympDirsCalculator":["magcos_running_scripts/runNoRewriteMAGCOSsimulation.sh", "magcos_running_scripts/AsymptoticDirection.g4mac", ]}, - version='1.0.4', + version='1.0.5', description='Python library containing tools for calculating asymptotic directions and vertical cut-off rigidities.', long_description=long_description, long_description_content_type='text/markdown',