ai.cdas


Nameai.cdas JSON
Version 1.2.3 PyPI version JSON
download
home_pagehttps://bitbucket.org/isavnin/ai.cdas
SummaryPython interface to CDAS data via REST API
upload_time2019-11-05 16:17:43
maintainer
docs_urlNone
authorAlexey Isavnin
requires_python
licenseMIT
keywords coordinated data analysis web cdaweb cdas spdf research space physics data facility nasa science
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            AI.CDAS: python interface to `CDAS <http://cdaweb.gsfc.nasa.gov/>`_ data
=========================================================================

This library provides access to CDAS database from python in a simple and fluid way through `CDAS REST api <http://cdaweb.gsfc.nasa.gov/WebServices/REST/>`_. It fetches the data either in `CDF (Common Data Format) <http://cdf.gsfc.nasa.gov/>`_ or ASCII format and returns it in the form of dictionaries of numpy arrays.

The full documentation is available at `aicdas.rtfd.io <http://aicdas.rtfd.io>`_.

Getting started
===============

Dependencies
------------

-  Python 3
-  `numpy <http://www.numpy.org/>`_
-  `requests <http://docs.python-requests.org/en/latest/>`_
-  `wget <https://pypi.python.org/pypi/wget>`_

Extra dependencies (at least one of the following)
--------------------------------------------------

-  `astropy <http://www.astropy.org/>`_
-  `CDF <http://cdf.gsfc.nasa.gov/>`_ +
   `spacepy <http://spacepy.lanl.gov/doc/index.html>`_

Installation
------------

Starting from version 1.2.0 AI.CDAS officially supports only Python 3, so make sure that you have a working isntallation of it.

Assuming the above requirement is satisfied install the package with Python package manager::

    $ pip install ai.cs

Known issues
------------

NASA CDAS REST API endpoint currently does not support IPv6 addressing. However, newer linux distros (for example, Ubuntu 16.04) are set up to prefer IPv6 addressing over IPv4 by default. This may result in unneeded delays in communication with server and data polling. If you experience the issue it might be that is the case with your system. Here is how it can be cured on Ubuntu 16.04::

    $ sudoedit /etc/gai.conf
    # Uncomment the line
    # precedence ::ffff:0:0/96  100

Now you machine will try IPv4 prior to IPv6. For other distros refer to respective docs. 

Examples
--------

**Example 1**: Retrieving observatory groups and associated instruments which measure plasma and solar wind:

.. code-block:: python

    from ai import cdas
    import json # for pretty output

    obsGroupsAndInstruments = cdas.get_observatory_groups_and_instruments(
        'istp_public',
        instrumentType='Plasma and Solar Wind'
    )
    print(json.dumps(obsGroupsAndInstruments, indent=4))

**Example 2**: Getting STEREO-A datasets using regular expressions for dataset id and label:

.. code-block:: python

    from ai import cdas
    import json # for pretty output

    datasets = cdas.get_datasets(
        'istp_public',
        idPattern='STA.*',
        labelPattern='.*STEREO.*'
    )
    print(json.dumps(datasets, indent=4))

**Example 3**: Fetching a list of variables in one of STEREO datasets:

.. code-block:: python

    from ai import cdas
    import json # for pretty output

    variables = cdas.get_variables('istp_public', 'STA_L1_MAGB_RTN')
    print(json.dumps(variables, indent=4))

**Example 4**: This snippet of code gets magnetic field data from STEREO-A spacecraft for one hour of 01.01.2010 and plots it (requires matplotlib):

.. code-block:: python

    from ai import cdas
    from datetime import datetime
    from matplotlib import pyplot as plt

    data = cdas.get_data(
        'sp_phys',
        'STA_L1_MAG_RTN',
        datetime(2010, 1, 1),
        datetime(2010, 1, 1, 0, 59, 59),
        ['BFIELD']
    )
    plt.plot(data['EPOCH'], data['BTOTAL'])
    plt.show()

**Example 5**: This snippet of code gets magnetic field data from STEREO-A spacecraft for one hour of 01.01.2010 and plots it (requires matplotlib). The data are downloaded in CDF format in this case. CDF format is binary and results in a much smaller filesize and hence faster downloads. In order for this to work you have to have NASA CDF library on your machine and spacepy installed afterwards:

.. code-block:: python

    from ai import cdas
    from datetime import datetime
    from matplotlib import pyplot as plt

    data = cdas.get_data(
        'sp_phys',
        'STA_L1_MAG_RTN',
        datetime(2010, 1, 1),
        datetime(2010, 1, 1, 0, 59, 59),
        ['BFIELD'],
        cdf=True # download data in CDF format
    )
    # Note that variables identifiers are different than in the previous
    # example. It often the case with CDAS data. You should check the
    # variables names by printing out `data` dictionary.
    plt.plot(data['Epoch'], data['BFIELD'][:, 3])
    plt.show()

**Example 6**: This snippet of code gets magnetic field data from STEREO-A spacecraft for 01.01.2010 and saves it to cache directory. The next time the same data is requested it is taken from cache without downloading:

.. code-block:: python

    import os
    from ai import cdas
    from datetime import datetime

    # For the sake of example we are using your current working
    # directory as a cache directory
    cache_dir = os.getcwd()
    cdas.set_cache(True, cache_dir)
    # this data is downloaded from CDAS
    data = cdas.get_data(
        'sp_phys',
        'STA_L1_MAG_RTN',
        datetime(2010, 1, 1),
        datetime(2010, 1, 1, 0, 59, 59),
        ['BFIELD']
    )
    # this data is taken from cache
    data = cdas.get_data(
        'sp_phys',
        'STA_L1_MAG_RTN',
        datetime(2010, 1, 1),
        datetime(2010, 1, 1, 0, 59, 59),
        ['BFIELD']
    )



            

Raw data

            {
    "_id": null,
    "home_page": "https://bitbucket.org/isavnin/ai.cdas",
    "name": "ai.cdas",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "coordinated data analysis web cdaweb cdas spdf research space physics data facility nasa science",
    "author": "Alexey Isavnin",
    "author_email": "alexey.isavnin@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/8a/b3/536cc3c794353f13a405c3ede03d93efe2b920076babb1efbf6e3327068a/ai.cdas-1.2.3.tar.gz",
    "platform": "",
    "description": "AI.CDAS: python interface to `CDAS <http://cdaweb.gsfc.nasa.gov/>`_ data\n=========================================================================\n\nThis library provides access to CDAS database from python in a simple and fluid way through `CDAS REST api <http://cdaweb.gsfc.nasa.gov/WebServices/REST/>`_. It fetches the data either in `CDF (Common Data Format) <http://cdf.gsfc.nasa.gov/>`_ or ASCII format and returns it in the form of dictionaries of numpy arrays.\n\nThe full documentation is available at `aicdas.rtfd.io <http://aicdas.rtfd.io>`_.\n\nGetting started\n===============\n\nDependencies\n------------\n\n-  Python 3\n-  `numpy <http://www.numpy.org/>`_\n-  `requests <http://docs.python-requests.org/en/latest/>`_\n-  `wget <https://pypi.python.org/pypi/wget>`_\n\nExtra dependencies (at least one of the following)\n--------------------------------------------------\n\n-  `astropy <http://www.astropy.org/>`_\n-  `CDF <http://cdf.gsfc.nasa.gov/>`_ +\n   `spacepy <http://spacepy.lanl.gov/doc/index.html>`_\n\nInstallation\n------------\n\nStarting from version 1.2.0 AI.CDAS officially supports only Python 3, so make sure that you have a working isntallation of it.\n\nAssuming the above requirement is satisfied install the package with Python package manager::\n\n    $ pip install ai.cs\n\nKnown issues\n------------\n\nNASA CDAS REST API endpoint currently does not support IPv6 addressing. However, newer linux distros (for example, Ubuntu 16.04) are set up to prefer IPv6 addressing over IPv4 by default. This may result in unneeded delays in communication with server and data polling. If you experience the issue it might be that is the case with your system. Here is how it can be cured on Ubuntu 16.04::\n\n    $ sudoedit /etc/gai.conf\n    # Uncomment the line\n    # precedence ::ffff:0:0/96  100\n\nNow you machine will try IPv4 prior to IPv6. For other distros refer to respective docs. \n\nExamples\n--------\n\n**Example 1**: Retrieving observatory groups and associated instruments which measure plasma and solar wind:\n\n.. code-block:: python\n\n    from ai import cdas\n    import json # for pretty output\n\n    obsGroupsAndInstruments = cdas.get_observatory_groups_and_instruments(\n        'istp_public',\n        instrumentType='Plasma and Solar Wind'\n    )\n    print(json.dumps(obsGroupsAndInstruments, indent=4))\n\n**Example 2**: Getting STEREO-A datasets using regular expressions for dataset id and label:\n\n.. code-block:: python\n\n    from ai import cdas\n    import json # for pretty output\n\n    datasets = cdas.get_datasets(\n        'istp_public',\n        idPattern='STA.*',\n        labelPattern='.*STEREO.*'\n    )\n    print(json.dumps(datasets, indent=4))\n\n**Example 3**: Fetching a list of variables in one of STEREO datasets:\n\n.. code-block:: python\n\n    from ai import cdas\n    import json # for pretty output\n\n    variables = cdas.get_variables('istp_public', 'STA_L1_MAGB_RTN')\n    print(json.dumps(variables, indent=4))\n\n**Example 4**: This snippet of code gets magnetic field data from STEREO-A spacecraft for one hour of 01.01.2010 and plots it (requires matplotlib):\n\n.. code-block:: python\n\n    from ai import cdas\n    from datetime import datetime\n    from matplotlib import pyplot as plt\n\n    data = cdas.get_data(\n        'sp_phys',\n        'STA_L1_MAG_RTN',\n        datetime(2010, 1, 1),\n        datetime(2010, 1, 1, 0, 59, 59),\n        ['BFIELD']\n    )\n    plt.plot(data['EPOCH'], data['BTOTAL'])\n    plt.show()\n\n**Example 5**: This snippet of code gets magnetic field data from STEREO-A spacecraft for one hour of 01.01.2010 and plots it (requires matplotlib). The data are downloaded in CDF format in this case. CDF format is binary and results in a much smaller filesize and hence faster downloads. In order for this to work you have to have NASA CDF library on your machine and spacepy installed afterwards:\n\n.. code-block:: python\n\n    from ai import cdas\n    from datetime import datetime\n    from matplotlib import pyplot as plt\n\n    data = cdas.get_data(\n        'sp_phys',\n        'STA_L1_MAG_RTN',\n        datetime(2010, 1, 1),\n        datetime(2010, 1, 1, 0, 59, 59),\n        ['BFIELD'],\n        cdf=True # download data in CDF format\n    )\n    # Note that variables identifiers are different than in the previous\n    # example. It often the case with CDAS data. You should check the\n    # variables names by printing out `data` dictionary.\n    plt.plot(data['Epoch'], data['BFIELD'][:, 3])\n    plt.show()\n\n**Example 6**: This snippet of code gets magnetic field data from STEREO-A spacecraft for 01.01.2010 and saves it to cache directory. The next time the same data is requested it is taken from cache without downloading:\n\n.. code-block:: python\n\n    import os\n    from ai import cdas\n    from datetime import datetime\n\n    # For the sake of example we are using your current working\n    # directory as a cache directory\n    cache_dir = os.getcwd()\n    cdas.set_cache(True, cache_dir)\n    # this data is downloaded from CDAS\n    data = cdas.get_data(\n        'sp_phys',\n        'STA_L1_MAG_RTN',\n        datetime(2010, 1, 1),\n        datetime(2010, 1, 1, 0, 59, 59),\n        ['BFIELD']\n    )\n    # this data is taken from cache\n    data = cdas.get_data(\n        'sp_phys',\n        'STA_L1_MAG_RTN',\n        datetime(2010, 1, 1),\n        datetime(2010, 1, 1, 0, 59, 59),\n        ['BFIELD']\n    )\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python interface to CDAS data via REST API",
    "version": "1.2.3",
    "project_urls": {
        "Homepage": "https://bitbucket.org/isavnin/ai.cdas"
    },
    "split_keywords": [
        "coordinated",
        "data",
        "analysis",
        "web",
        "cdaweb",
        "cdas",
        "spdf",
        "research",
        "space",
        "physics",
        "data",
        "facility",
        "nasa",
        "science"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0696c970242f219b764ebb093b0896733227584f7a81e02d2f8e9b8eaaf9d889",
                "md5": "e0921482ace8662de90c72a12e63cddf",
                "sha256": "62ef31a7afc807158bd9d944aeb7f5f59293798b232116130e45c3e9a78b26e0"
            },
            "downloads": -1,
            "filename": "ai.cdas-1.2.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e0921482ace8662de90c72a12e63cddf",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5900,
            "upload_time": "2019-11-05T16:17:41",
            "upload_time_iso_8601": "2019-11-05T16:17:41.707529Z",
            "url": "https://files.pythonhosted.org/packages/06/96/c970242f219b764ebb093b0896733227584f7a81e02d2f8e9b8eaaf9d889/ai.cdas-1.2.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8ab3536cc3c794353f13a405c3ede03d93efe2b920076babb1efbf6e3327068a",
                "md5": "0e4b477adfd83497af44c9b24b879873",
                "sha256": "1e93c3f6f667496a6b265ab3df0f8a72c7b2aefe12ee70590584f62460fe36ca"
            },
            "downloads": -1,
            "filename": "ai.cdas-1.2.3.tar.gz",
            "has_sig": false,
            "md5_digest": "0e4b477adfd83497af44c9b24b879873",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6074,
            "upload_time": "2019-11-05T16:17:43",
            "upload_time_iso_8601": "2019-11-05T16:17:43.406869Z",
            "url": "https://files.pythonhosted.org/packages/8a/b3/536cc3c794353f13a405c3ede03d93efe2b920076babb1efbf6e3327068a/ai.cdas-1.2.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2019-11-05 16:17:43",
    "github": false,
    "gitlab": false,
    "bitbucket": true,
    "codeberg": false,
    "bitbucket_user": "isavnin",
    "bitbucket_project": "ai.cdas",
    "lcname": "ai.cdas"
}
        
Elapsed time: 0.18389s