Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
METRo projects
metro
Commits
fef3caaa
Commit
fef3caaa
authored
Dec 14, 2007
by
Miguel Tremblay
Browse files
Replace "na" by "np" in the variable name.
parent
65dd9a31
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/frontend/data_module/metro_data.py
View file @
fef3caaa
...
...
@@ -85,7 +85,7 @@ class Metro_data:
self
.
bRead_only
=
False
self
.
dHeader
=
{}
self
.
n
a
Matrix
=
numpy
.
array
([],
dtype
=
numpy
.
float
)
self
.
n
p
Matrix
=
numpy
.
array
([],
dtype
=
numpy
.
float
)
# Name of the columns of the matrix
self
.
lMatrix_col_name
=
[]
...
...
@@ -160,8 +160,8 @@ class Metro_data:
def
init_matrix
(
self
,
iNb_row
,
iNb_col
,
fVal
=
metro_constant
.
NaN
):
"""Init a matrix of n row and m column filled with a value."""
if
not
self
.
is_readonly
():
self
.
n
a
Matrix
=
numpy
.
zeros
((
iNb_row
,
iNb_col
))
self
.
n
a
Matrix
=
self
.
n
a
Matrix
+
fVal
self
.
n
p
Matrix
=
numpy
.
zeros
((
iNb_row
,
iNb_col
))
self
.
n
p
Matrix
=
self
.
n
p
Matrix
+
fVal
else
:
metro_logger
.
print_message
(
metro_logger
.
LOGGER_MSG_DEBUG
,
MESSAGE_READONLY
)
...
...
@@ -178,7 +178,7 @@ class Metro_data:
# Descriptions:
#
#-------------------------------------------------------------------------------
def
set_matrix
(
self
,
n
a
Matrix
):
def
set_matrix
(
self
,
n
p
Matrix
):
"""Set the whole matrix with a new one.
This method should be used with care because the new and old matrix
...
...
@@ -186,7 +186,7 @@ class Metro_data:
will be the only way to access column of the new one.
"""
if
not
self
.
is_readonly
():
self
.
n
a
Matrix
=
n
a
Matrix
self
.
n
p
Matrix
=
n
p
Matrix
else
:
metro_logger
.
print_message
(
metro_logger
.
LOGGER_MSG_DEBUG
,
MESSAGE_READONLY
)
...
...
@@ -197,7 +197,7 @@ class Metro_data:
#
# Name: set_matrix_col
#
# Parameters: I sCol_name : nom de la colonne, I n
a
Col : tableau de donnee
# Parameters: I sCol_name : nom de la colonne, I n
p
Col : tableau de donnee
#
# Returns: 0 si succes
#
...
...
@@ -205,7 +205,7 @@ class Metro_data:
# Descriptions: ecrase le contenue de la colonne iCol avec de nouvelle donnees
#
#-------------------------------------------------------------------------------
def
set_matrix_col
(
self
,
sCol_name
,
n
a
Col
):
def
set_matrix_col
(
self
,
sCol_name
,
n
p
Col
):
"""Set matrix column with a new one."""
if
sCol_name
in
self
.
lMatrix_col_name
:
...
...
@@ -218,17 +218,17 @@ class Metro_data:
raise
ERROR_METRO_DATA
,
sError
if
not
self
.
is_readonly
():
if
iCol
>
len
(
self
.
n
a
Matrix
[
0
,:]):
if
iCol
>
len
(
self
.
n
p
Matrix
[
0
,:]):
sOutOfBoundError
=
_
(
"Array does not contain this indice: %d"
)
\
%
iCol
raise
ERROR_METRO_DATA
,
sOutOfBoundError
elif
len
(
self
.
n
a
Matrix
[:,
iCol
])
!=
len
(
n
a
Col
):
elif
len
(
self
.
n
p
Matrix
[:,
iCol
])
!=
len
(
n
p
Col
):
sLengthError
=
_
(
"Array does not have the right lenght.
\n
"
)
+
\
_
(
"Array length: %d
\n
"
)
%
len
(
n
a
Col
)
+
\
_
(
"Matrix length: %d
\n
"
)
%
len
(
self
.
n
a
Matrix
[:,
icol
])
_
(
"Array length: %d
\n
"
)
%
len
(
n
p
Col
)
+
\
_
(
"Matrix length: %d
\n
"
)
%
len
(
self
.
n
p
Matrix
[:,
icol
])
raise
ERROR_METRO_DATA
,
sLengthError
else
:
self
.
n
a
Matrix
[:,
iCol
]
=
n
a
Col
self
.
n
p
Matrix
[:,
iCol
]
=
n
p
Col
else
:
metro_logger
.
print_message
(
metro_logger
.
LOGGER_MSG_DEBUG
,
MESSAGE_READONLY
)
...
...
@@ -250,19 +250,19 @@ class Metro_data:
while
None
in
lData_row
:
iIndex
=
lData_row
.
index
(
None
)
lData_row
[
iIndex
]
=
metro_constant
.
NaN
self
.
n
a
Matrix
=
self
.
__append_row_to_matrix
(
self
.
n
a
Matrix
,
lData_row
)
self
.
n
p
Matrix
=
self
.
__append_row_to_matrix
(
self
.
n
p
Matrix
,
lData_row
)
else
:
metro_logger
.
print_message
(
metro_logger
.
LOGGER_MSG_DEBUG
,
MESSAGE_READONLY
)
raise
ERROR_METRO_DATA
,
MESSAGE_READONLY
def
append_matrix_col
(
self
,
sCol_name
,
n
a
Data_col
):
def
append_matrix_col
(
self
,
sCol_name
,
n
p
Data_col
):
"""
Name: append_matrix_col
Parameters: I sCol_name : column name
I n
a
Data_col : column to insert in the matrix.
I n
p
Data_col : column to insert in the matrix.
Returns: 0 if success
...
...
@@ -275,8 +275,8 @@ class Metro_data:
self
.
lMatrix_col_name
.
append
(
sCol_name
)
# Append column in the matrix
self
.
n
a
Matrix
=
self
.
__append_col_to_matrix
(
self
.
n
a
Matrix
,
\
n
a
Data_col
)
self
.
n
p
Matrix
=
self
.
__append_col_to_matrix
(
self
.
n
p
Matrix
,
\
n
p
Data_col
)
else
:
sError
=
_
(
"Cant append column '%s'.%s"
)
%
(
sCol_name
,
MESSAGE_COL_EXIST
)
...
...
@@ -338,7 +338,7 @@ class Metro_data:
#-------------------------------------------------------------------------------
def
get_matrix
(
self
):
"""Get a copy of the whole matrix."""
return
self
.
n
a
Matrix
.
copy
()
return
self
.
n
p
Matrix
.
copy
()
def
get_matrix_col
(
self
,
sCol_name
):
...
...
@@ -363,7 +363,7 @@ class Metro_data:
iCol
=
self
.
lMatrix_col_name
.
index
(
sCol_name
)
return
self
.
n
a
Matrix
[:,
iCol
].
copy
()
return
self
.
n
p
Matrix
[:,
iCol
].
copy
()
def
index_of_matrix_col
(
self
,
sCol_name
):
"""Get index value of a matrix column identified by sCol_name."""
...
...
@@ -405,31 +405,31 @@ class Metro_data:
# Author Date Reason
# Miguel Tremblay August 4th 2004
#####################################################
def
del_matrix_row
(
self
,
n
a
IndiceToRemove
):
def
del_matrix_row
(
self
,
n
p
IndiceToRemove
):
"""Delete one or more row identified by indices.
Arguments:
n
a
IndiceToRemove: numpy of indices to remove.
n
p
IndiceToRemove: numpy of indices to remove.
Indices must be in increasing order.
"""
if
not
self
.
is_readonly
():
for
i
in
range
(
len
(
n
a
IndiceToRemove
)
-
1
,
-
1
,
-
1
):
nIndice
=
n
a
IndiceToRemove
[
i
]
for
i
in
range
(
len
(
n
p
IndiceToRemove
)
-
1
,
-
1
,
-
1
):
nIndice
=
n
p
IndiceToRemove
[
i
]
sMessage
=
"removing %d"
%
((
nIndice
))
metro_logger
.
print_message
(
metro_logger
.
LOGGER_MSG_DEBUG
,
\
sMessage
)
n
a
FirstPart
=
self
.
n
a
Matrix
[
0
:
nIndice
,:]
sMessage
=
"len(%s)"
%
(
len
(
self
.
n
a
Matrix
))
n
p
FirstPart
=
self
.
n
p
Matrix
[
0
:
nIndice
,:]
sMessage
=
"len(%s)"
%
(
len
(
self
.
n
p
Matrix
))
metro_logger
.
print_message
(
metro_logger
.
LOGGER_MSG_DEBUG
,
\
sMessage
)
if
nIndice
+
1
<
len
(
self
.
n
a
Matrix
)
:
n
a
SecondPart
=
self
.
n
a
Matrix
[
nIndice
+
1
:
len
(
self
.
n
a
Matrix
),:]
self
.
n
a
Matrix
=
numpy
.
concatenate
((
n
a
FirstPart
,
n
a
SecondPart
))
if
nIndice
+
1
<
len
(
self
.
n
p
Matrix
)
:
n
p
SecondPart
=
self
.
n
p
Matrix
[
nIndice
+
1
:
len
(
self
.
n
p
Matrix
),:]
self
.
n
p
Matrix
=
numpy
.
concatenate
((
n
p
FirstPart
,
n
p
SecondPart
))
else
:
self
.
n
a
Matrix
=
n
a
FirstPart
self
.
n
p
Matrix
=
n
p
FirstPart
# Check if there at least one element left
if
len
(
self
.
n
a
Matrix
)
==
0
:
if
len
(
self
.
n
p
Matrix
)
==
0
:
sEmptyMatrixError
=
_
(
"All the data are invalid"
)
metro_logger
.
print_message
(
metro_logger
.
LOGGER_MSG_WARNING
,
\
sMessage
)
...
...
@@ -438,15 +438,15 @@ class Metro_data:
else
:
raise
ERROR_METRO_DATA
,
MESSAGE_READONLY
def
__append_row_to_matrix
(
self
,
n
a
Matrix
,
n
a
Row
):
iCol
=
len
(
n
a
Row
)
iRow
=
len
(
n
a
Matrix
)
n
a
Matrix
=
numpy
.
resize
(
n
a
Matrix
,
(
iRow
+
1
,
iCol
)
)
n
a
Matrix
[
iRow
:]
=
n
a
Row
return
n
a
Matrix
def
__append_col_to_matrix
(
self
,
n
a
Matrix
,
n
a
Col
):
n
a
Matrix
=
n
a
Matrix
.
transpose
()
n
a
Matrix
=
self
.
__append_row_to_matrix
(
n
a
Matrix
,
n
a
Col
)
n
a
Matrix
=
n
a
Matrix
.
transpose
()
return
n
a
Matrix
def
__append_row_to_matrix
(
self
,
n
p
Matrix
,
n
p
Row
):
iCol
=
len
(
n
p
Row
)
iRow
=
len
(
n
p
Matrix
)
n
p
Matrix
=
numpy
.
resize
(
n
p
Matrix
,
(
iRow
+
1
,
iCol
)
)
n
p
Matrix
[
iRow
:]
=
n
p
Row
return
n
p
Matrix
def
__append_col_to_matrix
(
self
,
n
p
Matrix
,
n
p
Col
):
n
p
Matrix
=
n
p
Matrix
.
transpose
()
n
p
Matrix
=
self
.
__append_row_to_matrix
(
n
p
Matrix
,
n
p
Col
)
n
p
Matrix
=
n
p
Matrix
.
transpose
()
return
n
p
Matrix
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment