Skip to content

Commit

Permalink
Move GAC header attributes to config file
Browse files Browse the repository at this point in the history
  • Loading branch information
sfinkens committed Jul 8, 2020
1 parent c0f4584 commit daf88c2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion bin/pygac-fdr-run
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ if __name__ == '__main__':
LOG.info('Processing file {}'.format(filename))
try:
scene = read_gac(filename, reader_kwargs=config['controls'].get('reader_kwargs'))
writer = NetcdfWriter(global_attrs=config.get('metadata'),
writer = NetcdfWriter(global_attrs=config.get('global_attrs'),
gac_header_attrs=config.get('gac_header_attrs'),
fname_fmt=config['output'].get('fname_fmt'),
encoding=config['netcdf'].get('encoding'),
engine=config['netcdf'].get('engine'),
Expand Down
6 changes: 5 additions & 1 deletion etc/pygac-fdr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ controls:
output:
output_dir: /data/avhrr_gac/output/
fname_fmt: AVHRR-GAC_FDR_{processing_level}_{platform}_{start_time}_{end_time}_{processing_mode}_{disposition_mode}_{creation_time}_{version_int:04d}.nc
metadata:
global_attrs:
id: DOI:10.5676/EUM/AVHRR_GAC_L1C_FDR/V0100
title: AVHRR GAC L1C FDR
product_version: 1.0.0
Expand Down Expand Up @@ -44,6 +44,10 @@ metadata:
standard_name_vocabulary: CF Standard Name Table v73
licence: EUMETSAT data policy https://www.eumetsat.int/website/home/AboutUs/WhoWeAre/LegalFramework/DataPolicy/index.html
history:
gac_header_attrs:
title: Raw GAC Header
references: >-
NOAA POD & KLM user guides, https://www1.ncdc.noaa.gov/pub/data/satellite/publications/podguides/
netcdf:
engine: netcdf4
encoding:
Expand Down
6 changes: 4 additions & 2 deletions pygac_fdr/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,14 @@ class NetcdfWriter:
time_fmt = '%Y%m%dT%H%M%SZ'
def_engine = 'netcdf4'

def __init__(self, global_attrs=None, encoding=None, engine=None, fname_fmt=None, debug=None):
def __init__(self, global_attrs=None, gac_header_attrs=None, encoding=None, engine=None,
fname_fmt=None, debug=None):
"""
Args:
debug: If True, use constant creation time in output filenames.
"""
self.global_attrs = global_attrs or {}
self.gac_header_attrs = gac_header_attrs or {}
self.engine = engine or self.def_engine
self.fname_fmt = fname_fmt or self.def_fname_fmt
self.debug = bool(debug)
Expand Down Expand Up @@ -392,7 +394,7 @@ def _append_gac_header(self, filename, header):
"""Append raw GAC header to the given netCDF file."""
LOG.info('Appending GAC header')
data_vars = dict([(name, header[name]) for name in header.dtype.names])
header = xr.Dataset(data_vars, attrs={'title': 'Raw GAC header'})
header = xr.Dataset(data_vars, attrs=self.gac_header_attrs)
header.to_netcdf(filename, mode='a', group='gac_header')

def write(self, scene, output_dir=None):
Expand Down

0 comments on commit daf88c2

Please sign in to comment.