From b65ff851f04dbec8a1e0a3b03e236ec65a4b3766 Mon Sep 17 00:00:00 2001 From: Nick H <34072991+nickssl@users.noreply.github.com> Date: Tue, 16 Apr 2024 17:51:18 -0700 Subject: [PATCH] Fixed docstrings, examples --- pytplot/replace_data.py | 53 ++++++++++++++++++++----------------- pytplot/replace_metadata.py | 48 ++++++++++++++++----------------- 2 files changed, 51 insertions(+), 50 deletions(-) diff --git a/pytplot/replace_data.py b/pytplot/replace_data.py index d41a4ce9..f3bc6ee1 100644 --- a/pytplot/replace_data.py +++ b/pytplot/replace_data.py @@ -1,34 +1,33 @@ -# Copyright 2020 Regents of the University of Colorado. All Rights Reserved. -# Released under the MIT license. -# This software was developed at the University of Colorado's Laboratory for Atmospheric and Space Physics. -# Verify current version before use at: https://github.com/MAVENSDC/PyTplot - import pytplot import numpy as np from pytplot import tplot_utilities as utilities -from copy import deepcopy -from collections import OrderedDict import logging def replace_data(tplot_name, new_data): """ - This function will replace all of the data in a tplot variable - - Parameters: - tplot_name : str - The name of the tplot variable - new_data : np array (or something that can be converted to a np.array) - The data to replace the - - Returns: - None - - Examples: - >>> # Copy Variable 1 into a new Variable 2 - >>> import pytplot - >>> pytplot.replace_data("Variable1", [[1,2,3,4],[5,6,7,8]]) - + This function will replace all of the data in a tplot variable. + + Parameters + ---------- + tplot_name : str + The name of the tplot variable. + new_data : array_like + The new data to replace the existing data. + This can be any object that can be converted into an np.array. + + Returns + ------- + None + + Examples + -------- + >>> # Replace data into an existing variable + >>> import pytplot + >>> pytplot.store_data("v1", data={'x':[1,2,3,4],'y':[1,2,3,4]}) + >>> print(pytplot.get_data('v1')) + >>> pytplot.replace_data("v1",[5,6,7,8]) + >>> print(pytplot.get_data('v1')) """ # if old name input is a number, convert to corresponding name @@ -44,11 +43,15 @@ def replace_data(tplot_name, new_data): shape_old = pytplot.data_quants[tplot_name].values.shape shape_new = new_data_np.shape if shape_old != shape_new: - logging.info(f"Dimensions do not match for replace data. {shape_new} does not equal {shape_old}. Returning...") + logging.info( + f"Dimensions do not match for replace data. {shape_new} does not equal {shape_old}. Returning..." + ) return pytplot.data_quants[tplot_name].values = new_data_np - pytplot.data_quants[tplot_name].attrs['plot_options']['yaxis_opt']['y_range'] = utilities.get_y_range(pytplot.data_quants[tplot_name]) + pytplot.data_quants[tplot_name].attrs["plot_options"]["yaxis_opt"]["y_range"] = ( + utilities.get_y_range(pytplot.data_quants[tplot_name]) + ) return diff --git a/pytplot/replace_metadata.py b/pytplot/replace_metadata.py index 242d7525..5a9562de 100644 --- a/pytplot/replace_metadata.py +++ b/pytplot/replace_metadata.py @@ -1,35 +1,31 @@ -# Copyright 2020 Regents of the University of Colorado. All Rights Reserved. -# Released under the MIT license. -# This software was developed at the University of Colorado's Laboratory for Atmospheric and Space Physics. -# Verify current version before use at: https://github.com/MAVENSDC/PyTplot - import pytplot -import numpy as np from pytplot import tplot_utilities as utilities from copy import deepcopy -from collections import OrderedDict import logging def replace_metadata(tplot_name, new_metadata): """ - This function will replace all the metadata in a tplot variable - - Parameters: - tplot_name : str - The name of the tplot variable - new_metadata : A dictionary with metadata values. A deep copy will be performed so that - no references to new_metadata are retained. - - Returns: - None - - Examples: - >>> # Copy Variable 1 metadata into Variable 2, which must already exist - >>> import pytplot - >>> meta = pytplot_get_data('Variable1', metadata=True) - >>> pytplot.replace_metadata("Variable2", meta) - + This function will replace all the metadata in a tplot variable. + + Parameters + ---------- + tplot_name : str + The name of the tplot variable. + new_metadata : dict + A dictionary with metadata values. A deep copy will be performed so that + no references to new_metadata are retained. + + Returns + ------- + None + + Examples + -------- + >>> # Copy Variable 1 metadata into Variable 2, which must already exist + >>> import pytplot + >>> meta = pytplot_get_data('Variable1', metadata=True) + >>> pytplot.replace_metadata("Variable2", meta) """ # if old name input is a number, convert to corresponding name @@ -42,6 +38,8 @@ def replace_metadata(tplot_name, new_metadata): return pytplot.data_quants[tplot_name].attrs = deepcopy(new_metadata) - pytplot.data_quants[tplot_name].attrs['plot_options']['yaxis_opt']['y_range'] = utilities.get_y_range(pytplot.data_quants[tplot_name]) + pytplot.data_quants[tplot_name].attrs["plot_options"]["yaxis_opt"]["y_range"] = ( + utilities.get_y_range(pytplot.data_quants[tplot_name]) + ) return