Example #1
0
def yclip(names, ymin, ymax, flag=None, new_names=None, suffix=None,
          overwrite=None):
    """
    Clip data values.

    Parameters
    ----------
    names: str/list of str
        List of pytplot names.
    ymin: float
        Minimum value to clip.
    ymax: float
        Maximum value to clip.
    flag: float, optional
        Values outside (ymin, ymax) are replaced with flag.
        Default is float('nan').
    new_names: str/list of str, optional
        List of new_names for pytplot variables.
        If not given, then a suffix is applied.
    suffix: str, optional
        A suffix to apply. Default is '-clip'.
    overwrite: bool, optional
        Replace the existing tplot name.

    Returns
    -------
    None.

    """
    old_names = pyspedas.tnames(names)

    if len(old_names) < 1:
        print('yclip error: No pytplot names were provided.')
        return

    if suffix is None:
        suffix = '-clip'

    if flag is None:
        flag = np.nan

    if overwrite is not None:
        n_names = old_names
    elif new_names is None:
        n_names = [s + suffix for s in old_names]
    else:
        n_names = new_names

    if isinstance(n_names, str):
        n_names = [n_names]

    if len(n_names) != len(old_names):
        n_names = [s + suffix for s in old_names]

    for i, old in enumerate(old_names):
        new = n_names[i]

        data = pytplot.clip(old, ymin, ymax, new)

        print('yclip was applied to: ' + new)
Example #2
0
def pwe_hfa(trange=['2017-04-01', '2017-04-02'],
            datatype='spec',
            mode='low',
            level='l2',
            suffix='',
            get_support_data=False,
            varformat=None,
            varnames=[],
            downloadonly=False,
            notplot=False,
            no_update=False,
            uname=None,
            passwd=None,
            time_clip=False,
            ror=True):
    """
    This function loads data from the PWE experiment from the Arase mission

    Parameters:
        trange : list of str
            time range of interest [starttime, endtime] with the format
            'YYYY-MM-DD','YYYY-MM-DD'] or to specify more or less than a day
            ['YYYY-MM-DD/hh:mm:ss','YYYY-MM-DD/hh:mm:ss']

        datatype: str
            Data type; Valid options:

        level: str
            Data level; Valid options:

        suffix: str
            The tplot variable names will be given this suffix.  By default,
            no suffix is added.

        get_support_data: bool
            Data with an attribute "VAR_TYPE" with a value of "support_data"
            will be loaded into tplot.  By default, only loads in data with a
            "VAR_TYPE" attribute of "data".

        varformat: str
            The file variable formats to load into tplot.  Wildcard character
            "*" is accepted.  By default, all variables are loaded in.

        varnames: list of str
            List of variable names to load (if not specified,
            all data variables are loaded)

        downloadonly: bool
            Set this flag to download the CDF files, but not load them into
            tplot variables

        notplot: bool
            Return the data in hash tables instead of creating tplot variables

        no_update: bool
            If set, only load data from your local cache

        time_clip: bool
            Time clip the variables to exactly the range specified in the trange keyword

        ror: bool
            If set, print PI info and rules of the road

    Returns:
        List of tplot variables created.

    """

    initial_notplot_flag = False
    if notplot:
        initial_notplot_flag = True

    file_res = 3600. * 24

    if level == 'l2':
        prefix = 'erg_pwe_hfa_' + level + '_' + mode + '_'

    if level == 'l2':
        pathformat = 'satellite/erg/pwe/hfa/'+level+'/'+datatype+'/'+mode + \
            '/%Y/%m/erg_pwe_hfa_'+level+'_'+datatype+'_'+mode+'_%Y%m%d_v??_??.cdf'
    elif level == 'l3':
        prefix = 'erg_pwe_hfa_' + level + '_1min_'
        pathformat = 'satellite/erg/pwe/hfa/'+level + \
            '/%Y/%m/erg_pwe_hfa_'+level+'_1min_%Y%m%d_v??_??.cdf'

    loaded_data = load(pathformat=pathformat,
                       trange=trange,
                       level=level,
                       datatype=datatype,
                       file_res=file_res,
                       prefix=prefix,
                       suffix=suffix,
                       get_support_data=get_support_data,
                       varformat=varformat,
                       varnames=varnames,
                       downloadonly=downloadonly,
                       notplot=notplot,
                       time_clip=time_clip,
                       no_update=no_update,
                       uname=uname,
                       passwd=passwd)

    if (len(loaded_data) > 0) and ror:

        try:
            if isinstance(loaded_data, list):
                if downloadonly:
                    cdf_file = cdflib.CDF(loaded_data[-1])
                    gatt = cdf_file.globalattsget()
                else:
                    gatt = get_data(loaded_data[-1],
                                    metadata=True)['CDF']['GATT']
            elif isinstance(loaded_data, dict):
                gatt = loaded_data[list(loaded_data.keys())[-1]]['CDF']['GATT']

            # --- print PI info and rules of the road

            print(' ')
            print(' ')
            print(
                '**************************************************************************'
            )
            print(gatt["LOGICAL_SOURCE_DESCRIPTION"])
            print('')
            print('Information about ERG PWE HFA')
            print('')
            print('PI: ', gatt['PI_NAME'])
            print("Affiliation: " + gatt["PI_AFFILIATION"])
            print('')
            print(
                'RoR of ERG project common: https://ergsc.isee.nagoya-u.ac.jp/data_info/rules_of_the_road.shtml.en'
            )
            print(
                'RoR of PWE/HFA: https://ergsc.isee.nagoya-u.ac.jp/mw/index.php/ErgSat/Pwe/Hfa'
            )
            print('')
            print('Contact: erg_pwe_info at isee.nagoya-u.ac.jp')
            print(
                '**************************************************************************'
            )
        except:
            print('printing PI info and rules of the road was failed')

    if initial_notplot_flag or downloadonly:
        return loaded_data

    if (level == 'l2') and (mode == 'low') and (not notplot):

        # set spectrogram plot option
        options(prefix + 'spectra_eu' + suffix, 'Spec', 1)
        options(prefix + 'spectra_ev' + suffix, 'Spec', 1)
        options(prefix + 'spectra_bgamma' + suffix, 'Spec', 1)
        options(prefix + 'spectra_esum' + suffix, 'Spec', 1)
        options(prefix + 'spectra_er' + suffix, 'Spec', 1)
        options(prefix + 'spectra_el' + suffix, 'Spec', 1)
        options(prefix + 'spectra_e_mix' + suffix, 'Spec', 1)
        options(prefix + 'spectra_e_ar' + suffix, 'Spec', 1)

        if prefix + 'spectra_er' + suffix in loaded_data:
            # remove minus values in y array
            clip(prefix + 'spectra_er' + suffix, 0., 5000.)
        if prefix + 'spectra_el' + suffix in loaded_data:
            # remove minus values in y array
            clip(prefix + 'spectra_el' + suffix, 0., 5000.)

        if prefix + 'spectra_eu' + suffix in loaded_data:
            # remove minus values in y array
            clip(prefix + 'spectra_eu' + suffix, 0., 5000.)
            # set ylim
            ylim(prefix + 'spectra_eu' + suffix, 2.0, 10000.0)
            # set zlim
            zlim(prefix + 'spectra_eu' + suffix, 1e-10, 1e-3)

        if prefix + 'spectra_ev' + suffix in loaded_data:
            # remove minus values in y array
            clip(prefix + 'spectra_ev' + suffix, 0., 5000.)
            # set ylim
            ylim(prefix + 'spectra_ev' + suffix, 2.0, 10000.0)
            # set zlim
            zlim(prefix + 'spectra_ev' + suffix, 1e-10, 1e-3)

        if prefix + 'spectra_bgamma' + suffix in loaded_data:
            # set ylim
            ylim(prefix + 'spectra_bgamma' + suffix, 2.0, 200.0)
            # set zlim
            zlim(prefix + 'spectra_bgamma' + suffix, 1e-4, 1e+2)

        if prefix + 'spectra_esum' + suffix in loaded_data:
            # set ylim
            ylim(prefix + 'spectra_esum' + suffix, 2.0, 10000.0)
            # set zlim
            zlim(prefix + 'spectra_esum' + suffix, 1e-10, 1e-3)

        if prefix + 'spectra_e_ar' + suffix in loaded_data:
            # set ylim
            ylim(prefix + 'spectra_e_ar' + suffix, 2.0, 10000.0)
            # set zlim
            zlim(prefix + 'spectra_e_ar' + suffix, -1, 1)

        # set y axis to logscale
        options(prefix + 'spectra_eu' + suffix, 'ylog', 1)
        options(prefix + 'spectra_ev' + suffix, 'ylog', 1)
        options(prefix + 'spectra_bgamma' + suffix, 'ylog', 1)
        options(prefix + 'spectra_esum' + suffix, 'ylog', 1)
        options(prefix + 'spectra_er' + suffix, 'ylog', 1)
        options(prefix + 'spectra_el' + suffix, 'ylog', 1)
        options(prefix + 'spectra_e_mix' + suffix, 'ylog', 1)
        options(prefix + 'spectra_e_ar' + suffix, 'ylog', 1)

        # set z axis to logscale
        options(prefix + 'spectra_eu' + suffix, 'zlog', 1)
        options(prefix + 'spectra_ev' + suffix, 'zlog', 1)
        options(prefix + 'spectra_bgamma' + suffix, 'zlog', 1)
        options(prefix + 'spectra_esum' + suffix, 'zlog', 1)
        options(prefix + 'spectra_er' + suffix, 'zlog', 1)
        options(prefix + 'spectra_el' + suffix, 'zlog', 1)
        options(prefix + 'spectra_e_mix' + suffix, 'zlog', 1)

        # set ytitle
        options(prefix + 'spectra_eu' + suffix, 'ytitle', 'ERG PWE/HFA (EU)')
        options(prefix + 'spectra_ev' + suffix, 'ytitle', 'ERG PWE/HFA (EV)')
        options(prefix + 'spectra_esum' + suffix, 'ytitle',
                'ERG PWE/HFA (ESUM)')
        options(prefix + 'spectra_e_ar' + suffix, 'ytitle',
                'ERG PWE/HFA (E_AR)')
        options(prefix + 'spectra_bgamma' + suffix, 'ytitle',
                'ERG PWE/HFA (BGAMMA)')

        # set ysubtitle
        options(prefix + 'spectra_eu' + suffix, 'ysubtitle', 'frequency [Hz]')
        options(prefix + 'spectra_ev' + suffix, 'ysubtitle', 'frequency [Hz]')
        options(prefix + 'spectra_esum' + suffix, 'ysubtitle',
                'frequency [Hz]')
        options(prefix + 'spectra_e_ar' + suffix, 'ysubtitle',
                'frequency [Hz]')
        options(prefix + 'spectra_bgamma' + suffix, 'ysubtitle',
                'frequency [Hz]')

        # set ztitle
        options(prefix + 'spectra_eu' + suffix, 'ztitle', 'mV^2/m^2/Hz')
        options(prefix + 'spectra_ev' + suffix, 'ztitle', 'mV^2/m^2/Hz')
        options(prefix + 'spectra_esum' + suffix, 'ztitle', 'mV^2/m^2/Hz')
        options(prefix + 'spectra_e_ar' + suffix, 'ztitle', 'LH:-1/RH:+1')
        options(prefix + 'spectra_bgamma' + suffix, 'ztitle', 'pT^2/Hz')

        # change colormap option
        options(prefix + 'spectra_eu' + suffix, 'Colormap', 'jet')
        options(prefix + 'spectra_ev' + suffix, 'Colormap', 'jet')
        options(prefix + 'spectra_bgamma' + suffix, 'Colormap', 'jet')
        options(prefix + 'spectra_esum' + suffix, 'Colormap', 'jet')
        options(prefix + 'spectra_er' + suffix, 'Colormap', 'jet')
        options(prefix + 'spectra_el' + suffix, 'Colormap', 'jet')
        options(prefix + 'spectra_e_mix' + suffix, 'Colormap', 'jet')
        options(prefix + 'spectra_e_ar' + suffix, 'Colormap', 'jet')

    elif level == 'l3':

        # set ytitle
        options(prefix + 'Fuhr' + suffix, 'ytitle', 'UHR frequency [Mhz]')
        options(prefix + 'ne_mgf' + suffix, 'ytitle',
                'eletctorn density [/cc]')

        # set y axis to logscale
        options(prefix + 'Fuhr' + suffix, 'ylog', 1)
        options(prefix + 'ne_mgf' + suffix, 'ylog', 1)

    return loaded_data
Example #3
0
def lepi(trange=['2017-07-01', '2017-07-02'],
         datatype='omniflux',
         level='l2',
         suffix='',
         get_support_data=False,
         varformat=None,
         varnames=[],
         downloadonly=False,
         notplot=False,
         no_update=False,
         uname=None,
         passwd=None,
         time_clip=False,
         ror=True,
         version=None):
    """
    This function loads data from the LEP-i experiment from the Arase mission

    Parameters:
        trange : list of str
            time range of interest [starttime, endtime] with the format
            'YYYY-MM-DD','YYYY-MM-DD'] or to specify more or less than a day
            ['YYYY-MM-DD/hh:mm:ss','YYYY-MM-DD/hh:mm:ss']

        datatype: str
            Data type; Valid options:

        level: str
            Data level; Valid options:

        suffix: str
            The tplot variable names will be given this suffix.  By default,
            no suffix is added.

        get_support_data: bool
            Data with an attribute "VAR_TYPE" with a value of "support_data"
            will be loaded into tplot.  By default, only loads in data with a
            "VAR_TYPE" attribute of "data".

        varformat: str
            The file variable formats to load into tplot.  Wildcard character
            "*" is accepted.  By default, all variables are loaded in.

        varnames: list of str
            List of variable names to load (if not specified,
            all data variables are loaded)

        downloadonly: bool
            Set this flag to download the CDF files, but not load them into
            tplot variables

        notplot: bool
            Return the data in hash tables instead of creating tplot variables

        no_update: bool
            If set, only load data from your local cache

        time_clip: bool
            Time clip the variables to exactly the range specified in the trange keyword

        ror: bool
            If set, print PI info and rules of the road


        version: str
            Set this value to specify the version of cdf files (such as "v03_00")

    Returns:
        List of tplot variables created.

    """
    initial_notplot_flag = False
    if notplot:
        initial_notplot_flag = True

    if level == 'l3':
        datatype = 'pa'

    file_res = 3600. * 24
    prefix = 'erg_lepi_' + level + '_' + datatype + '_'

    pathformat = 'satellite/erg/lepi/'+level+'/'+datatype + \
        '/%Y/%m/erg_lepi_'+level+'_'+datatype+'_%Y%m%d_'
    if version is None:
        pathformat += 'v??_??.cdf'
    else:
        pathformat += version + '.cdf'

    loaded_data = load(pathformat=pathformat,
                       trange=trange,
                       file_res=file_res,
                       prefix=prefix,
                       suffix=suffix,
                       get_support_data=get_support_data,
                       varformat=varformat,
                       varnames=varnames,
                       downloadonly=downloadonly,
                       notplot=notplot,
                       time_clip=time_clip,
                       no_update=no_update,
                       uname=uname,
                       passwd=passwd)

    if (len(loaded_data) > 0) and ror:
        try:
            if isinstance(loaded_data, list):
                if downloadonly:
                    cdf_file = cdflib.CDF(loaded_data[-1])
                    gatt = cdf_file.globalattsget()
                else:
                    gatt = get_data(loaded_data[-1],
                                    metadata=True)['CDF']['GATT']
            elif isinstance(loaded_data, dict):
                gatt = loaded_data[list(loaded_data.keys())[-1]]['CDF']['GATT']

            # --- print PI info and rules of the road

            print(' ')
            print(
                '**************************************************************************'
            )
            print(gatt["LOGICAL_SOURCE_DESCRIPTION"])
            print('')
            print('Information about ERG LEPi')
            print('')
            print('PI: ', gatt['PI_NAME'])
            print("Affiliation: " + gatt["PI_AFFILIATION"])
            print('')
            print(
                'RoR of ERG project common: https://ergsc.isee.nagoya-u.ac.jp/data_info/rules_of_the_road.shtml.en'
            )
            print(
                'RoR of LEPi L2: https://ergsc.isee.nagoya-u.ac.jp/mw/index.php/ErgSat/Lepi'
            )
            print(
                'RoR of ERG/LEPi: https://ergsc.isee.nagoya-u.ac.jp/mw/index.php/ErgSat/Lepi#Rules_of_the_Road'
            )
            print('')
            print('Contact: erg_lepi_info at isee.nagoya-u.ac.jp')
            print(
                '**************************************************************************'
            )
        except:
            print('printing PI info and rules of the road was failed')

    if initial_notplot_flag or downloadonly:
        return loaded_data

    if (datatype == 'omniflux') and (level == 'l2'):
        tplot_variables = []

        if prefix + 'FPDO' + suffix in loaded_data:
            store_data(prefix + 'FPDO' + suffix,
                       newname=prefix + 'FPDO_raw' + suffix)
            loaded_data.append(prefix + 'FPDO_raw' + suffix)
            get_data_vars = get_data(prefix + 'FPDO_raw' + suffix)
            flag_FPDO = store_data(prefix + 'FPDO' + suffix,
                                   data={
                                       'x': get_data_vars[0],
                                       'y': get_data_vars[1][:, :-2],
                                       'v': get_data_vars[2][:-2]
                                   })
            tplot_variables.append(prefix + 'FPDO' + suffix)

        if prefix + 'FHEDO' + suffix in loaded_data:
            store_data(prefix + 'FHEDO' + suffix,
                       newname=prefix + 'FHEDO_raw' + suffix)
            loaded_data.append(prefix + 'FHEDO_raw' + suffix)
            get_data_vars = get_data(prefix + 'FHEDO_raw' + suffix)
            store_data(prefix + 'FHEDO' + suffix,
                       data={
                           'x': get_data_vars[0],
                           'y': get_data_vars[1][:, :-2],
                           'v': get_data_vars[2][:-2]
                       })
            tplot_variables.append(prefix + 'FHEDO' + suffix)

        if prefix + 'FODO' + suffix in loaded_data:
            store_data(prefix + 'FODO' + suffix,
                       newname=prefix + 'FODO_raw' + suffix)
            loaded_data.append(prefix + 'FODO_raw' + suffix)
            get_data_vars = get_data(prefix + 'FODO_raw' + suffix)
            store_data(prefix + 'FODO' + suffix,
                       data={
                           'x': get_data_vars[0],
                           'y': get_data_vars[1][:, :-2],
                           'v': get_data_vars[2][:-2]
                       })
            tplot_variables.append(prefix + 'FODO' + suffix)

        # remove minus valuse of y array
        if flag_FPDO:
            clip(prefix + 'FPDO' + suffix, 0., 2.e+16)

        # set ytitle
        options(tplot_variables, 'ytitle', 'LEPi\nomniflux\nLv2\nEnergy')

        # set ysubtitle
        options(tplot_variables, 'ysubtitle', '[keV/q]')

        # set spectrogram plot option
        options(tplot_variables, 'Spec', 1)

        # set y axis to logscale
        options(tplot_variables, 'ylog', 1)

        for i in range(len(tplot_variables)):
            # set ylim
            ylim(tplot_variables[i], 0.01, 25.0)
            # set zlim
            zlim(tplot_variables[i], 1e+1, 1e+9)

        # set ztitle
        options(tplot_variables, 'ztitle', '[/cm^2-str-s-keV]')

        # set z axis to logscale
        options(tplot_variables, 'zlog', 1)

        # change colormap option
        options(tplot_variables, 'Colormap', 'jet')

    elif (datatype == '3dflux') and (level == 'l2') and (not notplot):
        vns_fidu = [
            'FPDU', 'FPDU_sub', 'FHEDU', 'FHEDU_sub', 'FODU', 'FODU_sub'
        ]
        vns_fiedu = [
            'FPEDU', 'FPEDU_sub', 'FHEEDU', 'FHEEDU_sub', 'FOEDU', 'FOEDU_sub'
        ]
        vns_cnt = [
            'FPDU_COUNT_RAW', 'FPDU_COUNT_RAW_sub', 'FHEDU_COUNT_RAW',
            'FHEDU_COUNT_RAW_sub', 'FODU_COUNT_RAW', 'FODU_COUNT_RAW_sub'
        ]
        vns_list = vns_fidu + vns_fiedu + vns_cnt

        v2_array_for_not_sub = np.arange(8)
        v2_array_for_sub = np.arange(7) + 8
        v3_array = np.arange(16)

        for vns_pattarn in vns_list:
            t_plot_name = prefix + vns_pattarn + suffix
            if t_plot_name in loaded_data:
                tplot_copy(t_plot_name, t_plot_name + '_raw')
                get_data_vars_temporal = get_data(t_plot_name)
                meta_data_in = get_data(t_plot_name, metadata=True)
                if 'sub' in t_plot_name:
                    store_data(t_plot_name,
                               data={
                                   'x': get_data_vars_temporal[0],
                                   'y': get_data_vars_temporal[1][:,
                                                                  0:30, :, :],
                                   'v1': get_data_vars_temporal[2][0:30],
                                   'v2': v2_array_for_sub,
                                   'v3': v3_array
                               },
                               attr_dict=meta_data_in)
                else:
                    store_data(t_plot_name,
                               data={
                                   'x': get_data_vars_temporal[0],
                                   'y': get_data_vars_temporal[1][:,
                                                                  0:30, :, :],
                                   'v1': get_data_vars_temporal[2][0:30],
                                   'v2': v2_array_for_not_sub,
                                   'v3': v3_array
                               },
                               attr_dict=meta_data_in)
                ylim(t_plot_name, 0.01, 30.)
                options(t_plot_name, 'ylog', 1)
                options(t_plot_name, 'zlog', 1)
        """comment out in order to match the result of part_product of IDL.
        if prefix + 'FPDU' + suffix in loaded_data:
            clip(prefix + 'FPDU' + suffix, -1.0e+10, 1.0e+10)
        if prefix + 'FHEDU' + suffix in loaded_data:
            clip(prefix + 'FHEDU' + suffix, -1.0e+10, 1.0e+10)
        if prefix + 'FODU' + suffix in loaded_data:
            clip(prefix + 'FODU' + suffix, -1.0e+10, 1.0e+10)"""

    elif level == 'l3':
        tplot_variables = []

        if prefix + 'FPDU' + suffix in loaded_data:
            tplot_variables.append(prefix + 'FPDU' + suffix)
            get_data_vars = get_data(prefix + 'FPDU' + suffix)
            ylim(prefix + 'FPDU' + suffix, 0, 180)
            zlim(prefix + 'FPDU' + suffix, 1e2, 1e5)
            options(prefix + 'FPDU' + suffix, 'spec', 1)
            ytitle_keV_array = np.round(np.nan_to_num(get_data_vars[2]), 2)
            for i in range(get_data_vars[1].shape[1]):
                tplot_name = prefix + 'pabin_' + \
                    str(i).zfill(2) + '_FPDU' + suffix
                store_data(tplot_name,
                           data={
                               'x': get_data_vars[0],
                               'y': get_data_vars[1][:, i, :],
                               'v': get_data_vars[3]
                           })
                options(tplot_name, 'spec', 1)
                ylim(tplot_name, 0, 180)
                zlim(tplot_name, 1e2, 1e5)
                options(
                    tplot_name, 'ytitle', 'ERG LEP-i P\n' +
                    str(ytitle_keV_array[i]) + ' keV\nPitch angle')
                tplot_variables.append(tplot_name)

            loaded_data += tplot_variables[1:]

        tplot_variables_length = len(tplot_variables)

        if prefix + 'FHEDU' + suffix in loaded_data:
            tplot_variables.append(prefix + 'FHEDU' + suffix)
            get_data_vars = get_data(prefix + 'FHEDU' + suffix)
            options(prefix + 'FHEDU' + suffix, 'spec', 1)
            ylim(prefix + 'FHEDU' + suffix, 0, 180)
            zlim(prefix + 'FHEDU' + suffix, 1e2, 1e5)
            ytitle_keV_array = np.round(np.nan_to_num(get_data_vars[2]), 2)
            for i in range(get_data_vars[1].shape[1]):
                tplot_name = prefix + 'pabin_' + \
                    str(i).zfill(2) + '_FHEDU' + suffix
                store_data(tplot_name,
                           data={
                               'x': get_data_vars[0],
                               'y': get_data_vars[1][:, i, :],
                               'v': get_data_vars[3]
                           })
                options(tplot_name, 'spec', 1)
                ylim(tplot_name, 0, 180)
                zlim(tplot_name, 1e2, 1e5)
                options(
                    tplot_name, 'ytitle', 'ERG LEP-i P\n' +
                    str(ytitle_keV_array[i]) + ' keV\nPitch angle')
                tplot_variables.append(tplot_name)

            loaded_data += tplot_variables[tplot_variables_length + 1:]

        tplot_variables_length = len(tplot_variables)

        if prefix + 'FODU' + suffix in loaded_data:
            tplot_variables.append(prefix + 'FODU' + suffix)
            get_data_vars = get_data(prefix + 'FODU' + suffix)
            options(prefix + 'FODU' + suffix, 'spec', 1)
            ylim(prefix + 'FODU' + suffix, 0, 180)
            zlim(prefix + 'FODU' + suffix, 1e2, 1e5)
            ytitle_keV_array = np.round(np.nan_to_num(get_data_vars[2]), 2)
            for i in range(get_data_vars[1].shape[1]):
                tplot_name = prefix + 'pabin_' + \
                    str(i).zfill(2) + '_FODU' + suffix
                store_data(tplot_name,
                           data={
                               'x': get_data_vars[0],
                               'y': get_data_vars[1][:, i, :],
                               'v': get_data_vars[3]
                           })
                options(tplot_name, 'spec', 1)
                ylim(tplot_name, 0, 180)
                zlim(tplot_name, 1e2, 1e5)
                options(
                    tplot_name, 'ytitle', 'ERG LEP-i P\n' +
                    str(ytitle_keV_array[i]) + ' keV\nPitch angle')
                tplot_variables.append(tplot_name)

            loaded_data += tplot_variables[tplot_variables_length + 1:]

        options(tplot_variables, 'zlog', 1)
        options(tplot_variables, 'ysubtitle', 'PA [deg]')
        options(tplot_variables, 'colormap', 'jet')
        options(tplot_variables, 'ztitle', '[/s-cm^{2}-sr-keV/q]')

    return loaded_data
