Skip to content

Commit

Permalink
ENH: added minimum periods kwarg
Browse files Browse the repository at this point in the history
Added a minimum period kwarg to `calc_daily_Ap` for more flexibility.
  • Loading branch information
aburrell committed Nov 1, 2023
1 parent 3663662 commit 41d5d34
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pysatSpaceWeather/instruments/methods/kp_ap.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def ap(kk):


def calc_daily_Ap(ap_inst, ap_name='3hr_ap', daily_name='Ap',
running_name=None):
running_name=None, min_periods=8):
"""Calculate the daily Ap index from the 3hr ap index.
Parameters
Expand All @@ -252,6 +252,9 @@ def calc_daily_Ap(ap_inst, ap_name='3hr_ap', daily_name='Ap',
running_name : str or NoneType
Column name for daily running average of ap, not output if None
(default=None)
min_periods : int
Mininmum number of observations needed to output an average value
(default=8)
Raises
------
Expand All @@ -276,7 +279,8 @@ def calc_daily_Ap(ap_inst, ap_name='3hr_ap', daily_name='Ap',
raise ValueError("daily Ap column name already exists: " + daily_name)

# Calculate the daily mean value
ap_mean = ap_inst[ap_name].rolling(window='1D', min_periods=8).mean()
ap_mean = ap_inst[ap_name].rolling(window='1D',
min_periods=min_periods).mean()

if running_name is not None:
ap_inst[running_name] = ap_mean
Expand Down Expand Up @@ -430,9 +434,9 @@ def convert_ap_to_kp(ap_data, fill_val=-1, ap_name='ap', kp_name='Kp'):

# Set the metadata
meta = pysat.Meta()
meta[kp_name] = initialize_kp_metadata(meta, 'Kp', fill_val)
meta[meta.labels.desc] = 'Kp converted from {:}'.format(ap_name)
meta[meta.labels.notes] = ''.join(
initialize_kp_metadata(meta, 'Kp', fill_val)
meta['Kp', meta.labels.desc] = 'Kp converted from {:}'.format(ap_name)
meta['Kp', meta.labels.notes] = ''.join(
['Kp converted from ', ap_name, 'as described at: ',
'https://www.ngdc.noaa.gov/stp/GEOMAG/kp_ap.html'])

Expand Down

0 comments on commit 41d5d34

Please sign in to comment.