Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ift
NIFTy
Commits
698d5799
Commit
698d5799
authored
Jun 05, 2013
by
Marco Selig
Browse files
pundex improved.
parent
c7163ebd
Changes
2
Hide whitespace changes
Inline
Side-by-side
nifty_core.py
View file @
698d5799
...
...
@@ -1133,7 +1133,8 @@ class space(object):
about
.
warnings
.
cprint
(
"WARNING: 'get_power_undex' is deprecated."
)
if
(
pindex
is
None
):
pindex
=
self
.
get_power_index
(
irreducible
=
False
)
return
list
(
np
.
unravel_index
(
np
.
unique
(
pindex
,
return_index
=
True
,
return_inverse
=
False
)[
1
],
pindex
.
shape
,
order
=
'C'
))
# return list(np.unravel_index(np.unique(pindex,return_index=True,return_inverse=False)[1],pindex.shape,order='C')) ## < version 0.4
return
np
.
unique
(
pindex
,
return_index
=
True
,
return_inverse
=
False
)[
1
]
def
set_power_indices
(
self
,
**
kwargs
):
"""
...
...
@@ -2567,7 +2568,7 @@ class rg_space(space):
if
(
np
.
any
(
rho
==
0
)):
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR: empty bin(s)."
))
## binning too fine
## power undex
pundex
=
list
(
np
.
unravel_index
(
np
.
unique
(
pindex
,
return_index
=
True
,
return_inverse
=
False
)[
1
]
,
pindex
.
shape
,
order
=
'C'
))
pundex
=
np
.
unique
(
pindex
,
return_index
=
True
,
return_inverse
=
False
)[
1
]
## storage
self
.
power_indices
=
{
"config"
:
config
,
"kindex"
:
kindex
,
"pindex"
:
pindex
,
"pundex"
:
pundex
,
"rho"
:
rho
}
## alphabetical
about
.
infos
.
cprint
(
" done."
)
...
...
@@ -3620,7 +3621,7 @@ class lm_space(space):
kindex
=
np
.
arange
(
self
.
para
[
0
]
+
1
,
dtype
=
np
.
int
)
rho
=
2
*
kindex
+
1
pindex
=
hp
.
Alm
.
getlm
(
self
.
para
[
0
],
i
=
None
)[
0
]
## l of (l,m)
pundex
=
list
(
np
.
unravel_index
(
np
.
unique
(
pindex
,
return_index
=
True
,
return_inverse
=
False
)[
1
]
,
pindex
.
shape
,
order
=
'C'
))
pundex
=
np
.
unique
(
pindex
,
return_index
=
True
,
return_inverse
=
False
)[
1
]
## storage
self
.
power_indices
=
{
"kindex"
:
kindex
,
"pindex"
:
pindex
,
"pundex"
:
pundex
,
"rho"
:
rho
}
## alphabetical
# about.infos.cprint(" done.")
...
...
@@ -9383,15 +9384,12 @@ class power_operator(diagonal_operator):
if
(
not
np
.
all
(
np
.
array
(
np
.
shape
(
pindex
))
==
self
.
domain
.
dim
(
split
=
True
))):
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR: shape mismatch ( "
+
str
(
np
.
array
(
np
.
shape
(
pindex
)))
+
" <> "
+
str
(
self
.
domain
.
dim
(
split
=
True
))
+
" )."
))
## quick pundex
pundex
=
list
(
np
.
unravel_index
(
np
.
unique
(
pindex
,
return_index
=
True
,
return_inverse
=
False
)[
1
]
,
pindex
.
shape
,
order
=
'C'
))
pundex
=
np
.
unique
(
pindex
,
return_index
=
True
,
return_inverse
=
False
)[
1
]
## check explicit pundex
else
:
if
(
not
isinstance
(
pundex
,
list
)):
raise
TypeError
(
about
.
_errors
.
cstring
(
"ERROR: invalid input."
))
elif
(
len
(
pundex
)
!=
np
.
size
(
self
.
domain
.
dim
(
split
=
True
))):
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR: dimension mismatch ( "
+
str
(
len
(
pundex
))
+
" <> "
+
str
(
np
.
size
(
self
.
domain
.
dim
(
split
=
True
)))
+
" )."
))
pundex
=
np
.
array
(
pundex
,
dtype
=
np
.
int
)
return
diag
[
pundex
]
return
diag
.
flatten
(
order
=
'C'
)
[
pundex
]
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
...
...
nifty_power.py
View file @
698d5799
...
...
@@ -111,10 +111,10 @@ def weight_power(domain,spec,power=1,pindex=None,pundex=None,**kwargs):
pindex
=
domain
.
power_indices
.
get
(
"pindex"
)
if
(
pundex
is
None
):
pundex
=
domain
.
power_indices
.
get
(
"pundex"
)
el
if
(
not
isinstance
(
pundex
,
list
))
:
raise
TypeError
(
about
.
_errors
.
cstring
(
"ERROR: invalid input."
)
)
elif
(
len
(
pundex
)
!=
np
.
size
(
domain
.
dim
(
split
=
True
))
):
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR:
dimension
mismatch ( "
+
str
(
len
(
pundex
))
+
" <> "
+
str
(
np
.
size
(
domain
.
dim
(
split
=
True
))
)
+
" )."
))
el
se
:
pundex
=
np
.
array
(
pundex
,
dtype
=
np
.
int
)
if
(
np
.
size
(
pundex
)
!=
np
.
max
(
pindex
,
axis
=
None
,
out
=
None
)
+
1
):
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR:
size
mismatch ( "
+
str
(
np
.
size
(
pundex
))
+
" <> "
+
str
(
np
.
max
(
pindex
,
axis
=
None
,
out
=
None
)
+
1
)
+
" )."
))
## check explicit power indices
else
:
pindex
=
np
.
array
(
pindex
,
dtype
=
np
.
int
)
...
...
@@ -122,13 +122,13 @@ def weight_power(domain,spec,power=1,pindex=None,pundex=None,**kwargs):
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR: shape mismatch ( "
+
str
(
np
.
array
(
np
.
shape
(
pindex
)))
+
" <> "
+
str
(
domain
.
dim
(
split
=
True
))
+
" )."
))
if
(
pundex
is
None
):
## quick pundex
pundex
=
list
(
np
.
unravel_index
(
np
.
unique
(
pindex
,
return_index
=
True
,
return_inverse
=
False
)[
1
]
,
pindex
.
shape
,
order
=
'C'
))
el
if
(
not
isinstance
(
pundex
,
list
))
:
raise
TypeError
(
about
.
_errors
.
cstring
(
"ERROR: invalid input."
)
)
elif
(
len
(
pundex
)
!=
np
.
size
(
domain
.
dim
(
split
=
True
))
):
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR:
dimension
mismatch ( "
+
str
(
len
(
pundex
))
+
" <> "
+
str
(
np
.
size
(
domain
.
dim
(
split
=
True
))
)
+
" )."
))
pundex
=
np
.
unique
(
pindex
,
return_index
=
True
,
return_inverse
=
False
)[
1
]
el
se
:
pundex
=
np
.
array
(
pundex
,
dtype
=
np
.
int
)
if
(
np
.
size
(
pundex
)
!=
np
.
max
(
pindex
,
axis
=
None
,
out
=
None
)
+
1
):
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR:
size
mismatch ( "
+
str
(
np
.
size
(
pundex
))
+
" <> "
+
str
(
np
.
max
(
pindex
,
axis
=
None
,
out
=
None
)
+
1
)
+
" )."
))
return
np
.
real
(
domain
.
calc_weight
(
domain
.
enforce_power
(
spec
,
size
=
np
.
max
(
pindex
,
axis
=
None
,
out
=
None
)
+
1
)[
pindex
],
power
=
power
)[
pundex
])
return
np
.
real
(
domain
.
calc_weight
(
domain
.
enforce_power
(
spec
,
size
=
np
.
max
(
pindex
,
axis
=
None
,
out
=
None
)
+
1
)[
pindex
],
power
=
power
)
.
flatten
(
order
=
'C'
)
[
pundex
])
##-----------------------------------------------------------------------------
...
...
@@ -441,14 +441,9 @@ def infer_power(m,domain=None,Sk=None,D=None,pindex=None,pundex=None,kindex=None
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR: invalid input."
))
else
:
pindex
=
domain
.
power_indices
.
get
(
"pindex"
)
pundex
=
domain
.
power_indices
.
get
(
"pundex"
)
kindex
=
domain
.
power_indices
.
get
(
"kindex"
)
rho
=
domain
.
power_indices
.
get
(
"rho"
)
if
(
pundex
is
None
):
pundex
=
domain
.
power_indices
.
get
(
"pundex"
)
elif
(
not
isinstance
(
pundex
,
list
)):
raise
TypeError
(
about
.
_errors
.
cstring
(
"ERROR: invalid input."
))
elif
(
len
(
pundex
)
!=
np
.
size
(
domain
.
dim
(
split
=
True
))):
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR: dimension mismatch ( "
+
str
(
len
(
pundex
))
+
" <> "
+
str
(
np
.
size
(
domain
.
dim
(
split
=
True
)))
+
" )."
))
## check explicit power indices
else
:
pindex
=
np
.
array
(
pindex
,
dtype
=
np
.
int
)
...
...
@@ -458,11 +453,9 @@ def infer_power(m,domain=None,Sk=None,D=None,pindex=None,pundex=None,kindex=None
rho
=
np
.
array
(
rho
,
dtype
=
np
.
int
)
if
(
pundex
is
None
):
## quick pundex
pundex
=
list
(
np
.
unravel_index
(
np
.
unique
(
pindex
,
return_index
=
True
,
return_inverse
=
False
)[
1
],
pindex
.
shape
,
order
=
'C'
))
elif
(
not
isinstance
(
pundex
,
list
)):
raise
TypeError
(
about
.
_errors
.
cstring
(
"ERROR: invalid input."
))
elif
(
len
(
pundex
)
!=
np
.
size
(
domain
.
dim
(
split
=
True
))):
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR: dimension mismatch ( "
+
str
(
len
(
pundex
))
+
" <> "
+
str
(
np
.
size
(
domain
.
dim
(
split
=
True
)))
+
" )."
))
pundex
=
np
.
unique
(
pindex
,
return_index
=
True
,
return_inverse
=
False
)[
1
]
else
:
pundex
=
np
.
array
(
pundex
,
dtype
=
np
.
int
)
## check projection operator
if
(
Sk
is
None
):
Sk
=
projection_operator
(
domain
,
assign
=
pindex
)
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment