Refactoring and adding more tests#129
Conversation
…(one common) Started to implement geolocation list as in mersi for other sensorrs (avhrr and slstr). Use function to get pps, all or default bands. Instead of many lists in every file. Added tests for main function in slstr, viirs, avhrr. Fixed tests
BengtRydberg
left a comment
There was a problem hiding this comment.
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.
| BANDNAMES = list(PPS_TAGNAMES.keys()) | ||
|
|
||
| refl_bands = get_refl_bands(PPS_TAGNAMES) | ||
| bandnames = sorted(list(PPS_TAGNAMES.keys())) |
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
BengtRydberg
left a comment
There was a problem hiding this comment.
Looks good. Added some minor comments mainly to make it more user friendly.
| parser.add_argument('-ch', '--channel_selection', nargs='?', | ||
| required=False, default="default", | ||
| choices=["default", "all", "pps"], | ||
| help="Channels to use.") |
There was a problem hiding this comment.
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"
)
| 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='?', |
| 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='?', |
There was a problem hiding this comment.
I think you should remove nargs. It is only confusing here.
| 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", |
There was a problem hiding this comment.
not needed, since this happen automatically if argument starts with -
| 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='?', |
| 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]] |
There was a problem hiding this comment.
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}")
|
|
||
| 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]] |
There was a problem hiding this comment.
simpler with:
return [key for key, val in pps_tags_dict.items() if "ch_r" in val]
BengtRydberg
left a comment
There was a problem hiding this comment.
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.
Refactoring.
pytest level1c4ppsflake8AUTHORS.mdif not there already