diff --git a/bin/pygac-fdr-dump b/bin/pygac-fdr-dump new file mode 100755 index 0000000..9a02cc9 --- /dev/null +++ b/bin/pygac-fdr-dump @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2020 pygac-fdr developers +# +# This file is part of pygac-fdr. +# +# pygac-fdr is free software: you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# pygac-fdr is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# pygac-fdr. If not, see . +"""Print contents of metadata database.""" + +import argparse +import pandas as pd + +from pygac_fdr.metadata import MetadataCollector + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('dbfile', help='Metadata database') + parser.add_argument('-n', help='Maximum number of rows to be printed', + type=int) + args = parser.parse_args() + + collector = MetadataCollector() + mda = collector.read_sql(args.dbfile) + + pd.set_option('display.max_rows', args.n) + pd.set_option('display.max_columns', None) + pd.set_option('display.width', None) + pd.set_option('display.max_colwidth', 22) + + print(mda) diff --git a/bin/pygac-fdr-mda-collect b/bin/pygac-fdr-mda-collect index 625183c..7025980 100755 --- a/bin/pygac-fdr-mda-collect +++ b/bin/pygac-fdr-mda-collect @@ -41,14 +41,7 @@ if __name__ == '__main__': parser.add_argument('--verbose', action='store_true', help='Increase verbosity') args = parser.parse_args() logging_on(logging.DEBUG if args.verbose else logging.INFO) - if args.verbose: - import pandas as pd - pd.set_option('display.max_rows', None) - pd.set_option('display.max_columns', None) - pd.set_option('display.width', None) - pd.set_option('display.max_colwidth', 22) collector = MetadataCollector() mda = collector.get_metadata(args.filenames) - LOG.debug(mda) collector.save_sql(mda, args.dbfile, args.if_exists) diff --git a/pygac_fdr/reader.py b/pygac_fdr/reader.py index c4cb053..fb5e9e7 100644 --- a/pygac_fdr/reader.py +++ b/pygac_fdr/reader.py @@ -20,6 +20,8 @@ import os import satpy +import trollsift + BANDS = ['1', '2', '3', '3a', '3b', '4', '5'] AUX_DATA = ['latitude', @@ -30,6 +32,8 @@ 'solar_azimuth_angle', 'sensor_azimuth_angle', 'sun_sensor_azimuth_difference_angle'] +GAC_FORMAT = '{creation_site:3s}.{transfer_mode:4s}.{platform_id:2s}.D{start_time:%y%j.S%H%M}.' \ + 'E{end_time:%H%M}.B{orbit_number:05d}{end_orbit_last_digits:02d}.{station:2s}' def read_gac(filename, reader_kwargs=None): @@ -47,10 +51,11 @@ def read_gac(filename, reader_kwargs=None): scene.load(AUX_DATA) # Add additional metadata - fname_info = scene.readers['avhrr_l1b_gaclac'].file_handlers['gac_lac_l1b'][0].filename_info + basename = os.path.basename(filename) + fname_info = trollsift.parse(GAC_FORMAT, basename) orbit_number_end = fname_info['orbit_number'] // 100 * 100 + fname_info['end_orbit_last_digits'] scene.attrs.update({ - 'gac_filename': os.path.basename(filename), + 'gac_filename': basename, 'orbit_number_start': fname_info['orbit_number'], 'orbit_number_end': orbit_number_end, 'ground_station': fname_info['station'] diff --git a/pygac_fdr/writer.py b/pygac_fdr/writer.py index 406a296..34edea3 100644 --- a/pygac_fdr/writer.py +++ b/pygac_fdr/writer.py @@ -39,7 +39,7 @@ DATASET_NAMES = { '1': 'reflectance_channel_1', '2': 'reflectance_channel_2', - '3': 'reflectance_channel_3', + '3': 'brightness_temperature_channel_3', '3a': 'reflectance_channel_3a', '3b': 'brightness_temperature_channel_3b', '4': 'brightness_temperature_channel_4', diff --git a/setup.py b/setup.py index 441ca83..202901f 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ if __name__ == '__main__': requires = ['setuptools_scm', 'numpy', 'xarray >=0.15.1', 'pandas >=1.0.3', 'netCDF4', - 'h5py', 'pygac >=1.3.1', 'satpy >=0.21.0', 'pyyaml'] + 'h5py', 'pygac >=1.3.1', 'satpy >=0.21.0', 'pyyaml', 'trollsift'] README = open('README.md', 'r').read() setup(name='pygac-fdr', description='Python package for creating a Fundamental Data Record (FDR) of AVHRR GAC '