How to use the spacepy.datamodel.SpaceData function in spacepy

To help you get started, we’ve selected a few spacepy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github drsteve / LANLGeoMag / Python / lgmpy / Lstar.py View on Github external
MagEphemInfo.LstarInfo.contents.mInfo.contents.Bfield(pointer(Pgsm), pointer(Bvec),
                                                          MagEphemInfo.LstarInfo.contents.mInfo)
    ans['Bcalc'] = datamodel.dmarray(Bvec.tolist(), attrs={'units':'nT'})
    ans['Bcalc'].attrs['model'] = Bfield
    ans['Bcalc'].attrs['Kp'] = Kp
    ans['Bcalc'].attrs['coord_system'] = 'GSM'

    # save its magnitude in the structure
    MagEphemInfo.B = Bvec.magnitude()

    # check and see if the field line is closed before doing much work
    trace, northern, southern, minB, Lsimple = Closed_Field.Closed_Field(MagEphemInfo, extended_out=True)

    # presetup the ans[Angle] so that it can be filled correctly
    for pa in Alpha:
        ans[pa] = datamodel.SpaceData()
        ans[pa]['Lsimple'] = datamodel.dmarray([Lsimple])
        #sets up nans in case of Lstar failure
        ans[pa]['I'] = datamodel.dmarray([numpy.nan])
        ans[pa]['Lstar'] = datamodel.dmarray([numpy.nan], attrs={'info':trace})
        ans[pa]['LMcIlwain'] = datamodel.dmarray([numpy.nan])
        ans[pa]['LHilton'] = datamodel.dmarray([numpy.nan])
        ans[pa]['Bmin'] = datamodel.dmarray([numpy.nan], attrs={'units':'nT'})
        ans[pa]['Bmirror'] = datamodel.dmarray([numpy.nan], attrs={'units':'nT'})
    
    if trace != 'LGM_CLOSED':
        return ans
        # if this is not LGM_CLOSED then don't both with any pitch angle?  true?

    #  Save field-related quantities for each Pitch Angle.
    MagEphemInfo.Pmin = Lgm_Vector.Lgm_Vector(*minB)
    MagEphemInfo.Bmin = MagEphemInfo.LstarInfo.contents.mInfo.contents.Bmin
github drsteve / LANLGeoMag / Python / lgmpy / Lstar.py View on Github external
raise(NotImplementedError("Only GSM or SM input currently supported"))
    
## void Lgm_ComputeLstarVersusPA( long int Date, double UTC, Lgm_Vector *u, int nAlpha, 
##                                 double *Alpha, int Quality, int Colorize, Lgm_MagEphemInfo *MagEphemInfo ) {


    if QinDenton:# and Bfield == 'Lgm_B_TS04': # these are the params we will use.
        # Grab the QinDenton data
        # Lgm_get_QinDenton_at_JD( JD, &p, 1 );
        # JD = Lgm_Date_to_JD( Date, UTC, mInfo->c );
        JD = Lgm_Wrap.Lgm_Date_to_JD(datelong, utc, pointer(mmi.c))
        qd_one = Lgm_Wrap.Lgm_QinDentonOne()
        Lgm_Wrap.Lgm_get_QinDenton_at_JD( JD, pointer(qd_one), cverbosity, 0)
        Lgm_Wrap.Lgm_set_QinDenton(pointer(qd_one), pointer(mmi.c))
        
        ans['params'] = dm.SpaceData()
        for att in dir(qd_one):
            if att[0] != '_':
                ans['params'][att] = getattr(qd_one, att)
    else:
        # save params
        ans['params'] = params
        if params == None:
            params = {}
        # step through the params dict and populate MagEphemInfo
        for key in params:
            if key == 'W':
                double6 = c_double*6
                W = double6(*params[key])
                MagEphemInfo.LstarInfo.contents.mInfo.contents.__setattr__(key, W)
            else:
                MagEphemInfo.LstarInfo.contents.mInfo.contents.__setattr__(key, params[key])
