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 1.95 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
14
15

These are not automatically imported. Might have extra dependancies.

Qusai Al Shidi's avatar
Qusai Al Shidi committed
16
*None yet.*
Qusai Al Shidi's avatar
Qusai Al Shidi committed
17
"""
18
19
__author__ = 'Qusai Al Shidi'
__license__ = 'MIT'
20
__version__ = '2020.1'
21
22
__maintainer__ = 'Qusai Al Shidi'
__email__ = 'qusai@umich.edu'
Qusai Al Shidi's avatar
Qusai Al Shidi committed
23
24


Qusai Al Shidi's avatar
Qusai Al Shidi committed
25
import sys
Qusai Al Shidi's avatar
Qusai Al Shidi committed
26
27
from . import paramin
from . import io
28
from . import web
29
assert sys.version_info >= (3, 6), "swmfpy requires Python >=3.6. Sorry :(."
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64


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'.
        **kwargs:
            see #swmfpy.io.write_imf_input() and #swmfpy.web.get_omni_data()

    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)