Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
NIFTy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
14
Issues
14
List
Boards
Labels
Service Desk
Milestones
Merge Requests
14
Merge Requests
14
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ift
NIFTy
Commits
2f6d4a97
Commit
2f6d4a97
authored
Apr 25, 2013
by
Marco Selig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bugfix in powerspectrum.draw_nd; callable spec.
parent
1482483d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
27 deletions
+50
-27
nifty_core.py
nifty_core.py
+47
-24
nifty_power.py
nifty_power.py
+2
-2
powerspectrum.py
powerspectrum.py
+1
-1
No files found.
nifty_core.py
View file @
2f6d4a97
...
...
@@ -2383,28 +2383,14 @@ class rg_space(space):
(default: 0).
"""
if
(
isinstance
(
spec
,
field
)):
spec
=
spec
.
val
.
astype
(
self
.
datatype
)
elif
(
np
.
isscalar
(
spec
)):
spec
=
np
.
array
([
spec
],
dtype
=
self
.
datatype
)
else
:
spec
=
np
.
array
(
spec
,
dtype
=
self
.
datatype
)
## check finiteness
if
(
not
np
.
all
(
np
.
isfinite
(
spec
))):
about
.
warnings
.
cprint
(
"WARNING: infinite value(s)."
)
## check positivity (excluding null)
if
(
np
.
any
(
spec
<
0
)):
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR: nonpositive value(s)."
))
elif
(
np
.
any
(
spec
==
0
)):
about
.
warnings
.
cprint
(
"WARNING: nonpositive value(s)."
)
if
(
size
is
None
):
if
(
size
is
None
)
or
(
callable
(
spec
))
:
## explicit kindex
if
(
"kindex"
in
kwargs
):
size
=
len
(
kwargs
.
get
(
"kindex"
)
)
kindex
=
kwargs
.
get
(
"kindex"
)
## quick kindex
elif
(
self
.
fourier
)
and
(
not
hasattr
(
self
,
"power_indices"
))
and
(
len
(
kwargs
)
==
0
):
size
=
gp
.
nklength
(
gp
.
nkdict
(
self
.
para
[:(
np
.
size
(
self
.
para
)
-
1
)
//
2
],
self
.
vol
,
fourier
=
True
))
kindex
=
gp
.
nklength
(
gp
.
nkdict
(
self
.
para
[:(
np
.
size
(
self
.
para
)
-
1
)
//
2
],
self
.
vol
,
fourier
=
True
))
## implicit kindex
else
:
try
:
...
...
@@ -2412,11 +2398,33 @@ class rg_space(space):
except
:
codomain
=
kwargs
.
get
(
"codomain"
,
self
.
get_codomain
())
codomain
.
set_power_indices
(
**
kwargs
)
size
=
len
(
codomain
.
power_indices
.
get
(
"kindex"
)
)
kindex
=
codomain
.
power_indices
.
get
(
"kindex"
)
else
:
size
=
len
(
self
.
power_indices
.
get
(
"kindex"
))
kindex
=
self
.
power_indices
.
get
(
"kindex"
)
size
=
len
(
kindex
)
if
(
isinstance
(
spec
,
field
)):
spec
=
spec
.
val
.
astype
(
self
.
datatype
)
elif
(
callable
(
spec
)):
try
:
spec
=
np
.
array
(
spec
(
kindex
),
dtype
=
self
.
datatype
)
except
:
TypeError
(
about
.
_errors
.
cstring
(
"ERROR: invalid power spectra function."
))
## exception in ``spec(kindex)``
elif
(
np
.
isscalar
(
spec
)):
spec
=
np
.
array
([
spec
],
dtype
=
self
.
datatype
)
else
:
spec
=
np
.
array
(
spec
,
dtype
=
self
.
datatype
)
## drop imaginary part
spec
=
np
.
real
(
spec
)
## check finiteness
if
(
not
np
.
all
(
np
.
isfinite
(
spec
))):
about
.
warnings
.
cprint
(
"WARNING: infinite value(s)."
)
## check positivity (excluding null)
if
(
np
.
any
(
spec
<
0
)):
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR: nonpositive value(s)."
))
elif
(
np
.
any
(
spec
==
0
)):
about
.
warnings
.
cprint
(
"WARNING: nonpositive value(s)."
)
## extend
if
(
np
.
size
(
spec
)
==
1
):
...
...
@@ -3482,10 +3490,18 @@ class lm_space(space):
"""
if
(
isinstance
(
spec
,
field
)):
spec
=
spec
.
val
.
astype
(
self
.
datatype
)
elif
(
callable
(
spec
)):
try
:
spec
=
np
.
array
(
spec
(
np
.
arange
(
self
.
para
[
0
]
+
1
,
dtype
=
np
.
int
)),
dtype
=
self
.
datatype
)
except
:
TypeError
(
about
.
_errors
.
cstring
(
"ERROR: invalid power spectra function."
))
## exception in ``spec(kindex)``
elif
(
np
.
isscalar
(
spec
)):
spec
=
np
.
array
([
spec
],
dtype
=
self
.
datatype
)
else
:
spec
=
np
.
array
(
spec
,
dtype
=
self
.
datatype
)
## drop imaginary part
spec
=
np
.
real
(
spec
)
## check finiteness
if
(
not
np
.
all
(
np
.
isfinite
(
spec
))):
about
.
warnings
.
cprint
(
"WARNING: infinite value(s)."
)
...
...
@@ -3496,9 +3512,6 @@ class lm_space(space):
about
.
warnings
.
cprint
(
"WARNING: nonpositive value(s)."
)
size
=
self
.
para
[
0
]
+
1
## lmax+1
## drop imaginary part
spec
=
np
.
real
(
spec
)
## extend
if
(
np
.
size
(
spec
)
==
1
):
spec
=
spec
*
np
.
ones
(
size
,
dtype
=
spec
.
dtype
,
order
=
'C'
)
...
...
@@ -4303,10 +4316,16 @@ class gl_space(space):
"""
if
(
isinstance
(
spec
,
field
)):
spec
=
spec
.
val
.
astype
(
self
.
datatype
)
elif
(
callable
(
spec
)):
try
:
spec
=
np
.
array
(
spec
(
np
.
arange
(
self
.
para
[
0
],
dtype
=
np
.
int
)),
dtype
=
self
.
datatype
)
except
:
TypeError
(
about
.
_errors
.
cstring
(
"ERROR: invalid power spectra function."
))
## exception in ``spec(kindex)``
elif
(
np
.
isscalar
(
spec
)):
spec
=
np
.
array
([
spec
],
dtype
=
self
.
datatype
)
else
:
spec
=
np
.
array
(
spec
,
dtype
=
self
.
datatype
)
## check finiteness
if
(
not
np
.
all
(
np
.
isfinite
(
spec
))):
about
.
warnings
.
cprint
(
"WARNING: infinite value(s)."
)
...
...
@@ -4317,7 +4336,6 @@ class gl_space(space):
about
.
warnings
.
cprint
(
"WARNING: nonpositive value(s)."
)
size
=
self
.
para
[
0
]
## nlat
## extend
if
(
np
.
size
(
spec
)
==
1
):
spec
=
spec
*
np
.
ones
(
size
,
dtype
=
spec
.
dtype
,
order
=
'C'
)
...
...
@@ -4930,10 +4948,16 @@ class hp_space(space):
"""
if
(
isinstance
(
spec
,
field
)):
spec
=
spec
.
val
.
astype
(
self
.
datatype
)
elif
(
callable
(
spec
)):
try
:
spec
=
np
.
array
(
spec
(
np
.
arange
(
3
*
self
.
para
[
0
],
dtype
=
np
.
int
)),
dtype
=
self
.
datatype
)
except
:
TypeError
(
about
.
_errors
.
cstring
(
"ERROR: invalid power spectra function."
))
## exception in ``spec(kindex)``
elif
(
np
.
isscalar
(
spec
)):
spec
=
np
.
array
([
spec
],
dtype
=
self
.
datatype
)
else
:
spec
=
np
.
array
(
spec
,
dtype
=
self
.
datatype
)
## check finiteness
if
(
not
np
.
all
(
np
.
isfinite
(
spec
))):
about
.
warnings
.
cprint
(
"WARNING: infinite value(s)."
)
...
...
@@ -4944,7 +4968,6 @@ class hp_space(space):
about
.
warnings
.
cprint
(
"WARNING: nonpositive value(s)."
)
size
=
3
*
self
.
para
[
0
]
## 3*nside
## extend
if
(
np
.
size
(
spec
)
==
1
):
spec
=
spec
*
np
.
ones
(
size
,
dtype
=
spec
.
dtype
,
order
=
'C'
)
...
...
nifty_power.py
View file @
2f6d4a97
...
...
@@ -213,7 +213,7 @@ def smooth_power(spec,domain=None,kindex=None,mode="2s",exclude=1,sigma=-1,**kwa
spec
=
spec
.
val
.
astype
(
kindex
.
dtype
)
elif
(
callable
(
spec
)):
try
:
spec
=
spec
(
kindex
)
spec
=
np
.
array
(
spec
(
kindex
),
dtype
=
kindex
.
dtype
)
except
:
TypeError
(
about
.
_errors
.
cstring
(
"ERROR: invalid power spectra function."
))
## exception in ``spec(kindex)``
elif
(
np
.
isscalar
(
spec
)):
...
...
@@ -640,7 +640,7 @@ def interpolate_power(spec,mode="linear",domain=None,kindex=None,newkindex=None,
spec
=
spec
.
val
.
astype
(
kindex
.
dtype
)
elif
(
callable
(
spec
)):
try
:
spec
=
spec
(
kindex
)
spec
=
np
.
array
(
spec
(
kindex
),
dtype
=
kindex
.
dtype
)
except
:
TypeError
(
about
.
_errors
.
cstring
(
"ERROR: invalid power spectra function."
))
## exception in ``spec(kindex)``
elif
(
np
.
isscalar
(
spec
)):
...
...
powerspectrum.py
View file @
2f6d4a97
...
...
@@ -68,7 +68,7 @@ def draw_vector_nd(axes,dgrid,ps,symtype=0,fourier=False,zerocentered=False,kpac
kdict
=
np
.
fft
.
fftshift
(
nkdict
(
axes
,
dgrid
,
fourier
))
klength
=
nklength
(
kdict
)
else
:
kdict
=
kpack
[
1
][
kpack
[
0
]
]
kdict
=
kpack
[
1
][
np
.
fft
.
ifftshift
(
kpack
[
0
],
axes
=
shiftaxes
(
zerocentered
,
st_to_zero_mode
=
False
))
]
klength
=
kpack
[
1
]
#output is in position space
...
...
Write
Preview
Markdown
is supported
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