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
Caillat Michel
yafits
Commits
b3c9215e
Commit
b3c9215e
authored
Nov 29, 2019
by
Caillat Michel
Browse files
Code cleaning and debugging - Nothing fundamental
parent
cb126a45
Changes
1
Hide whitespace changes
Inline
Side-by-side
yafitss/DataBlock.py
View file @
b3c9215e
...
...
@@ -404,21 +404,15 @@ class DataBlock:
def
__getSumOverSliceRectArea_0
(
self
,
iFREQ
,
iRA0
=
None
,
iRA1
=
None
,
iDEC0
=
None
,
iDEC1
=
None
):
self
.
__logger
.
debug
(
"__getSumOverSliceRectArea_0: entering"
)
with_dask
=
True
if
with_dask
:
if
self
.
__header
[
"NAXIS"
]
>
2
:
x
=
(
dask
.
array
.
nansum
(
self
.
__data
[
iFREQ
,
iDEC0
:
iDEC1
,
iRA0
:
iRA1
])
/
self
.
__convert
*
self
.
__cdelt
).
compute
().
tolist
()
else
:
x
=
(
dask
.
array
.
nansum
(
self
.
__data
[
iDEC0
:
iDEC1
,
iRA0
:
iRA1
])
/
self
.
__convert
*
self
.
__cdelt
).
compute
().
tolist
()
else
:
if
self
.
__header
[
"NAXIS"
]
>
2
:
x
=
np
.
nansum
(
self
.
__data
[
iFREQ
,
iDEC0
:
iDEC1
,
iRA0
:
iRA1
])
/
self
.
__convert
*
self
.
__cdelt
else
:
x
=
np
.
nansum
(
self
.
__data
[
iDEC0
:
iDEC1
,
iRA0
:
iRA1
])
/
self
.
__convert
*
self
.
__cdelt
if
self
.
__header
[
"NAXIS"
]
>
2
:
result
=
(
dask
.
array
.
nansum
(
self
.
__data
[
iFREQ
,
iDEC0
:
iDEC1
,
iRA0
:
iRA1
])
/
self
.
__convert
*
self
.
__cdelt
).
compute
().
tolist
()
else
:
result
=
(
dask
.
array
.
nansum
(
self
.
__data
[
iDEC0
:
iDEC1
,
iRA0
:
iRA1
])
/
self
.
__convert
*
self
.
__cdelt
).
compute
().
tolist
()
self
.
__logger
.
debug
(
"__getSumOverSliceRectArea__0: exiting"
)
return
x
return
result
def
__getAverage_0
(
self
,
iFREQ0
=
None
,
iFREQ1
=
None
,
iDEC0
=
None
,
iDEC1
=
None
,
iRA0
=
None
,
iRA1
=
None
):
self
.
__logger
.
debug
(
"__getAverage_0: entering"
)
...
...
@@ -438,12 +432,6 @@ class DataBlock:
iFREQ1
=
self
.
__data
.
shape
[
0
]
self
.
__logger
.
debug
(
f
"
{
iFREQ0
}
,
{
iFREQ1
}
,
{
iDEC0
}
,
{
iDEC1
}
,
{
iRA0
}
,
{
iRA1
}
"
)
if
self
.
__data
.
shape
[
0
]
==
1
:
res
=
self
.
__data
self
.
__logger
.
debug
(
"Returning"
)
return
res
res
=
[[]]
*
(
iDEC1
-
iDEC0
+
1
)
if
(
self
.
__header
[
"ORIGIN"
]
==
"GILDAS Consortium"
):
self
.
__logger
.
debug
(
"Gildas data"
)
...
...
@@ -467,24 +455,18 @@ class DataBlock:
self
.
__logger
.
debug
(
"slice sum begin"
)
with_dask
=
True
if
with_dask
:
if
self
.
__header
[
"NAXIS"
]
>
2
:
res
=
(
dask
.
array
.
nansum
(
self
.
__data
[
iFREQ0
:
iFREQ1
,
iDEC0
:
iDEC1
,
iRA0
:
iRA1
],
0
)
*
cdelt
)
else
:
res
=
(
dask
.
array
.
nansum
(
self
.
__data
[
iDEC0
:
iDEC1
,
iRA0
:
iRA1
],
0
)
*
cdelt
)
self
.
__collectStatistics
(
"%d-%d"
%
(
iFREQ0
,
iFREQ1
),
res
.
compute
())
if
self
.
__header
[
"NAXIS"
]
>
2
:
result
=
(
dask
.
array
.
nansum
(
self
.
__data
[
iFREQ0
:
iFREQ1
,
iDEC0
:
iDEC1
,
iRA0
:
iRA1
],
0
)
*
cdelt
).
compute
()
else
:
if
self
.
__header
[
"NAXIS"
]
>
2
:
res
=
np
.
nansum
(
self
.
__data
[
iFREQ0
:
iFREQ1
,
iDEC0
:
iDEC1
,
iRA0
:
iRA1
],
0
)
*
cdelt
else
:
res
=
np
.
nansum
(
self
.
__data
[
iFREQ0
:
iFREQ1
,
iDEC0
:
iDEC1
,
iRA0
:
iRA1
],
0
)
*
cdelt
self
.
__collectStatistics
(
"%d-%d"
%
(
iFREQ0
,
iFREQ1
),
res
)
result
=
self
.
__data
[
iDEC0
:
iDEC1
,
iRA0
:
iRA1
]
*
cdelt
.
compute
()
self
.
__collectStatistics
(
"%d-%d"
%
(
iFREQ0
,
iFREQ1
),
result
)
self
.
__logger
.
debug
(
"slice sum end"
)
self
.
__logger
.
debug
(
f
"res=
{
res
}
"
)
self
.
__logger
.
debug
(
f
"res
ult
=
{
res
ult
}
"
)
self
.
__logger
.
debug
(
"__getAverage_0: exiting"
)
return
res
return
res
ult
def
__getPercentile
(
self
,
a
,
percent
):
return
np
.
nanpercentile
(
a
,
percent
)
...
...
@@ -704,12 +686,12 @@ class DataBlock:
def
getDimensions
(
self
):
return
{
"status"
:
True
,
"message"
:
""
,
"result"
:
self
.
__data
.
shape
}
def
__collectStatistics
(
self
,
key
,
data
):
def
__collectStatistics
(
self
,
key
,
data
):
# data is expected to be a numpy array
self
.
__logger
.
debug
(
"__collectStatistics : entering"
)
if
key
in
self
.
__statistics
:
self
.
__logger
.
debug
(
"Statistics are already collected
"
)
self
.
__logger
.
debug
(
"Statistics are already collected
for key %s"
%
key
)
else
:
self
.
__logger
.
debug
(
"Statistics have to be collected
"
)
self
.
__logger
.
debug
(
"Statistics have to be collected
for key %s"
%
key
)
results
=
[]
t
=
dd
(
np
.
nanmin
)(
data
);
results
.
append
(
t
)
t
=
dd
(
np
.
nanmax
)(
data
);
results
.
append
(
t
)
...
...
@@ -731,22 +713,22 @@ class DataBlock:
def
__getSlice
(
self
,
iFREQ
,
step
=
1
):
self
.
__logger
.
debug
(
"__getSlice: entering"
)
x
=
None
result
=
None
numDimensions
=
len
(
self
.
__data
.
shape
)
if
numDimensions
==
2
:
x
=
self
.
__data
[
0
:
self
.
__data
.
shape
[
0
]:
step
,
0
:
self
.
__data
.
shape
[
1
]:
step
]
result
=
self
.
__data
[
0
:
self
.
__data
.
shape
[
0
]:
step
,
0
:
self
.
__data
.
shape
[
1
]:
step
]
elif
numDimensions
==
3
:
if
iFREQ
==
None
:
iFREQ
=
self
.
__data
.
shape
[
0
]
/
2
x
=
self
.
__data
[
iFREQ
,
0
:
self
.
__data
.
shape
[
1
]:
step
,
0
:
self
.
__data
.
shape
[
2
]:
step
]
result
=
self
.
__data
[
iFREQ
,
0
:
self
.
__data
.
shape
[
1
]:
step
,
0
:
self
.
__data
.
shape
[
2
]:
step
]
#
# Collect some statistics if not already done
#
self
.
__collectStatistics
(
"%d"
%
iFREQ
,
x
.
compute
())
self
.
__collectStatistics
(
"%d"
%
iFREQ
,
result
.
compute
())
self
.
__logger
.
debug
(
"__getSlice: exiting"
)
return
x
return
result
# A DASK array
def
getSlice
(
self
,
iFREQ
,
step
=
1
):
self
.
__logger
.
debug
(
"getSlice: entering"
)
...
...
@@ -772,7 +754,7 @@ class DataBlock:
result
[
"message"
]
=
""
result
[
"result"
]
=
{}
result
[
"result"
][
"slice"
]
=
x
.
tolist
()
result
[
"result"
][
"statistics"
]
=
self
.
__statistics
[
iFREQ
]
result
[
"result"
][
"statistics"
]
=
self
.
__statistics
[
"%d"
%
iFREQ
]
except
Exception
as
e
:
result
[
"message"
]
=
f
"An exception occurred with message
{
e
}
"
result
[
"status"
]
=
False
...
...
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