__init__.py 1.94 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
65
"""A collection of tools to read, write, visualize with the
Space Weather Modeling Framework (SWMF).

### Modules

These are automatically imported.

- `swmfpy.io` Input/Output 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.

*None yet.*
"""
__author__ = 'Qusai Al Shidi'
__license__ = 'MIT'
__version__ = '2020.1'
__maintainer__ = 'Qusai Al Shidi'
__email__ = 'qusai@umich.edu'


import sys
from . import paramin
from . import io
from . import web
assert sys.version_info >= (3, 6), "swmfpy requires Python >=3.6. Sorry :(."


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)