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
546a83a2
Show latest version
2 files
+
141
−
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)
546a83a2
Add mapping between MOSA/SC and array indices
· 546a83a2
Jean-Baptiste Bayle
authored
3 years ago
lisainstrument/indexing.py
0 → 100644
+
93
−
0
Options
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Utility functions for indexing MOSAs and SC.
Authors:
Jean-Baptiste Bayle <j2b.bayle@gmail.com>
"""
import
logging
logger
=
logging
.
getLogger
(
__name__
)
"""
List of MOSA index as two-figure strings, in the order they are used in an array.
"""
MOSAS
=
[
'
12
'
,
'
23
'
,
'
31
'
,
'
13
'
,
'
32
'
,
'
21
'
]
def
index2mosa
(
index
):
"""
Return MOSA index associated with a given array index.
Args:
index: array index
Returns:
MOSA index as a two-figure string, e.g.,
'
12
'
.
"""
try
:
return
MOSAS
[
index
]
except
IndexError
as
error
:
raise
IndexError
(
f
"
invalid array index
'
{
index
}
'
for MOSA
"
)
from
error
def
mosa2index
(
mosa
):
"""
Return array index associated with a given MOSA index.
Args:
mosa: MOSA index as a two-figure string or integer
Returns:
Array index as an integer.
"""
try
:
return
MOSAS
.
index
(
str
(
mosa
))
except
ValueError
as
error
:
raise
ValueError
(
f
"
invalid MOSA index
'
{
mosa
}
'"
)
from
error
MOSA12
=
mosa2index
(
'
12
'
)
MOSA23
=
mosa2index
(
'
23
'
)
MOSA31
=
mosa2index
(
'
31
'
)
MOSA13
=
mosa2index
(
'
13
'
)
MOSA32
=
mosa2index
(
'
32
'
)
MOSA21
=
mosa2index
(
'
21
'
)
"""
List of SC indices as one-figure strings, in the order they are used in an array.
"""
SC
=
[
'
1
'
,
'
2
'
,
'
3
'
]
def
index2sc
(
index
):
"""
Return SC index associated with a given array index.
Args:
index: array index
Returns:
SC index as a one-figure string, e.g.,
'
1
'
.
"""
try
:
return
SC
[
index
]
except
IndexError
as
error
:
raise
IndexError
(
f
"
invalid array index
'
{
index
}
'
for SC
"
)
from
error
def
sc2index
(
mosa
):
"""
Return array index associated with a given SC index.
Args:
mosa: SC index as a one-figure string, or integer
Returns:
Array index as an integer.
"""
try
:
return
SC
.
index
(
str
(
mosa
))
except
ValueError
as
error
:
raise
ValueError
(
f
"
invalid SC index
'
{
mosa
}
'"
)
from
error
SC1
=
sc2index
(
1
)
SC2
=
sc2index
(
2
)
SC3
=
sc2index
(
3
)
Loading