Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cspp-geo-gridded-glm
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
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
cspp_geo
cspp-geo-gridded-glm
Commits
2cf618c9
Commit
2cf618c9
authored
4 years ago
by
Nick Bearson
Browse files
Options
Downloads
Patches
Plain Diff
add traceability attributes to our output files (fixes #3)
parent
9530d3da
No related branches found
No related tags found
1 merge request
!6
Resolve "add tracability attributes to grid (and maybe tile) files"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gridded_glm/libexec/_minute_gridder.py
+27
-0
27 additions, 0 deletions
gridded_glm/libexec/_minute_gridder.py
with
27 additions
and
0 deletions
gridded_glm/libexec/_minute_gridder.py
+
27
−
0
View file @
2cf618c9
...
@@ -21,6 +21,8 @@ import tempfile
...
@@ -21,6 +21,8 @@ import tempfile
import
shutil
import
shutil
import
atexit
import
atexit
from
glob
import
glob
from
glob
import
glob
import
socket
from
netCDF4
import
Dataset
#from multiprocessing import freeze_support # https://docs.python.org/2/library/multiprocessing.html#multiprocessing.freeze_support
#from multiprocessing import freeze_support # https://docs.python.org/2/library/multiprocessing.html#multiprocessing.freeze_support
from
functools
import
partial
from
functools
import
partial
from
lmatools.grid.make_grids
import
write_cf_netcdf_latlon
,
write_cf_netcdf_noproj
,
write_cf_netcdf_fixedgrid
from
lmatools.grid.make_grids
import
write_cf_netcdf_latlon
,
write_cf_netcdf_noproj
,
write_cf_netcdf_fixedgrid
...
@@ -186,6 +188,25 @@ def grid_setup(args, work_dir=os.getcwd()):
...
@@ -186,6 +188,25 @@ def grid_setup(args, work_dir=os.getcwd()):
return
gridder
,
args
.
filenames
,
start_time
,
end_time
,
grid_kwargs
return
gridder
,
args
.
filenames
,
start_time
,
end_time
,
grid_kwargs
def
get_cspp_gglm_version
():
try
:
version_filename
=
os
.
path
.
join
(
os
.
getenv
(
'
CSPP_GEO_GGLM_HOME
'
),
"
.VERSION.txt
"
)
return
open
(
version_filename
,
'
r
'
).
read
()
except
:
return
"
unknown
"
def
add_gglm_attrs
(
netcdf_filename
,
input_filenames
):
try
:
nc
=
Dataset
(
netcdf_filename
,
'
a
'
)
setattr
(
nc
,
'
cspp_geo_gglm_version
'
,
get_cspp_gglm_version
())
setattr
(
nc
,
'
cspp_geo_gglm_production_host
'
,
socket
.
gethostname
())
setattr
(
nc
,
'
cspp_geo_gglm_input_files
'
,
"
,
"
.
join
(
input_filenames
))
# this probably needs to be added somewhere else?
nc
.
close
()
except
:
log
.
error
(
"
could not add CSPP Geo GGLM attributes to {}
"
.
format
(
netcdf_filename
))
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
# freeze_support() # nb. I don't think this is needed as we're not making windows execs at this time
# freeze_support() # nb. I don't think this is needed as we're not making windows execs at this time
parser
=
create_parser
()
parser
=
create_parser
()
...
@@ -222,6 +243,11 @@ if __name__ == '__main__':
...
@@ -222,6 +243,11 @@ if __name__ == '__main__':
gridded_files
=
glob
(
gridded_path
)
gridded_files
=
glob
(
gridded_path
)
log
.
debug
(
gridded_files
)
log
.
debug
(
gridded_files
)
# we need to add attributes here due to an issue where satpy (or its dependencies) are
# holding the input gridded file open until the process exits
for
f
in
gridded_files
:
add_gglm_attrs
(
f
,
glm_filenames
)
# (optionally) do tiling
# (optionally) do tiling
if
args
.
create_tiles
:
if
args
.
create_tiles
:
from
satpy
import
Scene
from
satpy
import
Scene
...
@@ -252,6 +278,7 @@ if __name__ == '__main__':
...
@@ -252,6 +278,7 @@ if __name__ == '__main__':
tiled_path
=
os
.
path
.
join
(
tempdir_path
,
'
OR_GLM-L2-GLM?-M?_G??_T??_*.nc
'
)
tiled_path
=
os
.
path
.
join
(
tempdir_path
,
'
OR_GLM-L2-GLM?-M?_G??_T??_*.nc
'
)
tiled_files
=
glob
(
tiled_path
)
tiled_files
=
glob
(
tiled_path
)
for
f
in
tiled_files
:
for
f
in
tiled_files
:
add_gglm_attrs
(
f
,
glm_filenames
)
shutil
.
move
(
f
,
os
.
path
.
join
(
args
.
output_dir
,
os
.
path
.
basename
(
f
)))
shutil
.
move
(
f
,
os
.
path
.
join
(
args
.
output_dir
,
os
.
path
.
basename
(
f
)))
for
f
in
gridded_files
:
for
f
in
gridded_files
:
shutil
.
move
(
f
,
os
.
path
.
join
(
args
.
output_dir
,
os
.
path
.
basename
(
f
)))
shutil
.
move
(
f
,
os
.
path
.
join
(
args
.
output_dir
,
os
.
path
.
basename
(
f
)))
...
...
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