funcsim 0.2.0__tar.gz → 0.2.2__tar.gz
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.
- {funcsim-0.2.0/funcsim.egg-info → funcsim-0.2.2}/PKG-INFO +1 -1
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/__init__.py +1 -1
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/kde.py +4 -1
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/plotting.py +32 -42
- {funcsim-0.2.0 → funcsim-0.2.2/funcsim.egg-info}/PKG-INFO +1 -1
- {funcsim-0.2.0 → funcsim-0.2.2}/setup.py +1 -1
- {funcsim-0.2.0 → funcsim-0.2.2}/LICENSE +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/MANIFEST.in +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/README.md +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/addist.py +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/conversions.py +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/copfit.py +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/core.py +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/cpt.py +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/cvmdist.py +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/dependence.py +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/distfit.py +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/ecdfgof.py +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/edf.py +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/eut.py +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/imanconover.py +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/ksdist.py +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/multicore.py +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/nearby.py +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/rdarrays.py +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/screen.py +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/shapiro.py +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/shrinkage.py +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/testsim.py +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/utests.py +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/vect.py +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim.egg-info/SOURCES.txt +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim.egg-info/dependency_links.txt +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim.egg-info/requires.txt +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/funcsim.egg-info/top_level.txt +0 -0
- {funcsim-0.2.0 → funcsim-0.2.2}/setup.cfg +0 -0
|
@@ -75,7 +75,10 @@ class Kde():
|
|
|
75
75
|
float
|
|
76
76
|
The estimated probability density at v.
|
|
77
77
|
"""
|
|
78
|
-
|
|
78
|
+
# gaussian_kde returns a length-1 array for a scalar input, and
|
|
79
|
+
# NumPy >= 2.5 raises TypeError on float() of any array that is
|
|
80
|
+
# not 0-dimensional, so index out the single element first
|
|
81
|
+
return float(self.gkde(v)[0])
|
|
79
82
|
|
|
80
83
|
@vectorized_method
|
|
81
84
|
def cdf(self,
|
|
@@ -8,6 +8,32 @@ from typing import Callable, Optional
|
|
|
8
8
|
from . import conversions
|
|
9
9
|
|
|
10
10
|
|
|
11
|
+
def _xvalues(idx: pd.Index) -> list:
|
|
12
|
+
"""
|
|
13
|
+
Convert a 'steps' index into a list of x values that any JSON encoder
|
|
14
|
+
can serialize.
|
|
15
|
+
|
|
16
|
+
pandas Period and Timestamp labels are rendered as ISO 8601 strings,
|
|
17
|
+
which plotly.js parses back into a date axis. Static image export via
|
|
18
|
+
kaleido >= 1.0 serializes the figure with orjson, which rejects pandas
|
|
19
|
+
Timestamp objects outright, so the conversion cannot be left to plotly.
|
|
20
|
+
Other label types (e.g. integers) pass through unchanged.
|
|
21
|
+
"""
|
|
22
|
+
if isinstance(idx, pd.PeriodIndex):
|
|
23
|
+
idx = idx.to_timestamp()
|
|
24
|
+
if isinstance(idx, pd.DatetimeIndex):
|
|
25
|
+
return [ts.isoformat() for ts in idx]
|
|
26
|
+
|
|
27
|
+
def conv(item):
|
|
28
|
+
if isinstance(item, pd.Period):
|
|
29
|
+
return item.to_timestamp().isoformat()
|
|
30
|
+
if isinstance(item, pd.Timestamp):
|
|
31
|
+
return item.isoformat()
|
|
32
|
+
return item
|
|
33
|
+
|
|
34
|
+
return [conv(item) for item in idx]
|
|
35
|
+
|
|
36
|
+
|
|
11
37
|
def fan(da: xr.DataArray,
|
|
12
38
|
varname: str,
|
|
13
39
|
filepath: str = None,
|
|
@@ -24,7 +50,7 @@ def fan(da: xr.DataArray,
|
|
|
24
50
|
Simulation results with dimensions "trials", "variables", "steps".
|
|
25
51
|
varname : str
|
|
26
52
|
Name of the variable to plot from the "variables" dimension.
|
|
27
|
-
filepath : str,
|
|
53
|
+
filepath : str, optional
|
|
28
54
|
Path to save the chart. Supports HTML and image formats. Default None.
|
|
29
55
|
line_color : str, optional
|
|
30
56
|
Color of the mean line. Default is 'blue'.
|
|
@@ -75,45 +101,9 @@ def fan(da: xr.DataArray,
|
|
|
75
101
|
fig.update_layout(title_text=f"{varname} (No data)")
|
|
76
102
|
return fig
|
|
77
103
|
|
|
78
|
-
# 'steps'
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
# Ensure index is JSON serializable by converting to Timestamps if it
|
|
83
|
-
# contains Periods. This handles both PeriodIndex and object-dtype Index
|
|
84
|
-
# containing Period objects.
|
|
85
|
-
if isinstance(idx, pd.PeriodIndex):
|
|
86
|
-
idx = idx.to_timestamp()
|
|
87
|
-
# print("DEBUG: Converted PeriodIndex to DatetimeIndex.") # Optional
|
|
88
|
-
elif hasattr(idx, 'dtype') and pd.api.types.is_object_dtype(idx.dtype):
|
|
89
|
-
# If it's an object-dtype idx, check if it might contain Period objects.
|
|
90
|
-
if len(idx) > 0:
|
|
91
|
-
try:
|
|
92
|
-
converted_values = []
|
|
93
|
-
needs_conversion = False
|
|
94
|
-
for item in idx:
|
|
95
|
-
if isinstance(item, pd.Period):
|
|
96
|
-
converted_values.append(item.to_timestamp())
|
|
97
|
-
needs_conversion = True
|
|
98
|
-
else:
|
|
99
|
-
# Pass through other types (e.g., pd.NaT, None, or
|
|
100
|
-
# other data if mixed)
|
|
101
|
-
converted_values.append(item)
|
|
102
|
-
|
|
103
|
-
if needs_conversion:
|
|
104
|
-
idx = pd.DatetimeIndex(converted_values)
|
|
105
|
-
# print("DEBUG: Converted object-dtype index with Period "
|
|
106
|
-
# "objects to DatetimeIndex.") # Optional debug
|
|
107
|
-
# If no Period objects were found and converted, idx remains the
|
|
108
|
-
# original object-dtype index.
|
|
109
|
-
|
|
110
|
-
except Exception as e:
|
|
111
|
-
# This might happen if conversion of an item fails unexpectedly.
|
|
112
|
-
warnings.warn(f"Attempted to convert an object-dtype "
|
|
113
|
-
f"index that might contain Periods, but an error "
|
|
114
|
-
f"occurred: {e}. Using original index for x-axis,"
|
|
115
|
-
f" which may lead to Plotly errors.", UserWarning)
|
|
116
|
-
idx = idx_original # Revert to original index
|
|
104
|
+
# x values for the 'steps' axis, in a form every JSON encoder can
|
|
105
|
+
# serialize (see _xvalues)
|
|
106
|
+
xs = _xvalues(dt.index)
|
|
117
107
|
|
|
118
108
|
# Calculate the mean across trials for each step
|
|
119
109
|
mean_values = dt.mean(axis=1)
|
|
@@ -140,7 +130,7 @@ def fan(da: xr.DataArray,
|
|
|
140
130
|
# start for the lower bound
|
|
141
131
|
# Y-coordinates match this path to create a closed shape
|
|
142
132
|
fig.add_trace(go.Scatter(
|
|
143
|
-
x=
|
|
133
|
+
x=xs + xs[::-1],
|
|
144
134
|
y=list(y_upper) + list(y_lower[::-1]),
|
|
145
135
|
fill='toself', # Fill the area enclosed by the trace
|
|
146
136
|
fillcolor='rgba(173, 216, 230, 0.4)', # Light blue with 20% opacity
|
|
@@ -152,7 +142,7 @@ def fan(da: xr.DataArray,
|
|
|
152
142
|
|
|
153
143
|
# Add the mean line (plotted on top of the bands)
|
|
154
144
|
fig.add_trace(go.Scatter(
|
|
155
|
-
x=
|
|
145
|
+
x=xs,
|
|
156
146
|
y=mean_values,
|
|
157
147
|
mode='lines',
|
|
158
148
|
line=dict(color=line_color), # Use the specified line color
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|