Example #4
0
def hep(trange=['2017-03-27', '2017-03-28'],
        datatype='omniflux',
        level='l2',
        suffix='',
        get_support_data=False,
        varformat=None,
        varnames=[],
        downloadonly=False,
        notplot=False,
        no_update=False,
        uname=None,
        passwd=None,
        time_clip=False,
        ror=True,
        version=None):
    """
    This function loads data from the HEP experiment from the Arase mission

    Parameters:
        trange : list of str
            time range of interest [starttime, endtime] with the format
            'YYYY-MM-DD','YYYY-MM-DD'] or to specify more or less than a day
            ['YYYY-MM-DD/hh:mm:ss','YYYY-MM-DD/hh:mm:ss']

        datatype: str
            Data type; Valid options:

        level: str
            Data level; Valid options:

        suffix: str
            The tplot variable names will be given this suffix.  By default,
            no suffix is added.

        get_support_data: bool
            Data with an attribute "VAR_TYPE" with a value of "support_data"
            will be loaded into tplot.  By default, only loads in data with a
            "VAR_TYPE" attribute of "data".

        varformat: str
            The file variable formats to load into tplot.  Wildcard character
            "*" is accepted.  By default, all variables are loaded in.

        varnames: list of str
            List of variable names to load (if not specified,
            all data variables are loaded)

        downloadonly: bool
            Set this flag to download the CDF files, but not load them into
            tplot variables

        notplot: bool
            Return the data in hash tables instead of creating tplot variables

        no_update: bool
            If set, only load data from your local cache

        time_clip: bool
            Time clip the variables to exactly the range specified in the trange keyword

        ror: bool
            If set, print PI info and rules of the road

        version: str
            Set this value to specify the version of cdf files (such as "v01_02", "v01_03", ...)

    Returns:
        List of tplot variables created.

    """

    file_res = 3600. * 24
    prefix = 'erg_hep_'+level+'_'

    if level == 'l2':
        pathformat = 'satellite/erg/hep/'+level+'/'+datatype + \
            '/%Y/%m/erg_hep_'+level+'_'+datatype + '_%Y%m%d_'
        if version is None:
            pathformat += 'v??_??.cdf'
        else:
            pathformat += version + '.cdf'
    if level == 'l3':
        pathformat = 'satellite/erg/hep/'+level + \
            '/pa/%Y/%m/erg_hep_'+level+'_pa_%Y%m%d_'
        if version is None:
            pathformat += 'v??_??.cdf'
        else:
            pathformat += version + '.cdf'

    initial_notplot_flag = False
    if notplot:
        initial_notplot_flag = True

    if ((level == 'l2') and (datatype == 'omniflux')) or (datatype == '3dflux') or (level == 'l3'):
        # to avoid failure of creation plot variables (at store_data.py) of hep
        notplot = True

    loaded_data = load(pathformat=pathformat, trange=trange, level=level, datatype=datatype, file_res=file_res, prefix=prefix, suffix=suffix, get_support_data=get_support_data,
                       varformat=varformat, varnames=varnames, downloadonly=downloadonly, notplot=notplot, time_clip=time_clip, no_update=no_update, uname=uname, passwd=passwd, version=version)

    if (len(loaded_data) > 0) and ror:

        try:
            if isinstance(loaded_data, list):
                if downloadonly:
                    cdf_file = cdflib.CDF(loaded_data[-1])
                    gatt = cdf_file.globalattsget()
                else:
                    gatt = get_data(loaded_data[-1], metadata=True)['CDF']['GATT']
            elif isinstance(loaded_data, dict):
                gatt = loaded_data[list(loaded_data.keys())[-1]]['CDF']['GATT']
                
            # --- print PI info and rules of the road

            print(' ')
            print(
                '**************************************************************************')
            print(gatt["LOGICAL_SOURCE_DESCRIPTION"])
            print('')
            print('PI: ', gatt['PI_NAME'])
            print("Affiliation: "+gatt["PI_AFFILIATION"])
            print('')
            print('- The rules of the road (RoR) common to the ERG project:')
            print(
                '       https://ergsc.isee.nagoya-u.ac.jp/data_info/rules_of_the_road.shtml.en')
            print(
                '- RoR for HEP data: https://ergsc.isee.nagoya-u.ac.jp/mw/index.php/ErgSat/Hep')
            if level == 'l3':
                print(
                    '- RoR for MGF data: https://ergsc.isee.nagoya-u.ac.jp/mw/index.php/ErgSat/Mgf')
            print('')
            print('Contact: erg_hep_info at isee.nagoya-u.ac.jp')
            print(
                '**************************************************************************')
        except:
            print('printing PI info and rules of the road was failed')

    if initial_notplot_flag or downloadonly:
        return loaded_data

    if isinstance(loaded_data, dict):

        if (level == 'l2') and (datatype == 'omniflux'):
            tplot_variables = []
            if prefix + 'FEDO_L' + suffix in loaded_data:
                v_vars_min = loaded_data[prefix + 'FEDO_L' + suffix]['v'][0]
                v_vars_max = loaded_data[prefix + 'FEDO_L' + suffix]['v'][1]
                # log average of energy bins
                v_vars = np.power(
                    10., (np.log10(v_vars_min) + np.log10(v_vars_max)) / 2.)
                store_data(prefix + 'FEDO_L' + suffix, data={'x': loaded_data[prefix + 'FEDO_L' + suffix]['x'],
                                                             'y': loaded_data[prefix + 'FEDO_L' + suffix]['y'],
                                                             'v': v_vars},
                           attr_dict={'CDF':loaded_data[prefix + 'FEDO_L' + suffix]['CDF']})
                tplot_variables.append(prefix + 'FEDO_L' + suffix)

            if prefix + 'FEDO_H' + suffix in loaded_data:
                v_vars_min = loaded_data[prefix + 'FEDO_H' + suffix]['v'][0]
                v_vars_max = loaded_data[prefix + 'FEDO_H' + suffix]['v'][1]
                # log average of energy bins
                v_vars = np.power(
                    10., (np.log10(v_vars_min) + np.log10(v_vars_max)) / 2.)
                store_data(prefix + 'FEDO_H' + suffix, data={'x': loaded_data[prefix + 'FEDO_H' + suffix]['x'],
                                                             'y': loaded_data[prefix + 'FEDO_H' + suffix]['y'],
                                                             'v': v_vars},
                           attr_dict={'CDF':loaded_data[prefix + 'FEDO_H' + suffix]['CDF']})
                tplot_variables.append(prefix + 'FEDO_H' + suffix)

            # remove minus valuse of y array
            if prefix + 'FEDO_L' + suffix in tplot_variables:
                clip(prefix + 'FEDO_L' + suffix, 0., 1.0e+10)
            if prefix + 'FEDO_H' + suffix in tplot_variables:
                clip(prefix + 'FEDO_H' + suffix, 0., 1.0e+10)

            # set spectrogram plot option
            options(prefix + 'FEDO_L' + suffix, 'Spec', 1)
            options(prefix + 'FEDO_H' + suffix, 'Spec', 1)

            # set y axis to logscale
            options(prefix + 'FEDO_L' + suffix, 'ylog', 1)
            options(prefix + 'FEDO_H' + suffix, 'ylog', 1)

            # set yrange
            options(prefix + 'FEDO_L' + suffix, 'yrange', [3.0e+01, 2.0e+03])
            options(prefix + 'FEDO_H' + suffix, 'yrange', [7.0e+01, 2.0e+03])

            # set ytitle
            options(prefix + 'FEDO_L' + suffix, 'ytitle',
                    'HEP-L\nomniflux\nLv2\nEnergy')
            options(prefix + 'FEDO_H' + suffix, 'ytitle',
                    'HEP-H\nomniflux\nLv2\nEnergy')

            # set ysubtitle
            options(prefix + 'FEDO_L' + suffix, 'ysubtitle', '[keV]')
            options(prefix + 'FEDO_H' + suffix, 'ysubtitle', '[keV]')

            # set ylim
            if prefix + 'FEDO_L' + suffix in tplot_variables:
                ylim(prefix + 'FEDO_L' + suffix, 30, 1800)
            if prefix + 'FEDO_H' + suffix in tplot_variables:
                ylim(prefix + 'FEDO_H' + suffix, 500, 2048)

            # set z axis to logscale
            options(prefix + 'FEDO_L' + suffix, 'zlog', 1)
            options(prefix + 'FEDO_H' + suffix, 'zlog', 1)

            # set zrange
            options(prefix + 'FEDO_L' + suffix, 'zrange', [1.0e-15, 1.0e+06])
            options(prefix + 'FEDO_H' + suffix, 'zrange', [1.0e-10, 1.0e+5])

            # set ztitle
            options(prefix + 'FEDO_L' + suffix,
                    'ztitle', '[/cm^{2}-str-s-keV]')
            options(prefix + 'FEDO_H' + suffix,
                    'ztitle', '[/cm^{2}-str-s-keV]')

            # set zlim
            if prefix + 'FEDO_L' + suffix in tplot_variables:
                zlim(prefix + 'FEDO_L' + suffix, 1e+0, 1e+5)
            if prefix + 'FEDO_H' + suffix in tplot_variables:
                zlim(prefix + 'FEDO_H' + suffix, 1e+0, 1e+5)

            # change colormap option
            options(prefix + 'FEDO_L' + suffix,  'Colormap', 'jet')
            options(prefix + 'FEDO_H' + suffix,  'Colormap', 'jet')

            return tplot_variables

        if (level == 'l2') and (datatype == '3dflux'):
            tplot_variables = []
            v2_array = [i for i in range(15)]

            if prefix + 'FEDU_L' + suffix in loaded_data:

                store_data(prefix + 'FEDU_L' + suffix, data={'x': loaded_data[prefix + 'FEDU_L' + suffix]['x'],
                                                             'y': loaded_data[prefix + 'FEDU_L' + suffix]['y'],
                                                             'v1': np.sqrt(loaded_data[prefix + 'FEDU_L' + suffix]['v'][0, :] *
                                                                           loaded_data[prefix + 'FEDU_L' + suffix]['v'][1, :]),  # geometric mean for 'v1'
                                                             'v2': v2_array},
                           attr_dict={'CDF':loaded_data[prefix + 'FEDU_L' + suffix]['CDF']})
                tplot_variables.append(prefix + 'FEDU_L' + suffix)
                clip(prefix + 'FEDU_L' + suffix, -1.0e+10, 1.0e+10)

            if prefix + 'FEDU_H' + suffix in loaded_data:

                store_data(prefix + 'FEDU_H' + suffix, data={'x': loaded_data[prefix + 'FEDU_H' + suffix]['x'],
                                                             'y': loaded_data[prefix + 'FEDU_H' + suffix]['y'],
                                                             'v1': np.sqrt(loaded_data[prefix + 'FEDU_H' + suffix]['v'][0, :] *
                                                                           loaded_data[prefix + 'FEDU_H' + suffix]['v'][1, :]),  # geometric mean for 'v1'
                                                             'v2': v2_array},
                           attr_dict={'CDF':loaded_data[prefix + 'FEDU_H' + suffix]['CDF']})
                tplot_variables.append(prefix + 'FEDU_H' + suffix)
                clip(prefix + 'FEDU_H' + suffix, -1.0e+10, 1.0e+10)

            return tplot_variables

        if level == 'l3':  # implementation for level = 'l3'

            tplot_variables = []

            if prefix + 'FEDU_L' + suffix in loaded_data:

                L_energy_array_ave = np.sqrt(loaded_data[prefix + 'FEDU_L' + suffix]['v1'][0, :] *
                                             loaded_data[prefix + 'FEDU_L' + suffix]['v1'][1, :])  # geometric mean for 'v1'

                # get energy [keV] array for ytitle options
                L_energy_array = np.trunc(L_energy_array_ave).astype(int)
                non_negative_y_array = np.where(
                    loaded_data[prefix + 'FEDU_L' + suffix]['y'] < 0., np.nan, loaded_data[prefix + 'FEDU_L' + suffix]['y'])
                store_data(prefix + 'FEDU_L' + suffix, data={'x': loaded_data[prefix + 'FEDU_L' + suffix]['x'],
                                                             'y': non_negative_y_array,
                                                             'v1': L_energy_array_ave,
                                                             'v2': loaded_data[prefix + 'FEDU_L' + suffix]['v2']},
                           attr_dict={'CDF':loaded_data[prefix + 'FEDU_L' + suffix]['CDF']})

                options(prefix + 'FEDU_L' + suffix, 'spec', 1)
                # set ylim
                ylim(prefix + 'FEDU_L' + suffix, 0, 180)
                # set zlim
                zlim(prefix + 'FEDU_L' + suffix, 1e+2, 1e+6)

                tplot_variables.append(prefix + 'FEDU_L' + suffix)

                # make Tplot Variables of erg_hep_l3_FEDU_L_paspec_ene?? (??: 00, 01, 02, ..., 15)
                for i in range(loaded_data[prefix + 'FEDU_L' + suffix]['y'].shape[1]):
                    tplot_name = prefix + 'FEDU_L_paspec_ene' + \
                        str(i).zfill(2) + suffix
                    store_data(tplot_name, data={'x': loaded_data[prefix + 'FEDU_L' + suffix]['x'],
                                                 'y': non_negative_y_array[:, i, :],
                                                 'v': loaded_data[prefix + 'FEDU_L' + suffix]['v2']},
                               attr_dict={'CDF':loaded_data[prefix + 'FEDU_L' + suffix]['CDF']})

                    options(tplot_name, 'spec', 1)
                    # set ylim
                    ylim(tplot_name, 0, 180)
                    # set zlim
                    zlim(tplot_name, 1e+2, 1e+6)
                    # set ytitle
                    options(
                        tplot_name, 'ytitle', f'HEP-L\nEne{str(i).zfill(2)}\n{L_energy_array[i]} keV')

                    tplot_variables.append(tplot_name)

            if prefix + 'FEDU_H' + suffix in loaded_data:

                H_energy_array_ave = np.sqrt(loaded_data[prefix + 'FEDU_H' + suffix]['v1'][0, :] *
                                             loaded_data[prefix + 'FEDU_H' + suffix]['v1'][1, :])  # geometric mean for 'v1'

                # get energy [keV] array for ytitle options
                H_energy_array = np.trunc(H_energy_array_ave).astype(int)
                non_negative_y_array = np.where(
                    loaded_data[prefix + 'FEDU_H' + suffix]['y'] < 0., np.nan, loaded_data[prefix + 'FEDU_H' + suffix]['y'])
                store_data(prefix + 'FEDU_H' + suffix, data={'x': loaded_data[prefix + 'FEDU_H' + suffix]['x'],
                                                             'y': non_negative_y_array,
                                                             'v1': H_energy_array_ave,
                                                             'v2': loaded_data[prefix + 'FEDU_H' + suffix]['v2']},
                           attr_dict={'CDF':loaded_data[prefix + 'FEDU_H' + suffix]['CDF']})

                options(prefix + 'FEDU_H' + suffix, 'spec', 1)
                # set ylim
                ylim(prefix + 'FEDU_H' + suffix, 0, 180)
                # set zlim
                zlim(prefix + 'FEDU_H' + suffix, 1e+1, 1e+4)

                tplot_variables.append(prefix + 'FEDU_H' + suffix)

                # make Tplot Variables of erg_hep_l3_FEDU_H_paspec_ene?? (??: 00, 01, 02, ..., 10)
                for i in range(loaded_data[prefix + 'FEDU_H' + suffix]['y'].shape[1]):
                    tplot_name = prefix + 'FEDU_H_paspec_ene' + \
                        str(i).zfill(2) + suffix
                    store_data(tplot_name, data={'x': loaded_data[prefix + 'FEDU_H' + suffix]['x'],
                                                 'y': non_negative_y_array[:, i, :],
                                                 'v': loaded_data[prefix + 'FEDU_H' + suffix]['v2']},
                               attr_dict={'CDF':loaded_data[prefix + 'FEDU_H' + suffix]['CDF']})

                    options(tplot_name, 'spec', 1)
                    # set ylim
                    ylim(tplot_name, 0, 180)
                    # set zlim
                    zlim(tplot_name, 1e+1, 1e+4)
                    # set ytitle
                    options(
                        tplot_name, 'ytitle', f'HEP-H\nEne{str(i).zfill(2)}\n{H_energy_array[i]} keV')

                    tplot_variables.append(tplot_name)

            # set z axis to logscale
            options(tplot_variables, 'zlog', 1)
            # change colormap option
            options(tplot_variables, 'colormap', 'jet')
            # set ysubtitle
            options(tplot_variables, 'ysubtitle', 'PA [deg]')
            # set ztitle
            options(tplot_variables, 'ztitle', '[/keV/cm^{2}/sr/s]')

            return tplot_variables

    return loaded_data
Example #5
0
def xep(trange=['2017-06-01', '2017-06-02'],
        datatype='omniflux',
        level='l2',
        suffix='',
        get_support_data=False,
        varformat=None,
        varnames=[],
        downloadonly=False,
        notplot=False,
        no_update=False,
        uname=None,
        passwd=None,
        time_clip=False,
        ror=True):
    """
    This function loads data from the XEP-e experiment from the Arase mission

    Parameters:
        trange : list of str
            time range of interest [starttime, endtime] with the format
            'YYYY-MM-DD','YYYY-MM-DD'] or to specify more or less than a day
            ['YYYY-MM-DD/hh:mm:ss','YYYY-MM-DD/hh:mm:ss']

        datatype: str
            Data type; Valid options:

        level: str
            Data level; Valid options:

        suffix: str
            The tplot variable names will be given this suffix.  By default,
            no suffix is added.

        get_support_data: bool
            Data with an attribute "VAR_TYPE" with a value of "support_data"
            will be loaded into tplot.  By default, only loads in data with a
            "VAR_TYPE" attribute of "data".

        varformat: str
            The file variable formats to load into tplot.  Wildcard character
            "*" is accepted.  By default, all variables are loaded in.

        varnames: list of str
            List of variable names to load (if not specified,
            all data variables are loaded)

        downloadonly: bool
            Set this flag to download the CDF files, but not load them into
            tplot variables

        notplot: bool
            Return the data in hash tables instead of creating tplot variables

        no_update: bool
            If set, only load data from your local cache

        time_clip: bool
            Time clip the variables to exactly the range specified in the trange keyword

        ror: bool
            If set, print PI info and rules of the road

    Returns:
        List of tplot variables created.

    """
    initial_notplot_flag = False
    if notplot:
        initial_notplot_flag = True

    if (datatype == 'omniflux') or (datatype == '2dflux'):
        # to avoid failure of creation Tplot variables (at store_data.py) of xep
        notplot = True
    file_res = 3600. * 24
    prefix = 'erg_xep_'+level+'_'
    pathformat = 'satellite/erg/xep/'+level+'/'+datatype + \
        '/%Y/%m/erg_xep_'+level+'_'+datatype+'_%Y%m%d_v??_??.cdf'
    loaded_data = load(pathformat=pathformat, trange=trange, level=level, datatype=datatype, file_res=file_res, prefix=prefix, suffix=suffix, get_support_data=get_support_data,
                       varformat=varformat, varnames=varnames, downloadonly=downloadonly, notplot=notplot, time_clip=time_clip, no_update=no_update, uname=uname, passwd=passwd)

    if (len(loaded_data) > 0) and ror:

        try:
            if isinstance(loaded_data, list):
                if downloadonly:
                    cdf_file = cdflib.CDF(loaded_data[-1])
                    gatt = cdf_file.globalattsget()
                else:
                    gatt = get_data(loaded_data[-1], metadata=True)['CDF']['GATT']
            elif isinstance(loaded_data, dict):
                gatt = loaded_data[list(loaded_data.keys())[-1]]['CDF']['GATT']

            # --- print PI info and rules of the road

            print(' ')
            print(
                '**************************************************************************')
            print(gatt["LOGICAL_SOURCE_DESCRIPTION"])
            print('')
            print('Information about ERG XEP')
            print('')
            print('PI: ', gatt['PI_NAME'])
            print("Affiliation: "+gatt["PI_AFFILIATION"])
            print('')
            print('RoR of ERG project common: https://ergsc.isee.nagoya-u.ac.jp/data_info/rules_of_the_road.shtml.en')
            print('RoR of XEP: https://ergsc.isee.nagoya-u.ac.jp/mw/index.php/ErgSat/Xep')
            print('')
            print('Contact: erg_xep_info at isee.nagoya-u.ac.jp')
            print(
                '**************************************************************************')
        except:
            print('printing PI info and rules of the road was failed')

    if initial_notplot_flag or downloadonly:
        return loaded_data

    if isinstance(loaded_data, dict):

        if datatype == 'omniflux':
            tplot_variables = []

            if prefix + 'FEDO_SSD' + suffix in loaded_data:
                v_vars_min = loaded_data[prefix + 'FEDO_SSD' + suffix]['v'][0]
                v_vars_max = loaded_data[prefix + 'FEDO_SSD' + suffix]['v'][1]
                v_vars = np.sqrt(v_vars_min * v_vars_max)  # Geometric mean

                store_data(prefix + 'FEDO_SSD' + suffix, data={'x': loaded_data[prefix + 'FEDO_SSD' + suffix]['x'],
                                                               'y': loaded_data[prefix + 'FEDO_SSD' + suffix]['y'],
                                                               'v': v_vars},
                           attr_dict={'CDF':loaded_data[prefix + 'FEDO_SSD' + suffix]['CDF']})
                tplot_variables.append(prefix + 'FEDO_SSD' + suffix)

                if prefix + 'FEDO_SSD' + suffix in tplot_variables:
                    # remove minus valuse of y array
                    clip(prefix + 'FEDO_SSD' + suffix, 0., 5000.)
                # set spectrogram plot option
                options(prefix + 'FEDO_SSD' + suffix, 'Spec', 1)
                # set y axis to logscale
                options(prefix + 'FEDO_SSD' + suffix, 'ylog', 1)
                # set yrange
                options(prefix + 'FEDO_SSD' + suffix,
                        'yrange', [4.0e+02, 4.5e+03])
                # set z axis to logscale
                options(prefix + 'FEDO_SSD' + suffix, 'zlog', 1)
                # set zrange
                options(prefix + 'FEDO_SSD' + suffix,
                        'zrange', [1.0e-01, 1.0e+3])
                # change colormap option
                options(prefix + 'FEDO_SSD' + suffix, 'Colormap', 'jet')

                # set ztitle
                options(prefix + 'FEDO_SSD' + suffix,
                        'ztitle', '[/cm^{2}-str-s-keV]')
                # set ytitle
                options(prefix + 'FEDO_SSD' + suffix,
                        'ytitle', 'XEP\nomniflux\nLv2\nEnergy')
                # set ysubtitle
                options(prefix + 'FEDO_SSD' + suffix, 'ysubtitle', '[keV]')

                ylim(prefix + 'FEDO_SSD' + suffix, 4.0e+02, 4.5e+03)
                zlim(prefix + 'FEDO_SSD' + suffix, 1.0e-01, 1.0e+3)

            return tplot_variables

        if datatype == '2dflux':
            tplot_variables = []

            if prefix + 'FEDU_SSD' + suffix in loaded_data:
                store_data(prefix + 'FEDU_SSD' + suffix,
                           data={'x': loaded_data[prefix + 'FEDU_SSD' + suffix]['x'],
                                 'y': loaded_data[prefix + 'FEDU_SSD' + suffix]['y'],
                                 'v1': np.sqrt(loaded_data[prefix + 'FEDU_SSD' + suffix]['v'][:, 0]
                                               * loaded_data[prefix + 'FEDU_SSD' + suffix]['v'][:, 1]),  # Geometric mean of 'v'
                                 'v2': [i for i in range(16)]},  # [0, 1, 2, .., 15]
                           attr_dict={'CDF':loaded_data[prefix + 'FEDU_SSD' + suffix]['CDF']})

                tplot_variables.append(prefix + 'FEDU_SSD' + suffix)

                if prefix + 'FEDU_SSD' + suffix in tplot_variables:
                    clip(prefix + 'FEDU_SSD' + suffix, -1.0e+10, 1.0e+10)

                return tplot_variables

    return loaded_data
Example #6
0
def orb(trange=['2017-03-27', '2017-03-28'],
        datatype='def',
        level='l2',
        model="op",
        suffix='',
        get_support_data=False,
        varformat=None,
        varnames=[],
        downloadonly=False,
        notplot=False,
        no_update=False,
        uname=None,
        passwd=None,
        time_clip=False,
        version=None,
        ror=True):
    """
    This function loads orbit data from the Arase mission

    Parameters:
        trange : list of str
            time range of interest [starttime, endtime] with the format
            'YYYY-MM-DD','YYYY-MM-DD'] or to specify more or less than a day
            ['YYYY-MM-DD/hh:mm:ss','YYYY-MM-DD/hh:mm:ss']

        datatype: str
            Data type; Valid options:

        level: str
            Data level; Valid options:

        suffix: str
            The tplot variable names will be given this suffix.  By default,
            no suffix is added.

        get_support_data: bool
            Data with an attribute "VAR_TYPE" with a value of "support_data"
            will be loaded into tplot.  By default, only loads in data with a
            "VAR_TYPE" attribute of "data".

        varformat: str
            The file variable formats to load into tplot.  Wildcard character
            "*" is accepted.  By default, all variables are loaded in.

        varnames: list of str
            List of variable names to load (if not specified,
            all data variables are loaded)

        downloadonly: bool
            Set this flag to download the CDF files, but not load them into
            tplot variables

        notplot: bool
            Return the data in hash tables instead of creating tplot variables

        no_update: bool
            If set, only load data from your local cache

        time_clip: bool
            Time clip the variables to exactly the range specified in the trange keyword

        version: str
            Set this value to specify the version of cdf files (such as "v03")

    Returns:
        List of tplot variables created.

    """
    initial_notplot_flag = False
    if notplot:
        initial_notplot_flag = True

    file_res = 3600. * 24

    prefix = 'erg_orb_' + level + '_'

    if (datatype in ["pre", "spre", "mpre", "lpre"]) and (level == 'l2'):
        prefix = 'erg_orb_' + datatype + '_' + level + '_'

    if level == 'l3':
        if model == 'op':
            pathformat = 'satellite/erg/orb/'+level + \
                '/opq/%Y/%m/erg_orb_'+level+'_op_%Y%m%d_'
        else:
            pathformat = 'satellite/erg/orb/'+level+'/'+model + \
                '/%Y/%m/erg_orb_'+level+'_'+model+'_%Y%m%d_'
    elif level == 'l2':
        if datatype == 'def':
            pathformat = 'satellite/erg/orb/' + datatype + '/%Y/erg_orb_' + level + '_%Y%m%d_'
        else:
            pathformat = 'satellite/erg/orb/' + datatype + \
                '/%Y/erg_orb_' + datatype + '_'+level+'_%Y%m%d_'
    if version is None:
        pathformat += 'v??.cdf'
    else:
        pathformat += version + '.cdf'

    loaded_data = load(pathformat=pathformat,
                       trange=trange,
                       level=level,
                       datatype=datatype,
                       file_res=file_res,
                       prefix=prefix,
                       suffix=suffix,
                       get_support_data=get_support_data,
                       varformat=varformat,
                       varnames=varnames,
                       downloadonly=downloadonly,
                       notplot=notplot,
                       time_clip=time_clip,
                       no_update=no_update,
                       uname=uname,
                       passwd=passwd,
                       version=version)

    if (len(loaded_data) > 0) and ror:

        try:
            if isinstance(loaded_data, list):
                if downloadonly:
                    cdf_file = cdflib.CDF(loaded_data[-1])
                    gatt = cdf_file.globalattsget()
                else:
                    gatt = get_data(loaded_data[-1],
                                    metadata=True)['CDF']['GATT']
            elif isinstance(loaded_data, dict):
                gatt = loaded_data[list(loaded_data.keys())[-1]]['CDF']['GATT']
            # --- print PI info and rules of the road

            print(' ')
            print(
                '**************************************************************************'
            )
            print(gatt["LOGICAL_SOURCE_DESCRIPTION"])
            print('')
            if level == 'l3':
                print('Information about ERG L3 orbit')
            elif level == 'l2':
                print('Information about ERG orbit')
            print('')
            # print('PI: ', gatt['PI_NAME']) # not need?
            # print("Affiliation: "+gatt["PI_AFFILIATION"]) # not need?
            print('')
            print(
                'RoR of ERG project common: https://ergsc.isee.nagoya-u.ac.jp/data_info/rules_of_the_road.shtml.en'
            )
            print('')
            print('Contact: erg-sc-core at isee.nagoya-u.ac.jp')
            print(
                '**************************************************************************'
            )
        except:
            print('printing PI info and rules of the road was failed')

    if initial_notplot_flag or downloadonly:
        return loaded_data

    remove_duplicated_tframe(tnames(prefix + '*pos*'))

    if (level == 'l2') and (datatype == 'def'):

        # remove -1.0e+30
        if prefix + 'pos_Lm' + suffix in loaded_data:
            clip(prefix + 'pos_Lm' + suffix, -1e+6, 1e6)
            _, bdata = get_data(prefix + 'pos_Lm' + suffix)
            ylim(prefix + 'pos_Lm' + suffix, np.nanmin(bdata),
                 np.nanmax(bdata))

        # set labels
        options(prefix + 'pos_gse' + suffix, 'legend_names', ['X', 'Y', 'Z'])
        options(prefix + 'pos_gsm' + suffix, 'legend_names', ['X', 'Y', 'Z'])
        options(prefix + 'pos_sm' + suffix, 'legend_names', ['X', 'Y', 'Z'])

        options(prefix + 'pos_rmlatmlt' + suffix, 'legend_names',
                ['Re', 'MLAT', 'MLT'])

        options(prefix + 'pos_eq' + suffix, 'legend_names', ['Req', 'MLT'])

        options(prefix + 'pos_iono_north' + suffix, 'legend_names',
                ['GLAT', 'GLON'])
        options(prefix + 'pos_iono_south' + suffix, 'legend_names',
                ['GLAT', 'GLON'])

        options(prefix + 'pos_blocal' + suffix, 'legend_names',
                ['X', 'Y', 'Z'])

        options(prefix + 'pos_blocal_mag' + suffix, 'legend_names',
                ['B(model)_at_ERG'])
        # options(prefix + 'pos_blocal_mag' + suffix, 'legend_names', ['B(model)\n_at_ERG']) # Can't break?

        options(prefix + 'pos_beq' + suffix, 'legend_names', ['X', 'Y', 'Z'])

        options(prefix + 'pos_Lm' + suffix, 'legend_names',
                ['90deg', '60deg', '30deg'])

        options(prefix + 'vel_gse' + suffix, 'legend_names',
                ['X[km/s]', 'Y[km/s]', 'Z[km/s]'])
        options(prefix + 'vel_gsm' + suffix, 'legend_names',
                ['X[km/s]', 'Y[km/s]', 'Z[km/s]'])
        options(prefix + 'vel_sm' + suffix, 'legend_names',
                ['X[km/s]', 'Y[km/s]', 'Z[km/s]'])

        # set color
        options(prefix + 'pos_gse' + suffix, 'Color', ['b', 'g', 'r'])
        options(prefix + 'pos_gsm' + suffix, 'Color', ['b', 'g', 'r'])
        options(prefix + 'pos_sm' + suffix, 'Color', ['b', 'g', 'r'])

        options(prefix + 'pos_rmlatmlt' + suffix, 'Color', ['b', 'g', 'r'])

        options(prefix + 'pos_blocal' + suffix, 'Color', ['b', 'g', 'r'])

        options(prefix + 'pos_beq' + suffix, 'Color', ['b', 'g', 'r'])

        options(prefix + 'pos_Lm' + suffix, 'Color', ['b', 'g', 'r'])

        options(prefix + 'vel_gse' + suffix, 'Color', ['b', 'g', 'r'])
        options(prefix + 'vel_gsm' + suffix, 'Color', ['b', 'g', 'r'])
        options(prefix + 'vel_sm' + suffix, 'Color', ['b', 'g', 'r'])

        # set y axis to logscale
        options(prefix + 'pos_blocal_mag' + suffix, 'ylog', 1)

        options(prefix + 'pos_beq' + suffix, 'ylog', 1)

    elif (datatype in ["pre", "spre", "mpre", "lpre"]) and (level == 'l2'):

        # set labels
        options(prefix + 'pos_gse' + suffix, 'legend_names', ['X', 'Y', 'Z'])
        options(prefix + 'pos_gsm' + suffix, 'legend_names', ['X', 'Y', 'Z'])
        options(prefix + 'pos_sm' + suffix, 'legend_names', ['X', 'Y', 'Z'])

        options(prefix + 'pos_rmlatmlt' + suffix, 'legend_names',
                ['Re', 'MLAT', 'MLT'])

        options(prefix + 'pos_eq' + suffix, 'legend_names', ['Req', 'MLT'])

        options(prefix + 'pos_iono_north' + suffix, 'legend_names',
                ['GLAT', 'GLON'])
        options(prefix + 'pos_iono_south' + suffix, 'legend_names',
                ['GLAT', 'GLON'])

        options(prefix + 'pos_blocal' + suffix, 'legend_names',
                ['X', 'Y', 'Z'])

        options(prefix + 'pos_blocal_mag' + suffix, 'legend_names',
                'B(' + datatype + ')\n_at ERG')

        options(prefix + 'pos_beq' + suffix, 'legend_names', ['X', 'Y', 'Z'])

        options(prefix + 'pos_Lm' + suffix, 'legend_names',
                ['90deg', '60deg', '30deg'])

        options(prefix + 'vel_gse' + suffix, 'legend_names',
                ['X[km/s]', 'Y[km/s]', 'Z[km/s]'])
        options(prefix + 'vel_gsm' + suffix, 'legend_names',
                ['X[km/s]', 'Y[km/s]', 'Z[km/s]'])
        options(prefix + 'vel_sm' + suffix, 'legend_names',
                ['X[km/s]', 'Y[km/s]', 'Z[km/s]'])

        # set color
        options(prefix + 'pos_gse' + suffix, 'Color', ['b', 'g', 'r'])
        options(prefix + 'pos_gsm' + suffix, 'Color', ['b', 'g', 'r'])
        options(prefix + 'pos_sm' + suffix, 'Color', ['b', 'g', 'r'])

        options(prefix + 'pos_rmlatmlt' + suffix, 'Color', ['b', 'g', 'r'])

        options(prefix + 'pos_blocal' + suffix, 'Color', ['b', 'g', 'r'])

        options(prefix + 'pos_beq' + suffix, 'Color', ['b', 'g', 'r'])

        options(prefix + 'pos_Lm' + suffix, 'Color', ['b', 'g', 'r'])

        options(prefix + 'vel_gse' + suffix, 'Color', ['b', 'g', 'r'])
        options(prefix + 'vel_gsm' + suffix, 'Color', ['b', 'g', 'r'])
        options(prefix + 'vel_sm' + suffix, 'Color', ['b', 'g', 'r'])

        # set y axis to logscale
        options(prefix + 'pos_blocal_mag' + suffix, 'ylog', 1)
        options(prefix + 'pos_beq' + suffix, 'ylog', 1)

    elif level == 'l3':

        # remove -1.0e+30
        for i in range(len(loaded_data)):
            get_data_vars = get_data(loaded_data[i])
            if len(get_data_vars) < 3:
                if np.nanmin(get_data_vars[1]) < -1.0e+29:
                    clip(loaded_data[i], -1e+6, 1e6)
                    _, bdata = get_data(loaded_data[i])
                    ylim(loaded_data[i], np.nanmin(bdata), np.nanmax(bdata))

        if model in ["op", "t89", "ts04"]:

            if model == "ts04":
                model = model.upper()

            # set ytitle
            options(prefix + 'pos_lmc_' + model + suffix, 'ytitle',
                    f'Lmc ({model})')
            options(prefix + 'pos_lstar_' + model + suffix, 'ytitle',
                    f'Lstar ({model})')
            options(prefix + 'pos_I_' + model + suffix, 'ytitle',
                    f'I ({model})')
            options(prefix + 'pos_blocal_' + model + suffix, 'ytitle',
                    f'Blocal ({model})')
            options(prefix + 'pos_beq_' + model + suffix, 'ytitle',
                    f'Beq ({model})')
            options(prefix + 'pos_eq_' + model + suffix, 'ytitle',
                    f'Eq_pos ({model})')
            options(prefix + 'pos_iono_north_' + model + suffix, 'ytitle',
                    f'footprint_north ({model})')
            options(prefix + 'pos_iono_south_' + model + suffix, 'ytitle',
                    f'footprint_south ({model})')

            # set ysubtitle
            options(prefix + 'pos_lmc_' + model + suffix, 'ysubtitle',
                    '[dimensionless]')
            options(prefix + 'pos_lstar_' + model + suffix, 'ysubtitle',
                    '[dimensionless]')
            options(prefix + 'pos_I_' + model + suffix, 'ysubtitle', '[Re]')
            options(prefix + 'pos_blocal_' + model + suffix, 'ysubtitle',
                    '[nT]')
            options(prefix + 'pos_beq_' + model + suffix, 'ysubtitle', '[nT]')
            options(prefix + 'pos_eq_' + model + suffix, 'ysubtitle',
                    '[Re Hour]')
            options(prefix + 'pos_iono_north_' + model + suffix, 'ysubtitle',
                    '[deg. deg.]')
            options(prefix + 'pos_iono_south_' + model + suffix, 'ysubtitle',
                    '[deg. deg.]')

            # set ylabels
            options(prefix + 'pos_lmc_' + model + suffix, 'legend_names', [
                '90deg', '80deg', '70deg', '60deg', '50deg', '40deg', '30deg',
                '20deg', '10deg'
            ])
            options(prefix + 'pos_lstar_' + model + suffix, 'legend_names', [
                '90deg', '80deg', '70deg', '60deg', '50deg', '40deg', '30deg',
                '20deg', '10deg'
            ])
            options(prefix + 'pos_I_' + model + suffix, 'legend_names', [
                '90deg', '80deg', '70deg', '60deg', '50deg', '40deg', '30deg',
                '20deg', '10deg'
            ])
            options(prefix + 'pos_blocal_' + model + suffix, 'legend_names',
                    '|B|')
            options(prefix + 'pos_beq_' + model + suffix, 'legend_names',
                    '|B|')
            options(prefix + 'pos_eq_' + model + suffix, 'legend_names',
                    ['Re', 'MLT'])
            options(prefix + 'pos_iono_north_' + model + suffix,
                    'legend_names', ['GLAT', 'GLON'])
            options(prefix + 'pos_iono_south_' + model + suffix,
                    'legend_names', ['GLAT', 'GLON'])

            # set y axis to logscale
            options(prefix + 'pos_blocal_' + model + suffix, 'ylog', 1)
            options(prefix + 'pos_beq_' + model + suffix, 'ylog', 1)

    return loaded_data
Example #7
0
def mgf(trange=['2017-03-27', '2017-03-28'],
        datatype='8sec',
        level='l2',
        suffix='',
        get_support_data=False,
        varformat=None,
        varnames=[],
        downloadonly=False,
        notplot=False,
        no_update=False,
        uname=None,
        passwd=None,
        time_clip=False,
        ror=True,
        coord='dsi',
        version=None):
    """
    This function loads data from the MGF experiment from the Arase mission

    Parameters:
        trange : list of str
            time range of interest [starttime, endtime] with the format
            'YYYY-MM-DD','YYYY-MM-DD'] or to specify more or less than a day
            ['YYYY-MM-DD/hh:mm:ss','YYYY-MM-DD/hh:mm:ss']

        datatype: str
            Data type; Valid options:

        level: str
            Data level; Valid options:

        suffix: str
            The tplot variable names will be given this suffix.  By default,
            no suffix is added.

        get_support_data: bool
            Data with an attribute "VAR_TYPE" with a value of "support_data"
            will be loaded into tplot.  By default, only loads in data with a
            "VAR_TYPE" attribute of "data".

        varformat: str
            The file variable formats to load into tplot.  Wildcard character
            "*" is accepted.  By default, all variables are loaded in.

        downloadonly: bool
            Set this flag to download the CDF files, but not load them into
            tplot variables

        notplot: bool
            Return the data in hash tables instead of creating tplot variables

        no_update: bool
            If set, only load data from your local cache

        time_clip: bool
            Time clip the variables to exactly the range specified in the trange keyword

        ror: bool
            If set, print PI info and rules of the road

        coord: str
            "sm", "dsi", "gse", "gsm", "sgi"

        version: str
            Set this value to specify the version of cdf files (such as "v03.03", "v03.04", ...)

    Returns:
        List of tplot variables created.

    """
    initial_notplot_flag = False
    if notplot:
        initial_notplot_flag = True

    if datatype == '8s' or datatype == '8':
        datatype = '8sec'
    elif datatype == '64':
        datatype = '64hz'
    elif datatype == '128':
        datatype = '128hz'
    elif datatype == '256':
        datatype = '256hz'

    prefix = 'erg_mgf_'+level+'_'
    if datatype == '8sec':
        file_res = 3600. * 24
        pathformat = 'satellite/erg/mgf/'+level+'/'+datatype + \
            '/%Y/%m/erg_mgf_'+level+'_'+datatype+'_%Y%m%d_'
    else:
        file_res = 3600.
        pathformat = 'satellite/erg/mgf/'+level+'/'+datatype + \
            '/%Y/%m/erg_mgf_'+level+'_'+datatype+'_' + coord + '_%Y%m%d%H_'

    if version is None:
        pathformat += 'v??.??.cdf'
    else:
        pathformat += version + '.cdf'

    loaded_data = load(pathformat=pathformat, file_res=file_res, trange=trange, level=level, datatype=datatype, prefix=prefix, suffix=suffix, get_support_data=get_support_data,
                       varformat=varformat, downloadonly=downloadonly, notplot=notplot, time_clip=time_clip, no_update=no_update, uname=uname, passwd=passwd)

    if (loaded_data is None) or (loaded_data == []):
        return loaded_data

    if (len(loaded_data) > 0) and ror:

        try:
            if isinstance(loaded_data, list):
                if downloadonly:
                    cdf_file = cdflib.CDF(loaded_data[-1])
                    gatt = cdf_file.globalattsget()
                else:
                    gatt = get_data(loaded_data[-1], metadata=True)['CDF']['GATT']
            elif isinstance(loaded_data, dict):
                gatt = loaded_data[list(loaded_data.keys())[-1]]['CDF']['GATT']

            # --- print PI info and rules of the road
            print(' ')
            print(
                '**************************************************************************')
            print(gatt["LOGICAL_SOURCE_DESCRIPTION"])
            print('')
            print('Information about ERG MGF')
            print('')
            print('PI: ', gatt['PI_NAME'])
            print("Affiliation: "+gatt["PI_AFFILIATION"])
            print('')
            print('RoR of ERG project common: https://ergsc.isee.nagoya-u.ac.jp/data_info/rules_of_the_road.shtml.en')
            print(
                'RoR of MGF L2: https://ergsc.isee.nagoya-u.ac.jp/mw/index.php/ErgSat/Mgf')
            print('Contact: erg_mgf_info at isee.nagoya-u.ac.jp')
            print(
                '**************************************************************************')
        except:
            print('printing PI info and rules of the road was failed')

    if initial_notplot_flag or downloadonly:
        return loaded_data

    if datatype == '8sec':

        # remove -1.0e+30

        clip(prefix + 'mag_'+datatype+'_dsi'+suffix, -1e+6, 1e6)
        clip(prefix + 'mag_'+datatype+'_gse'+suffix, -1e+6, 1e6)
        clip(prefix + 'mag_'+datatype+'_gsm'+suffix, -1e+6, 1e6)
        clip(prefix + 'mag_'+datatype+'_sm'+suffix, -1e+6, 1e6)

        clip(prefix + 'magt_'+datatype+suffix, -1e+6, 1e6)

        clip(prefix + 'rmsd_'+datatype+'_dsi'+suffix, -1e+6, +1e+6)
        clip(prefix + 'rmsd_'+datatype+'_gse'+suffix, -1e+6, +1e+6)
        clip(prefix + 'rmsd_'+datatype+'_gsm'+suffix, -1e+6, +1e+6)
        clip(prefix + 'rmsd_'+datatype+'_sm'+suffix, -1e+6, +1e+6)

        clip(prefix + 'rmsd_'+datatype+suffix, 0., 80.)

        clip(prefix + 'dyn_rng_'+datatype+suffix, -120., +1e+6)

        clip(prefix + 'igrf_'+datatype+'_dsi'+suffix, -1e+6, +1e+6)
        clip(prefix + 'igrf_'+datatype+'_gse'+suffix, -1e+6, +1e+6)
        clip(prefix + 'igrf_'+datatype+'_gsm'+suffix, -1e+6, +1e+6)
        clip(prefix + 'igrf_'+datatype+'_sm'+suffix, -1e+6, +1e+6)

        # set yrange
        _, bdata = get_data(prefix + 'mag_'+datatype+'_dsi'+suffix)
        ylim(prefix + 'mag_'+datatype+'_dsi'+suffix,
             np.nanmin(bdata), np.nanmax(bdata))
        _, bdata = get_data(prefix + 'mag_'+datatype+'_gse'+suffix)
        ylim(prefix + 'mag_'+datatype+'_gse'+suffix,
             np.nanmin(bdata), np.nanmax(bdata))
        _, bdata = get_data(prefix + 'mag_'+datatype+'_gsm'+suffix)
        ylim(prefix + 'mag_'+datatype+'_gsm'+suffix,
             np.nanmin(bdata), np.nanmax(bdata))
        _, bdata = get_data(prefix + 'mag_'+datatype+'_sm'+suffix)
        ylim(prefix + 'mag_'+datatype+'_sm'+suffix,
             np.nanmin(bdata), np.nanmax(bdata))

        _, bdata = get_data(prefix + 'magt_'+datatype+suffix)
        ylim(prefix + 'magt_'+datatype+suffix,
             np.nanmin(bdata), np.nanmax(bdata))

        _, bdata = get_data(prefix + 'rmsd_'+datatype+suffix,)
        ylim(prefix + 'rmsd_'+datatype+suffix,
             np.nanmin(bdata), np.nanmax(bdata))

        _, bdata = get_data(prefix + 'rmsd_'+datatype+'_dsi'+suffix)
        ylim(prefix + 'rmsd_'+datatype+'_dsi'+suffix,
             np.nanmin(bdata), np.nanmax(bdata))
        _, bdata = get_data(prefix + 'rmsd_'+datatype+'_gse'+suffix)
        ylim(prefix + 'rmsd_'+datatype+'_gse'+suffix,
             np.nanmin(bdata), np.nanmax(bdata))
        _, bdata = get_data(prefix + 'rmsd_'+datatype+'_gsm'+suffix)
        ylim(prefix + 'rmsd_'+datatype+'_gsm'+suffix,
             np.nanmin(bdata), np.nanmax(bdata))
        _, bdata = get_data(prefix + 'rmsd_'+datatype+'_sm'+suffix)
        ylim(prefix + 'rmsd_'+datatype+'_sm'+suffix,
             np.nanmin(bdata), np.nanmax(bdata))

        _, bdata = get_data(prefix + 'rmsd_'+datatype+suffix)
        ylim(prefix + 'rmsd_'+datatype+suffix,
             np.nanmin(bdata), np.nanmax(bdata))

        _, bdata = get_data(prefix + 'quality_'+datatype+suffix)
        ylim(prefix + 'quality_'+datatype+suffix,
             np.nanmin(bdata), np.nanmax(bdata))
        _, bdata = get_data(prefix + 'quality_'+datatype+'_gc'+suffix)
        ylim(prefix + 'quality_'+datatype+'_gc' +
             suffix, np.nanmin(bdata), np.nanmax(bdata))

        # set labels
        options(prefix + 'mag_'+datatype+'_dsi'+suffix,
                'legend_names', ['Bx', 'By', 'Bz'])
        options(prefix + 'mag_'+datatype+'_gse'+suffix,
                'legend_names', ['Bx', 'By', 'Bz'])
        options(prefix + 'mag_'+datatype+'_gsm'+suffix,
                'legend_names', ['Bx', 'By', 'Bz'])
        options(prefix + 'mag_'+datatype+'_sm'+suffix,
                'legend_names', ['Bx', 'By', 'Bz'])

        options(prefix + 'rmsd_'+datatype+'_dsi'+suffix,
                'legend_names', ['Bx', 'By', 'Bz'])
        options(prefix + 'rmsd_'+datatype+'_gse'+suffix,
                'legend_names', ['Bx', 'By', 'Bz'])
        options(prefix + 'rmsd_'+datatype+'_gsm'+suffix,
                'legend_names', ['Bx', 'By', 'Bz'])
        options(prefix + 'rmsd_'+datatype+'_sm'+suffix,
                'legend_names', ['Bx', 'By', 'Bz'])

        options(prefix + 'igrf_'+datatype+'_dsi'+suffix,
                'legend_names', ['Bx', 'By', 'Bz'])
        options(prefix + 'igrf_'+datatype+'_gse'+suffix,
                'legend_names', ['Bx', 'By', 'Bz'])
        options(prefix + 'igrf_'+datatype+'_gsm'+suffix,
                'legend_names', ['Bx', 'By', 'Bz'])
        options(prefix + 'igrf_'+datatype+'_sm'+suffix,
                'legend_names', ['Bx', 'By', 'Bz'])

        # set color of the labels
        options(prefix + 'mag_'+datatype+'_dsi' +
                suffix, 'Color', ['b', 'g', 'r'])
        options(prefix + 'mag_'+datatype+'_gse' +
                suffix, 'Color', ['b', 'g', 'r'])
        options(prefix + 'mag_'+datatype+'_gsm' +
                suffix, 'Color', ['b', 'g', 'r'])
        options(prefix + 'mag_'+datatype+'_sm' +
                suffix, 'Color', ['b', 'g', 'r'])

        options(prefix + 'rmsd_'+datatype+'_dsi' +
                suffix, 'Color', ['b', 'g', 'r'])
        options(prefix + 'rmsd_'+datatype+'_gse' +
                suffix, 'Color', ['b', 'g', 'r'])
        options(prefix + 'rmsd_'+datatype+'_gsm' +
                suffix, 'Color', ['b', 'g', 'r'])
        options(prefix + 'rmsd_'+datatype+'_sm' +
                suffix, 'Color', ['b', 'g', 'r'])

        options(prefix + 'quality_'+datatype+suffix, 'Color', ['r', 'g', 'b'])

        options(prefix + 'igrf_'+datatype+'_dsi' +
                suffix, 'Color', ['b', 'g', 'r'])
        options(prefix + 'igrf_'+datatype+'_gse' +
                suffix, 'Color', ['b', 'g', 'r'])
        options(prefix + 'igrf_'+datatype+'_gsm' +
                suffix, 'Color', ['b', 'g', 'r'])
        options(prefix + 'igrf_'+datatype+'_sm' +
                suffix, 'Color', ['b', 'g', 'r'])
    else:
        # remove -1.0e+30
        clip(prefix + 'mag_'+datatype+'_' + coord + suffix, -1e+6, 1e6)
        # set yrange
        _, bdata = get_data(prefix + 'mag_'+datatype+'_' + coord + suffix)
        ylim(prefix + 'mag_'+datatype+'_' + coord +
             suffix, np.nanmin(bdata), np.nanmax(bdata))
        # set labels
        options(prefix + 'mag_'+datatype+'_' + coord +
                suffix, 'legend_names', ['Bx', 'By', 'Bz'])
        # set color of the labels
        options(prefix + 'mag_'+datatype+'_' + coord +
                suffix, 'Color', ['b', 'g', 'r'])
    return loaded_data
