scipp / scipp/scipp

Add `clip`

Open
#3,413 0 comments 2 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

enhancement good first issue
Dominant language
C++
Stars
146
Forks
23
Avg merge
2d 7h
Merged PRs (30d)
7

Description

Add sc.clip corresponding to np.clip https://numpy.org/doc/stable/reference/generated/numpy.clip.html
Alternatively, it can be called clamp (https://en.cppreference.com/w/cpp/algorithm/clamp) which I think is more common in graphics programming.

Currently, we need to either use numpy or workaround it like this

var = sc.where(var < lo, lo, var)
var = sc.where(var > hi, hi, var)

I encountered this for the second time now when setting fit windows and making sure they are within the range of the data.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.