Skip to content

Commit

Permalink
Refactor available_datasets()
Browse files Browse the repository at this point in the history
  • Loading branch information
lahtinep committed Feb 27, 2025
1 parent 8a57410 commit 32a0554
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions satpy/readers/nwcsaf_hrw_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,21 +204,26 @@ def available_datasets(self, configured_datasets=None):
for measurand in dset.dtype.fields.keys():
if measurand == "trajectory":
continue
ds_info = {
"file_type": self.filetype_info["file_type"],
"resolution": self.resolution,
"name": prefix + measurand,
}
if measurand not in ("longitude", "latitude"):
ds_info["coordinates"] = (prefix + "longitude", prefix + "latitude")
if measurand == "longitude":
ds_info["standard_name"] = "longitude"
if measurand == "latitude":
ds_info["standard_name"] = "latitude"
ds_info = self._measurand_ds_info(prefix, measurand)
yield True, ds_info
if self.merge_channels:
break

Check warning on line 210 in satpy/readers/nwcsaf_hrw_nc.py

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Bumpy Road Ahead

NWCSAFGEOHRWFileHandler.available_datasets has 2 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.

def _measurand_ds_info(self, prefix, measurand):
ds_info = {
"file_type": self.filetype_info["file_type"],
"resolution": self.resolution,
"name": prefix + measurand,
}
if measurand not in ("longitude", "latitude"):
ds_info["coordinates"] = (prefix + "longitude", prefix + "latitude")
if measurand == "longitude":
ds_info["standard_name"] = "longitude"
if measurand == "latitude":
ds_info["standard_name"] = "latitude"

return ds_info

def get_dataset(self, key, info):
"""Load a dataset."""
logger.debug("Reading %s.", key["name"])
Expand Down

0 comments on commit 32a0554

Please sign in to comment.