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
cris_l1b
user
Commits
e7314e09
Commit
e7314e09
authored
Apr 19, 2022
by
R.K.Garcia
Browse files
Autoscale utility for CRISPCA files or other simple netcdf float arrays
parent
84442b88
Pipeline
#36876
passed with stage
in 7 minutes and 43 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pca/l1b-pcs/autoscale.py
View file @
e7314e09
...
...
@@ -76,8 +76,8 @@ class Autoscale:
def
attrs
(
self
):
""" CF attributes and fill value
"""
return
{
'scale'
:
np
.
array
(
self
.
scale
,
dtype
=
self
.
dtype
),
'offset'
:
np
.
array
(
self
.
offset
,
dtype
=
self
.
dtype
),
return
{
'scale
_factor
'
:
np
.
array
(
self
.
scale
,
dtype
=
self
.
dtype
),
'
add_
offset'
:
np
.
array
(
self
.
offset
,
dtype
=
self
.
dtype
),
'_FillValue'
:
self
.
vnan
}
...
...
pca/l1b-pcs/nc_copy_autoscale.py
0 → 100755
View file @
e7314e09
#!/usr/bin/env python3
import
netCDF4
as
nc4
from
pathlib
import
Path
from
autoscale
import
Autoscale
def
copy
(
input_fn
:
Path
,
output_fn
:
Path
):
nci
=
nc4
.
Dataset
(
input_fn
,
'r'
)
nco
=
nc4
.
Dataset
(
output_fn
,
'w'
)
for
dname
,
dextent
in
nci
.
dimensions
.
items
():
nco
.
createDimension
(
dname
,
len
(
dextent
))
for
gname
in
nci
.
ncattrs
():
nco
.
setncattr
(
gname
,
getattr
(
nci
,
gname
))
for
vname
,
vdata
in
nci
.
variables
.
items
():
nd
=
vdata
[:]
sc
=
Autoscale
(
nd
)
sca
=
sc
.
attrs
scale
=
sca
[
'scale_factor'
]
offset
=
sca
[
'add_offset'
]
print
(
f
"scaling
{
vname
}
as m=
{
scale
}
b=
{
offset
}
"
)
ovdata
=
nco
.
createVariable
(
vname
,
sc
.
vdtype
,
vdata
.
dimensions
,
fill_value
=
sc
.
vnan
,
zlib
=
True
)
ovdata
.
set_auto_scale
(
False
)
ovdata
.
setncattr
(
'scale_factor'
,
scale
)
ovdata
.
setncattr
(
'add_offset'
,
offset
)
for
attr_name
in
vdata
.
ncattrs
():
if
attr_name
!=
'_FillValue'
:
setattr
(
ovdata
,
attr_name
,
vdata
[
attr_name
])
ovdata
[:]
=
sc
.
convert
(
nd
)
nco
.
close
()
nci
.
close
()
if
__name__
==
'__main__'
:
import
sys
ip
=
Path
(
sys
.
argv
[
1
])
op
=
Path
(
sys
.
argv
[
2
])
assert
not
op
.
exists
()
copy
(
ip
,
op
)
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