Commit cc466269 authored by Qusai Al Shidi's avatar Qusai Al Shidi 💬
Browse files

Improved pydoc

parent f9f3b691
"""Tools for SWMF
swmfpy
======
"""
SWMF Tools
==========
A collection of tools to read, write, visualize with the
Space Weather Modeling Framework (SWMF).
......@@ -12,15 +11,15 @@ Modules
These are automatically imported.
- swmfpy.io: Input/Output tools.
- paramin.io: PARAM.in editing tools.
- web.io: Internet tools.
- swmfpy.paramin: PARAM.in editing tools.
- swmfpy.web: Internet data downloading/uploading tools.
Extra Modules
-------------
These are not automatically imported. Might have extra dependancies.
*Non yet.*
*None yet.*
"""
__author__ = "Qusai Al Shidi"
__license__ = "MIT"
......
......@@ -6,8 +6,7 @@ These tools are to help script the editing of PARAM.in files.
"""
__all__ = [
'read_command',
'replace_command',
'get_command'
'replace_command'
]
__author__ = 'Qusai Al Shidi'
__email__ = 'qusai@umich.edu'
......@@ -15,25 +14,6 @@ __email__ = 'qusai@umich.edu'
import logging
def get_command(line):
"""Returns the '#COMMAND' if on line.
Args:
line (str, list, tuple): The line in the PARAM.in file.
Returns:
(str): '#COMMAND' if found and None if not.
"""
if isinstance(line, (str, list, tuple)): # Raises type error otherwise
if isinstance(line, str):
to_check = line.split()
if to_check and to_check[0].startswith('#'):
return to_check[0]
return None
return get_command(line[0])
return None
def replace_command(parameters, input_file, output_file='PARAM.in'):
"""Replace values for the parameters in a PARAM.in file.
......@@ -73,7 +53,7 @@ def replace_command(parameters, input_file, output_file='PARAM.in'):
for line_num, line in enumerate(lines):
# If the current command is what we want
command = get_command(line)
command = _get_command(line)
if command in parameters.keys():
for param, value in enumerate(parameters[command]):
......@@ -133,12 +113,12 @@ def read_command(command, paramin_file='PARAM.in', **kwargs):
command_found = False # to know if worked
in_command = False # when after command needed
for line in paramin:
if get_command(line) == command:
if _get_command(line) == command:
logger.info('Found command: %s', command)
command_found = True
in_command = True
return_values.append(command)
elif in_command and get_command(line): # Make sure not out of cmd
elif in_command and _get_command(line): # Make sure not out of cmd
in_command = False
elif line.split() and in_command:
value = line.split()[0]
......@@ -158,6 +138,7 @@ def read_command(command, paramin_file='PARAM.in', **kwargs):
return return_values # empty list might mean command not found
# HIDDEN FUNCTIONS
def _make_line(value):
"""Makes the paramin line based on value type recursively"""
if isinstance(value, str):
......@@ -165,3 +146,22 @@ def _make_line(value):
elif isinstance(value, list):
return '\t\t\t'.join([_make_line(v) for v in value])
return str(value)
def _get_command(line):
"""Returns the '#COMMAND' if on line.
Args:
line (str, list, tuple): The line in the PARAM.in file.
Returns:
(str): '#COMMAND' if found and None if not.
"""
if isinstance(line, (str, list, tuple)): # Raises type error otherwise
if isinstance(line, str):
to_check = line.split()
if to_check and to_check[0].startswith('#'):
return to_check[0]
return None
return _get_command(line[0])
return None
Supports Markdown
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