datastock 0.0.35__py3-none-any.whl → 0.0.37__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- datastock/_class1.py +88 -127
- datastock/_class1_check.py +1 -98
- datastock/_class1_compute.py +203 -43
- datastock/_class1_domain.py +2 -2
- datastock/_class1_interpolate.py +8 -8
- datastock/_class1_show.py +406 -0
- datastock/_class1_uniformize.py +37 -19
- datastock/_class2.py +4 -48
- datastock/_class3.py +14 -6
- datastock/_generic_check.py +41 -43
- datastock/_generic_utils.py +11 -1
- datastock/_generic_utils_plot.py +76 -3
- datastock/_plot_BvsA_as_distribution_check.py +9 -5
- datastock/_plot_as_array.py +368 -2523
- datastock/_plot_as_array_1d.py +298 -0
- datastock/_plot_as_array_234d.py +786 -0
- datastock/_plot_as_mobile_lines.py +18 -13
- datastock/_plot_as_profile1d.py +27 -12
- datastock/_saveload.py +2 -0
- datastock/tests/test_01_DataStock.py +102 -27
- datastock/version.py +1 -1
- {datastock-0.0.35.dist-info → datastock-0.0.37.dist-info}/METADATA +1 -1
- datastock-0.0.37.dist-info/RECORD +42 -0
- datastock-0.0.35.dist-info/RECORD +0 -39
- /datastock/{_plot_misc.py → _plot_old_backup.py} +0 -0
- {datastock-0.0.35.dist-info → datastock-0.0.37.dist-info}/LICENSE +0 -0
- {datastock-0.0.35.dist-info → datastock-0.0.37.dist-info}/WHEEL +0 -0
- {datastock-0.0.35.dist-info → datastock-0.0.37.dist-info}/top_level.txt +0 -0
datastock/_class1.py
CHANGED
@@ -14,6 +14,7 @@ import astropy.units as asunits
|
|
14
14
|
from . import _generic_check
|
15
15
|
from . import _generic_utils
|
16
16
|
from . import _class1_check
|
17
|
+
from . import _class1_show
|
17
18
|
from ._class0 import *
|
18
19
|
from . import _class1_compute
|
19
20
|
from . import _class1_domain
|
@@ -218,6 +219,28 @@ class DataStock1(DataStock0):
|
|
218
219
|
max_ndim=self._max_ndim,
|
219
220
|
)
|
220
221
|
|
222
|
+
def remove_all(self, excluded=None):
|
223
|
+
|
224
|
+
# check excluded
|
225
|
+
if isinstance(excluded, str):
|
226
|
+
excluded = [excluded]
|
227
|
+
|
228
|
+
# remove all obj
|
229
|
+
lw = list(self.dobj.keys())
|
230
|
+
for ww in lw:
|
231
|
+
if (excluded is not None) and ww in excluded:
|
232
|
+
continue
|
233
|
+
self.remove_obj(
|
234
|
+
list(self.dobj[ww].keys()),
|
235
|
+
which=ww,
|
236
|
+
propagate=True)
|
237
|
+
|
238
|
+
# remove all data
|
239
|
+
self.remove_data(list(self.ddata.keys()), propagate=True)
|
240
|
+
|
241
|
+
# remove all refs
|
242
|
+
self.remove_ref(list(self.dref.keys()), propagate=True)
|
243
|
+
|
221
244
|
# ---------------------
|
222
245
|
# Get / set / add / remove params
|
223
246
|
# ---------------------
|
@@ -243,7 +266,7 @@ class DataStock1(DataStock0):
|
|
243
266
|
which, dd = self.__check_which(which, return_dict=True)
|
244
267
|
if which in ['ref', 'data']:
|
245
268
|
for_show = False
|
246
|
-
return
|
269
|
+
return _class1_show._get_lparam(dd=dd, for_show=for_show)
|
247
270
|
|
248
271
|
def get_param(
|
249
272
|
self,
|
@@ -418,27 +441,46 @@ class DataStock1(DataStock0):
|
|
418
441
|
# extract
|
419
442
|
###########
|
420
443
|
|
421
|
-
def extract(
|
444
|
+
def extract(
|
445
|
+
self,
|
446
|
+
keys=None,
|
447
|
+
# optional includes
|
448
|
+
inc_monot=None,
|
449
|
+
inc_vectors=None,
|
450
|
+
inc_allrefs=None,
|
451
|
+
# output
|
452
|
+
coll2=None,
|
453
|
+
inplace=None,
|
454
|
+
return_keys=None,
|
455
|
+
):
|
422
456
|
""" Extract some selected data and return as new instance
|
423
457
|
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
- all associated monotonous vectors (optional)
|
458
|
+
Automatically includes:
|
459
|
+
- all desired data keys
|
460
|
+
- all relevant ref
|
428
461
|
|
429
|
-
|
462
|
+
Optionally can also include:
|
463
|
+
- inc_monot: monotonous vectors matching any ref
|
464
|
+
- inc_vectors: all (1d) vectors matching any ref
|
465
|
+
- inc_allrefs: all (nd) array matching any full ref set
|
430
466
|
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
)
|
467
|
+
Optionally:
|
468
|
+
coll2: DataStock instance to be populated
|
469
|
+
return_keys: returns the value of keys
|
470
|
+
|
471
|
+
"""
|
437
472
|
|
438
473
|
return _class1_compute._extract_instance(
|
439
474
|
self,
|
440
|
-
|
441
|
-
|
475
|
+
keys=keys,
|
476
|
+
# optional includes
|
477
|
+
inc_monot=inc_monot,
|
478
|
+
inc_vectors=inc_vectors,
|
479
|
+
inc_allrefs=inc_allrefs,
|
480
|
+
# output
|
481
|
+
coll2=coll2,
|
482
|
+
inplace=inplace,
|
483
|
+
return_keys=return_keys,
|
442
484
|
)
|
443
485
|
|
444
486
|
###########
|
@@ -567,8 +609,9 @@ class DataStock1(DataStock0):
|
|
567
609
|
def get_ref_vector(
|
568
610
|
self,
|
569
611
|
# key
|
570
|
-
|
612
|
+
key0=None,
|
571
613
|
# which ref / dimension
|
614
|
+
key=None,
|
572
615
|
ref=None,
|
573
616
|
dim=None,
|
574
617
|
quant=None,
|
@@ -616,6 +659,7 @@ class DataStock1(DataStock0):
|
|
616
659
|
ddata=self._ddata,
|
617
660
|
dref=self._dref,
|
618
661
|
# inputs
|
662
|
+
key0=key0,
|
619
663
|
key=key,
|
620
664
|
ref=ref,
|
621
665
|
dim=dim,
|
@@ -633,6 +677,7 @@ class DataStock1(DataStock0):
|
|
633
677
|
self,
|
634
678
|
keys=None,
|
635
679
|
# for selecting ref vector
|
680
|
+
key=None,
|
636
681
|
ref=None,
|
637
682
|
dim=None,
|
638
683
|
quant=None,
|
@@ -665,6 +710,7 @@ class DataStock1(DataStock0):
|
|
665
710
|
# inputs
|
666
711
|
keys=keys,
|
667
712
|
# for selecting ref vector
|
713
|
+
key=key,
|
668
714
|
ref=ref,
|
669
715
|
dim=dim,
|
670
716
|
quant=quant,
|
@@ -742,41 +788,41 @@ class DataStock1(DataStock0):
|
|
742
788
|
store_keys=None,
|
743
789
|
):
|
744
790
|
""" Return the binned data
|
745
|
-
|
791
|
+
|
746
792
|
data: the data on which to apply binning, can be
|
747
793
|
- a list of np.ndarray to be binned
|
748
794
|
(any dimension as long as they all have the same)
|
749
795
|
- a list of keys to ddata items sharing the same refs
|
750
|
-
|
796
|
+
|
751
797
|
data_units: str only necessary if data is a list of arrays
|
752
|
-
|
798
|
+
|
753
799
|
axis: int or array of int indices
|
754
800
|
the axis of data along which to bin
|
755
801
|
data will be flattened along all those axis priori to binning
|
756
|
-
If None, assumes bin_data is not variable and uses all its axis
|
757
|
-
|
802
|
+
If None, assumes bin_data is not variable and uses all its axis
|
803
|
+
|
758
804
|
bins0: the bins (centers), can be
|
759
805
|
- a 1d vector of monotonous bins
|
760
806
|
- a int, used to compute a bins vector from max(data), min(data)
|
761
|
-
|
807
|
+
|
762
808
|
bin_data0: the data used to compute binning indices, can be:
|
763
809
|
- a str, key to a ddata item
|
764
810
|
- a np.ndarray
|
765
811
|
_ a list of any of the above if each data has different size along axis
|
766
|
-
|
812
|
+
|
767
813
|
bin_units: str
|
768
814
|
only used if integrate = True and bin_data is a np.ndarray
|
769
|
-
|
815
|
+
|
770
816
|
integrate: bool
|
771
817
|
flag indicating whether binning is used for integration
|
772
818
|
Implies that:
|
773
819
|
Only usable for 1d binning (axis has to be a single index)
|
774
820
|
data is multiplied by the underlying bin_data0 step prior to binning
|
775
|
-
|
821
|
+
|
776
822
|
statistic: str
|
777
823
|
the statistic kwd feed to scipy.stats.binned_statistic()
|
778
824
|
automatically set to 'sum' if integrate = True
|
779
|
-
|
825
|
+
|
780
826
|
store: bool
|
781
827
|
If True, will sotre the result in ddata
|
782
828
|
Only possible if all (data, bin_data and bin) are provided as keys
|
@@ -895,118 +941,33 @@ class DataStock1(DataStock0):
|
|
895
941
|
self,
|
896
942
|
show_which=None,
|
897
943
|
show=None,
|
898
|
-
|
899
|
-
sep=
|
900
|
-
line=
|
901
|
-
|
944
|
+
# pretty print options
|
945
|
+
sep=None,
|
946
|
+
line=None,
|
947
|
+
justify=None,
|
902
948
|
table_sep=None,
|
949
|
+
# bool options
|
903
950
|
verb=True,
|
904
951
|
returnas=False,
|
905
952
|
):
|
906
953
|
""" Summary description of the object content """
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
show_which = ['ref', 'data', 'obj']
|
913
|
-
elif isinstance(show_which, tuple):
|
914
|
-
if 'obj' in show_which:
|
915
|
-
show_which = [
|
916
|
-
k0 for k0 in ['ref', 'data'] if k0 not in show_which
|
917
|
-
]
|
918
|
-
else:
|
919
|
-
show_which = [
|
920
|
-
k0 for k0 in ['ref', 'data'] + list(self._dobj.keys())
|
921
|
-
if k0 not in show_which
|
922
|
-
]
|
923
|
-
|
924
|
-
lcol, lar = [], []
|
925
|
-
|
926
|
-
# -----------------------
|
927
|
-
# Build for dref
|
928
|
-
|
929
|
-
if 'ref' in show_which and len(self._dref) > 0:
|
930
|
-
lcol.append(['ref key', 'size', 'nb. data', 'nb. data monot.'])
|
931
|
-
lar.append([
|
932
|
-
[
|
933
|
-
k0,
|
934
|
-
str(self._dref[k0]['size']),
|
935
|
-
str(len(self._dref[k0]['ldata'])),
|
936
|
-
str(len(self._dref[k0]['ldata_monot'])),
|
937
|
-
]
|
938
|
-
for k0 in self._dref.keys()
|
939
|
-
])
|
940
|
-
|
941
|
-
lp = self.get_lparam(which='ref')
|
942
|
-
if 'indices' in lp:
|
943
|
-
lcol[0].append('indices')
|
944
|
-
for ii, (k0, v0) in enumerate(self._dref.items()):
|
945
|
-
if self._dref[k0]['indices'] is None:
|
946
|
-
lar[0][ii].append(str(v0['indices']))
|
947
|
-
else:
|
948
|
-
lar[0][ii].append(str(list(v0['indices'])))
|
949
|
-
|
950
|
-
if 'group' in lp:
|
951
|
-
lcol[0].append('group')
|
952
|
-
for ii, (k0, v0) in enumerate(self._dref.items()):
|
953
|
-
lar[0][ii].append(str(self._dref[k0]['group']))
|
954
|
-
|
955
|
-
if 'inc' in lp:
|
956
|
-
lcol[0].append('increment')
|
957
|
-
for ii, (k0, v0) in enumerate(self._dref.items()):
|
958
|
-
lar[0][ii].append(str(self._dref[k0]['inc']))
|
959
|
-
|
960
|
-
# -----------------------
|
961
|
-
# Build for ddata
|
962
|
-
|
963
|
-
if 'data' in show_which and len(self._ddata) > 0:
|
964
|
-
|
965
|
-
lk = _class1_check._show_get_fields(
|
966
|
-
which='data',
|
967
|
-
lparam=self.get_lparam(which='data', for_show=True),
|
968
|
-
dshow=self._dshow,
|
969
|
-
)
|
970
|
-
lcol.append(['data'] + [pp.split('.')[-1] for pp in lk])
|
971
|
-
lar.append([
|
972
|
-
[k1] + _class1_check._show_extract(dobj=v1, lk=lk)
|
973
|
-
for k1, v1 in self._ddata.items()
|
974
|
-
])
|
975
|
-
|
976
|
-
# -----------------------
|
977
|
-
# Build for dobj
|
978
|
-
|
979
|
-
anyobj = (
|
980
|
-
len(self._dobj) > 0
|
981
|
-
and any([
|
982
|
-
ss in show_which
|
983
|
-
for ss in ['obj'] + list(self._dobj.keys())
|
984
|
-
])
|
985
|
-
)
|
986
|
-
if anyobj:
|
987
|
-
for k0, v0 in self._dobj.items():
|
988
|
-
if 'obj' in show_which or k0 in show_which:
|
989
|
-
lk = _class1_check._show_get_fields(
|
990
|
-
which=k0,
|
991
|
-
lparam=self.get_lparam(which=k0, for_show=True),
|
992
|
-
dshow=self._dshow,
|
993
|
-
)
|
994
|
-
lcol.append([k0] + [pp.split('.')[-1] for pp in lk])
|
995
|
-
lar.append([
|
996
|
-
[k1] + _class1_check._show_extract(dobj=v1, lk=lk)
|
997
|
-
for k1, v1 in v0.items()
|
998
|
-
])
|
999
|
-
|
1000
|
-
return _generic_utils.pretty_print(
|
1001
|
-
headers=lcol,
|
1002
|
-
content=lar,
|
954
|
+
return _class1_show.main(
|
955
|
+
coll=self,
|
956
|
+
show_which=show_which,
|
957
|
+
show=show,
|
958
|
+
# pretty print options
|
1003
959
|
sep=sep,
|
1004
960
|
line=line,
|
961
|
+
justify=justify,
|
1005
962
|
table_sep=table_sep,
|
963
|
+
# bool options
|
1006
964
|
verb=verb,
|
1007
965
|
returnas=returnas,
|
1008
966
|
)
|
1009
967
|
|
968
|
+
def _get_show_obj(self, which=None):
|
969
|
+
return _class1_show._show_obj_def
|
970
|
+
|
1010
971
|
def show_data(self):
|
1011
972
|
self.show(show_which=['ref', 'data'])
|
1012
973
|
|
@@ -1048,4 +1009,4 @@ class DataStock1(DataStock0):
|
|
1048
1009
|
|
1049
1010
|
__all__ = [
|
1050
1011
|
sorted([k0 for k0 in locals() if k0.startswith('DataStock')])[-1]
|
1051
|
-
]
|
1012
|
+
]
|
datastock/_class1_check.py
CHANGED
@@ -1888,101 +1888,4 @@ def _select(dd=None, dd_name=None, log=None, returnas=None, **kwdargs):
|
|
1888
1888
|
[k0 for jj, k0 in enumerate(dd.keys()) if ind[jj]],
|
1889
1889
|
dtype=str,
|
1890
1890
|
)
|
1891
|
-
return ind
|
1892
|
-
|
1893
|
-
|
1894
|
-
#############################################
|
1895
|
-
#############################################
|
1896
|
-
# show
|
1897
|
-
#############################################
|
1898
|
-
|
1899
|
-
|
1900
|
-
def _get_lparam_show_append(which, key, val, lparam, for_show):
|
1901
|
-
|
1902
|
-
c0 = (
|
1903
|
-
callable(val)
|
1904
|
-
or 'class' in key
|
1905
|
-
or 'handle' in key
|
1906
|
-
or (which == 'axes' and key == 'bck')
|
1907
|
-
or isinstance(val, dict)
|
1908
|
-
)
|
1909
|
-
if key not in lparam and ((not for_show) or (for_show and not c0)):
|
1910
|
-
lparam.append(key)
|
1911
|
-
|
1912
|
-
|
1913
|
-
def _get_lparam(which=None, dd=None, for_show=None):
|
1914
|
-
|
1915
|
-
if for_show:
|
1916
|
-
lparam = []
|
1917
|
-
for k0, v0 in dd.items():
|
1918
|
-
for k1, v1 in v0.items():
|
1919
|
-
if isinstance(v1, dict):
|
1920
|
-
for k2, v2 in v1.items():
|
1921
|
-
k3 = f'{k1}.{k2}'
|
1922
|
-
_get_lparam_show_append(
|
1923
|
-
which, k3, v2, lparam, for_show,
|
1924
|
-
)
|
1925
|
-
else:
|
1926
|
-
_get_lparam_show_append(
|
1927
|
-
which, k1, v1, lparam, for_show,
|
1928
|
-
)
|
1929
|
-
|
1930
|
-
else:
|
1931
|
-
lparam = list(list(dd.values())[0].keys())
|
1932
|
-
|
1933
|
-
return lparam
|
1934
|
-
|
1935
|
-
|
1936
|
-
def _show_get_fields(which=None, lparam=None, dshow=None):
|
1937
|
-
|
1938
|
-
# show dict
|
1939
|
-
if which not in dshow.keys():
|
1940
|
-
lk = lparam
|
1941
|
-
|
1942
|
-
else:
|
1943
|
-
lk = dshow[which]
|
1944
|
-
|
1945
|
-
if isinstance(lk, list):
|
1946
|
-
lk = [
|
1947
|
-
kk for kk in dshow[which]
|
1948
|
-
if kk in lparam
|
1949
|
-
]
|
1950
|
-
elif isinstance(lk, tuple):
|
1951
|
-
lk = [
|
1952
|
-
kk for kk in lparam
|
1953
|
-
if kk not in dshow[which]
|
1954
|
-
]
|
1955
|
-
else:
|
1956
|
-
msg = f"Unreckognized dshow['{which}']"
|
1957
|
-
raise Exception(msg)
|
1958
|
-
|
1959
|
-
return lk
|
1960
|
-
|
1961
|
-
def _show_extract(dobj=None, lk=None):
|
1962
|
-
|
1963
|
-
lv0 = []
|
1964
|
-
for k0 in lk:
|
1965
|
-
|
1966
|
-
lk0 = k0.split('.')
|
1967
|
-
for ii in range(len(lk0)):
|
1968
|
-
if ii == 0:
|
1969
|
-
v0 = dobj[lk0[ii]]
|
1970
|
-
elif v0 is not None:
|
1971
|
-
v0 = v0[lk0[ii]]
|
1972
|
-
|
1973
|
-
# formatting
|
1974
|
-
if isinstance(v0, float):
|
1975
|
-
lv0.append(f'{v0:.2e}')
|
1976
|
-
elif isinstance(v0, np.ndarray) and v0.size == 3:
|
1977
|
-
if v0.dtype == float:
|
1978
|
-
lv0.append(
|
1979
|
-
np.array2string(
|
1980
|
-
v0,
|
1981
|
-
formatter={'float': lambda x: f'{x:.3e}'},
|
1982
|
-
),
|
1983
|
-
)
|
1984
|
-
else:
|
1985
|
-
lv0.append(str(v0))
|
1986
|
-
else:
|
1987
|
-
lv0.append(str(v0))
|
1988
|
-
return lv0
|
1891
|
+
return ind
|