1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
# Copyright (c) 2024-2025 Satpy developers
#
# This file is part of satpy.
#
# satpy 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.
#
# satpy 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
# satpy. If not, see <http://www.gnu.org/licenses/>.
"""Script to create image testing references.
Script to create reference images for the automated image testing system.
The input data directory must follow the data structure from the
image-comparison-tests repository with satellite_data/<satellite-name>.
This script is a work in progress and expected to change significantly.
DO NOT USE FOR OPERATIONAL PRODUCTION!
"""
import argparse
import os
import pathlib
import hdf5plugin # noqa: F401
from satpy import Scene
def generate_images(props):
"""Generate reference images for testing purposes.
Args:
props (namespace): Object with attributes corresponding to command line
arguments as defined by :func:get_parser.
"""
filenames = (props.basedir / "satellite_data" / props.satellite /
props.case).glob("*")
if "," in props.reader:
reader = props.reader.split(",")
resampler = "nearest" # use nearest when combining with cloud mask
else:
reader = props.reader
resampler = "gradient_search"
scn = Scene(reader=reader, filenames=filenames)
scn.load(props.composites)
if props.area == "native":
ls = scn.resample(resampler="native")
elif props.area is not None:
ls = scn.resample(props.area, resampler=resampler)
else:
ls = scn
from dask.diagnostics import ProgressBar
with ProgressBar():
ls.save_datasets(
writer="simple_image",
filename=os.fspath(
props.basedir / "reference_images" /
"satpy-reference-image-{platform_name}-{sensor}-"
"{start_time:%Y%m%d%H%M}-{area.area_id}-{name}.png"))
def get_parser():
"""Return argument parser."""
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"satellite", action="store", type=str,
help="Satellite name.")
parser.add_argument(
"reader", action="store", type=str,
help="Reader name. Multiple readers (if needed) can be comma-seperated.")
parser.add_argument(
"case", help="case to generate", type=str)
parser.add_argument(
"-b", "--basedir", action="store", type=pathlib.Path,
default=pathlib.Path("."),
help="Base directory for reference data. "
"This must contain a subdirectories satellite_data and "
"reference_images. The directory satellite_data must contain "
"input data in a subdirectory for the satellite and case. Output images "
"will be written to the subdirectory reference_images.")
parser.add_argument(
"-c", "--composites", nargs="+", help="composites to generate",
type=str, default=["ash", "airmass"])
parser.add_argument(
"-a", "--area", action="store",
default=None,
help="Area name, or 'native' (native resampling)")
return parser
def main():
"""Main function."""
parsed = get_parser().parse_args()
generate_images(parsed)
if __name__ == "__main__":
main()
|