예제 #1
0
def test_2_1():
    # All TestData2.1 parameters

    server = 'http://hapi-server.org/servers-dev/TestData2.1/hapi'
    dataset = 'dataset1'
    start = '1970-01-01Z'
    stop = '1970-01-01T00:00:11Z'
    opts = {'logging': logging, 'usecache': False}

    meta = hapi(server, dataset, **opts)
    for i in range(0, len(meta['parameters'])):
        parameter = meta['parameters'][i]['name']
        data, metax = hapi(server, dataset, parameter, start, stop, **opts)
        if False and i > 0:  # Time parameter alone when i = 0. No fill allowed for time parameter.
            # Change fill value to be same as second element of parameter array.
            metax["parameters"][1]['fill'] = data[parameter].take(1).astype(
                'U')

        popts = {
            'useimagecache': False,
            'logging': logging,
            'returnimage': returnimage
        }

        if parameter == 'matrix':
            # The string
            #   '$\Delta T_{xy}=1$'
            # causes the error
            #    Unknown symbol: \Delta, found '\'  (at char 0), (line:1, col:1)
            # only when FigCanvasAgg is the back-end an using Matplotlib 3.2.2 and 3.4.2
            # The string
            #   '$\Delta$ $T_{xy}=1$'
            # does not cause an error. Seems to be a bug in Matplotlib.
            metax['parameters'][1]['label'][0][1] = r'$\Delta$ $T_{xy}=1$'

        metap = hapiplot(data, metax, **popts)

        if returnimage == False:
            continue

        idx = 1
        if i == 0:  # Time parameter
            idx = 0

        img2 = metap['parameters'][idx]['hapiplot']['image']

        dir_path = os.path.dirname(os.path.realpath(__file__))

        ref_file = os.path.join(dir_path, "imgs", "2.1",
                                parameter + ".ref.png")

        imgcheck(ref_file, img2, show_diff=False, generate_ref_files=False)
예제 #2
0
def test_saveimage():
    # Returned image should be same when saveimage is True or False

    server = 'http://hapi-server.org/servers/TestData2.0/hapi'
    dataset = 'dataset1'
    start = '1970-01-01Z'
    stop = '1970-01-01T00:00:11Z'
    parameters = 'scalar'
    opts = {'logging': False, 'usecache': True}
    data, meta = hapi(server, dataset, parameters, start, stop, **opts)

    popts = {
        'usecache': True,
        'useimagecache': False,
        'logging': True,
        'saveimage': False,
        'returnimage': True
    }

    meta = hapiplot(data, meta, **popts)
    img1 = meta['parameters'][1]['hapiplot']['image']
    #Image.open(io.BytesIO(img1)).show()

    popts['saveimage'] = True
    meta = hapiplot(data, meta, **popts)
    img2 = meta['parameters'][1]['hapiplot']['image']
    #Image.open(io.BytesIO(img1)).show()

    if img1 != img2:
        print('Images do not match')
        return False

    return True
예제 #3
0
def test_2_0():
    # All TestData2.0 parameters

    server = 'http://hapi-server.org/servers/TestData2.0/hapi'
    dataset = 'dataset1'
    start = '1970-01-01Z'
    stop = '1970-01-01T00:00:11Z'
    opts = {'logging': logging, 'usecache': False}

    meta = hapi(server, dataset, **opts)

    for i in range(0, len(meta['parameters'])):
        parameter = meta['parameters'][i]['name']
        data, metax = hapi(server, dataset, parameter, start, stop, **opts)

        if False and i > 0:  # Time parameter alone when i = 0. No fill allowed for time parameter.
            # Change fill value to be same as second element of parameter array.
            metax["parameters"][1]['fill'] = data[parameter].take(1).astype(
                'U')

        popts = {
            'useimagecache': False,
            'logging': logging,
            'returnimage': True
        }

        metap = hapiplot(data, metax, **popts)

        idx = 1
        if i == 0:  # Time parameter
            idx = 0

        img2 = metap['parameters'][idx]['hapiplot']['image']

        dir_path = os.path.dirname(os.path.realpath(__file__))

        ref_file = os.path.join(dir_path, "imgs", "2.0",
                                parameter + ".ref.png")

        imgcheck(ref_file, img2, show_diff=False, generate_ref_files=False)
예제 #4
0
def sscweb():

    from hapiclient.hapi import hapi
    from hapiclient.hapiplot import hapiplot

    # SSCWeb data
    server = 'http://hapi-server.org/servers/SSCWeb/hapi'
    dataset = 'ace'
    start = '2001-01-01T05:00:00'
    stop = '2001-01-01T10:00:00'
    parameters = 'X_GSE,Y_GSE,Z_GSE'
    opts = {'logging': True, 'usecache': True}
    data, meta = hapi(server, dataset, parameters, start, stop, **opts)
    hapiplot(data, meta, **opts)
예제 #5
0
def lisird():

    from hapiclient import hapi
    from hapiplot import hapiplot

    server = 'http://lasp.colorado.edu/lisird/hapi'
    dataset = 'sme_ssi'
    parameters = 'irradiance'
    start = '1981-10-09T00:00:00.000Z'
    stop = '1981-10-14T00:00:00.000Z'

    opts = {'usecache': True, 'logging': True}
    data, meta = hapi(server, dataset, parameters, start, stop, **opts)
    hapiplot(data, meta)