Example #8
0
def lepe(trange=['2017-04-04', '2017-04-05'],
         datatype='omniflux',
         level='l2',
         suffix='',
         get_support_data=False,
         varformat=None,
         varnames=[],
         downloadonly=False,
         notplot=False,
         no_update=False,
         uname=None,
         passwd=None,
         time_clip=False,
         ror=True,
         version=None,
         only_fedu=False,
         et_diagram=False):
    """
    This function loads data from the LEP-e experiment from the Arase mission

    Parameters:
        trange : list of str
            time range of interest [starttime, endtime] with the format
            'YYYY-MM-DD','YYYY-MM-DD'] or to specify more or less than a day
            ['YYYY-MM-DD/hh:mm:ss','YYYY-MM-DD/hh:mm:ss']

        datatype: str
            Data type; Valid options:

        level: str
            Data level; Valid options:

        suffix: str
            The tplot variable names will be given this suffix.  By default,
            no suffix is added.

        get_support_data: bool
            Data with an attribute "VAR_TYPE" with a value of "support_data"
            will be loaded into tplot.  By default, only loads in data with a
            "VAR_TYPE" attribute of "data".

        varformat: str
            The file variable formats to load into tplot.  Wildcard character
            "*" is accepted.  By default, all variables are loaded in.

        varnames: list of str
            List of variable names to load (if not specified,
            all data variables are loaded)

        downloadonly: bool
            Set this flag to download the CDF files, but not load them into
            tplot variables

        notplot: bool
            Return the data in hash tables instead of creating tplot variables

        no_update: bool
            If set, only load data from your local cache

        time_clip: bool
            Time clip the variables to exactly the range specified in the trange keyword

        ror: bool
            If set, print PI info and rules of the road

        version: str
            Set this value to specify the version of cdf files (such as "v02_02")

        only_fedu: bool
            If set, not make erg_lepe_l3_pa_enech_??(??:01,01,..32)_FEDU Tplot Variables

        et_diagram: bool
            If set, make erg_lepe_l3_pa_pabin_??(??:01,01,..16)_FEDU Tplot Variables

    Returns:
        List of tplot variables created.

    """

    initial_notplot_flag = False
    if notplot:
        initial_notplot_flag = True

    if level == 'l3':
        datatype = 'pa'

    if ((level == 'l2') and (datatype == 'omniflux')) or \
        ((level == 'l2') and (datatype == '3dflux')) or \
            (level == 'l3'):
        # to avoid failure of creation plot variables (at store_data.py) of lepe
        notplot = True

    file_res = 3600. * 24
    prefix = 'erg_lepe_'+level+'_' + datatype + '_'
    pathformat = 'satellite/erg/lepe/'+level+'/'+datatype + \
        '/%Y/%m/erg_lepe_'+level+'_'+datatype+'_%Y%m%d_'

    if version is None:
        pathformat += 'v??_??.cdf'
    else:
        pathformat += version + '.cdf'

    loaded_data = load(pathformat=pathformat, trange=trange, level=level, datatype=datatype, file_res=file_res, prefix=prefix, suffix=suffix, get_support_data=get_support_data,
                       varformat=varformat, varnames=varnames, downloadonly=downloadonly, notplot=notplot, time_clip=time_clip, no_update=no_update, uname=uname, passwd=passwd)


    if (len(loaded_data) > 0) and ror:

        try:
            if isinstance(loaded_data, list):
                if downloadonly:
                    cdf_file = cdflib.CDF(loaded_data[-1])
                    gatt = cdf_file.globalattsget()
                else:
                    gatt = get_data(loaded_data[-1], metadata=True)['CDF']['GATT']
            elif isinstance(loaded_data, dict):
                gatt = loaded_data[list(loaded_data.keys())[-1]]['CDF']['GATT']

            # --- print PI info and rules of the road

            print(' ')
            print(
                '**************************************************************************')
            print(gatt["LOGICAL_SOURCE_DESCRIPTION"])
            print('')
            print('Information about ERG LEPe')
            print('')
            print('PI: ', gatt['PI_NAME'])
            print("Affiliation: "+gatt["PI_AFFILIATION"])
            print('')
            print('RoR of ERG project common: https://ergsc.isee.nagoya-u.ac.jp/data_info/rules_of_the_road.shtml.en')
            if level == 'l2':
                print(
                    'RoR of LEPe L2: https://ergsc.isee.nagoya-u.ac.jp/mw/index.php/ErgSat/Lepe')
            if level == 'l3':
                print(
                    'RoR of LEPe L3: https://ergsc.isee.nagoya-u.ac.jp/mw/index.php/ErgSat/Lepe')
                print(
                    'RoR of MGF L2: https://ergsc.isee.nagoya-u.ac.jp/mw/index.php/ErgSat/Mgf')
            print('')
            print('Contact: erg_lepe_info at isee.nagoya-u.ac.jp')
            print(
                '**************************************************************************')
        except:
            print('printing PI info and rules of the road was failed')

    if initial_notplot_flag or downloadonly:
        return loaded_data

    if (isinstance(loaded_data, dict)) and (len(loaded_data) > 0):
        if (level == 'l2') and (datatype == 'omniflux'):
            tplot_variables = []
            v_array = (loaded_data[prefix + 'FEDO' + suffix]['v'][:, 0, :] +
                       loaded_data[prefix + 'FEDO' + suffix]['v'][:, 1, :]) / 2.
            # change minus values to NaN
            v_array = np.where(v_array < 0., np.nan, v_array)
            all_nan_v_indices_array = np.where(
                np.all(np.isnan(v_array), axis=1))[0]
            store_data(prefix + 'FEDO' + suffix,
                       data={'x': np.delete(loaded_data[prefix + 'FEDO' + suffix]['x'], all_nan_v_indices_array, axis=0),
                             'y': np.delete(loaded_data[prefix + 'FEDO' + suffix]['y'], all_nan_v_indices_array, axis=0),
                             'v': np.delete(v_array, all_nan_v_indices_array, 0)},
                       attr_dict={'CDF':loaded_data[prefix + 'FEDO' + suffix]['CDF']})
            tplot_variables.append(prefix + 'FEDO' + suffix)

            # set spectrogram plot option
            options(prefix + 'FEDO' + suffix, 'Spec', 1)
            # change minus values to NaN in y array
            clip(prefix + 'FEDO' + suffix, 0.,
                 np.nanmax(loaded_data[prefix + 'FEDO' + suffix]['y']))

            # set y axis to logscale
            options(prefix + 'FEDO' + suffix, 'ylog', 1)

            # set ylim
            ylim(prefix + 'FEDO' + suffix, 19, 21*1e3)

            # set ytitle
            options(prefix + 'FEDO' + suffix, 'ytitle',
                    'ERG\nLEP-e\nFEDO\nEnergy')

            # set ysubtitle
            options(prefix + 'FEDO' + suffix, 'ysubtitle', '[eV]')

            # set z axis to logscale
            options(prefix + 'FEDO' + suffix, 'zlog', 1)

            # set zlim
            zlim(prefix + 'FEDO' + suffix,  1, 1e6)

            # set ztitle
            options(prefix + 'FEDO' + suffix, 'ztitle',  '[/cm^{2}-str-s-eV]')

            # change colormap option
            options(prefix + 'FEDO' + suffix, 'Colormap', 'jet')

            return tplot_variables

        if (level == 'l2') and (datatype == '3dflux'):
            tplot_variables = []
            other_variables_dict = {}
            if prefix + 'FEDU' + suffix in loaded_data:
                store_data(prefix + 'FEDU' + suffix,
                           data={'x': loaded_data[prefix + 'FEDU' + suffix]['x'],
                                 'y': loaded_data[prefix + 'FEDU' + suffix]['y'],
                                 'v1': np.sqrt(loaded_data[prefix + 'FEDU' + suffix]['v'][:, 0, :]
                                               * loaded_data[prefix + 'FEDU' + suffix]['v'][:, 1, :]),  # geometric mean
                                 'v2': ['01', '02', '03', '04', '05', 'A', 'B', '18', '19', '20', '21', '22'],
                                 'v3': [i for i in range(16)]},
                       attr_dict={'CDF':loaded_data[prefix + 'FEDU' + suffix]['CDF']})

                tplot_variables.append(prefix + 'FEDU' + suffix)

                options(prefix + 'FEDU' + suffix, 'spec', 1)
                if prefix + 'FEDU' + suffix in tplot_variables:
                    clip(prefix + 'FEDU' + suffix, 0,
                         np.nanmax(loaded_data[prefix + 'FEDU' + suffix]['y']))
                ylim(prefix + 'FEDU' + suffix, 19, 21*1e3)
                zlim(prefix + 'FEDU' + suffix, 1, 1e6)
                options(prefix + 'FEDU' + suffix, 'zlog', 1)
                options(prefix + 'FEDU' + suffix, 'ylog', 1)
                options(prefix + 'FEDU' + suffix, 'ysubtitle', '[eV]')

                other_variables_dict[prefix + 'Count_Rate' +
                                     suffix] = loaded_data[prefix + 'Count_Rate' + suffix]
                other_variables_dict[prefix + 'Count_Rate_BG' +
                                     suffix] = loaded_data[prefix + 'Count_Rate_BG' + suffix]

                tplot_variables.append(other_variables_dict)

                return tplot_variables

        if level == 'l3':
            tplot_variables = []

            if prefix + 'FEDU' + suffix in loaded_data:
                store_data(prefix + 'FEDU' + suffix,
                           data={'x': loaded_data[prefix + 'FEDU' + suffix]['x'],
                                 'y': loaded_data[prefix + 'FEDU' + suffix]['y'],
                                 'v1': (loaded_data[prefix + 'FEDU' + suffix]['v1'][:, 0, :]
                                        + loaded_data[prefix + 'FEDU' + suffix]['v1'][:, 1, :]) / 2.,  # arithmetic mean
                                 'v2': loaded_data[prefix + 'FEDU' + suffix]['v2']},
                       attr_dict={'CDF':loaded_data[prefix + 'FEDU' + suffix]['CDF']})
                tplot_variables.append(prefix + 'FEDU' + suffix)

                options(prefix + 'FEDU' + suffix, 'spec', 1)
                if prefix + 'FEDU' + suffix in tplot_variables:
                    clip(prefix + 'FEDU' + suffix, 0,
                         np.nanmax(loaded_data[prefix + 'FEDU' + suffix]['y']))
                ylim(prefix + 'FEDU' + suffix, 19, 21*1e3)
                zlim(prefix + 'FEDU' + suffix, 1, 1e6)
                options(prefix + 'FEDU' + suffix, 'zlog', 1)
                options(prefix + 'FEDU' + suffix, 'ylog', 1)
                options(prefix + 'FEDU' + suffix, 'ysubtitle', '[eV]')

                FEDU_get_data = get_data(prefix + 'FEDU' + suffix)
                FEDU_CDF_data = loaded_data[prefix + 'FEDU' + suffix]['CDF']

                if not only_fedu:

                    ytitle_eV_array = np.round(
                        np.nan_to_num(FEDU_get_data[2][0, :]), 2)
                    # processing for erg_lepe_l3_pa_enech_??(??:01,01,..32)_FEDU
                    for i in range(FEDU_get_data[1].shape[1]):
                        tplot_name = prefix + 'enech_' + \
                            str(i + 1).zfill(2) + '_FEDU' + suffix
                        store_data(tplot_name, data={'x': FEDU_get_data[0],
                                                     'y': FEDU_get_data[1][:, i, :],
                                                     'v': FEDU_get_data[3]},
                                    attr_dict={'CDF':FEDU_CDF_data})
                        options(tplot_name, 'spec', 1)
                        ylim(tplot_name, 0, 180)
                        zlim(tplot_name, 1, 1e6)
                        options(tplot_name, 'ytitle', 'ERG LEP-e\n' +
                                str(ytitle_eV_array[i]) + ' eV\nPitch angle')
                        tplot_variables.append(tplot_name)

                    options(tplot_variables[1:], 'zlog', 1)
                    options(tplot_variables[1:], 'ysubtitle', '[deg]')
                    options(tplot_variables[1:], 'yrange', [0, 180])
                    options(tplot_variables[1:], 'colormap', 'jet')
                    options(tplot_variables[1:],
                            'ztitle', '[/s-cm^{2}-sr-keV/q]')

                if et_diagram:
                    ytitle_deg_array = np.round(
                        np.nan_to_num(FEDU_get_data[3]), 3)
                    all_nan_v_indices_array = np.where(
                        np.all(np.isnan(FEDU_get_data[2]), axis=1))[0]
                    x_all_nan_deleted_array = np.delete(
                        FEDU_get_data[0], all_nan_v_indices_array, axis=0)
                    y_all_nan_deleted_array = np.delete(
                        FEDU_get_data[1], all_nan_v_indices_array, axis=0)
                    v_all_nan_deleted_array = np.delete(
                        FEDU_get_data[2], all_nan_v_indices_array, axis=0)
                    # processing for erg_lepe_l3_pa_pabin_??(??:01,01,..16)_FEDU
                    for i in range(FEDU_get_data[1].shape[2]):
                        tplot_name = prefix + 'pabin_' + \
                            str(i + 1).zfill(2) + '_FEDU' + suffix
                        store_data(tplot_name, data={'x': x_all_nan_deleted_array,
                                                     'y': y_all_nan_deleted_array[:, :, i],
                                                     'v': v_all_nan_deleted_array},
                                    attr_dict={'CDF':FEDU_CDF_data})
                        options(tplot_name, 'spec', 1)
                        ylim(tplot_name,  19, 21*1e3)
                        zlim(tplot_name, 1, 1e6)
                        options(tplot_name, 'ytitle', 'ERG LEP-e\n' +
                                str(ytitle_deg_array[i]) + ' deg\nEnergy')
                        tplot_variables.append(tplot_name)

                    options(
                        tplot_variables[-FEDU_get_data[1].shape[2]:], 'ysubtitle', '[eV]')
                    options(
                        tplot_variables[-FEDU_get_data[1].shape[2]:], 'zlog', 1)
                    options(
                        tplot_variables[-FEDU_get_data[1].shape[2]:], 'ylog', 1)
                    options(
                        tplot_variables[-FEDU_get_data[1].shape[2]:], 'colormap', 'jet')
                    options(
                        tplot_variables[-FEDU_get_data[1].shape[2]:], 'ztitle', '[/s-cm^{2}-sr-eV]')

                return tplot_variables

    return loaded_data
