Skip to content

Refactoring and adding more tests#129

Merged
ninahakansson merged 65 commits into
foua-pps:mainfrom
ninahakansson:cleaning
Jun 1, 2026
Merged

Refactoring and adding more tests#129
ninahakansson merged 65 commits into
foua-pps:mainfrom
ninahakansson:cleaning

Conversation

@ninahakansson

@ninahakansson ninahakansson commented May 25, 2026

Copy link
Copy Markdown
Collaborator

Refactoring.

  1. Make one common function for saving data.
  2. Make one function per sensor for loading and remapping data. This makes it possible to test all main functions.
  3. Remove code for very old satpy versions.
  4. Remove test-code not needed with pytest
  5. Replace print with logging
  6. Use the variables GEOLOCATION_NAMES and ONE_IR_CHANNEL for used in mersi for other converters.
  7. Added tests
  8. Use function to get pps, all, avhrr_heritage or default bands. Instead of many lists in every converter file.
  9. Rename some variables
  • Closes #xxxx <!-- remove if there is no corresponding issue
  • Tests added
  • Tests passed: Passes pytest level1c4pps
  • Passes flake8
  • Add your name to AUTHORS.md if not there already

@BengtRydberg BengtRydberg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice MR. Always good to clean up. Added some minor type of comments. Did not comment everywhere since the same type of comment applies to many modules.

Comment thread level1c4pps/tests/test_avhrr2pps.py
Comment thread level1c4pps/tests/test_avhrr2pps.py Outdated
Comment thread level1c4pps/tests/test_fci2pp.py Outdated
Comment thread level1c4pps/tests/test_fci2pp.py Outdated
Comment thread level1c4pps/tests/test_isccpng.py Outdated
Comment thread level1c4pps/fci2pps_lib.py Outdated
Comment thread level1c4pps/fci2pps_lib.py Outdated
Comment thread level1c4pps/fci2pps_lib.py Outdated
Comment thread level1c4pps/gac2pps_lib.py Outdated
Comment thread level1c4pps/isccpng2pps_lib.py Outdated
BANDNAMES = list(PPS_TAGNAMES.keys())

refl_bands = get_refl_bands(PPS_TAGNAMES)
bandnames = sorted(list(PPS_TAGNAMES.keys()))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@codecov

codecov Bot commented May 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.08497% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.72%. Comparing base (de5692d) to head (1807a5c).
⚠️ Report is 30 commits behind head on main.

Files with missing lines Patch % Lines
level1c4pps/eumgacfdr2pps_lib.py 95.55% 1 Missing and 1 partial ⚠️
level1c4pps/seviri2pps_lib.py 96.00% 1 Missing and 1 partial ⚠️
level1c4pps/tests/test_vgac2pps.py 95.23% 1 Missing ⚠️
level1c4pps/vgac2pps_lib.py 97.82% 1 Missing ⚠️
level1c4pps/viirs2pps_lib.py 97.72% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #129       +/-   ##
===========================================
+ Coverage   72.61%   93.72%   +21.10%     
===========================================
  Files          26       27        +1     
  Lines        2085     2166       +81     
  Branches      197      187       -10     
===========================================
+ Hits         1514     2030      +516     
+ Misses        523       93      -430     
+ Partials       48       43        -5     
Flag Coverage Δ
unittests 93.72% <99.08%> (+21.20%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@BengtRydberg BengtRydberg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Added some minor comments mainly to make it more user friendly.

Comment thread bin/fci2pps.py Outdated
parser.add_argument('-ch', '--channel_selection', nargs='?',
required=False, default="default",
choices=["default", "all", "pps"],
help="Channels to use.")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should describe each option.

help="Channels to use. Choose from:\n"
         "  default - Uses the standard channels\n"
         "  all  - Uses all available channels\n"
         "  pps - Uses the channels required for PPS only"
)

Comment thread bin/mersi2pps.py Outdated
parser.add_argument('-on', '--orbit_number', type=int, nargs='?',
required=False, default=0,
help="Orbit number (default is 00000).")
parser.add_argument('-ch', '--channel_selection', type=str, nargs='?',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above.

Comment thread bin/fci2pps.py Outdated
help="Save all 20 channels to level1c4pps file.")
parser.add_argument('-pps_ch', '--pps_channels', action='store_true',
help="Save only the necessary (for PPS) channels to level1c4pps file.")
parser.add_argument('-ch', '--channel_selection', nargs='?',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should remove nargs. It is only confusing here.

Comment thread bin/fci2pps.py
parser.add_argument('-pps_ch', '--pps_channels', action='store_true',
help="Save only the necessary (for PPS) channels to level1c4pps file.")
parser.add_argument('-ch', '--channel_selection', nargs='?',
required=False, default="default",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed, since this happen automatically if argument starts with -

Comment thread bin/metimage2pps.py Outdated
help="Save all 20 channels to level1c4pps file.")
parser.add_argument('-pps_ch', '--pps_channels', action='store_true',
help="Save only the necessary (for PPS) channels to level1c4pps file.")
parser.add_argument('-ch', '--channel_selection', type=str, nargs='?',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Comment thread level1c4pps/__init__.py Outdated
Comment on lines +615 to +625
def get_band_names(pps_tags_dict, mode="default"):
"""Get bands to use from all, default and recommended for pps."""
PPS_BANDS = ['ch_r06', 'ch_r09', 'ch_r13', 'ch_r16', 'ch_tb37', 'ch_tb85', 'ch_tb11', 'ch_tb12']
AVHRR_BANDS = ['ch_r06', 'ch_r09', 'ch_r16', 'ch_tb37', 'ch_tb11', 'ch_tb12']
if mode == "all":
return sorted(list(pps_tags_dict.keys()))
if mode == "pps":
return [key for key in pps_tags_dict if pps_tags_dict[key] in PPS_BANDS]
if mode == "avhrr_heritage":
return [key for key in pps_tags_dict if pps_tags_dict[key] in AVHRR_BANDS]
return [key for key in pps_tags_dict if "xx" not in pps_tags_dict[key]]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic is a bit hidden, more clear with something like:

PPS_BANDS = {'ch_r06', 'ch_r09', 'ch_r13', 'ch_r16', 'ch_tb37', 'ch_tb85', 'ch_tb11', 'ch_tb12'}
AVHRR_BANDS = {'ch_r06', 'ch_r09', 'ch_r16', 'ch_tb37', 'ch_tb11', 'ch_tb12'}


def get_band_names(pps_tags_dict, mode="default"):
    """Get bands to use based on mode selection."""
    if mode == "all":
        return sorted(pps_tags_dict)
        
    if mode == "pps":
        return [key for key, val in pps_tags_dict.items() if val in PPS_BANDS]
        
    if mode == "avhrr_heritage":
        return [key for key, val in pps_tags_dict.items() if val in AVHRR_BANDS]
        
    if mode == "default":
        return [key for key, val in pps_tags_dict.items() if "xx" not in val]
        
    raise ValueError(f"Unknown mode: {mode}")

Comment thread level1c4pps/__init__.py Outdated

def get_refl_bands(pps_tags_dict):
"""Get reflective bands."""
return [key for key in pps_tags_dict if "ch_r" in pps_tags_dict[key]]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simpler with:
return [key for key, val in pps_tags_dict.items() if "ch_r" in val]

@BengtRydberg BengtRydberg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it looks good! I left some comments yesterday, that will improve the user experience, that you could have a look at if you have the energy.

@ninahakansson ninahakansson merged commit e9253bc into foua-pps:main Jun 1, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants