Note: The default ITS GitLab runner is a shared resource and is subject to slowdowns during heavy usage.
You can run your own GitLab runner that is dedicated just to your group if you need to avoid processing delays.

__init__.py 2.21 KB
Newer Older
1
"""A collection of tools to read, write, visualize with the
2
3
Space Weather Modeling Framework (SWMF).

4
### Modules
5
6
7

These are automatically imported.

8
9
10
- `swmfpy.io` Input/Output tools.
- `swmfpy.paramin` PARAM.in editing tools.
- `swmfpy.web` Internet data downloading/uploading tools.
11

12
### Extra Modules
13

Qusai Al Shidi's avatar
Qusai Al Shidi committed
14
15
These must be imported manually.

16
17
- `swmfpy.tools` Tools used in swmfpy. You might find these useful but it is
  unecessary.
18
19
- `swmfpy.tecplottools` Tools for working with the Tecplot visualization
  software. Requires a Tecplot license and the pytecplot python package.
Qusai Al Shidi's avatar
Qusai Al Shidi committed
20
"""
21
__author__ = 'Qusai Al Shidi'
22
23
__license__ = 'LGPLv3'
__version__ = '2020.7'
24
25
__maintainer__ = 'Qusai Al Shidi'
__email__ = 'qusai@umich.edu'
Qusai Al Shidi's avatar
Qusai Al Shidi committed
26
27


Qusai Al Shidi's avatar
Qusai Al Shidi committed
28
import sys
Qusai Al Shidi's avatar
Qusai Al Shidi committed
29
30
from . import paramin
from . import io
31
from . import web
32
assert sys.version_info >= (3, 6), "swmfpy requires Python >=3.6. Sorry :(."
33
34
35
36
37
38
39
40
41
42


def write_imf_from_omni(time_from, time_to, filename='IMF.dat', **kwargs):
    """Writes an IMF.dat file for the geospace model runs for a specific time
    period.

    Args:
        time_from (datetime.datetime): Time to begin omni data retrieval
        time_to (datetime.datetime): Time to end omni data retrieval
        filename (str): The filename for the dat file, defaults to 'IMF.dat'.
43
44
45

    **kwargs:
        see #swmfpy.io.write_imf_input() and #swmfpy.web.get_omni_data()
46

47
48
49
    Returns:
        (dict): Dictionary of omni data.

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
    Examples:
        Using this function is simple:
        ```python
        import swmfpy
        import datetime as dt
        times = (dt.datetime(2014, 2, 2), dt.datetime(2014, 2, 4))
        # Usually the kwargs are unecessary
        swmfpy.write_imf_input(*times)
        # Sometimes this
        swmfpy.write_imf_input(*times, filename='run/IMF.dat')
        ```
    """
    omni_data = web.get_omni_data(time_from, time_to, **kwargs)
    commands = ['#COOR', 'GSE']
    if kwargs.get('commands', None):
        kwargs['commands'] += commands
    else:
        kwargs['commands'] = commands
    column_keys = ['times',
                   'bx', 'by_gse', 'bz_gse', 'vx_gse', 'vy_gse', 'vz_gse',
                   'density', 'temperature']
    io.write_imf_input(omni_data, filename, column_keys=column_keys, **kwargs)
72
    return omni_data