xskillscore icon indicating copy to clipboard operation
xskillscore copied to clipboard

potential code to refactor in deterministic.py

Open raybellwaves opened this issue 4 years ago • 2 comments

In doing https://github.com/raybellwaves/xskillscore/pull/83

There is some refactoring which can be done to slim the code and make it easier to add other metrics

https://github.com/raybellwaves/xskillscore/pull/83#discussion_r394777966

APPLY_UFUNC_KWDS = dict(
        dask="parallelized",
        output_dtypes=[float]
)


xr.apply_ufunc(..., **APPLY_UFUNC_KWDS)

Potentially some kind of

def _prep_data_for_metric(a, b, dim, metric, weights=None, skipna=False)
...
    return np_metric, a, b, weights, input_core_dims

in https://github.com/raybellwaves/xskillscore/blob/master/xskillscore/core/deterministic.py

That does the handling of

dim, _ = _preprocess_dims(dim)
a, b, new_dim, weights = _stack_input_if_needed(a, b, dim, weights)
weights = _preprocess_weights(a, dim, new_dim, weights)
input_core_dims = _determine_input_core_dims(new_dim, weights)

or the variants of that for the metric.

raybellwaves avatar Mar 19 '20 13:03 raybellwaves

also all the testing code is very much the same. here we could use fixtures and parametrizatsions even more

aaronspring avatar Mar 19 '20 13:03 aaronspring

also all the testing code is very much the same. here we could use fixtures and parametrizatsions even more

Yeah especially https://github.com/raybellwaves/xskillscore/blob/master/xskillscore/tests/test_np_deterministic.py

raybellwaves avatar Mar 19 '20 14:03 raybellwaves