pytroll / pytroll/satpy

Reference optional composite dependencies by name

Open
#161 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug enhancement
Dominant language
Python
Stars
1.2k
Forks
335
Avg merge
1d 18h
Merged PRs (30d)
10

Description

Code Sample, a minimal, complete, and verifiable piece of code

Sample compositor config

  my_composite:
    compositor: !!python/name:my_composites.MyCompositor
    prerequisites:
      - 10.8
    optional_prerequisites:
      - solar_zenith_angle
      - 0.6

The compositor for above config

class MyCompositor(CompositeBase):

    def __call__(self, projectables=None, optional_datasets=None, **info):
        data_1 = projectables[0].copy()
        sza, data_2 = optional_datasets
        # If data 2 not available, use plain IR image
        if data_2 is None:
            return Dataset(data_1, **info.copy())
        # If SZA not available, calculate them
        if sza is None:
            from pyorbital.astronomy import sun_zenith_angle
            sza = sun_zenith_angle(data_1.info["start_time"], *data_1.info["area"].get_lonlats())
        # Use data 2 where Sun is high enough
        data_1[sza < 90] = data_2[sza < 90]
        return Dataset(data_1, **info.copy())

Test script

from satpy import Scene
import glob
# Use data that does no yield solar_zenith_angle, and/or remove 0.6 um data
fnames = glob.glob("/path/to/data/*")
glbl = Scene(filenames=fnames)
glbl.load(['my_composite'])
Problem description

If, when creating the above composite, either of the optional datasets are unavailable, the optional_dataset is a list of length one, and thus the unpacking fails. Also, the missing dataset can't be determined as the order is critical.

Expected Output
  1. With all data available: composite with night-side data from dataset 1 and day-side from dataset 2
  2. With SZA unavailable: composite with night-side data from dataset 1 and day-side from dataset 2
  3. With dataset 1 missing: composite with everything from dataset 1
  4. With SZA and dataset 2 missing: composite with everything from dataset 1
Actual Result, Traceback if applicable

For the above list:

  1. works as planned
  2. ValueError: need more than 1 values to unpack
  3. ValueError: need more than 1 values to unpack
  4. ValueError: need more than 0 values to unpack
Versions of Python, package at hand and relevant dependencies

Current SatPy develop branch

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing Scene.load for the sample composite configuration and inspect how CompositeBase receives optional_datasets. Reproduce the four availability cases from the issue, then verify that optional dependencies remain identifiable and that each expected composite result works.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.