Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Neel Shah
NIFTy
Commits
046d074c
Commit
046d074c
authored
Nov 02, 2019
by
Martin Reinecke
Browse files
Merge branch 'total_volume' into 'NIFTy_5'
Add total_volume property to DomainTuple See merge request
!359
parents
b43ef800
f14b80e3
Changes
3
Hide whitespace changes
Inline
Side-by-side
nifty5/domain_tuple.py
View file @
046d074c
...
...
@@ -19,6 +19,8 @@ from functools import reduce
from
.
import
utilities
from
.domains.domain
import
Domain
import
numpy
as
np
class
DomainTuple
(
object
):
"""Ordered sequence of Domain objects.
...
...
@@ -125,6 +127,58 @@ class DomainTuple(object):
"""
return
self
.
_size
def
scalar_weight
(
self
,
spaces
=
None
):
"""Returns the uniform volume element for a sub-domain of `self`.
Parameters
----------
spaces : int, tuple of int or None
Indices of the sub-domains to be considered.
If `None`, the entire domain is used.
Returns
-------
float or None
If the requested sub-domain has a uniform volume element, it is
returned. Otherwise, `None` is returned.
"""
if
np
.
isscalar
(
spaces
):
return
self
.
_dom
[
spaces
].
scalar_dvol
if
spaces
is
None
:
spaces
=
range
(
len
(
self
.
_dom
))
res
=
1.
for
i
in
spaces
:
tmp
=
self
.
_dom
[
i
].
scalar_dvol
if
tmp
is
None
:
return
None
res
*=
tmp
return
res
def
total_volume
(
self
,
spaces
=
None
):
"""Returns the total volume of `self` or of a subspace of it.
Parameters
----------
spaces : int, tuple of int or None
Indices of the sub-domains of the domain to be considered.
If `None`, the total volume of the whole domain is returned.
Returns
-------
float
the total volume of the requested (sub-)domain.
"""
if
np
.
isscalar
(
spaces
):
return
self
.
_dom
[
spaces
].
total_volume
if
spaces
is
None
:
spaces
=
range
(
len
(
self
.
_dom
))
res
=
1.
for
i
in
spaces
:
res
*=
self
.
_dom
[
i
].
total_volume
return
res
@
property
def
axes
(
self
):
"""tuple of tuple of int : axis indices of the underlying domains"""
...
...
nifty5/field.py
View file @
046d074c
...
...
@@ -246,42 +246,23 @@ class Field(object):
If the requested sub-domain has a uniform volume element, it is
returned. Otherwise, `None` is returned.
"""
if
np
.
isscalar
(
spaces
):
return
self
.
_domain
[
spaces
].
scalar_dvol
if
spaces
is
None
:
spaces
=
range
(
len
(
self
.
_domain
))
res
=
1.
for
i
in
spaces
:
tmp
=
self
.
_domain
[
i
].
scalar_dvol
if
tmp
is
None
:
return
None
res
*=
tmp
return
res
return
self
.
_domain
.
scalar_weight
(
spaces
)
def
total_volume
(
self
,
spaces
=
None
):
"""Returns the total volume of
a sub-
domain of
`self`
.
"""Returns the total volume of
the field's
domain
or
of
a subspace of it
.
Parameters
----------
spaces : int, tuple of int or None
Indices of the sub-domains of the field's domain to be considered.
If `None`, the
entir
e domain is
us
ed.
If `None`, the
total volume of the whol
e domain is
return
ed.
Returns
-------
float
the total volume of the requested sub-domain.
the total volume of the requested
(
sub-
)
domain.
"""
if
np
.
isscalar
(
spaces
):
return
self
.
_domain
[
spaces
].
total_volume
if
spaces
is
None
:
spaces
=
range
(
len
(
self
.
_domain
))
res
=
1.
for
i
in
spaces
:
res
*=
self
.
_domain
[
i
].
total_volume
return
res
return
self
.
_domain
.
total_volume
(
spaces
)
def
weight
(
self
,
power
=
1
,
spaces
=
None
):
"""Weights the pixels of `self` with their invidual pixel volumes.
...
...
test/test_field.py
View file @
046d074c
...
...
@@ -219,17 +219,23 @@ def test_weight():
f
=
ift
.
Field
.
full
(
s1
,
10.
)
f2
=
f
.
weight
(
1
)
assert_equal
(
f
.
weight
(
1
).
local_data
,
f2
.
local_data
)
assert_equal
(
f
.
domain
.
total_volume
(),
1
)
assert_equal
(
f
.
domain
.
total_volume
(
0
),
1
)
assert_equal
(
f
.
domain
.
total_volume
((
0
,)),
1
)
assert_equal
(
f
.
total_volume
(),
1
)
assert_equal
(
f
.
total_volume
(
0
),
1
)
assert_equal
(
f
.
total_volume
((
0
,)),
1
)
assert_equal
(
f
.
domain
.
scalar_weight
(),
0.1
)
assert_equal
(
f
.
domain
.
scalar_weight
(
0
),
0.1
)
assert_equal
(
f
.
domain
.
scalar_weight
((
0
,)),
0.1
)
assert_equal
(
f
.
scalar_weight
(),
0.1
)
assert_equal
(
f
.
scalar_weight
(
0
),
0.1
)
assert_equal
(
f
.
scalar_weight
((
0
,)),
0.1
)
s1
=
ift
.
GLSpace
(
10
)
f
=
ift
.
Field
.
full
(
s1
,
10.
)
assert_equal
(
f
.
scalar_weight
(),
None
)
assert_equal
(
f
.
scalar_weight
(
0
),
None
)
assert_equal
(
f
.
scalar_weight
((
0
,)),
None
)
assert_equal
(
f
.
domain
.
scalar_weight
(),
None
)
assert_equal
(
f
.
domain
.
scalar_weight
(
0
),
None
)
assert_equal
(
f
.
domain
.
scalar_weight
((
0
,)),
None
)
@
pmp
(
'dom'
,
[
ift
.
RGSpace
(
10
),
ift
.
GLSpace
(
10
)])
...
...
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