github drsteve / LANLGeoMag / Python / lgmpy / Lstar.py View on Github external
import Lgm_Wrap
from Lgm_Wrap import Lgm_Set_Coord_Transforms, SM_TO_GSM, Lgm_Convert_Coords, \
    Lgm_SetLstarTolerances, RadPerDeg, GSM_TO_WGS84, WGS84_TO_EDMAG,\
    Lgm_McIlwain_L, Lgm_EDMAG_to_R_MLAT_MLON_MLT, Lgm_FreeMagEphemInfo_Children, \
    Lgm_ComputeLstarVersusPA, Lgm_B_TS04, Lgm_B_T96, Lgm_QinDentonOne, Lgm_set_QinDenton, Lgm_get_QinDenton_at_JD
from Lgm_Wrap import Lstar as Lgm_Lstar
import Lgm_Vector
import Lgm_CTrans
import Lgm_MagEphemInfo
import Closed_Field
from _Bfield_dict import Bfield_dict

__author__ = 'Brian Larsen, Steve Morley, Mike Henderson - LANL'

class Lstar_Data(datamodel.SpaceData):
    """
    Class to store Lstar data and associated attributes
        - this class is a dictionary of numpy arrays that have attributes

    Examples
    ========
    >>> import spacepy.datamodel as dm
    >>> from lgmpy import Lstar
    >>> dat = Lstar.Lstar_Data()
    >>> dat.attrs['Author'] = 'John Doe'
    >>> dat['position'] = dm.dmarray([1,2,3], attrs={'system':'GSM'})
    >>> print(dat)
    +
    :|____Author (str [8])
    |____position (spacepy.datamodel.dmarray (3,))
        :|____system (str [3])
github drsteve / LANLGeoMag / Python / lgmpy / MagData.py View on Github external
"""
Overview
========
Data model for magnetic field data.

The SpaceData class is a derived dictionary used to hold information in a common
format
"""
__author__ = 'Brian Larsen'

import numpy as np
import spacepy.toolbox as tb

from spacepy import datamodel

class MagData(datamodel.SpaceData):
    """
    Class to store data and attributes

    Parameters
    ==========
    args : arguments, optional
        passed directly to datamodel.SpaceData
    kwargs : keyword arguments, optional
        passed directly to datamodel.SpaceData

    See Also
    ========
    spacepy.datamodel.SpaceData
    """
    def __init__(self, *args, **kwargs):
        super(MagData, self).__init__(*args, **kwargs)
github drsteve / LANLGeoMag / Python / lgmpy / Lstar.py View on Github external
MagEphemInfo.LstarInfo.contents.mInfo.contents.Bfield(pointer(Pgsm), pointer(Bvec),
                                                          MagEphemInfo.LstarInfo.contents.mInfo)
    ans['Bcalc'] = datamodel.dmarray(Bvec.tolist(), attrs={'units':'nT'})
    ans['Bcalc'].attrs['model'] = Bfield
    ans['Bcalc'].attrs['params'] = params
    ans['Bcalc'].attrs['coord_system'] = 'GSM'

    # save its magnitude in the structure
    MagEphemInfo.B = Bvec.magnitude()

    # check and see if the field line is closed before doing much work
    trace, northern, southern, minB, Lsimple = Closed_Field.Closed_Field(MagEphemInfo, extended_out=True)

    # presetup the ans[Angle] so that it can be filled correctly
    for pa in Alpha:
        ans[pa] = datamodel.SpaceData()
        ans[pa]['Lsimple'] = datamodel.dmarray([Lsimple])
        #sets up nans in case of Lstar failure
        ans[pa]['I'] = datamodel.dmarray(numpy.nan)
        ans[pa]['Lstar'] = datamodel.dmarray(numpy.nan, attrs={'info':trace})
        ans[pa]['LMcIlwain'] = datamodel.dmarray(numpy.nan)
        ans[pa]['LHilton'] = datamodel.dmarray(numpy.nan)
        ans[pa]['Bmin'] = datamodel.dmarray(numpy.nan, attrs={'units':'nT'})
        ans[pa]['Bmirror'] = datamodel.dmarray(numpy.nan, attrs={'units':'nT'})

    if trace != 'LGM_CLOSED':
        return ans
        # if this is not LGM_CLOSED then don't both with any pitch angle?  true?

    #  Save field-related quantities for each Pitch Angle.
    MagEphemInfo.Pmin = Lgm_Vector.Lgm_Vector(*minB)
    MagEphemInfo.Bmin = MagEphemInfo.LstarInfo.contents.mInfo.contents.Bmin