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.17 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
- `swmfpy.tools` Tools used in swmfpy. You might find these useful but it is
  unecessary.
16
17
- `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
18
"""
19
20
__author__ = 'Qusai Al Shidi'
__license__ = 'MIT'
21
__version__ = '2020.6'
22
23
__maintainer__ = 'Qusai Al Shidi'
__email__ = 'qusai@umich.edu'
Qusai Al Shidi's avatar
Qusai Al Shidi committed
24
25


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


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'.
41
42
43

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

45
46
47
    Returns:
        (dict): Dictionary of omni data.

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
    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)
70
    return omni_data