Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
LISA Instrument
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LISA Simulation
LISA Instrument
Merge requests
!46
Draft: Resolve "Use Numpy arrays instead of `ForEachObject` instances"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
Draft: Resolve "Use Numpy arrays instead of `ForEachObject` instances"
34-use-numpy-arrays-instead-of-foreachobject-instances
into
master
Overview
7
Commits
3
Pipelines
10
Changes
2
Closed
Jean-Baptiste Bayle
requested to merge
34-use-numpy-arrays-instead-of-foreachobject-instances
into
master
3 years ago
Overview
7
Commits
3
Pipelines
10
Changes
2
Expand
Closes
#34 (closed)
0
0
Merge request reports
Viewing commit
d86decb0
Show latest version
2 files
+
90
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
d86decb0
Add functions to transform MOSA to distant or adjacent
· d86decb0
Jean-Baptiste Bayle
authored
3 years ago
lisainstrument/indexing.py
+
46
−
0
Options
@@ -239,3 +239,49 @@ def sc2bothmosas(x):
raise
TypeError
(
"
invalid SC array
"
)
sc_mosas
=
[
sc2index
(
mosa2sc
(
mosa
))
for
mosa
in
MOSAS
]
return
x
[
sc_mosas
]
DISTANT_MOSAS
=
[
f
'
{
mosa
[
1
]
}{
mosa
[
0
]
}
'
for
mosa
in
MOSAS
]
ADJACENT_MOSAS
=
[
f
'
{
mosa
[
0
]
}{
reflect
(
mosa
[
1
],
axis
=
mosa
[
0
])
}
'
for
mosa
in
MOSAS
]
def
mosa2distant
(
x
):
"""
Transform MOSA index or array into distant MOSA.
Args:
x: MOSA index (as a string or integer), or MOSA array
"""
# Transform MOSA array
if
isinstance
(
x
,
np
.
ndarray
)
and
x
.
shape
[
0
]
==
6
:
transformed_mosas
=
list
(
map
(
mosa2index
,
DISTANT_MOSAS
))
return
x
[
transformed_mosas
]
# Raise an error if we have an array of invalid shape
if
isinstance
(
x
,
np
.
ndarray
):
raise
TypeError
(
f
"
invalid MOSA array shape
'
{
x
.
shape
}
'"
)
# Check that index is correct
index
=
str
(
x
)
if
index
not
in
MOSAS
:
raise
IndexError
(
f
"
invalid MOSA index
'
{
index
}
'"
)
# Transform index
return
DISTANT_MOSAS
[
mosa2index
(
x
)]
def
mosa2adjacent
(
x
):
"""
Transform MOSA index or array into adjacent MOSA.
Args:
x: MOSA index (as a string or integer), or MOSA array
"""
# Transform MOSA array
if
isinstance
(
x
,
np
.
ndarray
)
and
x
.
shape
[
0
]
==
6
:
transformed_mosas
=
list
(
map
(
mosa2index
,
ADJACENT_MOSAS
))
return
x
[
transformed_mosas
]
# Raise an error if we have an array of invalid shape
if
isinstance
(
x
,
np
.
ndarray
):
raise
TypeError
(
f
"
invalid MOSA array shape
'
{
x
.
shape
}
'"
)
# Check that index is correct
index
=
str
(
x
)
if
index
not
in
MOSAS
:
raise
IndexError
(
f
"
invalid MOSA index
'
{
index
}
'"
)
# Transform index
return
ADJACENT_MOSAS
[
mosa2index
(
x
)]
Loading