Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pygwinc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kevin Kuns
pygwinc
Commits
4c87d005
Commit
4c87d005
authored
3 years ago
by
Kevin Kuns
Browse files
Options
Downloads
Patches
Plain Diff
make BudgetItem.freq a property; setter recurses and clears precomp cache
parent
c606f75b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#337957
passed
3 years ago
Stage: dist
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
gwinc/__init__.py
+3
-3
3 additions, 3 deletions
gwinc/__init__.py
gwinc/nb.py
+18
-5
18 additions, 5 deletions
gwinc/nb.py
test/budgets/test_budgets.py
+36
-0
36 additions, 0 deletions
test/budgets/test_budgets.py
with
57 additions
and
8 deletions
gwinc/__init__.py
+
3
−
3
View file @
4c87d005
...
...
@@ -44,8 +44,8 @@ def freq_from_spec(spec=None):
return
spec
elif
spec
is
None
:
spec
=
DEFAULT_FREQ
fspec
=
spec
.
split
(
'
:
'
)
try
:
fspec
=
spec
.
split
(
'
:
'
)
if
len
(
fspec
)
==
2
:
fspec
=
fspec
[
0
],
DEFAULT_FREQ
.
split
(
'
:
'
)[
1
],
fspec
[
1
]
return
np
.
logspace
(
...
...
@@ -53,7 +53,7 @@ def freq_from_spec(spec=None):
np
.
log10
(
float
(
fspec
[
2
])),
int
(
fspec
[
1
]),
)
except
(
ValueError
,
IndexError
):
except
(
ValueError
,
IndexError
,
AttributeError
):
raise
InvalidFrequencySpec
(
f
'
Improper frequency specification:
{
spec
}
'
)
...
...
@@ -154,7 +154,7 @@ def load_budget(name_or_path, freq=None, bname=None):
mod
,
modpath
=
load_module
(
modname
)
Budget
=
getattr
(
mod
,
bname
)
if
freq
is
None
:
freq
=
getattr
(
Budget
,
'
freq
'
,
None
)
freq
=
getattr
(
Budget
,
'
_
freq
'
,
None
)
freq
=
freq_from_spec
(
freq
)
ifopath
=
os
.
path
.
join
(
modpath
,
'
ifo.yaml
'
)
if
not
ifo
and
os
.
path
.
exists
(
ifopath
):
...
...
This diff is collapsed.
Click to expand it.
gwinc/nb.py
+
18
−
5
View file @
4c87d005
...
...
@@ -139,9 +139,8 @@ class BudgetItem:
variables to the initialized object.
"""
if
freq
is
not
None
:
assert
isinstance
(
freq
,
np
.
ndarray
)
self
.
freq
=
freq
assert
isinstance
(
freq
,
np
.
ndarray
)
or
freq
is
None
self
.
_freq
=
freq
self
.
ifo
=
None
for
key
,
val
in
kwargs
.
items
():
setattr
(
self
,
key
,
val
)
...
...
@@ -153,6 +152,20 @@ class BudgetItem:
""""
Name of this BudgetItem class.
"""
return
self
.
__class__
.
__name__
@property
def
freq
(
self
):
"""
Frequency array [Hz]
"""
return
self
.
_freq
@freq.setter
def
freq
(
self
,
val
):
assert
isinstance
(
val
,
np
.
ndarray
)
# clear the precomp cache
self
.
_precomp
=
dict
()
# use update instead of setting _freq directly so that Budget.update
# recurses through all cal_objs and noise_objs
self
.
update
(
_freq
=
val
)
def
__str__
(
self
):
# FIXME: provide info on internal state (load/update/calc/etc.)
return
'
<{} {}>
'
.
format
(
...
...
@@ -353,7 +366,7 @@ class Budget(Noise):
if
freq
is
not
None
:
self
.
kwargs
[
'
freq
'
]
=
freq
else
:
self
.
kwargs
[
'
freq
'
]
=
getattr
(
self
,
'
freq
'
,
None
)
self
.
kwargs
[
'
freq
'
]
=
getattr
(
self
,
'
_
freq
'
,
None
)
# FIXME: special casing the ifo kwarg here, in case it's
# defined as a class attribute rather than passed at
# initialization. we do this because we're not defining a
...
...
@@ -498,7 +511,7 @@ class Budget(Noise):
logger
.
debug
(
"
load {}
"
.
format
(
item
))
item
.
load
()
def
update
(
self
,
_precomp
=
None
,
**
kwargs
):
def
update
(
self
,
**
kwargs
):
"""
Recursively update all noise and cal objects with supplied kwargs.
See BudgetItem.update() for more info.
...
...
This diff is collapsed.
Click to expand it.
test/budgets/test_budgets.py
+
36
−
0
View file @
4c87d005
...
...
@@ -47,3 +47,39 @@ def test_change_ifo_struct():
assert
np
.
all
(
tr2
.
Seismic
.
SeismicVertical
.
asd
==
2
*
tr1
.
Seismic
.
SeismicVertical
.
asd
)
@pytest.mark.logic
@pytest.mark.fast
def
test_update_freq
():
"""
Test three methods of updating a Budget frequency
"""
freq1
=
np
.
logspace
(
1
,
3
,
10
)
freq2
=
np
.
logspace
(
0.8
,
3.5
,
11
)
freq3
=
np
.
logspace
(
0.5
,
3.6
,
12
)
budget
=
gwinc
.
load_budget
(
'
Aplus
'
,
freq
=
freq1
)
traces1
=
budget
.
run
()
traces2
=
budget
.
run
(
freq
=
freq2
)
budget
.
freq
=
freq3
traces3
=
budget
.
run
()
assert
np
.
all
(
traces1
.
freq
==
freq1
)
assert
np
.
all
(
traces2
.
freq
==
freq2
)
assert
np
.
all
(
traces3
.
freq
==
freq3
)
@pytest.mark.logic
@pytest.mark.fast
def
test_freq_spec_error
():
"""
Test that three methods of setting Budget frequencies raise errors
"""
freq
=
[
1
,
2
,
3
]
with
pytest
.
raises
(
gwinc
.
InvalidFrequencySpec
):
budget
=
gwinc
.
load_budget
(
'
Aplus
'
,
freq
=
freq
)
with
pytest
.
raises
(
AssertionError
):
budget
=
gwinc
.
load_budget
(
'
Aplus
'
)
traces
=
budget
.
run
(
freq
=
freq
)
with
pytest
.
raises
(
AssertionError
):
budget
=
gwinc
.
load_budget
(
'
Aplus
'
)
budget
.
freq
=
freq
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment