Skip to content

Move sanity check of inputs within argument-parse function to fail fast #34

@atteggiani

Description

@atteggiani

In the code there are several lines in which sanity check of inputs take place.
For example in the bounding_box class:

if Path(maskfname).exists():
d = iris.load(maskfname, var)
d = d[0]
d = xr.DataArray.from_iris(d)
lons = d['longitude'].data
lonmin = np.min(lons)
lonmax = np.max(lons)
if lonmax > 180.:
lonmax = lonmax-360.
lats = d['latitude'].data
latmin = np.min(lats)
latmax = np.max(lats)
d.close()
else:
print(f'ERROR: File {maskfname} not found', file=sys.stderr)
raise

or

if Path(ncfname).exists():
d = xr.open_dataset(ncfname)
else:
print(f'ERROR: File {ncfname} not found', file=sys.stderr)
sys.exit(1)

Since the inputs for the class come from command line arguments (parsed through argparse in the hres_ic.py), it would be best to move all input argument's sanity check within a "parse_argument" function to:

  • fail fast (at the beginning of the parent script)
  • improve testing
  • clear up code and group similar functionality all in one place

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

Status

Todo ⏳

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions