예제 #1
0
def test_altitude_plot():

    pytplot.netcdf_to_tplot(current_directory +
                            "/testfiles/g15_xrs_2s_20170619_20170619.nc",
                            time='time_tag')
    pytplot.store_data(
        'altitude',
        data={
            'x':
            pytplot.data_quants['A_COUNT'].coords['time'].values,
            'y':
            np.arange(
                0,
                len(pytplot.data_quants['A_COUNT'].coords['time'].values),
                step=1)
        })
    pytplot.link('A_COUNT', 'altitude')
    pytplot.xlim('2017-06-19 02:00:00', '2017-06-19 04:00:00')
    pytplot.ylim("A_COUNT", 17000, 18000)
    pytplot.timebar('2017-06-19 03:00:00',
                    "A_COUNT",
                    color=(100, 255, 0),
                    thick=3)
    pytplot.timebar('2017-06-19 03:30:00', "A_COUNT", color='g')
    pytplot.options("A_COUNT", 'alt', 1)
    pytplot.tplot(2, testing=True)
    pytplot.tplot(2, testing=True, bokeh=True)
예제 #2
0
def load_data(filenames=None,
              instruments=None,
              level='l2',
              type=None,
              insitu=True,
              iuvs=False,
              start_date='2014-01-01',
              end_date='2020-01-01',
              update_prefs=False,
              only_update_prefs=False,
              local_dir=None,
              list_files=False,
              new_files=True,
              exclude_orbit_file=False,
              download_only=False,
              varformat=None,
              varnames=[],
              prefix='',
              suffix='',
              get_support_data=False,
              auto_yes=False):
    """
    This function downloads MAVEN data loads it into tplot variables, if applicable.
    """

    if not isinstance(instruments, list) and instruments is not None:
        instruments = [instruments]

    if not isinstance(type, list) and type is not None:
        type = [type]

    if not isinstance(filenames, list) and filenames is not None:
        filenames = [filenames]

    # 1. Get a list of MAVEN files queries from the above seach parameters
    maven_files = maven_filenames(filenames, instruments, level, insitu, iuvs,
                                  start_date, end_date, update_prefs,
                                  only_update_prefs, local_dir)

    # If we are not asking for KP data, this flag ensures only ancillary data is loaded in from the KP files
    if level != 'kp':
        ancillary_only = True
    else:
        ancillary_only = False

    # Convert to list
    if not isinstance(type, list):
        type = [type]

    # Keep track of what files are downloaded
    files_to_load = []

    # Loop through all instruments, download files locally if needed
    for instr in maven_files.keys():
        bn_files_to_load = []
        if maven_files[instr]:
            s = maven_files[instr][0]
            data_dir = maven_files[instr][1]
            public = maven_files[instr][2]

            # Add to list of files to load
            for f in s:
                # Filter by type
                if type != [None] and instr != 'kp':
                    file_type_match = False
                    desc = l2_regex.match(f).group("description")
                    for t in type:
                        if t in desc:
                            file_type_match = True
                    if not file_type_match:
                        continue

                # Check if the files are KP data
                if instr == 'kp':
                    full_path = create_dir_if_needed(f, data_dir, 'insitu')
                else:
                    full_path = create_dir_if_needed(f, data_dir, level)
                bn_files_to_load.append(f)
                files_to_load.append(os.path.join(full_path, f))

            if list_files:
                for f in s:
                    print(f)
                return

            if new_files:
                if instr == 'kp':
                    s = get_new_files(bn_files_to_load, data_dir, instr,
                                      'insitu')
                else:
                    s = get_new_files(bn_files_to_load, data_dir, instr, level)
            if len(s) == 0:
                continue
            print("Your request will download a total of: " + str(len(s)) +
                  " files for instrument " + str(instr))
            print('Would you like to proceed with the download? ')
            valid_response = False
            cancel = False
            if auto_yes:
                valid_response = True
            while not valid_response:
                response = (input('(y/n) >  '))
                if response == 'y' or response == 'Y':
                    valid_response = True
                    cancel = False
                elif response == 'n' or response == 'N':
                    print('Cancelled download. Returning...')
                    valid_response = True
                    cancel = True
                else:
                    print('Invalid input.  Please answer with y or n.')

            if cancel:
                continue

            i = 0
            display_progress(i, len(s))
            for f in s:
                i = i + 1
                if instr == 'kp':
                    full_path = create_dir_if_needed(f, data_dir, 'insitu')
                else:
                    full_path = create_dir_if_needed(f, data_dir, level)
                get_file_from_site(f, public, full_path)
                display_progress(i, len(s))

    # 2. Load files into tplot

    if files_to_load:
        # Flatten out downloaded files from list of lists of filenames
        if isinstance(files_to_load[0], list):
            files_to_load = [
                item for sublist in files_to_load for item in sublist
            ]

        # Only load in files into tplot if we actually downloaded CDF files
        cdf_files = [f for f in files_to_load if '.cdf' in f]
        sts_files = [f for f in files_to_load if '.sts' in f]
        kp_files = [f for f in files_to_load if '.tab' in f]

        loaded_tplot_vars = []
        if not download_only:

            for f in cdf_files:
                # Loop through CDF files
                desc = l2_regex.match(os.path.basename(f)).group("description")
                if desc != '' and suffix == '':
                    created_vars = pytplot.cdf_to_tplot(
                        f,
                        varformat=varformat,
                        varnames=varnames,
                        string_encoding='utf-8',
                        get_support_data=get_support_data,
                        prefix=prefix,
                        suffix=desc,
                        merge=True)
                else:
                    created_vars = pytplot.cdf_to_tplot(
                        f,
                        varformat=varformat,
                        varnames=varnames,
                        string_encoding='utf-8',
                        get_support_data=get_support_data,
                        prefix=prefix,
                        suffix=suffix,
                        merge=True)

                # Specifically for SWIA and SWEA data, make sure the plots have log axes and are spectrograms
                instr = l2_regex.match(os.path.basename(f)).group("instrument")
                if instr in ["swi", "swe"]:
                    pytplot.options(created_vars, 'spec', 1)
                loaded_tplot_vars.append(created_vars)

            for f in sts_files:
                # Loop through STS (Mag) files
                desc = l2_regex.match(os.path.basename(f)).group("description")
                if desc != '' and suffix == '':
                    loaded_tplot_vars.append(
                        pytplot.sts_to_tplot(f,
                                             prefix=prefix,
                                             suffix=desc,
                                             merge=True))
                else:
                    loaded_tplot_vars.append(
                        pytplot.sts_to_tplot(f,
                                             prefix=prefix,
                                             suffix=suffix,
                                             merge=True))

                # Remove the Decimal Day column, not really useful
                for tvar in loaded_tplot_vars:
                    if "DDAY_" in tvar:
                        pytplot.del_data(tvar)
                        del tvar

            # Flatten out the list and only grab the unique tplot variables
            flat_list = list(
                set([
                    item for sublist in loaded_tplot_vars for item in sublist
                ]))

            # Load in KP data specifically for all of the Ancillary data (position, attitude, Ls, etc)
            if kp_files != []:
                kp_data_loaded = maven_kp_to_tplot(
                    filename=kp_files,
                    ancillary_only=ancillary_only,
                    instruments=instruments)

                # Link all created KP data to the ancillary KP data
                for tvar in kp_data_loaded:
                    pytplot.link(tvar,
                                 "mvn_kp::spacecraft::altitude",
                                 link_type='alt')
                    pytplot.link(tvar,
                                 "mvn_kp::spacecraft::mso_x",
                                 link_type='x')
                    pytplot.link(tvar,
                                 "mvn_kp::spacecraft::mso_y",
                                 link_type='y')
                    pytplot.link(tvar,
                                 "mvn_kp::spacecraft::mso_z",
                                 link_type='z')
                    pytplot.link(tvar,
                                 "mvn_kp::spacecraft::geo_x",
                                 link_type='geo_x')
                    pytplot.link(tvar,
                                 "mvn_kp::spacecraft::geo_y",
                                 link_type='geo_y')
                    pytplot.link(tvar,
                                 "mvn_kp::spacecraft::geo_z",
                                 link_type='geo_z')
                    pytplot.link(tvar,
                                 "mvn_kp::spacecraft::sub_sc_longitude",
                                 link_type='lon')
                    pytplot.link(tvar,
                                 "mvn_kp::spacecraft::sub_sc_latitude",
                                 link_type='lat')

            # Link all created tplot variables to the corresponding KP data
            for tvar in flat_list:
                pytplot.link(tvar,
                             "mvn_kp::spacecraft::altitude",
                             link_type='alt')
                pytplot.link(tvar, "mvn_kp::spacecraft::mso_x", link_type='x')
                pytplot.link(tvar, "mvn_kp::spacecraft::mso_y", link_type='y')
                pytplot.link(tvar, "mvn_kp::spacecraft::mso_z", link_type='z')
                pytplot.link(tvar,
                             "mvn_kp::spacecraft::geo_x",
                             link_type='geo_x')
                pytplot.link(tvar,
                             "mvn_kp::spacecraft::geo_y",
                             link_type='geo_y')
                pytplot.link(tvar,
                             "mvn_kp::spacecraft::geo_z",
                             link_type='geo_z')
                pytplot.link(tvar,
                             "mvn_kp::spacecraft::sub_sc_longitude",
                             link_type='lon')
                pytplot.link(tvar,
                             "mvn_kp::spacecraft::sub_sc_latitude",
                             link_type='lat')

            # Return list of unique KP data
            return flat_list
예제 #3
0
파일: plot.py 프로젝트: MAVENSDC/Pydivide
def plot(kp,
         parameter=None,
         time=None,
         errors=None,
         sameplot=True,
         list=False,
         title='',
         qt=True,
         exec_qt=True,
         log=False):
    '''

    Plot time-series data from insitu data structure.

    Parameters:
        kp : dict
            insitu kp data structure/dictionary read from file(s)
        parameter : list of str/int
            The parameter(s) to be plotted.  Can be provided as
            integers (by index) or strings (by name: inst.obs).  If a
            single parameter is provided, it must be an int or str.  If
            several are provided it must be a list.  A list may contain
            a mixture of data types.
        time : list of str
            Two-element list of strings or integers indicating the
            range of Time to be plotted.  At present, there are no
            checks on whether provided Times are within provided data
        sameplot : bool
            if True, put all curves on same axes
            if False, generate new axes for each plot
        list : bool
            Lists all Key Parameters instead of plotting
        title : str
            The Title to give the plot
        qt : bool
            If true, plots with qt.  Else creates an HTML page with bokeh.
        exec_qt : bool
            If False, does not run the event loop for pyqtgraph.

    Returns :
        None

    Examples:
        >>> # Plot SWIA H+ density.
        >>> pydivide.plot(insitu,parameter='swia.hplus_density')
        >>> # Plot SWIA H+ density and altitude in the same window.
        >>> pydivide.plot(insitu,parameter=['swia.hplus_density', 'spacecraft.altitude'],sameplot=True)
    '''

    if list:
        x = param_list(kp)
        for param in x:
            print(param)
        return
    # Check for orbit num rather than time string
    if isinstance(time, builtins.list):
        if isinstance(time[0], int):
            time = orbit_time(time[0], time[1])
    elif isinstance(time, int):
        time = orbit_time(time)

    # Check existence of parameter
    if parameter is None:
        print("Must provide an index (or name) for param to be plotted.")
        return
    # Store instrument and observation of parameter(s) in lists
    inst = []
    obs = []
    if type(parameter) is int or type(parameter) is str:
        a, b = get_inst_obs_labels(kp, parameter)
        inst.append(a.upper())
        obs.append(b.upper())
        nparam = 1
    else:
        nparam = len(parameter)
        for param in parameter:
            a, b = get_inst_obs_labels(kp, param)
            inst.append(a.upper())
            obs.append(b.upper())
    inst_obs = builtins.list(zip(inst, obs))

    # Cycle through the parameters, plotting each according to
    #  the given keywords
    #
    iplot = 1  # subplot indexes on 1
    legend_names = []

    y_list = pydivide.tplot_varcreate(kp, instruments=inst, observations=obs)
    for inst_temp, obs_temp in inst_obs:
        legend_names.append(obs_temp)
        iplot += 1
    if time is not None:
        pytplot.xlim(time[0], time[1])

    if sameplot:
        pytplot_name = ''.join(legend_names)
        pytplot.store_data(pytplot_name, data=y_list)
        pytplot.options(pytplot_name, 'legend_names', legend_names)
        pytplot.options(pytplot_name, 'ylog', log)
        pytplot.link(pytplot_name,
                     "mvn_kp::spacecraft::altitude",
                     link_type='alt')
        pytplot.link(pytplot_name, "mvn_kp::spacecraft::mso_x", link_type='x')
        pytplot.link(pytplot_name, "mvn_kp::spacecraft::mso_y", link_type='y')
        pytplot.link(pytplot_name, "mvn_kp::spacecraft::mso_z", link_type='z')
        pytplot.link(pytplot_name,
                     "mvn_kp::spacecraft::geo_x",
                     link_type='geo_x')
        pytplot.link(pytplot_name,
                     "mvn_kp::spacecraft::geo_y",
                     link_type='geo_y')
        pytplot.link(pytplot_name,
                     "mvn_kp::spacecraft::geo_z",
                     link_type='geo_z')
        pytplot.link(pytplot_name,
                     "mvn_kp::spacecraft::sub_sc_longitude",
                     link_type='lon')
        pytplot.link(pytplot_name,
                     "mvn_kp::spacecraft::sub_sc_latitude",
                     link_type='lat')
        pytplot.tplot_options('title', title)
        pytplot.tplot_options('wsize', [1000, 300])
        pytplot.tplot(pytplot_name,
                      bokeh=not qt,
                      exec_qt=exec_qt,
                      window_name='PYDIVIDE_PLOT')
    else:
        pytplot.tplot_options('title', title)
        pytplot.tplot_options('wsize', [1000, 300 * (iplot - 1)])
        pytplot.tplot(y_list,
                      bokeh=not qt,
                      exec_qt=exec_qt,
                      window_name='PYDIVIDE_PLOT')

    return
