Skip to content

Commit

Permalink
Moved tdeflag to pytplot.tplot_math
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim McTiernan committed Dec 8, 2023
1 parent 9899445 commit 1da2826
Showing 1 changed file with 6 additions and 37 deletions.
43 changes: 6 additions & 37 deletions pyspedas/analysis/tdeflag.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
----
Allowed wildcards are ? for a single character, * from multiple characters.
Similar to tdeflag.pro in IDL SPEDAS.
Moved to PyTplot/pytplot/tplot_math, 2023-11-30
"""
import logging
import pyspedas
Expand All @@ -30,7 +30,7 @@ def tdeflag(names, method=None, new_names=None, suffix=None,
If '', then pytplot variables are replaced.
If not given, then a suffix is applied.
suffix: str, optional
A suffix to apply. Default is '-clip'.
A suffix to apply. Default is '-deflag'.
overwrite: bool, optional
Replace the existing tplot name.
Expand All @@ -39,38 +39,7 @@ def tdeflag(names, method=None, new_names=None, suffix=None,
None.
"""
old_names = pyspedas.tnames(names)

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

if suffix is None:
suffix = '-deflag'

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 in range(len(old_names)):
alldata = pytplot.get_data(old_names[i])
time = alldata[0]
data = alldata[1]
new_time = []
new_data = []
for j in range(len(time)):
if not numpy.isnan(data[j]):
new_time.append(time[j])
new_data.append(data[j])
pytplot.store_data(n_names[i], data={'x': new_time, 'y': new_data})

logging.info('tdeflag was applied to: ' + n_names[i])
logging.info("tdeflag has been moved to the pytplot.tplot_math module. Please update your imports!")
logging.info("This version will eventually be removed.")
pytplot.tplot_math.tdeflag(names,method=method,new_names=new_names,
suffix=suffix,overwrite=overwrite)

0 comments on commit 1da2826

Please sign in to comment.