Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clip negative FCI radiances #3013

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
16 changes: 9 additions & 7 deletions satpy/tests/behave/features/image_comparison.feature
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
Feature: Image Comparison

Scenario Outline: Compare generated image with reference image
Given I have a <composite> reference image file from <satellite>
When I generate a new <composite> image file from <satellite>
Given I have a <composite> reference image file from <satellite> resampled to <area>
When I generate a new <composite> image file from <satellite> with <reader> for <area>
Then the generated image should be the same as the reference image

Examples:
|satellite |composite |
|GOES17 |airmass |
|GOES16 |airmass |
|GOES16 |ash |
|GOES17 |ash |
|satellite |composite | reader | area |
|Meteosat-12 | cloudtop | fci_l1c_nc | sve |
|Meteosat-12 | night_microphysics | fci_l1c_nc | sve |
|GOES17 |airmass | abi_l1b | null |
|GOES16 |airmass | abi_l1b | null |
|GOES16 |ash | abi_l1b | null |
|GOES17 |ash | abi_l1b | null |
23 changes: 15 additions & 8 deletions satpy/tests/behave/features/steps/image_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# satpy. If not, see <http://www.gnu.org/licenses/>.
"""Image comparison tests."""

import hdf5plugin # noqa: F401 isort:skip
import os
import warnings
from datetime import datetime
Expand Down Expand Up @@ -51,34 +52,40 @@
use_fixture(before_all, Context)

setup_hooks()
@given("I have a {composite} reference image file from {satellite}")
def step_given_reference_image(context, composite, satellite):
@given("I have a {composite} reference image file from {satellite} resampled to {area}")
def step_given_reference_image(context, composite, satellite, area):
"""Prepare a reference image."""
reference_image = f"reference_image_{satellite}_{composite}.png"
reference_image = f"satpy-reference-image-{satellite}-{composite}-{area}.png"
context.reference_image = cv2.imread(f"{ext_data_path}/reference_images/{reference_image}")
context.satellite = satellite
context.composite = composite
context.area = area


@when("I generate a new {composite} image file from {satellite}")
def step_when_generate_image(context, composite, satellite):
@when("I generate a new {composite} image file from {satellite} with {reader} for {area}")
def step_when_generate_image(context, composite, satellite, reader, area):
"""Generate test images."""
os.environ["OMP_NUM_THREADS"] = os.environ["MKL_NUM_THREADS"] = "2"
os.environ["PYTROLL_CHUNK_SIZE"] = "1024"
warnings.simplefilter("ignore")
dask.config.set(scheduler="threads", num_workers=4)

# Get the list of satellite files to open
filenames = glob(f"{ext_data_path}/satellite_data/{satellite}/*.nc")

scn = Scene(reader="abi_l1b", filenames=filenames)
scn = Scene(reader=reader, filenames=filenames)

scn.load([composite])

if area == "null":
ls = scn
else:
ls = scn.resample(area, resampler="gradient_search")

# Save the generated image in the generated folder
generated_image_path = os.path.join(context.test_results_dir, "generated",
f"generated_{context.satellite}_{context.composite}.png")
scn.save_datasets(writer="simple_image", filename=generated_image_path)
f"generated_{context.satellite}_{context.composite}_{context.area}.png")
ls.save_datasets(writer="simple_image", filename=generated_image_path)

Check warning on line 88 in satpy/tests/behave/features/steps/image_comparison.py

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Excess Number of Function Arguments

step_when_generate_image has 5 arguments, threshold = 4. This function has too many arguments, indicating a lack of encapsulation. Avoid adding more arguments.

# Save the generated image in the context
context.generated_image = cv2.imread(generated_image_path)
Expand Down
95 changes: 77 additions & 18 deletions utils/create_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,93 @@

Script to create reference images for the automated image testing system.

create_reference.py <input-data> <output-directory> <satellite-name>

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.
It is absolutely not intended for any operational production of satellite
imagery.

DO NOT USE FOR OPERATIONAL PRODUCTION!
"""

import sys
from glob import glob
import argparse
import os
import pathlib

from dask.diagnostics import ProgressBar
import hdf5plugin # noqa: F401

from satpy import Scene

ext_data_path = sys.argv[1]
outdir = sys.argv[2]
satellite = sys.argv[3]

filenames = glob(f"{ext_data_path}/satellite_data/{satellite}/*.nc")
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).glob("*")

scn = Scene(reader=props.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="gradient_search")
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.")

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. Output images "
"will be written to the subdirectory reference_images.")

parser.add_argument(
"-o", "--outdir", action="store", type=pathlib.Path,
default=pathlib.Path("."),
help="Directory where to write resulting 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()

scn = Scene(reader="abi_l1b", filenames=filenames)
generate_images(parsed)

composites = ["ash", "airmass"]
scn.load(composites)
ls = scn.resample(resampler="native")
with ProgressBar():
ls.save_datasets(writer="simple_image", filename=outdir +
"/satpy-reference-image-{platform_name}-{sensor}-{start_time:%Y%m%d%H%M}-{area.area_id}-{name}.png")
if __name__ == "__main__":
main()
Loading