scilens 0.4.7__py3-none-any.whl → 0.4.9__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.
- scilens/config/models/reader_metrics.py +1 -1
- scilens/readers/cols_dataset.py +48 -29
- scilens/readers/reader_csv.py +13 -13
- {scilens-0.4.7.dist-info → scilens-0.4.9.dist-info}/METADATA +1 -1
- {scilens-0.4.7.dist-info → scilens-0.4.9.dist-info}/RECORD +7 -7
- {scilens-0.4.7.dist-info → scilens-0.4.9.dist-info}/WHEEL +0 -0
- {scilens-0.4.7.dist-info → scilens-0.4.9.dist-info}/entry_points.txt +0 -0
|
@@ -3,4 +3,4 @@ _B='forbid'
|
|
|
3
3
|
_A=None
|
|
4
4
|
from pydantic import BaseModel,Field
|
|
5
5
|
class ReaderTxtMetricsConfig(BaseModel,extra=_B):name:str|_A=Field(default=_A,description=_C);pattern:str=Field(default=_A,description='Expression régulière pour identifier la métrique.');number_position:int=Field(default=1,description='Position du nombre dans le tableau de nombres de la ligne.')
|
|
6
|
-
class ReaderColsMetricsConfig(BaseModel,extra=_B):name:str|_A=Field(default=_A,description=_C);
|
|
6
|
+
class ReaderColsMetricsConfig(BaseModel,extra=_B):name:str|_A=Field(default=_A,description=_C);aggregation:str=Field(default='sum',description="Méthode d'agrégation du vecteur `col` ou du vecteur résultat de la `function`. Peut être `mean`, `sum`, `min`, `max`.");col:int|str|_A=Field(default=_A,description='Colonnes (index ou noms) de la métrique.');function:str|_A=Field(default=_A,description="Fonction norme de l'espace vectoriel . Peut être `euclidean_norm`.");components:list[int]|list[str]|_A=Field(default=_A,description='Colonnes (index ou noms) de la `function`.')
|
scilens/readers/cols_dataset.py
CHANGED
|
@@ -9,40 +9,59 @@ from scilens.components.compare_models import CompareGroup
|
|
|
9
9
|
from scilens.components.compare_floats import CompareFloats
|
|
10
10
|
from scilens.config.models.reader_format_cols import ReaderCurveParserNameConfig
|
|
11
11
|
from scilens.config.models.reader_metrics import ReaderColsMetricsConfig
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if isinstance(A,
|
|
16
|
-
if isinstance(A,
|
|
12
|
+
import math
|
|
13
|
+
def get_col_indexes(source,numeric_col_indexes,names):
|
|
14
|
+
C=names;A=source;B=[]
|
|
15
|
+
if not isinstance(A,list):A=[A]
|
|
16
|
+
if isinstance(A[0],int):
|
|
17
|
+
for F in A:B.append(F-1)
|
|
18
|
+
else:
|
|
17
19
|
for D in A:
|
|
18
|
-
if D in C:B
|
|
19
|
-
|
|
20
|
-
if
|
|
20
|
+
if D in C:B.append(C.index(D))
|
|
21
|
+
for E in B:
|
|
22
|
+
if E not in numeric_col_indexes:raise ValueError(f"Index column index {E} is not a numeric column.")
|
|
21
23
|
return B
|
|
22
24
|
@dataclass
|
|
23
25
|
class ColsDataset:
|
|
24
26
|
cols_count:int=0;rows_count:int=0;names:list[str]=field(default_factory=lambda:[]);numeric_col_indexes:list[int]=field(default_factory=lambda:[]);data:list[list[float]]=field(default_factory=lambda:[]);origin_line_nb:list[int]=field(default_factory=lambda:[])
|
|
25
|
-
def
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
D=
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
27
|
+
def get_col_indexes(A,col_x):return get_col_indexes(col_x,A.numeric_col_indexes,A.names)
|
|
28
|
+
def get_curves_col_x(F,col_x):
|
|
29
|
+
J='title';C=col_x;A=F;G={};H=F.get_col_indexes(C)
|
|
30
|
+
if not H:raise ValueError(f"get_curves_col_x Column {C} not found in numeric columns.")
|
|
31
|
+
D=H[0];G[_D]=D;K=[B for(A,B)in enumerate(A.numeric_col_indexes)if A!=D];E=[];I=[]
|
|
32
|
+
for B in K:C=A.data[D];L=A.data[B];M={J:A.names[B],'short_title':A.names[B],'series':[[C[A],L[A]]for A in range(A.rows_count)],_C:B};E+=[M];N={J:A.names[B],'type':'simple','xaxis':A.names[D],'yaxis':A.names[B],_B:[len(E)-1]};I+=[N]
|
|
33
|
+
return{_B:E,_E:I},G
|
|
34
|
+
def compute_metrics(K,config):
|
|
35
|
+
C=K;L={}
|
|
36
|
+
for(H,F)in enumerate(config):
|
|
37
|
+
I=F.name;B=F.col;J=F.function;D=F.aggregation
|
|
38
|
+
if not B and not J:raise ValueError(f"Metric #{H} must have either a column or a function.")
|
|
39
|
+
if B and J:raise ValueError(f"Metric #{H} cannot have both a column and a function.")
|
|
40
|
+
if B:
|
|
41
|
+
E=_A
|
|
42
|
+
if isinstance(B,int):E=C.numeric_col_indexes.index(B-1)
|
|
43
|
+
if isinstance(B,str):E=C.names.index(B)
|
|
44
|
+
if E is _A or E<0 or E>=C.cols_count:raise ValueError(f"Metric #{H} has an invalid column: {B}.")
|
|
45
|
+
if not I:I=f"{C.names[E]} {D}"
|
|
46
|
+
A=C.data[E]
|
|
47
|
+
elif J:
|
|
48
|
+
A=[0 for A in range(C.rows_count)]
|
|
49
|
+
if J=='euclidean_norm':
|
|
50
|
+
if not I:I=f"Euclidean Norm {F.components} {D}"
|
|
51
|
+
M=K.get_col_indexes(F.components)
|
|
52
|
+
if not M:continue
|
|
53
|
+
for N in M:
|
|
54
|
+
for(O,P)in enumerate(C.data[N]):A[O]+=P**2
|
|
55
|
+
A=[math.sqrt(A)for A in A]
|
|
56
|
+
else:raise ValueError(f"Metric #{H} has an invalid function: {J}.")
|
|
57
|
+
G=_A
|
|
58
|
+
if D=='mean':G=sum(A)/len(A)
|
|
59
|
+
elif D=='sum':G=sum(A)
|
|
60
|
+
elif D=='min':G=min(A)
|
|
61
|
+
elif D=='max':G=max(A)
|
|
62
|
+
if G is _A:raise ValueError(f"Metric #{H} has an invalid aggregation: {D}.")
|
|
63
|
+
L[I]=G
|
|
64
|
+
return L
|
|
46
65
|
@dataclass
|
|
47
66
|
class ColsCurves:type:str;info:dict;curves:dict
|
|
48
67
|
def compare(group,compare_floats,reader_test,reader_ref,cols_curve):
|
scilens/readers/reader_csv.py
CHANGED
|
@@ -2,7 +2,7 @@ _B=True
|
|
|
2
2
|
_A=None
|
|
3
3
|
import logging,csv,re
|
|
4
4
|
from scilens.readers.reader_interface import ReaderInterface
|
|
5
|
-
from scilens.readers.cols_dataset import ColsDataset,ColsCurves,compare as cols_compare,
|
|
5
|
+
from scilens.readers.cols_dataset import ColsDataset,ColsCurves,compare as cols_compare,get_col_indexes
|
|
6
6
|
from scilens.readers.mat_dataset import MatDataset,from_iterator as mat_from_iterator,compare as mat_compare,get_data
|
|
7
7
|
from scilens.config.models.reader_format_csv import ReaderCsvConfig,ReaderCsvMatrixConfig
|
|
8
8
|
from scilens.config.models.reader_format_cols import ReaderCurveParserNameConfig
|
|
@@ -27,10 +27,10 @@ class ReaderCsv(ReaderInterface):
|
|
|
27
27
|
if bool(re.match(B,line)):return _B
|
|
28
28
|
return False
|
|
29
29
|
def read(A,reader_options):
|
|
30
|
-
C=reader_options;A.reader_options=C;F,L,
|
|
30
|
+
C=reader_options;A.reader_options=C;F,L,V=csv_detect(A.origin.path,A.reader_options.delimiter,A.reader_options.quotechar,encoding=A.encoding);A.has_header=F;A.cols=L;A.numeric_col_indexes=V;A.index_col_index=_A;A.ignore_lines_patterns=_A;G=_A;H=_A;I=_A;J=_A;B=C.cols
|
|
31
31
|
if B:
|
|
32
32
|
if B.index_col:
|
|
33
|
-
if B.index_col:
|
|
33
|
+
if B.index_col:R=get_col_indexes(B.index_col,A.numeric_col_indexes,L);A.index_col_index=R[0]if R else _A
|
|
34
34
|
if B.rows:
|
|
35
35
|
A.ignore_lines_patterns=B.rows.ignore_patterns;G=B.rows.line_start;H=B.rows.line_end
|
|
36
36
|
if G and H and H<G:raise ValueError(f"Line end {H} cannot be before line start {G}.")
|
|
@@ -39,8 +39,8 @@ class ReaderCsv(ReaderInterface):
|
|
|
39
39
|
I=B.rows.index_min_value;J=B.rows.index_max_value
|
|
40
40
|
if I and J and I>J:raise ValueError(f"Index min value {I} cannot be greater than index max value {J}.")
|
|
41
41
|
A.raw_lines_number=_A;A.curves=_A;A.report_matrices=_A
|
|
42
|
-
with open(A.origin.path,'r',encoding=A.encoding)as
|
|
43
|
-
|
|
42
|
+
with open(A.origin.path,'r',encoding=A.encoding)as W:
|
|
43
|
+
S=W.readlines();M=csv.reader(S,delimiter=A.reader_options.delimiter,quotechar=A.reader_options.quotechar)
|
|
44
44
|
if C.is_matrix:
|
|
45
45
|
K=C.matrix or ReaderCsvMatrixConfig();P=mat_from_iterator(x_name=K.x_name,y_name=K.y_name,reader=M,has_header=F,x_value_line=K.x_value_line,has_y=K.has_y)
|
|
46
46
|
if K.export_report:A.report_matrices=get_data([P],['csv'])
|
|
@@ -49,8 +49,8 @@ class ReaderCsv(ReaderInterface):
|
|
|
49
49
|
if C.cols and C.cols.ignore_columns:
|
|
50
50
|
if not F:raise Exception('Ignore columns is not supported without header.')
|
|
51
51
|
if isinstance(C.cols.ignore_columns[0],str):A.numeric_col_indexes=[B for B in A.numeric_col_indexes if A.cols[B]not in C.cols.ignore_columns]
|
|
52
|
-
if isinstance(C.cols.ignore_columns[0],int):
|
|
53
|
-
|
|
52
|
+
if isinstance(C.cols.ignore_columns[0],int):X=[A-1 for A in B.ignore_columns];A.numeric_col_indexes=[A for A in A.numeric_col_indexes if A not in X]
|
|
53
|
+
T=len(L);D=ColsDataset(cols_count=T,names=L,numeric_col_indexes=A.numeric_col_indexes,data=[[]for A in range(T)]);E=0
|
|
54
54
|
if F and E==0:next(M);E+=1
|
|
55
55
|
if G:
|
|
56
56
|
try:
|
|
@@ -63,11 +63,11 @@ class ReaderCsv(ReaderInterface):
|
|
|
63
63
|
N=next(M);E+=1
|
|
64
64
|
if H and E>H:break
|
|
65
65
|
if J is not _A and float(N[A.index_col_index])>J:break
|
|
66
|
-
if A.ignore_lines_patterns and A._ignore_line(
|
|
66
|
+
if A.ignore_lines_patterns and A._ignore_line(S[E-1].rstrip('\n')):continue
|
|
67
67
|
if I is not _A and float(N[A.index_col_index])<I:continue
|
|
68
|
-
for(
|
|
69
|
-
if
|
|
70
|
-
D.data[
|
|
68
|
+
for(U,Q)in enumerate(N):
|
|
69
|
+
if U in D.numeric_col_indexes:Q=float(Q)
|
|
70
|
+
D.data[U].append(Q)
|
|
71
71
|
D.origin_line_nb.append(E)
|
|
72
72
|
except StopIteration:pass
|
|
73
73
|
D.rows_count=len(D.origin_line_nb);A.cols_dataset=D;A.raw_lines_number=D.rows_count+(1 if F else 0);A.metrics=_A
|
|
@@ -78,8 +78,8 @@ class ReaderCsv(ReaderInterface):
|
|
|
78
78
|
if B.curve_parser.parameters:O=B.curve_parser.parameters.x
|
|
79
79
|
elif B.index_col:O=B.index_col
|
|
80
80
|
if not O:raise ValueError('Curve parser COL_X requires a parameter x, or index_col to be defined.')
|
|
81
|
-
A.curves,
|
|
82
|
-
if A.curves:A.cols_curve=ColsCurves(type=ReaderCurveParserNameConfig.COL_X,info=
|
|
81
|
+
A.curves,Y=D.get_curves_col_x(O)
|
|
82
|
+
if A.curves:A.cols_curve=ColsCurves(type=ReaderCurveParserNameConfig.COL_X,info=Y,curves=A.curves)
|
|
83
83
|
elif B.curve_parser.name==ReaderCurveParserNameConfig.COLS_COUPLE:raise NotImplementedError('cols_couple not implemented')
|
|
84
84
|
else:raise Exception('Curve parser not supported.')
|
|
85
85
|
def compare(A,compare_floats,param_reader,param_is_ref=_B):
|
|
@@ -32,7 +32,7 @@ scilens/config/models/reader_format_csv.py,sha256=KWEH0c12n6hdaWAKdHXYMT5SvH4UqB
|
|
|
32
32
|
scilens/config/models/reader_format_netcdf.py,sha256=Skr5lZACqVRrrlvs7R1RVFBpMTDthLJN-Fbs24jtb7o,1271
|
|
33
33
|
scilens/config/models/reader_format_txt.py,sha256=35rvhg311DN9miE47QM9NN_gcZHglYG2lBZPLJy4iyg,1462
|
|
34
34
|
scilens/config/models/reader_format_txt_fixed_cols.py,sha256=XmmFS0LdGR81XCjJIyW4cngivFo_8drckqe_k8fhqJk,1385
|
|
35
|
-
scilens/config/models/reader_metrics.py,sha256=
|
|
35
|
+
scilens/config/models/reader_metrics.py,sha256=uLwyd2vE4GRHbArYRv1BRH_acTL1hbFB7HgZRDJiAJg,965
|
|
36
36
|
scilens/config/models/readers.py,sha256=NpEjXbLv11k9N8UsnuS55KEYlRijF9C3eOrI0SB9dqM,1723
|
|
37
37
|
scilens/config/models/report.py,sha256=_4W96v5izWCC_CrMzh3PM0mZIUAa3L26ZQqjV0Mv0f4,1008
|
|
38
38
|
scilens/config/models/report_html.py,sha256=IsKlmE7QbSTiPrOaxPc48Ne7xPE5yqTcLjxqN_i-unY,3803
|
|
@@ -49,10 +49,10 @@ scilens/processors/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJW
|
|
|
49
49
|
scilens/processors/models/results.py,sha256=KoWxh13Zgi7PuPql8hkf4VjCis42ZxAuzIgJxBWVaX8,119
|
|
50
50
|
scilens/processors/processor_interface.py,sha256=jzMp1529JXnMGTJijVy6b_1zmARAMNv70f2lgys7vn4,452
|
|
51
51
|
scilens/readers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
52
|
-
scilens/readers/cols_dataset.py,sha256=
|
|
52
|
+
scilens/readers/cols_dataset.py,sha256=6Cq9aIG4UMOdam_zx64lf2f0e2f0lI2VZDNZklccBaI,3964
|
|
53
53
|
scilens/readers/exceptions.py,sha256=JzmxcjnR5sH-IOWVeCC5A1bSwxv-jCAtIJvDjzx1CTI,32
|
|
54
54
|
scilens/readers/mat_dataset.py,sha256=Z9TYDWaH2aqdniLNDjlpR6VVNHMSARjh52clhdMyOn4,1496
|
|
55
|
-
scilens/readers/reader_csv.py,sha256=
|
|
55
|
+
scilens/readers/reader_csv.py,sha256=FKxx26Vzf_h25cFX37DwFXy_-toUGw3481iMbyRa-vg,5550
|
|
56
56
|
scilens/readers/reader_interface.py,sha256=r1pu9LyweTGXU8YfI3FPZy1Em4stzmJb-6j90j1tPQQ,938
|
|
57
57
|
scilens/readers/reader_manager.py,sha256=DFinxIk3IIIcB6JxybGcv-mXt3jhXgCwUtzR0TqhB2Q,2684
|
|
58
58
|
scilens/readers/reader_txt.py,sha256=U3hGIorj-Nv-jq6zYtvbDv2LQBHTgW52PHbV8A5FMA8,4526
|
|
@@ -113,7 +113,7 @@ scilens/utils/template.py,sha256=9dlXX3nmfzDRUwzPJOkoxk15UXivZ2SW-McdCwokFa4,443
|
|
|
113
113
|
scilens/utils/time_tracker.py,sha256=DdVBoMpVLXrX0qZZXyLm4g38EwDVLlRcBqcpNex1mYY,545
|
|
114
114
|
scilens/utils/vectors.py,sha256=4N2BZSC5n3HgZqPujDGF5NdjVmSL1rOHb_qw4OoABQY,103
|
|
115
115
|
scilens/utils/web.py,sha256=MAFWpIFOKz7QhqDoFh-Qwstvc76KpcxstSgHFT8FOL4,901
|
|
116
|
-
scilens-0.4.
|
|
117
|
-
scilens-0.4.
|
|
118
|
-
scilens-0.4.
|
|
119
|
-
scilens-0.4.
|
|
116
|
+
scilens-0.4.9.dist-info/METADATA,sha256=pz6dHk21Xl_u0bwZeCj6clWQivZddEpxCJ2KsLVW2Xk,1367
|
|
117
|
+
scilens-0.4.9.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
118
|
+
scilens-0.4.9.dist-info/entry_points.txt,sha256=DaKGgxUEUv34GJAoXtta6ecL37ercejep9sCSSRQK2s,48
|
|
119
|
+
scilens-0.4.9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|