Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
lofar-scripts-repo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vlad Kondratiev
lofar-scripts-repo
Commits
0deb2ff6
Commit
0deb2ff6
authored
6 months ago
by
Vlad Kondratiev
Browse files
Options
Downloads
Patches
Plain Diff
labels improved, png filename now has also stokes component and scrunching factors
parent
7151e732
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
l2com/plot-bf-hdf5-spectrum.py
+15
-10
15 additions, 10 deletions
l2com/plot-bf-hdf5-spectrum.py
with
15 additions
and
10 deletions
l2com/plot-bf-hdf5-spectrum.py
+
15
−
10
View file @
0deb2ff6
...
...
@@ -42,6 +42,7 @@ def read_hdf5_file(fname, tscrunch, fscrunch, memory_usage_limit):
group_name
=
f
"
{
sap_id
}
/
{
beam_id
}
"
beamno
=
int
(
beam_id
[
5
:])
chanpersub
=
h5
[
group_name
].
attrs
[
"
CHANNELS_PER_SUBBAND
"
]
chanbw
=
h5
[
group_name
].
attrs
[
"
CHANNEL_WIDTH
"
]
# in Hz
freq
=
h5
[
group_name
+
"
/COORDINATES/COORDINATE_1
"
].
attrs
[
"
AXIS_VALUES_WORLD
"
]
tsamp
=
h5
[
group_name
+
"
/COORDINATES/COORDINATE_0
"
].
attrs
[
"
INCREMENT
"
]
...
...
@@ -51,10 +52,12 @@ def read_hdf5_file(fname, tscrunch, fscrunch, memory_usage_limit):
nof
=
h5
[
group_name
].
attrs
[
"
NOF_STOKES
"
]
if
nof
>
1
:
print
(
f
"
\n
Warning: there are more than 1 Stokes component in the file, only the first one will be read!
"
)
#stokes_ids = [key for key in h5[group_name].keys() if "STOKES" in key]
(
nsamp
,
nchan
)
=
np
.
shape
(
h5
[
group_name
+
"
/STOKES_0
"
])
dtype
=
np
.
dtype
(
h5
[
group_name
+
"
/STOKES_0
"
])
stokes_comp
=
h5
[
group_name
+
"
/STOKES_0
"
].
attrs
[
"
STOKES_COMPONENT
"
]
stokes_ids
=
[
key
for
key
in
h5
[
group_name
].
keys
()
if
"
STOKES_
"
in
key
]
stokes_group
=
group_name
+
"
/
"
+
stokes_ids
[
0
]
(
nsamp
,
nchan
)
=
np
.
shape
(
h5
[
stokes_group
])
dtype
=
np
.
dtype
(
h5
[
stokes_group
])
stokes_comp
=
h5
[
stokes_group
].
attrs
[
"
STOKES_COMPONENT
"
]
nsubs
=
h5
[
stokes_group
].
attrs
[
"
NOF_SUBBANDS
"
]
itemsize
=
np
.
dtype
(
dtype
).
itemsize
# size of an element in bytes
nsamp_fromfile
=
int
(
os
.
path
.
getsize
(
rawfile
)
/
nchan
/
itemsize
)
...
...
@@ -73,7 +76,7 @@ def read_hdf5_file(fname, tscrunch, fscrunch, memory_usage_limit):
print
(
f
"
Expected RAM usage is >
{
memory_usage_limit
}
% of the total RAM (
{
expected_ram_usage
*
100.
/
ramsize
:
.
1
f
}
%,
{
expected_ram_usage_GB
}
GB)
"
)
print
(
"
(based on lofar-default.lua AOFlagger strategy)
"
)
print
(
f
"
Reading of the input file will be done in
{
nsteps
}
steps
"
)
print
(
"
You can also decrease the RAM usage by
t
scrunching the data
"
)
print
(
"
You can also decrease the RAM usage by scrunching the data
"
)
print
(
""
)
else
:
nsteps
=
1
...
...
@@ -119,7 +122,7 @@ def read_hdf5_file(fname, tscrunch, fscrunch, memory_usage_limit):
# f-scrunching the freq values as well
freq
=
np
.
mean
(
np
.
reshape
(
freq
,
(
int
(
nchan
/
fscrunch
),
fscrunch
)),
axis
=
1
)
return
(
tsamp
,
freq
,
chanbw
,
data
,
stations
,
nstations
,
band
,
antenna_set
,
stokes_comp
,
obsid
,
targets
)
return
(
tsamp
,
freq
,
chanbw
,
chanpersub
,
nsubs
,
data
,
stations
,
nstations
,
band
,
antenna_set
,
stokes_comp
,
obsid
,
targets
)
###
###--- m a i n ---
...
...
@@ -143,7 +146,7 @@ if __name__ == "__main__":
args
=
parser
.
parse_args
()
# Read data
(
tsamp
,
freq
,
chanbw
,
data
,
stations
,
nstations
,
band
,
antenna_set
,
stokes
,
obsid
,
targets
)
=
\
(
tsamp
,
freq
,
chanbw
,
chanpersub
,
nsubs
,
data
,
stations
,
nstations
,
band
,
antenna_set
,
stokes
,
obsid
,
targets
)
=
\
read_hdf5_file
(
args
.
h5file
,
args
.
tscrunch
,
args
.
fscrunch
,
args
.
memory_usage_limit
)
nsamp
,
nchan
=
data
.
shape
# here nsamp is already t-scrunched
freq
*=
1e-6
# in MHz
...
...
@@ -205,7 +208,7 @@ if __name__ == "__main__":
fig
,
(
ax1
,
ax2
,
ax3
)
=
plt
.
subplots
(
3
,
1
,
figsize
=
(
18
,
8
),
sharex
=
True
,
gridspec_kw
=
{
"
height_ratios
"
:
[
0.1
,
0.2
,
0.7
],
"
hspace
"
:
0.02
})
# Top RFI fraction subplot
ax1
.
set_title
(
f
"
L
{
obsid
}
|
{
antenna_set
}
|
{
band
}
| Nstations =
{
nstations
}
|
{
stations
}
"
,
loc
=
'
left
'
)
ax1
.
set_title
(
f
"
L
{
obsid
}
|
{
antenna_set
}
|
{
band
}
|
Nsub:
{
nsubs
}
| Nchan/sub =
{
chanpersub
}
|
Nstations =
{
nstations
}
|
{
stations
}
"
,
loc
=
'
left
'
)
ax1
.
set_title
(
f
"
{
targets
}
| Stokes:
{
stokes
}
"
,
loc
=
'
right
'
)
ax1
.
set_ylabel
(
"
RFI (%)
"
)
ax1
.
set_ylim
(
-
10
,
110
)
...
...
@@ -214,7 +217,6 @@ if __name__ == "__main__":
ax1
.
legend
(
loc
=
1
)
# Average spectrum
print
(
freq
)
ax2
.
plot
(
freq
,
z
,
color
=
"
k
"
,
linewidth
=
0.5
)
ax2
.
set_ylabel
(
"
Power (dB)
"
)
ax2
.
set_ylim
(
vmin
,
vmax
)
...
...
@@ -232,8 +234,11 @@ if __name__ == "__main__":
img
=
ax3
.
imshow
(
v
,
origin
=
"
lower
"
,
aspect
=
"
auto
"
,
interpolation
=
"
None
"
,
extent
=
[
fmin
,
fmax
,
tmin
,
tmax
],
vmin
=
vmin
,
vmax
=
vmax
)
ax3
.
set_xlabel
(
"
Frequency (MHz)
"
)
ax3
.
set_ylabel
(
"
Time (s)
"
)
ax3label
=
f
"
Tscrunch:
{
args
.
tscrunch
}
Fscrunch:
{
args
.
fscrunch
}
"
props
=
dict
(
boxstyle
=
'
round
'
,
facecolor
=
'
white
'
,
alpha
=
0.7
)
ax3
.
text
(
0.01
,
0.95
,
ax3label
,
transform
=
ax3
.
transAxes
,
fontsize
=
10
,
verticalalignment
=
'
center
'
,
bbox
=
props
)
fig
.
colorbar
(
img
,
ax
=
ax3
,
location
=
"
bottom
"
,
orientation
=
"
horizontal
"
,
label
=
"
Power (dB)
"
,
shrink
=
1
,
pad
=
0.12
,
fraction
=
0.05
)
plt
.
savefig
(
f
"
L
{
obsid
}
_bf_spectrum.png
"
,
bbox_inches
=
"
tight
"
)
plt
.
savefig
(
f
"
L
{
obsid
}
_bf_spectrum
_stokes
{
stokes
}
_tscr
{
args
.
tscrunch
}
_fscr
{
args
.
fscrunch
}
.png
"
,
bbox_inches
=
"
tight
"
)
plt
.
show
()
plt
.
close
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment