Skip to content

Commit

Permalink
[#159] Cleanup 2
Browse files Browse the repository at this point in the history
  • Loading branch information
dvezinet committed Nov 14, 2024
1 parent 7e7f71d commit 50264be
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions datastock/_class01.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# -*- coding: utf-8 -*-


# Built-in
import copy


# Common
import numpy as np
import astropy.units as asunits
Expand Down Expand Up @@ -556,14 +552,22 @@ def _get_sort_index(self, which=None, param=None):
return

if param == 'key':
ind = np.argsort(list(dd.keys()))
if which == 'ref':
lk = list(self.dref.keys())
elif which == 'data':
lk = list(self.ddata.keys())
else:
lk = list(self.dobj.get(which, {}).keys())
ind = np.argsort(lk)

elif isinstance(param, str):
ind = np.argsort(
self.get_param(param, which=which, returnas=np.ndarray)[param]
)
else:
msg = "Arg param must be a valid str\n Provided: {}".format(param)
raise Exception(msg)

return ind

def sortby(self, param=None, order=None, which=None):
Expand Down Expand Up @@ -640,7 +644,9 @@ def get_ref_vector(
>>> st.add_data(key='t0', data=t0)
>>> st.add_data(key='x', data=x)
>>> st.add_data(key='xt', data=xt)
>>> hasref, hasvect, ref, key_vect, dind = st.get_ref_vector(key='xt', ref='nt', values=[2, 3, 3.1, 5])
>>> hasref, hasvect, ref, key_vect, dind = st.get_ref_vector(
>>> key='xt', ref='nt', values=[2, 3, 3.1, 5],
>>> )
In the above example:
- hasref = True: 'xt' has 'nt' has ref
Expand All @@ -651,7 +657,7 @@ def get_ref_vector(
'key': [2, 3, 3.1, 5], # the desired time points
'ind': [2, 3, 3, 5], # the indices of t in t0
'indu': [2, 3, 5] # the unique indices of t in t0
'indr': (3, 4), # bool array showing, for each indu, matching ind
'indr': (3, 4), # bool array with ind for each indu
'indok': [True, False, ...]
}
Expand Down Expand Up @@ -820,7 +826,7 @@ def binning(
bin_data0: the data used to compute binning indices, can be:
- a str, key to a ddata item
- a np.ndarray
_ a list of any of the above if each data has different size along axis
- a list of any of the above if each data has diff. size along axis
bin_units: str
only used if integrate = True and bin_data is a np.ndarray
Expand All @@ -829,7 +835,7 @@ def binning(
flag indicating whether binning is used for integration
Implies that:
Only usable for 1d binning (axis has to be a single index)
data is multiplied by the underlying bin_data0 step prior to binning
data is multiplied by bin_data0 step prior to binning
statistic: str
the statistic kwd feed to scipy.stats.binned_statistic()
Expand Down

0 comments on commit 50264be

Please sign in to comment.