Toggle navigation
Ocean Color Science Software
Jump to content
ocssw
V2022
web
ocssw
ocssw_src
src
scripts
convert2ocrvc.py
Go to the documentation of this file.
1
#!/usr/bin/env python3
2
#
3
import
sys
4
from
netCDF4
import
Dataset
5
6
if
len(sys.argv) != 2:
7
print(
'usage:'
, sys.argv[0],
'<L3b file>'
)
8
print(
' convert an L3 bin file with the following products to'
)
9
print(
' an OCRVC sensor L3 bin file:'
)
10
print(
' Rrs_vc_412'
)
11
print(
' Rrs_vc_443'
)
12
print(
' Rrs_vc_490'
)
13
print(
' Rrs_vc_510'
)
14
print(
' Rrs_vc_555'
)
15
print(
' Rrs_vc_670'
)
16
sys.exit(1)
17
18
inFile = sys.argv[1]
19
rootgrp = Dataset(inFile,
'a'
)
20
datagrp = rootgrp.groups[
'level-3_binned_data'
]
21
22
# make sure it is a L3b file
23
if
'Level-3 Binned Data'
not
in
rootgrp.title:
24
print(inFile,
'is not a L3 bin file'
)
25
sys.exit(1)
26
27
# change global attrbutes
28
rootgrp.title =
'OCRVC Level-3 Binned Data'
29
rootgrp.instrument =
'OCRVC'
30
rootgrp.platform =
'OCRVC'
31
#rootgrp.history += ', Convert to OCRVC sensor'
32
33
datagrp.renameVariable(
'Rrs_vc_412'
,
'Rrs_412'
)
34
datagrp.renameVariable(
'Rrs_vc_443'
,
'Rrs_443'
)
35
datagrp.renameVariable(
'Rrs_vc_490'
,
'Rrs_490'
)
36
datagrp.renameVariable(
'Rrs_vc_510'
,
'Rrs_510'
)
37
datagrp.renameVariable(
'Rrs_vc_531'
,
'Rrs_531'
)
38
datagrp.renameVariable(
'Rrs_vc_555'
,
'Rrs_555'
)
39
datagrp.renameVariable(
'Rrs_vc_670'
,
'Rrs_670'
)
40
41
rootgrp.close()
42
43
print(
'Converted'
, inFile,
'to an OCRVC bin file.'
)
44
45
sys.exit(0)