Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
goesr
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ray Garcia
goesr
Commits
ada75c9e
Commit
ada75c9e
authored
8 years ago
by
Ray Garcia
Browse files
Options
Downloads
Patches
Plain Diff
rad_count_dist with plotting utility
parent
78e34b87
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
goesr/rad_count_dist.py
+58
-0
58 additions, 0 deletions
goesr/rad_count_dist.py
with
58 additions
and
0 deletions
goesr/rad_count_dist.py
0 → 100644
+
58
−
0
View file @
ada75c9e
#!/usr/bin/env python
"""
Compute distribution of unscaled pixel values in GOES-16 ABI L1B files
Copyright 2017 University of Wisconsin Regents
License: GPLv3 as of 2017-01-01
Author: R.K.Garcia <rayg@ssec.wisc.edu>
Recommended runtime: Python 3.6 with netCDF4, numba, numpy, e.g. Continuum.IO Anaconda
"""
import
netCDF4
as
nc4
import
numpy
as
np
import
numba
def
load
(
ncfilename
,
varname
):
nc
=
nc4
.
Dataset
(
ncfilename
)
nc
.
set_auto_scale
(
False
)
ncv
=
nc
[
varname
]
counts
=
ncv
[:]
bit_depth
=
ncv
.
sensor_band_bit_depth
splat
=
counts
.
ravel
()
return
splat
,
bit_depth
@numba.jit
((
numba
.
int16
[:],
numba
.
int32
))
def
dist
(
splat
,
bit_depth
):
z
=
np
.
zeros
((
2
**
bit_depth
,),
dtype
=
np
.
uint32
)
for
v
in
splat
:
z
[
v
]
+=
1
return
z
def
hist
(
pngname
,
filename
,
distribution
,
extra
=
''
):
import
matplotlib
matplotlib
.
use
(
'
Agg
'
)
import
matplotlib.pyplot
as
plt
fig
=
plt
.
figure
(
figsize
=
(
60
,
20
))
ax
=
fig
.
add_subplot
(
111
)
#, axisbg='#EEEEEE')
# ax.grid(color='white', linestyle='solid')
ax
.
grid
()
ax
.
plot
(
np
.
log
(
distribution
+
1
),
'
.
'
)
ax
.
set_xlabel
(
'
unscaled pixel value
'
)
ax
.
set_ylabel
(
'
log(occurrences+1)
'
)
ax
.
set_title
(
'
log(n+1) {} value distribution
'
.
format
(
filename
)
+
extra
)
fig
.
savefig
(
pngname
)
if
__name__
==
'
__main__
'
:
import
sys
,
os
if
len
(
sys
.
argv
)
==
1
:
print
(
"
parameters: netcdf-filename counts-variable-name optional-histogram optional-histogram-bins
"
)
ncfilename
,
varname
=
sys
.
argv
[
1
:
3
]
splat
,
bit_depth
=
load
(
ncfilename
,
varname
)
distribution
=
dist
(
splat
,
bit_depth
)
uniq
=
np
.
argwhere
(
distribution
!=
0
).
squeeze
()
fn
=
os
.
path
.
split
(
ncfilename
)[
-
1
]
nvals
=
len
(
uniq
)
print
(
"
{} of {} unique values in {}
"
.
format
(
nvals
,
2
**
bit_depth
,
fn
))
if
len
(
sys
.
argv
)
>=
4
:
stem
=
sys
.
argv
[
3
]
with
open
(
stem
+
'
.tsv
'
,
'
wt
'
)
as
fp
:
fp
.
write
(
'
\n
'
.
join
([
'
{}
\t
{}
'
.
format
(
i
,
x
)
for
i
,
x
in
enumerate
(
distribution
)])
+
'
\n
'
)
hist
(
stem
+
'
.png
'
,
fn
,
distribution
,
'
{} unique values of {}
'
.
format
(
nvals
,
2
**
bit_depth
))
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