예제 #4
0
def options(name, option, value):
    """
    This function allows the user to set a large variety of options for individual plots.

    Parameters:
        name : str
            Name of the tplot variable
        option : str
            The name of the option.  See section below
        value : str/int/float/list
            The value of the option.  See section below.

    Options:
        =================== ==========   =====
        Options             Value type   Notes
        =================== ==========   =====
        Color               str/list     Red, Orange, Yellow, Green, Blue, etc.
        Colormap            str/list     https://matplotlib.org/examples/color/colormaps_reference.html.
        Spec                int          1 sets the Tplot Variable to spectrogram mode, 0 reverts.
        Alt                 int          1 sets the Tplot Variable to altitude plot mode, 0 reverts.
        Map                 int          1 sets the Tplot Variable to latitude/longitude mode, 0 reverts.
        link                list         Allows a user to reference one tplot variable to another.
        ylog                int          1 sets the y axis to log scale, 0 reverts.
        zlog                int          1 sets the z axis to log scale, 0 reverts (spectrograms only).
        legend_names        list         A list of strings that will be used to identify the lines.
        xlog_interactive    bool         Sets x axis on interactive plot to log scale if True.
        ylog                bool         Set y axis on main plot window to log scale if True.
        ylog_interactive    bool         Sets y axis on interactive plot to log scale if True.
        zlog                bool         Sets z axis on main plot window to log scale if True.
        line_style          str          scatter (to make scatter plots), or solid_line, dot, dash, dash_dot, dash_dot_dot_dot, long_dash.
        char_size           int          Defines character size for plot labels, etc.
        name                str          The title of the plot.
        panel_size          flt          Number between (0,1], representing the percent size of the plot.
        basemap             str          Full path and name of a background image for "Map" plots.
        alpha               flt          Number between [0,1], gives the transparancy of the plot lines.
        thick               flt          Sets plot line width.
        yrange              flt list     Two numbers that give the y axis range of the plot.
        zrange              flt list     Two numbers that give the z axis range of the plot.
        xrange_interactive  flt list     Two numberes that give the x axis range of interactive plots.
        yrange_interactive  flt list     Two numberes that give the y axis range of interactive plots.
        ytitle              str          Title shown on the y axis.
        ztitle              str          Title shown on the z axis.  Spec plots only.
        plotter             str          Allows a user to implement their own plotting script in place of the ones
                                         herein.
        crosshair_x         str          Title for x-axis crosshair.
        crosshair_y         str          Title for y-axis crosshair.
        crosshair_z         str          Title for z-axis crosshair.
        static              str          Datetime string that gives desired time to plot y and z values from a spec
                                         plot.
        static_tavg         str          Datetime string that gives desired time-averaged y and z values to plot
                                         from a spec plot.
        t_average           int          Seconds around which the cursor is averaged when hovering over spectrogram
                                         plots.
        =================== ==========   =====
    Returns:
        None

    Examples:
        >>> # Change the y range of Variable1
        >>> import pytplot
        >>> x_data = [1,2,3,4,5]
        >>> y_data = [1,2,3,4,5]
        >>> pytplot.store_data("Variable1", data={'x':x_data, 'y':y_data})
        >>> pytplot.options('Variable1', 'yrange', [2,4])

        >>> # Change Variable1 to use a log scale
        >>> pytplot.options('Variable1', 'ylog', 1)

    """

    if not isinstance(name, list):
        name = [name]

    option = option.lower()

    for i in name:
        if i not in data_quants.keys():
            print(str(i) + " is currently not in pytplot.")
            return

        if option == 'color':
            if isinstance(value, list):
                data_quants[i].attrs['plot_options']['extras']['line_color'] = value
            else:
                data_quants[i].attrs['plot_options']['extras']['line_color'] = [value]

        if option == 'link':
            if isinstance(value, list):
                pytplot.link(i, value[1], value[0])

        if option == 'colormap':
            if isinstance(value, list):
                data_quants[i].attrs['plot_options']['extras']['colormap'] = value
            else:
                data_quants[i].attrs['plot_options']['extras']['colormap'] = [value]

        if option == 'spec':
            _reset_plots(i)
            data_quants[i].attrs['plot_options']['extras']['spec'] = value

        if option == 'alt':
            _reset_plots(i)
            data_quants[i].attrs['plot_options']['extras']['alt'] = value

        if option == 'map':
            _reset_plots(i)
            data_quants[i].attrs['plot_options']['extras']['map'] = value

        if option == 'legend_names':
            data_quants[i].attrs['plot_options']['yaxis_opt']['legend_names'] = value

        if option == 'xlog_interactive':
            if value:
                data_quants[i].attrs['plot_options']['interactive_xaxis_opt']['xi_axis_type'] = 'log'
            else:
                data_quants[i].attrs['plot_options']['interactive_xaxis_opt']['xi_axis_type'] = 'linear'

        if option == 'ylog':
            negflag = 0 # _ylog_check(data_quants, value, i)
            if negflag == 0 and value:
                data_quants[i].attrs['plot_options']['yaxis_opt']['y_axis_type'] = 'log'
            else:
                data_quants[i].attrs['plot_options']['yaxis_opt']['y_axis_type'] = 'linear'

        if option == 'ylog_interactive':
            if value:
                data_quants[i].attrs['plot_options']['interactive_yaxis_opt']['yi_axis_type'] = 'log'
            else:
                data_quants[i].attrs['plot_options']['interactive_yaxis_opt']['yi_axis_type'] = 'linear'

        if option == 'zlog':
            negflag = _zlog_check(data_quants, value, i)
            if negflag == 0:
                data_quants[i].attrs['plot_options']['zaxis_opt']['z_axis_type'] = 'log'
            else:
                data_quants[i].attrs['plot_options']['zaxis_opt']['z_axis_type'] = 'linear'

        if option == 'nodata':
            data_quants[i].attrs['plot_options']['line_opt']['visible'] = value

        if option == 'line_style':
            to_be = []
            if value == 0 or value == 'solid_line':
                to_be = []
            elif value == 1 or value == 'dot':
                to_be = [2, 4]
            elif value == 2 or value == 'dash':
                to_be = [6]
            elif value == 3 or value == 'dash_dot':
                to_be = [6, 4, 2, 4]
            elif value == 4 or value == 'dash_dot_dot_dot':
                to_be = [6, 4, 2, 4, 2, 4, 2, 4]
            elif value == 5 or value == 'long_dash':
                to_be = [10]
            else:
                to_be=value

            data_quants[i].attrs['plot_options']['line_opt']['line_style'] = to_be

            if(value == 6 or value == 'none'):
                data_quants[i].attrs['plot_options']['line_opt']['visible'] = False

        if option == 'char_size':
            data_quants[i].attrs['plot_options']['extras']['char_size'] = value

        if option == 'name':
            data_quants[i].attrs['plot_options']['line_opt']['name'] = value

        if option == "panel_size":
            if value > 1 or value <= 0:
                print("Invalid value. Should be (0, 1]")
                return
            data_quants[i].attrs['plot_options']['extras']['panel_size'] = value

        if option == 'basemap':
            data_quants[i].attrs['plot_options']['extras']['basemap'] = value

        if option == 'alpha':
            if value > 1 or value < 0:
                print("Invalid value. Should be [0, 1]")
                return
            data_quants[i].attrs['plot_options']['extras']['alpha'] = value

        if option == 'thick':
            data_quants[i].attrs['plot_options']['line_opt']['line_width'] = value

        if option == ('yrange' or 'y_range'):
            data_quants[i].attrs['plot_options']['yaxis_opt']['y_range'] = [value[0], value[1]]

        if option == ('zrange' or 'z_range'):
            data_quants[i].attrs['plot_options']['zaxis_opt']['z_range'] = [value[0], value[1]]

        if option == 'xrange_interactive':
            data_quants[i].attrs['plot_options']['interactive_xaxis_opt']['xi_range'] = [value[0], value[1]]

        if option == 'yrange_interactive':
            data_quants[i].attrs['plot_options']['interactive_yaxis_opt']['yi_range'] = [value[0], value[1]]

        if option == 'xtitle':
            data_quants[i].attrs['plot_options']['xaxis_opt']['axis_label'] = value

        if option == 'ytitle':
            data_quants[i].attrs['plot_options']['yaxis_opt']['axis_label'] = value

        if option == 'ztitle':
            data_quants[i].attrs['plot_options']['zaxis_opt']['axis_label'] = value

        if option == 'plotter':
            _reset_plots(i)
            data_quants[i].attrs['plot_options']['extras']['plotter'] = value

        if option == 'crosshair_x':
            data_quants[i].attrs['plot_options']['xaxis_opt']['crosshair'] = value

        if option == 'crosshair_y':
            data_quants[i].attrs['plot_options']['yaxis_opt']['crosshair'] = value

        if option == 'crosshair_z':
            data_quants[i].attrs['plot_options']['zaxis_opt']['crosshair'] = value

        if option == 'static':
            data_quants[i].attrs['plot_options']['extras']['static'] = value

        if option == 'static_tavg':
            data_quants[i].attrs['plot_options']['extras']['static_tavg'] = [value[0], value[1]]

        if option == 't_average':
            data_quants[i].attrs['plot_options']['extras']['t_average'] = value
    return
