Skip to content

Commit c955217

Browse files
authored
Merge pull request #116 from falconstryker/devel
Fixed MarsPull -list; added docstrings
2 parents 45f758b + 21d4dec commit c955217

File tree

8 files changed

+2398
-578
lines changed

8 files changed

+2398
-578
lines changed

amescap/Script_utils.py

Lines changed: 307 additions & 163 deletions
Large diffs are not rendered by default.

bin/MarsCalendar.py

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
66
The executable requires 1 of the following arguments:
77
8-
* ``[-sol --sol]`` The sol to convert to Ls, OR
9-
* ``[-ls --ls]`` The Ls to convert to sol
8+
* ``[-sol --sol]`` The sol to convert to Ls, OR
9+
* ``[-ls --ls]`` The Ls to convert to sol
1010
1111
and optionally accepts:
1212
13-
* ``[-my --marsyear]`` The Mars Year of the simulation to compute sol or Ls from, AND/OR
14-
* ``[-c --continuous]`` Returns Ls in continuous form
13+
* ``[-my --marsyear]`` The Mars Year of the simulation to compute sol or Ls from, AND/OR
14+
* ``[-c --continuous]`` Returns Ls in continuous form
1515
1616
Third-party Requirements:
1717
@@ -41,8 +41,39 @@
4141

4242
def debug_wrapper(func):
4343
"""
44-
A decorator that wraps a function with error handling based on the
45-
--debug flag.
44+
A decorator that wraps a function with error handling
45+
based on the --debug flag.
46+
47+
If the --debug flag is set, it prints the full traceback
48+
of any exception that occurs. Otherwise, it prints a
49+
simplified error message.
50+
51+
:param func: The function to wrap.
52+
:type func: function
53+
:return: The wrapped function.
54+
:rtype: function
55+
:raises Exception: If an error occurs during the function call.
56+
:raises TypeError: If the function is not callable.
57+
:raises ValueError: If the function is not found.
58+
:raises NameError: If the function is not defined.
59+
:raises AttributeError: If the function does not have the
60+
specified attribute.
61+
:raises ImportError: If the function cannot be imported.
62+
:raises RuntimeError: If the function cannot be run.
63+
:raises KeyError: If the function does not have the
64+
specified key.
65+
:raises IndexError: If the function does not have the
66+
specified index.
67+
:raises IOError: If the function cannot be opened.
68+
:raises OSError: If the function cannot be accessed.
69+
:raises EOFError: If the function cannot be read.
70+
:raises MemoryError: If the function cannot be allocated.
71+
:raises OverflowError: If the function cannot be overflowed.
72+
:raises ZeroDivisionError: If the function cannot be divided by zero.
73+
:raises StopIteration: If the function cannot be stopped.
74+
:raises KeyboardInterrupt: If the function cannot be interrupted.
75+
:raises SystemExit: If the function cannot be exited.
76+
:raises AssertionError: If the function cannot be asserted.
4677
"""
4778

4879
@functools.wraps(func)
@@ -164,13 +195,24 @@ def parse_array(len_input):
164195
165196
:param len_input: The input Ls or sol to convert. Can either be
166197
one number (e.g., 300) or start stop step (e.g., 300 310 2).
167-
:type len_input: float or list of floats
198+
:type len_input: float or list of floats
168199
:raises: Error if neither ``[-ls --ls]`` or ``[-sol --sol]`` are
169200
provided.
170201
:return: ``input_as_arr`` An array formatted for input into
171202
``ls2sol`` or ``sol2ls``. If ``len_input = 300``, then
172203
``input_as_arr=[300]``. If ``len_input = 300 310 2``, then
173-
``input_as_arr = [300, 302, 304, 306, 308]``.\n
204+
``input_as_arr = [300, 302, 304, 306, 308]``.
205+
:rtype: list of floats
206+
:raises ValueError: If the input is not a valid number or
207+
range.
208+
:raises TypeError: If the input is not a valid type.
209+
:raises IndexError: If the input is not a valid index.
210+
:raises KeyError: If the input is not a valid key.
211+
:raises AttributeError: If the input is not a valid attribute.
212+
:raises ImportError: If the input is not a valid import.
213+
:raises RuntimeError: If the input is not a valid runtime.
214+
:raises OverflowError: If the input is not a valid overflow.
215+
:raises MemoryError: If the input is not a valid memory.
174216
"""
175217

176218
if len(len_input) == 1:
@@ -197,6 +239,36 @@ def parse_array(len_input):
197239

198240
@debug_wrapper
199241
def main():
242+
"""
243+
Main function for MarsCalendar command-line tool.
244+
245+
This function processes user-specified arguments to convert between
246+
Mars solar longitude (Ls) and sol (Martian day) values for a given
247+
Mars year. It supports both continuous and discrete sol
248+
calculations, and can handle input in either Ls or sol, returning
249+
the corresponding converted values. The results are printed in a
250+
formatted table.
251+
252+
Arguments are expected to be provided via the `args` namespace:
253+
254+
- args.marsyear: Mars year (default is 0)
255+
- args.continuous: If set, enables continuous sol calculation
256+
- args.ls: List of Ls values to convert to sol
257+
- args.sol: List of sol values to convert to Ls
258+
259+
:param args: Command-line arguments parsed using argparse.
260+
:type args: argparse.Namespace
261+
:raises ValueError: If the input is not a valid number or
262+
range.
263+
:returns: 0 if the program runs successfully, 1 if an error occurs.
264+
:rtype: int
265+
:raises RuntimeError: If the input is not a valid runtime.
266+
:raises TypeError: If the input is not a valid type.
267+
:raises IndexError: If the input is not a valid index.
268+
:raises KeyError: If the input is not a valid key.
269+
:raises AttributeError: If the input is not a valid attribute.
270+
:raises ImportError: If the input is not a valid import.
271+
"""
200272
# Load in user-specified Mars year, if any. Default = 0
201273
MY = np.squeeze(args.marsyear)
202274
print(f"MARS YEAR = {MY}")

0 commit comments

Comments
 (0)