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
ef5dde19
Commit
ef5dde19
authored
Sep 16, 2017
by
Theo Steininger
Browse files
Put the binbound methods in PowerSpace in the right section.
parent
a0434ced
Changes
1
Hide whitespace changes
Inline
Sidebyside
nifty/spaces/power_space/power_space.py
View file @
ef5dde19
...
...
@@ 85,72 +85,6 @@ class PowerSpace(Space):
# Overwritten properties and methods
@
staticmethod
def
linear_binbounds
(
nbin
,
first_bound
,
last_bound
):
"""
nbin: integer
the number of bins
first_bound, last_bound: float
the k values for the right boundary of the first bin and the left
boundary of the last bin, respectively. They are given in length
units of the harmonic partner space.
This will produce a binbounds array with nbin1 entries with
binbounds[0]=first_bound and binbounds[1]=last_bound and the remaining
values equidistantly spaced (in linear scale) between these two.
"""
nbin
=
int
(
nbin
)
assert
nbin
>=
3
,
"nbin must be at least 3"
return
np
.
linspace
(
float
(
first_bound
),
float
(
last_bound
),
nbin

1
)
@
staticmethod
def
logarithmic_binbounds
(
nbin
,
first_bound
,
last_bound
):
"""
nbin: integer
the number of bins
first_bound, last_bound: float
the k values for the right boundary of the first bin and the left
boundary of the last bin, respectively. They are given in length
units of the harmonic partner space.
This will produce a binbounds array with nbin1 entries with
binbounds[0]=first_bound and binbounds[1]=last_bound and the remaining
values equidistantly spaced (in natural logarithmic scale)
between these two.
"""
nbin
=
int
(
nbin
)
assert
nbin
>=
3
,
"nbin must be at least 3"
return
np
.
logspace
(
np
.
log
(
float
(
first_bound
)),
np
.
log
(
float
(
last_bound
)),
nbin

1
,
base
=
np
.
e
)
@
staticmethod
def
useful_binbounds
(
space
,
logarithmic
,
nbin
=
None
):
if
not
(
isinstance
(
space
,
Space
)
and
space
.
harmonic
):
raise
ValueError
(
"first argument must be a harmonic space."
)
if
logarithmic
is
None
and
nbin
is
None
:
return
None
nbin
=
None
if
nbin
is
None
else
int
(
nbin
)
logarithmic
=
bool
(
logarithmic
)
dists
=
space
.
get_unique_distances
()
if
len
(
dists
)
<
3
:
raise
ValueError
(
"Space does not have enough unique k lengths"
)
lbound
=
0.5
*
(
dists
[
0
]
+
dists
[
1
])
rbound
=
0.5
*
(
dists
[

2
]
+
dists
[

1
])
dists
[
0
]
=
lbound
dists
[

1
]
=
rbound
if
logarithmic
:
dists
=
np
.
log
(
dists
)
binsz_min
=
np
.
max
(
np
.
diff
(
dists
))
nbin_max
=
int
((
dists
[

1
]

dists
[
0
])
/
binsz_min
)
+
2
if
nbin
is
None
:
nbin
=
nbin_max
assert
nbin
>=
3
,
"nbin must be at least 3"
if
nbin
>
nbin_max
:
raise
ValueError
(
"nbin is too large"
)
if
logarithmic
:
return
PowerSpace
.
logarithmic_binbounds
(
nbin
,
lbound
,
rbound
)
else
:
return
PowerSpace
.
linear_binbounds
(
nbin
,
lbound
,
rbound
)
def
__init__
(
self
,
harmonic_partner
,
distribution_strategy
=
None
,
binbounds
=
None
):
super
(
PowerSpace
,
self
).
__init__
()
...
...
@@ 321,6 +255,72 @@ class PowerSpace(Space):
"""
return
self
.
_rho
@
staticmethod
def
linear_binbounds
(
nbin
,
first_bound
,
last_bound
):
"""
nbin: integer
the number of bins
first_bound, last_bound: float
the k values for the right boundary of the first bin and the left
boundary of the last bin, respectively. They are given in length
units of the harmonic partner space.
This will produce a binbounds array with nbin1 entries with
binbounds[0]=first_bound and binbounds[1]=last_bound and the remaining
values equidistantly spaced (in linear scale) between these two.
"""
nbin
=
int
(
nbin
)
assert
nbin
>=
3
,
"nbin must be at least 3"
return
np
.
linspace
(
float
(
first_bound
),
float
(
last_bound
),
nbin

1
)
@
staticmethod
def
logarithmic_binbounds
(
nbin
,
first_bound
,
last_bound
):
"""
nbin: integer
the number of bins
first_bound, last_bound: float
the k values for the right boundary of the first bin and the left
boundary of the last bin, respectively. They are given in length
units of the harmonic partner space.
This will produce a binbounds array with nbin1 entries with
binbounds[0]=first_bound and binbounds[1]=last_bound and the remaining
values equidistantly spaced (in natural logarithmic scale)
between these two.
"""
nbin
=
int
(
nbin
)
assert
nbin
>=
3
,
"nbin must be at least 3"
return
np
.
logspace
(
np
.
log
(
float
(
first_bound
)),
np
.
log
(
float
(
last_bound
)),
nbin

1
,
base
=
np
.
e
)
@
staticmethod
def
useful_binbounds
(
space
,
logarithmic
,
nbin
=
None
):
if
not
(
isinstance
(
space
,
Space
)
and
space
.
harmonic
):
raise
ValueError
(
"first argument must be a harmonic space."
)
if
logarithmic
is
None
and
nbin
is
None
:
return
None
nbin
=
None
if
nbin
is
None
else
int
(
nbin
)
logarithmic
=
bool
(
logarithmic
)
dists
=
space
.
get_unique_distances
()
if
len
(
dists
)
<
3
:
raise
ValueError
(
"Space does not have enough unique k lengths"
)
lbound
=
0.5
*
(
dists
[
0
]
+
dists
[
1
])
rbound
=
0.5
*
(
dists
[

2
]
+
dists
[

1
])
dists
[
0
]
=
lbound
dists
[

1
]
=
rbound
if
logarithmic
:
dists
=
np
.
log
(
dists
)
binsz_min
=
np
.
max
(
np
.
diff
(
dists
))
nbin_max
=
int
((
dists
[

1
]

dists
[
0
])
/
binsz_min
)
+
2
if
nbin
is
None
:
nbin
=
nbin_max
assert
nbin
>=
3
,
"nbin must be at least 3"
if
nbin
>
nbin_max
:
raise
ValueError
(
"nbin is too large"
)
if
logarithmic
:
return
PowerSpace
.
logarithmic_binbounds
(
nbin
,
lbound
,
rbound
)
else
:
return
PowerSpace
.
linear_binbounds
(
nbin
,
lbound
,
rbound
)
# Serialization
def
_to_hdf5
(
self
,
hdf5_group
):
...
...
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