예제 #5
0
def tplot_varcreate(insitu):
    """Creates tplot variables from the insitu variable
    """
    # initialize each instrument
    created_vars = []
    for obs in insitu["SPACECRAFT"]:
        obs_specific = "mvn_kp::spacecraft::" + obs.lower()
        try:
            pytplot.store_data(obs_specific,
                               data={
                                   'x': insitu['Time'],
                                   'y': insitu["SPACECRAFT"][obs]
                               })
            created_vars.append(obs_specific)
        except:
            pass

    # Join together the matricies and remove the individual points
    pytplot.join_vec([
        'mvn_kp::spacecraft::t11', 'mvn_kp::spacecraft::t12',
        'mvn_kp::spacecraft::t13', 'mvn_kp::spacecraft::t21',
        'mvn_kp::spacecraft::t22', 'mvn_kp::spacecraft::t23',
        'mvn_kp::spacecraft::t31', 'mvn_kp::spacecraft::t32',
        'mvn_kp::spacecraft::t33'
    ], 'mvn_kp::geo_to_mso_matrix')

    pytplot.del_data([
        'mvn_kp::spacecraft::t11', 'mvn_kp::spacecraft::t12',
        'mvn_kp::spacecraft::t13', 'mvn_kp::spacecraft::t21',
        'mvn_kp::spacecraft::t22', 'mvn_kp::spacecraft::t23',
        'mvn_kp::spacecraft::t31', 'mvn_kp::spacecraft::t32',
        'mvn_kp::spacecraft::t33'
    ])

    pytplot.join_vec([
        'mvn_kp::spacecraft::spacecraft_t11',
        'mvn_kp::spacecraft::spacecraft_t12',
        'mvn_kp::spacecraft::spacecraft_t13',
        'mvn_kp::spacecraft::spacecraft_t21',
        'mvn_kp::spacecraft::spacecraft_t22',
        'mvn_kp::spacecraft::spacecraft_t23',
        'mvn_kp::spacecraft::spacecraft_t31',
        'mvn_kp::spacecraft::spacecraft_t32',
        'mvn_kp::spacecraft::spacecraft_t33'
    ], 'mvn_kp::spacecraft_to_mso_matrix')

    pytplot.del_data([
        'mvn_kp::spacecraft::spacecraft_t11',
        'mvn_kp::spacecraft::spacecraft_t12',
        'mvn_kp::spacecraft::spacecraft_t13',
        'mvn_kp::spacecraft::spacecraft_t21',
        'mvn_kp::spacecraft::spacecraft_t22',
        'mvn_kp::spacecraft::spacecraft_t23',
        'mvn_kp::spacecraft::spacecraft_t31',
        'mvn_kp::spacecraft::spacecraft_t32',
        'mvn_kp::spacecraft::spacecraft_t33'
    ])

    created_vars.remove('mvn_kp::spacecraft::t11')
    created_vars.remove('mvn_kp::spacecraft::t12')
    created_vars.remove('mvn_kp::spacecraft::t13')
    created_vars.remove('mvn_kp::spacecraft::t21')
    created_vars.remove('mvn_kp::spacecraft::t22')
    created_vars.remove('mvn_kp::spacecraft::t23')
    created_vars.remove('mvn_kp::spacecraft::t31')
    created_vars.remove('mvn_kp::spacecraft::t32')
    created_vars.remove('mvn_kp::spacecraft::t33')
    created_vars.remove('mvn_kp::spacecraft::spacecraft_t11')
    created_vars.remove('mvn_kp::spacecraft::spacecraft_t12')
    created_vars.remove('mvn_kp::spacecraft::spacecraft_t13')
    created_vars.remove('mvn_kp::spacecraft::spacecraft_t21')
    created_vars.remove('mvn_kp::spacecraft::spacecraft_t22')
    created_vars.remove('mvn_kp::spacecraft::spacecraft_t23')
    created_vars.remove('mvn_kp::spacecraft::spacecraft_t31')
    created_vars.remove('mvn_kp::spacecraft::spacecraft_t32')
    created_vars.remove('mvn_kp::spacecraft::spacecraft_t33')

    inst_list = ["EUV", "LPW", "STATIC", "SWEA", "SWIA", "MAG", "SEP", "NGIMS"]
    for instrument in inst_list:
        # for each observation for each instrument
        if instrument in insitu:
            if insitu[instrument] is not None:
                for obs in insitu[instrument]:
                    # create variable name
                    obs_specific = "mvn_kp::" + instrument.lower(
                    ) + "::" + obs.lower()
                    try:
                        # store data in tplot variable
                        pytplot.store_data(obs_specific,
                                           data={
                                               'x': insitu['Time'],
                                               'y': insitu[instrument][obs]
                                           })
                        created_vars.append(obs_specific)
                        pytplot.link(obs_specific,
                                     "mvn_kp::spacecraft::altitude",
                                     link_type='alt')
                        pytplot.link(obs_specific,
                                     "mvn_kp::spacecraft::mso_x",
                                     link_type='x')
                        pytplot.link(obs_specific,
                                     "mvn_kp::spacecraft::mso_y",
                                     link_type='y')
                        pytplot.link(obs_specific,
                                     "mvn_kp::spacecraft::mso_z",
                                     link_type='z')
                        pytplot.link(obs_specific,
                                     "mvn_kp::spacecraft::geo_x",
                                     link_type='geo_x')
                        pytplot.link(obs_specific,
                                     "mvn_kp::spacecraft::geo_y",
                                     link_type='geo_y')
                        pytplot.link(obs_specific,
                                     "mvn_kp::spacecraft::geo_z",
                                     link_type='geo_z')
                        pytplot.link(obs_specific,
                                     "mvn_kp::spacecraft::sub_sc_longitude",
                                     link_type='lon')
                        pytplot.link(obs_specific,
                                     "mvn_kp::spacecraft::sub_sc_latitude",
                                     link_type='lat')
                    except:
                        pass
    return created_vars
예제 #6
0
파일: options.py 프로젝트: amanotk/PyTplot
def options(name, option=None, value=None, opt_dict=None):
    """
    This function allows the user to set a large variety of options for individual plots.

    Parameters:
        name : str
            Name or number of the tplot variable
        option : str
            The name of the option.  See section below.
        value : str/int/float/list
            The value of the option.  See section below.
        dict : dict
            This can be a dictionary of option:value pairs.  Option and value
            will not be needed if this dictionary item is supplied.

    Options:
        =================== ==========   =====
        Options             Value type   Notes
        =================== ==========   =====
        Color               str/list     red, green, blue, etc.  Also takes in RGB tuples, i.e. (0,255,0) for green
        Colormap            str/list     https://matplotlib.org/examples/color/colormaps_reference.html.
        Spec                int          1 sets the Tplot Variable to spectrogram mode, 0 reverts.
        Alt                 int          1 sets the Tplot Variable to altitude plot mode, 0 reverts.
        Map                 int          1 sets the Tplot Variable to latitude/longitude mode, 0 reverts.
        link                list         Allows a user to reference one tplot variable to another.
        ylog                int          1 sets the y axis to log scale, 0 reverts.
        zlog                int          1 sets the z axis to log scale, 0 reverts (spectrograms only).
        legend_names        list         A list of strings that will be used to identify the lines.
        xlog_slice          bool         Sets x axis on slice plot to log scale if True.
        ylog                bool         Set y axis on main plot window to log scale if True.
        ylog_slice          bool         Sets y axis on slice plot to log scale if True.
        zlog                bool         Sets z axis on main plot window to log scale if True.
        line_style          str          scatter (to make scatter plots), or solid_line, dot, dash, dash_dot, dash_dot_dot_dot, long_dash.
        char_size           int          Defines character size for plot labels, etc.
        name                str          The title of the plot.
        panel_size          flt          Number between (0,1], representing the percent size of the plot.
        basemap             str          Full path and name of a background image for "Map" plots.
        alpha               flt          Number between [0,1], gives the transparancy of the plot lines.
        thick               flt          Sets plot line width.
        yrange              flt list     Two numbers that give the y axis range of the plot.
        zrange              flt list     Two numbers that give the z axis range of the plot.
        xrange_slice        flt list     Two numbers that give the x axis range of spectrogram slicing plots.
        yrange_slice        flt list     Two numbers that give the y axis range of spectrogram slicing plots.
        ytitle              str          Title shown on the y axis.
        ztitle              str          Title shown on the z axis.  Spec plots only.
        ysubtitle           str          Subtitle shown on the y axis.
        zsubtitle           str          Subtitle shown on the z axis.  Spec plots only.
        plotter             str          Allows a user to implement their own plotting script in place of the ones
                                         herein.
        crosshair_x         str          Title for x-axis crosshair.
        crosshair_y         str          Title for y-axis crosshair.
        crosshair_z         str          Title for z-axis crosshair.
        static              str          Datetime string that gives desired time to plot y and z values from a spec
                                         plot.
        static_tavg         str          Datetime string that gives desired time-averaged y and z values to plot
                                         from a spec plot.
        t_average           int          Seconds around which the cursor is averaged when hovering over spectrogram
                                         plots.
        'spec_plot_dim'     int          If variable two dimensions, this sets which dimension the variable will have on
                                         on the y axis.  All other dimensions are summed into this one.
        =================== ==========   =====
    Returns:
        None

    Examples:
        >>> # Change the y range of Variable1
        >>> import pytplot
        >>> x_data = [1,2,3,4,5]
        >>> y_data = [1,2,3,4,5]
        >>> pytplot.store_data("Variable1", data={'x':x_data, 'y':y_data})
        >>> pytplot.options('Variable1', 'yrange', [2,4])

        >>> # Change Variable1 to use a log scale
        >>> pytplot.options('Variable1', 'ylog', 1)

    """

    if isinstance(name, int):
        name = list(pytplot.data_quants.keys())[name]

    if opt_dict is None:
        opt_dict = {option: value}
    else:
        if not isinstance(opt_dict, dict):
            print("dict must be a dictionary object.  Returning.")
            return

    if not isinstance(name, list):
        name = [name]

    for i in name:

        for option, value in opt_dict.items():

            # Lower case option for consistency
            option = option.lower()

            if i not in data_quants.keys():
                print(str(i) + " is currently not in pytplot.")
                return

            if option == 'color':
                if isinstance(value, list):
                    data_quants[i].attrs['plot_options']['extras'][
                        'line_color'] = value
                else:
                    data_quants[i].attrs['plot_options']['extras'][
                        'line_color'] = [value]

            if option == 'link':
                if isinstance(value, list):
                    pytplot.link(i, value[1], value[0])

            if option == 'colormap':
                if isinstance(value, list):
                    data_quants[i].attrs['plot_options']['extras'][
                        'colormap'] = value
                else:
                    data_quants[i].attrs['plot_options']['extras'][
                        'colormap'] = [value]

            if option == 'spec':
                _reset_plots(i)
                if value:
                    if 'spec_bins' not in data_quants[i].coords:
                        print(
                            f"{i} does not contain coordinates for spectrogram plotting.  Continuing..."
                        )
                    else:
                        data_quants[i].attrs['plot_options']['extras'][
                            'spec'] = value
                        data_quants[i].attrs['plot_options']['yaxis_opt'][
                            'y_range'] = utilities.get_y_range(data_quants[i])

                else:
                    data_quants[i].attrs['plot_options']['extras'][
                        'spec'] = value
                    data_quants[i].attrs['plot_options']['yaxis_opt'][
                        'y_range'] = utilities.get_y_range(data_quants[i])

            if option == 'alt':
                _reset_plots(i)
                data_quants[i].attrs['plot_options']['extras']['alt'] = value

            if option == 'map':
                _reset_plots(i)
                data_quants[i].attrs['plot_options']['extras']['map'] = value

            if option == 'legend_names':
                data_quants[i].attrs['plot_options']['yaxis_opt'][
                    'legend_names'] = value

            if option == 'xlog_slice':
                if value:
                    data_quants[i].attrs['plot_options']['slice_xaxis_opt'][
                        'xi_axis_type'] = 'log'
                else:
                    data_quants[i].attrs['plot_options']['slice_xaxis_opt'][
                        'xi_axis_type'] = 'linear'

            if option == 'ylog':
                negflag = 0  # _ylog_check(data_quants, value, i)
                if negflag == 0 and value:
                    data_quants[i].attrs['plot_options']['yaxis_opt'][
                        'y_axis_type'] = 'log'
                else:
                    data_quants[i].attrs['plot_options']['yaxis_opt'][
                        'y_axis_type'] = 'linear'

            if option == 'ylog_slice':
                if value:
                    data_quants[i].attrs['plot_options']['slice_yaxis_opt'][
                        'yi_axis_type'] = 'log'
                else:
                    data_quants[i].attrs['plot_options']['slice_yaxis_opt'][
                        'yi_axis_type'] = 'linear'

            if option == 'zlog':
                negflag = _zlog_check(data_quants, value, i)
                if negflag == 0:
                    data_quants[i].attrs['plot_options']['zaxis_opt'][
                        'z_axis_type'] = 'log'
                else:
                    data_quants[i].attrs['plot_options']['zaxis_opt'][
                        'z_axis_type'] = 'linear'

            if option == 'nodata':
                data_quants[i].attrs['plot_options']['line_opt'][
                    'visible'] = value

            if option == 'line_style':
                to_be = []
                if value == 0 or value == 'solid_line':
                    to_be = []
                elif value == 1 or value == 'dot':
                    to_be = [2, 4]
                elif value == 2 or value == 'dash':
                    to_be = [6]
                elif value == 3 or value == 'dash_dot':
                    to_be = [6, 4, 2, 4]
                elif value == 4 or value == 'dash_dot_dot_dot':
                    to_be = [6, 4, 2, 4, 2, 4, 2, 4]
                elif value == 5 or value == 'long_dash':
                    to_be = [10]
                else:
                    to_be = value

                data_quants[i].attrs['plot_options']['line_opt'][
                    'line_style'] = to_be

                if (value == 6 or value == 'none'):
                    data_quants[i].attrs['plot_options']['line_opt'][
                        'visible'] = False

            if option == 'char_size':
                data_quants[i].attrs['plot_options']['extras'][
                    'char_size'] = value

            if option == 'name':
                data_quants[i].attrs['plot_options']['line_opt'][
                    'name'] = value

            if option == "panel_size":
                if value > 1 or value <= 0:
                    print("Invalid value. Should be (0, 1]")
                    return
                data_quants[i].attrs['plot_options']['extras'][
                    'panel_size'] = value

            if option == 'basemap':
                data_quants[i].attrs['plot_options']['extras'][
                    'basemap'] = value

            if option == 'alpha':
                if value > 1 or value < 0:
                    print("Invalid value. Should be [0, 1]")
                    return
                data_quants[i].attrs['plot_options']['extras']['alpha'] = value

            if option == 'thick':
                data_quants[i].attrs['plot_options']['line_opt'][
                    'line_width'] = value

            if option == 'yrange' or option == 'y_range':
                data_quants[i].attrs['plot_options']['yaxis_opt'][
                    'y_range'] = [value[0], value[1]]

            if option == 'zrange' or option == 'z_range':
                data_quants[i].attrs['plot_options']['zaxis_opt'][
                    'z_range'] = [value[0], value[1]]

            if option == 'xrange_slice':
                data_quants[i].attrs['plot_options']['slice_xaxis_opt'][
                    'xi_range'] = [value[0], value[1]]

            if option == 'yrange_slice':
                data_quants[i].attrs['plot_options']['slice_yaxis_opt'][
                    'yi_range'] = [value[0], value[1]]

            if option == 'xtitle':
                data_quants[i].attrs['plot_options']['xaxis_opt'][
                    'axis_label'] = value

            if option == 'ytitle':
                data_quants[i].attrs['plot_options']['yaxis_opt'][
                    'axis_label'] = value

            if option == 'ztitle':
                data_quants[i].attrs['plot_options']['zaxis_opt'][
                    'axis_label'] = value

            if option == 'xsubtitle':
                data_quants[i].attrs['plot_options']['xaxis_opt'][
                    'axis_subtitle'] = value

            if option == 'ysubtitle':
                data_quants[i].attrs['plot_options']['yaxis_opt'][
                    'axis_subtitle'] = value

            if option == 'zsubtitle':
                data_quants[i].attrs['plot_options']['zaxis_opt'][
                    'axis_subtitle'] = value

            if option == 'ybar':
                data_quants[i].attrs['plot_options']['extras']['ybar'] = value

            if option == 'ybar_color':
                data_quants[i].attrs['plot_options']['extras']['ybar'] = value

            if option == 'ybar_size':
                data_quants[i].attrs['plot_options']['extras']['ysize'] = value

            if option == 'plotter':
                _reset_plots(i)
                data_quants[i].attrs['plot_options']['extras'][
                    'plotter'] = value

            if option == 'crosshair_x':
                data_quants[i].attrs['plot_options']['xaxis_opt'][
                    'crosshair'] = value

            if option == 'crosshair_y':
                data_quants[i].attrs['plot_options']['yaxis_opt'][
                    'crosshair'] = value

            if option == 'crosshair_z':
                data_quants[i].attrs['plot_options']['zaxis_opt'][
                    'crosshair'] = value

            if option == 'static':
                data_quants[i].attrs['plot_options']['extras'][
                    'static'] = value

            if option == 'static_tavg':
                data_quants[i].attrs['plot_options']['extras'][
                    'static_tavg'] = [value[0], value[1]]

            if option == 't_average':
                data_quants[i].attrs['plot_options']['extras'][
                    't_average'] = value

            if option == 'spec_plot_dim':
                attr_dict = deepcopy(data_quants[i].attrs)
                data_dict = {}
                data_dict['x'] = data_quants[i].coords['time'].values
                data_values = data_quants[i].values
                if len(data_values.shape) <= 2:
                    pass
                else:
                    data_dict['y'] = np.swapaxes(data_values, 2, value)
                    for c in data_quants[i].coords:
                        if c == 'time' or c == 'spec_bins':
                            continue
                        data_dict[c] = data_quants[i].coords[c].values
                    v2_values = data_quants[i].coords["v2"].values
                    data_dict['v2'] = data_dict['v' + str(value)]
                    data_dict['v' + str(value)] = v2_values
                    pytplot.store_data(i, data=data_dict)
                    data_quants[i].attrs = attr_dict
                    data_quants[i].attrs['plot_options']['yaxis_opt'][
                        'y_range'] = utilities.get_y_range(data_quants[i])

    return
예제 #7
0
def options(name, option=None, value=None, opt_dict=None):
    """
    This function allows the user to set a large variety of options for individual plots.

    Parameters:
        name : str
            Name or number of the tplot variable
        option : str
            The name of the option.  See section below.
        value : str/int/float/list
            The value of the option.  See section below.
        dict : dict
            This can be a dictionary of option:value pairs.  Option and value
            will not be needed if this dictionary item is supplied.

    Options:
        =================== ==========   =====
        Options             Value type   Notes
        =================== ==========   =====
        Color               str/list     red, green, blue, etc.  Also takes in RGB tuples, i.e. (0,255,0) for green
        Colormap            str/list     https://matplotlib.org/examples/color/colormaps_reference.html.
        Spec                int          1 sets the Tplot Variable to spectrogram mode, 0 reverts.
        Alt                 int          1 sets the Tplot Variable to altitude plot mode, 0 reverts.
        Map                 int          1 sets the Tplot Variable to latitude/longitude mode, 0 reverts.
        link                list         Allows a user to reference one tplot variable to another.
        ylog                int          1 sets the y axis to log scale, 0 reverts.
        zlog                int          1 sets the z axis to log scale, 0 reverts (spectrograms only).
        legend_names        list         A list of strings that will be used to identify the lines.
        xlog_slice          bool         Sets x axis on slice plot to log scale if True.
        ylog                bool         Set y axis on main plot window to log scale if True.
        ylog_slice          bool         Sets y axis on slice plot to log scale if True.
        zlog                bool         Sets z axis on main plot window to log scale if True.
        line_style          str          scatter (to make scatter plots), or solid_line, dot, dash, dash_dot, dash_dot_dot_dot, long_dash.
        char_size           int          Defines character size for plot labels, etc.
        name                str          The title of the plot.
        panel_size          flt          Number between (0,1], representing the percent size of the plot.
        basemap             str          Full path and name of a background image for "Map" plots.
        alpha               flt          Number between [0,1], gives the transparency of the plot lines.
        thick               flt          Sets plot line width.
        yrange              flt list     Two numbers that give the y axis range of the plot.
        zrange              flt list     Two numbers that give the z axis range of the plot.
        xrange_slice        flt list     Two numbers that give the x axis range of spectrogram slicing plots.
        yrange_slice        flt list     Two numbers that give the y axis range of spectrogram slicing plots.
        ytitle              str          Title shown on the y axis.  Use backslash for new lines.
        ztitle              str          Title shown on the z axis.  Spec plots only.  Use backslash for new lines.
        ysubtitle           str          Subtitle shown on the y axis.
        zsubtitle           str          Subtitle shown on the z axis.  Spec plots only.
        plotter             str          Allows a user to implement their own plotting script in place of the ones
                                         herein.
        crosshair_x         str          Title for x-axis crosshair.
        crosshair_y         str          Title for y-axis crosshair.
        crosshair_z         str          Title for z-axis crosshair.
        static              str          Datetime string that gives desired time to plot y and z values from a spec
                                         plot.
        static_tavg         str          Datetime string that gives desired time-averaged y and z values to plot
                                         from a spec plot.
        t_average           int          Seconds around which the cursor is averaged when hovering over spectrogram
                                         plots.
        spec_plot_dim       int/str      If variable has more than two dimensions, this sets which dimension the v
                                         variable will display on the y axis in spectrogram plots.
                                         All other dimensions are summed into this one, unless "spec_slices_to_use"
                                         is also set for this variable.
        spec_dim_to_plot    int/str      Same as spec_plot_dim, just with a slightly more descriptive name
        spec_slices_to_use  str          Must be a dictionary of coordinate:values.  If a variable has more than two
                                         dimensions, spectrogram plots will plot values at that particular slice of
                                         that dimension.  See examples for how it works.
        border              bool         Turns on or off the top/right axes that would create a box around the plot
        var_label_ticks     int          Sets the number of ticks if this variable is displayed as an alternative x axis
        =================== ==========   =====
    Returns:
        None

    Examples:
        >>> # Change the y range of Variable1
        >>> import pytplot
        >>> x_data = [1,2,3,4,5]
        >>> y_data = [1,2,3,4,5]
        >>> pytplot.store_data("Variable1", data={'x':x_data, 'y':y_data})
        >>> pytplot.options('Variable1', 'yrange', [2,4])

        >>> # Change Variable1 to use a log scale
        >>> pytplot.options('Variable1', 'ylog', 1)

        >>> # Set the spectrogram plots to show dimension 'v2' at slice 'v1' = 0
        >>> pytplot.options("Variable2", "spec_dim_to_plot", 'v2')
        >>> pytplot.options("Variable2", "spec_slices_to_use", {'v1': 0})

    """

    if isinstance(name, int):
        name = list(pytplot.data_quants.keys())[name]

    if opt_dict is None:
        opt_dict = {option: value}
    else:
        if not isinstance(opt_dict,dict):
            print("dict must be a dictionary object.  Returning.")
            return

    if not isinstance(name, list):
        name = [name]

    for i in name:

        for option, value in opt_dict.items():

            # Lower case option for consistency
            option = option.lower()

            if i not in pytplot.data_quants.keys():
                print(str(i) + " is currently not in pytplot.")
                return

            if option == 'color':
                if isinstance(value, list):
                    pytplot.data_quants[i].attrs['plot_options']['extras']['line_color'] = value
                else:
                    pytplot.data_quants[i].attrs['plot_options']['extras']['line_color'] = [value]

            if option == 'link':
                if isinstance(value, list):
                    pytplot.link(i, value[1], value[0])

            if option == 'colormap':
                if isinstance(value, list):
                    pytplot.data_quants[i].attrs['plot_options']['extras']['colormap'] = value
                else:
                    pytplot.data_quants[i].attrs['plot_options']['extras']['colormap'] = [value]

            if option == 'spec':
                _reset_plots(i)
                if value:
                    if 'spec_bins' not in pytplot.data_quants[i].coords:
                        print(f"{i} does not contain coordinates for spectrogram plotting.  Continuing...")
                        continue
                    else:
                        pytplot.data_quants[i].attrs['plot_options']['extras']['spec'] = value
                        pytplot.data_quants[i].attrs['plot_options']['yaxis_opt']['y_range'] = utilities.get_y_range(pytplot.data_quants[i])

                else:
                    pytplot.data_quants[i].attrs['plot_options']['extras']['spec'] = value
                    pytplot.data_quants[i].attrs['plot_options']['yaxis_opt']['y_range'] = utilities.get_y_range(pytplot.data_quants[i])

                # Set the default dimension to plot by.  All others will be summed over.
                if 'spec_dim_to_plot' not in pytplot.data_quants[i].attrs['plot_options']['extras']:
                    if 'v' in pytplot.data_quants[i].coords:
                        pytplot.data_quants[i].attrs['plot_options']['extras']['spec_dim_to_plot'] = 'v'
                    elif 'v2' in pytplot.data_quants[i].coords:
                        pytplot.data_quants[i].attrs['plot_options']['extras']['spec_dim_to_plot'] = 'v2'
                    else:
                        pytplot.data_quants[i].attrs['plot_options']['extras']['spec_dim_to_plot'] = 'v1'

            if option == 'alt':
                _reset_plots(i)
                pytplot.data_quants[i].attrs['plot_options']['extras']['alt'] = value

            if option == 'map':
                _reset_plots(i)
                pytplot.data_quants[i].attrs['plot_options']['extras']['map'] = value

            if option == 'legend_names':
                if isinstance(value, list):
                    pytplot.data_quants[i].attrs['plot_options']['yaxis_opt']['legend_names'] = value
                else:
                    pytplot.data_quants[i].attrs['plot_options']['yaxis_opt']['legend_names'] = [value]

            if option == 'xlog_slice':
                if value:
                    pytplot.data_quants[i].attrs['plot_options']['slice_xaxis_opt']['xi_axis_type'] = 'log'
                else:
                    pytplot.data_quants[i].attrs['plot_options']['slice_xaxis_opt']['xi_axis_type'] = 'linear'

            if option == 'ylog':
                negflag = 0 # _ylog_check(data_quants, value, i)
                if negflag == 0 and value:
                    pytplot.data_quants[i].attrs['plot_options']['yaxis_opt']['y_axis_type'] = 'log'
                else:
                    pytplot.data_quants[i].attrs['plot_options']['yaxis_opt']['y_axis_type'] = 'linear'

            if option == 'ylog_slice':
                if value:
                    pytplot.data_quants[i].attrs['plot_options']['slice_yaxis_opt']['yi_axis_type'] = 'log'
                else:
                    pytplot.data_quants[i].attrs['plot_options']['slice_yaxis_opt']['yi_axis_type'] = 'linear'

            if option == 'zlog':
                # check for negative values and warn the user that they will be ignored
                negflag = _zlog_check(pytplot.data_quants, value, i)
                if negflag != 0 and value:
                    print(str(i) + ' contains negative values; setting the z-axis to log scale will cause the negative values to be ignored on figures.')

                if value:
                    pytplot.data_quants[i].attrs['plot_options']['zaxis_opt']['z_axis_type'] = 'log'
                else:
                    pytplot.data_quants[i].attrs['plot_options']['zaxis_opt']['z_axis_type'] = 'linear'

            if option == 'nodata':
                pytplot.data_quants[i].attrs['plot_options']['line_opt']['visible'] = value

            if option == 'line_style':
                if value == 0 or value == 'solid_line':
                    to_be = []
                elif value == 1 or value == 'dot':
                    to_be = [2, 4]
                elif value == 2 or value == 'dash':
                    to_be = [6]
                elif value == 3 or value == 'dash_dot':
                    to_be = [6, 4, 2, 4]
                elif value == 4 or value == 'dash_dot_dot_dot':
                    to_be = [6, 4, 2, 4, 2, 4, 2, 4]
                elif value == 5 or value == 'long_dash':
                    to_be = [10]
                else:
                    to_be=value

                pytplot.data_quants[i].attrs['plot_options']['line_opt']['line_style'] = to_be

                if(value == 6 or value == 'none'):
                    pytplot.data_quants[i].attrs['plot_options']['line_opt']['visible'] = False

            if option == 'char_size':
                pytplot.data_quants[i].attrs['plot_options']['extras']['char_size'] = value

            if option == 'name':
                pytplot.data_quants[i].attrs['plot_options']['line_opt']['name'] = value

            if option == "panel_size":
                if value > 1 or value <= 0:
                    print("Invalid value. Should be (0, 1]")
                    return
                pytplot.data_quants[i].attrs['plot_options']['extras']['panel_size'] = value

            if option == 'basemap':
                pytplot.data_quants[i].attrs['plot_options']['extras']['basemap'] = value

            if option == 'alpha':
                if value > 1 or value < 0:
                    print("Invalid value. Should be [0, 1]")
                    return
                pytplot.data_quants[i].attrs['plot_options']['extras']['alpha'] = value

            if option == 'thick':
                pytplot.data_quants[i].attrs['plot_options']['line_opt']['line_width'] = value

            if option == 'yrange' or option == 'y_range':
                pytplot.data_quants[i].attrs['plot_options']['yaxis_opt']['y_range'] = [value[0], value[1]]

            if option == 'zrange' or option == 'z_range':
                pytplot.data_quants[i].attrs['plot_options']['zaxis_opt']['z_range'] = [value[0], value[1]]

            if option == 'xrange_slice':
                pytplot.data_quants[i].attrs['plot_options']['slice_xaxis_opt']['xi_range'] = [value[0], value[1]]

            if option == 'yrange_slice':
                pytplot.data_quants[i].attrs['plot_options']['slice_yaxis_opt']['yi_range'] = [value[0], value[1]]

            if option == 'xtitle':
                pytplot.data_quants[i].attrs['plot_options']['xaxis_opt']['axis_label'] = value

            if option == 'ytitle':
                pytplot.data_quants[i].attrs['plot_options']['yaxis_opt']['axis_label'] = value

            if option == 'ztitle':
                pytplot.data_quants[i].attrs['plot_options']['zaxis_opt']['axis_label'] = value

            if option == 'xsubtitle':
                pytplot.data_quants[i].attrs['plot_options']['xaxis_opt']['axis_subtitle'] = value

            if option == 'ysubtitle':
                pytplot.data_quants[i].attrs['plot_options']['yaxis_opt']['axis_subtitle'] = value

            if option == 'zsubtitle':
                pytplot.data_quants[i].attrs['plot_options']['zaxis_opt']['axis_subtitle'] = value

            if option == 'ybar':
                pytplot.data_quants[i].attrs['plot_options']['extras']['ybar'] = value

            if option == 'ybar_color':
                pytplot.data_quants[i].attrs['plot_options']['extras']['ybar'] = value

            if option == 'ybar_size':
                pytplot.data_quants[i].attrs['plot_options']['extras']['ysize'] = value

            if option == 'plotter':
                _reset_plots(i)
                pytplot.data_quants[i].attrs['plot_options']['extras']['plotter'] = value

            if option == 'crosshair_x':
                pytplot.data_quants[i].attrs['plot_options']['xaxis_opt']['crosshair'] = value

            if option == 'crosshair_y':
                pytplot.data_quants[i].attrs['plot_options']['yaxis_opt']['crosshair'] = value

            if option == 'crosshair_z':
                pytplot.data_quants[i].attrs['plot_options']['zaxis_opt']['crosshair'] = value

            if option == 'static':
                pytplot.data_quants[i].attrs['plot_options']['extras']['static'] = value

            if option == 'static_tavg':
                pytplot.data_quants[i].attrs['plot_options']['extras']['static_tavg'] = [value[0], value[1]]

            if option == 't_average':
                pytplot.data_quants[i].attrs['plot_options']['extras']['t_average'] = value

            if option == 'spec_dim_to_plot' or option == 'spec_plot_dim':
                if len(pytplot.data_quants[i].values.shape) <= 2:
                    print(f"Must have more than 2 coordinate dimensions to set spec_coord_to_plot for {pytplot.data_quants[i].name}")
                    continue

                # Set the 'spec_dim_to_plot' value to either 'v' or 'v1', 'v2', 'v3', etc.
                if isinstance(value, int):
                    coord_to_plot = "v" + str(value)
                    if coord_to_plot not in pytplot.data_quants[i].coords:
                        if value == 1:
                            coord_to_plot = "v"
                            if coord_to_plot not in pytplot.data_quants[i].coords:
                                print(f"Dimension {value} not found in {pytplot.data_quants[i].name}")
                                continue
                        else:
                            print(f"Dimension {value} not found in {pytplot.data_quants[i].name}")
                            continue
                    pytplot.data_quants[i].attrs['plot_options']['extras']['spec_dim_to_plot'] = coord_to_plot
                elif isinstance(value, str):
                    coord_to_plot = value
                    if coord_to_plot not in pytplot.data_quants[i].coords:
                        print(f"Dimension {value} not found in {pytplot.data_quants[i].name}")
                        continue
                    else:
                        pytplot.data_quants[i].attrs['plot_options']['extras']['spec_dim_to_plot'] = value

                # If we're plotting against different coordinates, we need to change what we consider the "spec_bins"
                pytplot.data_quants[i].coords['spec_bins'] = pytplot.data_quants[i].coords[coord_to_plot]
                pytplot.data_quants[i].attrs['plot_options']['yaxis_opt']['y_range'] = utilities.get_y_range(pytplot.data_quants[i])

            if option == 'spec_slices_to_use':
                if not isinstance(value, dict):
                    print("Must be a dictionary object in the format {'v2':15, 'v3':7}")
                    return
                else:
                    for coord in value:
                        if coord not in pytplot.data_quants[i].coords:
                            print(f"Dimension {coord} not found in {pytplot.data_quants[i].name}")
                            continue

                pytplot.data_quants[i].attrs['plot_options']['extras']['spec_slices_to_use'] = value

            if option == 'border':
                pytplot.data_quants[i].attrs['plot_options']['extras']['border'] = value

            if option == 'var_label_ticks':
                pytplot.data_quants[i].attrs['plot_options']['var_label_ticks'] = value


    return