Example #9
0
def mgf(trange=['2017-03-27', '2017-03-28'],
        datatype='8sec',
        level='l2',
        suffix='',
        get_support_data=False,
        varformat=None,
        downloadonly=False,
        notplot=False,
        no_update=False,
        uname=None,
        passwd=None,
        time_clip=False):
    """
    This function loads data from the MGF experiment from the Arase mission
    
    Parameters:
        trange : list of str
            time range of interest [starttime, endtime] with the format 
            'YYYY-MM-DD','YYYY-MM-DD'] or to specify more or less than a day 
            ['YYYY-MM-DD/hh:mm:ss','YYYY-MM-DD/hh:mm:ss']

        datatype: str
            Data type; Valid options:

        level: str
            Data level; Valid options:

        suffix: str
            The tplot variable names will be given this suffix.  By default, 
            no suffix is added.

        get_support_data: bool
            Data with an attribute "VAR_TYPE" with a value of "support_data"
            will be loaded into tplot.  By default, only loads in data with a 
            "VAR_TYPE" attribute of "data".

        varformat: str
            The file variable formats to load into tplot.  Wildcard character
            "*" is accepted.  By default, all variables are loaded in.

        downloadonly: bool
            Set this flag to download the CDF files, but not load them into 
            tplot variables

        notplot: bool
            Return the data in hash tables instead of creating tplot variables

        no_update: bool
            If set, only load data from your local cache

        time_clip: bool
            Time clip the variables to exactly the range specified in the trange keyword

    Returns:
        List of tplot variables created.

    """

    if datatype == '8s' or datatype == '8':
        datatype = '8sec'
    elif datatype == '64':
        datatype = '64hz'
    elif datatype == '128':
        datatype = '128hz'
    elif datatype == '256':
        datatype = '256hz'

    loaded_data = load(instrument='mgf',
                       trange=trange,
                       level=level,
                       datatype=datatype,
                       suffix=suffix,
                       get_support_data=get_support_data,
                       varformat=varformat,
                       downloadonly=downloadonly,
                       notplot=notplot,
                       time_clip=time_clip,
                       no_update=no_update,
                       uname=uname,
                       passwd=passwd)

    if loaded_data == None or loaded_data == [] or notplot or downloadonly:
        return loaded_data

    clip('erg_mgf_' + level + '_mag_' + datatype + '_dsi' + suffix, -1e+6, 1e6)
    clip('erg_mgf_' + level + '_mag_' + datatype + '_gse' + suffix, -1e+6, 1e6)
    clip('erg_mgf_' + level + '_mag_' + datatype + '_gsm' + suffix, -1e+6, 1e6)
    clip('erg_mgf_' + level + '_mag_' + datatype + '_sm' + suffix, -1e+6, 1e6)

    # set yrange
    times, bdata = get_data('erg_mgf_' + level + '_mag_' + datatype + '_dsi' +
                            suffix)
    ylim('erg_mgf_' + level + '_mag_' + datatype + '_dsi' + suffix,
         np.nanmin(bdata), np.nanmax(bdata))
    times, bdata = get_data('erg_mgf_' + level + '_mag_' + datatype + '_gse' +
                            suffix)
    ylim('erg_mgf_' + level + '_mag_' + datatype + '_gse' + suffix,
         np.nanmin(bdata), np.nanmax(bdata))
    times, bdata = get_data('erg_mgf_' + level + '_mag_' + datatype + '_gsm' +
                            suffix)
    ylim('erg_mgf_' + level + '_mag_' + datatype + '_gsm' + suffix,
         np.nanmin(bdata), np.nanmax(bdata))
    times, bdata = get_data('erg_mgf_' + level + '_mag_' + datatype + '_sm' +
                            suffix)
    ylim('erg_mgf_' + level + '_mag_' + datatype + '_sm' + suffix,
         np.nanmin(bdata), np.nanmax(bdata))

    # set labels
    options('erg_mgf_' + level + '_mag_' + datatype + '_dsi' + suffix,
            'legend_names', ['Bx', 'By', 'Bz'])
    options('erg_mgf_' + level + '_mag_' + datatype + '_gse' + suffix,
            'legend_names', ['Bx', 'By', 'Bz'])
    options('erg_mgf_' + level + '_mag_' + datatype + '_gsm' + suffix,
            'legend_names', ['Bx', 'By', 'Bz'])
    options('erg_mgf_' + level + '_mag_' + datatype + '_sm' + suffix,
            'legend_names', ['Bx', 'By', 'Bz'])

    # set color of the labels
    options('erg_mgf_' + level + '_mag_' + datatype + '_dsi' + suffix, 'Color',
            ['b', 'g', 'r'])
    options('erg_mgf_' + level + '_mag_' + datatype + '_gse' + suffix, 'Color',
            ['b', 'g', 'r'])
    options('erg_mgf_' + level + '_mag_' + datatype + '_gsm' + suffix, 'Color',
            ['b', 'g', 'r'])
    options('erg_mgf_' + level + '_mag_' + datatype + '_sm' + suffix, 'Color',
            ['b', 'g', 'r'])

    return loaded_data
Example #10
0
print('add')
pytplot.add('a', 'c', 'a+c')
print(pytplot.data_quants['a+c'].data)

print('avg_res_data')
pytplot.avg_res_data('d', 2, 'd2res')
print(pytplot.data_quants['d'].data)
print(pytplot.data_quants['d2res'].data)
pytplot.avg_res_data('h', 7, 'h7res')
print(pytplot.data_quants['h'].data)
print(pytplot.data_quants['h'].spec_bins)
print(pytplot.data_quants['h7res'].data)
print(pytplot.data_quants['h7res'].spec_bins)

print('clip')
pytplot.clip('d', 2, 6, 'd_clip')
print(pytplot.data_quants['d_clip'].data)
pytplot.clip('h', 2, 6, 'h_clip')
print(pytplot.data_quants['h_clip'].data)
print(pytplot.data_quants['h_clip'].spec_bins)

print('crop')
pytplot.crop('a', 'b')

print('deflag')
pytplot.deflag('d', [100, 90, 7, 2, 57], 'd_deflag')
print(pytplot.data_quants['d'].data)
print(pytplot.data_quants['d_deflag'].data)
pytplot.deflag('h', [100, 90, 7, 2, 57], 'h_deflag')
print(pytplot.data_quants['h_deflag'].data)
print(pytplot.data_quants['h_deflag'].spec_bins)