예제 #6
0
def cdaweb():

    from hapiclient.hapi import hapi
    from hapiclient.hapiplot import hapiplot

    # CDAWeb data - Magnitude and BGSEc from dataset AC_H0_MFI
    server = 'https://cdaweb.gsfc.nasa.gov/hapi'
    dataset = 'AC_H0_MFI'
    start = '2001-01-01T05:00:00'
    stop = '2001-01-01T10:00:00'
    parameters = 'Magnitude,BGSEc'
    opts = {'logging': True, 'usecache': True}
    data, meta = hapi(server, dataset, parameters, start, stop, **opts)
    hapiplot(data, meta, **opts)

    # CDAWeb metadata for AC_H0_MFI
    server = 'https://cdaweb.gsfc.nasa.gov/hapi'
    dataset = 'AC_H0_MFI'
    meta = hapi(server, dataset, **opts)
    print('Parameters in %s' % dataset)
    for i in range(0, len(meta['parameters'])):
        print('  %s' % meta['parameters'][i]['name'])
    print('')

    # CDAWeb metadata for all datasets
    server = 'https://cdaweb.gsfc.nasa.gov/hapi'
    meta = hapi(server, **opts)
    print('%d CDAWeb datasets' % len(meta['catalog']))
    for i in range(0, 3):
        print('  %d. %s' % (i, meta['catalog'][i]['id']))
    print('  ...')
    print('  %d. %s' % (len(meta['catalog']), meta['catalog'][-1]['id']))
    print('')

    # List all servers
    servers = hapi(logging=True)  # servers is an array of URLs
    print('')
예제 #7
0
def cassini():
    from hapiclient import hapi
    from hapiclient import hapiplot

    server = 'http://datashop.elasticbeanstalk.com/hapi'
    dataset = 'CHEMS_PHA_BOX_FLUXES_FULL_TIME_RES'
    parameters = 'HPlus_BEST_T1'
    start = '2004-07-01T04:00:00Z'
    stop = '2004-07-01T06:00:00Z'
    opts = {'usecache': True}

    data, meta = hapi(server, dataset, parameters, start, stop, **opts)

    popts = {'logging': False, 'logy': True, 'logz': True}
    hapiplot(data, meta, **popts)
예제 #8
0
def omniweb():

    from hapiclient import hapi
    from hapiclient import hapiplot

    server = 'https://cdaweb.gsfc.nasa.gov/hapi'
    dataset = 'OMNI2_H0_MRG1HR'
    start = '2003-09-01T00:00:00'
    stop = '2003-12-01T00:00:00'
    parameters = 'DST1800'
    opts = {'logging': True, 'usecache': False}

    # Get data
    data, meta = hapi(server, dataset, parameters, start, stop, **opts)

    # Plot all parameters
    hapiplot(data, meta)
예제 #9
0
from hapiclient import hapi
from hapiplot import hapiplot

if True:
    server = 'http://hapi-server.org/servers-dev/TestData2.1/hapi'
    dataset = 'dataset1'
    parameter = 'matrix'
    start = '1970-01-01Z'
    stop = '1970-01-01T00:00:11Z'
    opts = {'logging': True, 'usecache': False}

    data, meta = hapi(server, dataset, parameter, start, stop, **opts)

    popts = {'logging': True, 'returnimage': True, 'usecache': False}
    hapiplot(data, meta, **popts)

if False:
    server = 'http://hapi-server.org/servers/SSCWeb/hapi'
    dataset = 'rbspa'
    start = '2012-08-31T00:00:00.000Z'
    stop = '2012-08-31T23:59:59.999Z'
    parameters = 'Time'
    opts = {'logging': True, 'usecache': True}
    data, meta = hapi(server, dataset, parameters, start, stop, **opts)
    hapiplot(data, meta, **opts)

if False:
    # CDAWeb data - Magnitude and BGSEc from dataset AC_H0_MFI
    server = 'https://cdaweb.gsfc.nasa.gov/hapi'
    dataset = 'AC_H0_MFI'
    start = '1997-12-10T00:00:00'
예제 #10
0
# Install latest hapiclient package from https://pypi.org/project/hapiclient/
# Only needs to be executed once.
import os; print(os.popen('pip install hapiclient --upgrade').read())

from hapiclient import hapi, hapiplot

server     = 'SERVER';
dataset    = 'DATASET';
# Notes:
# 1. Use parameters='' to request all parameters from DATASET.
# 2. Multiple parameters can be requested using a comma-separated
#    listCSV_EXAMPLE
parameters = 'PARAMETERS'; 
start      = 'START';
stop       = 'STOP';

data, meta = hapi(server, dataset, parameters, start, stop)

hapiplot(data, meta)

# Notes:
# 1. To convert the ISO 8601 strings in data['TIMENAME'] to Python
#    datetimes, use
#      from hapiclient import hapitime2datetime
#      Time = hapitime2datetime(data['TIMENAME'])
# 2. Details about the data and metadata structures `data`
#    and `meta` are given at 
#    https://github.com/hapi-server/client-python-notebooks/blob/master/hapi_demo.ipynb
# 3. Many examples for using `data` and `meta` with other
#    Python libraries (e.g., Pandas, Numpy, Astropy) are given
#    in above-referenced notebook.