|
| 1 | +--- |
| 2 | +title: Rebin |
| 3 | +parent: Data Manipulation |
| 4 | +grand_parent: Syntax |
| 5 | +nav_order: 3 |
| 6 | +permalink: /commands/data-manipulation/rebin/ |
| 7 | +math: katex |
| 8 | +--- |
| 9 | + |
| 10 | +# Rebin |
| 11 | + |
| 12 | +The `rebin` command bins data into fixed intervals and averages all points within each bin. This is a **destructive operation** that reduces noise but permanently replaces original data. |
| 13 | + |
| 14 | +(Note that the original data file remains unchanged; only the in-memory dataset is modified.) |
| 15 | + |
| 16 | +## Basic Usage |
| 17 | + |
| 18 | +```sh |
| 19 | +rebin <range> <--interval <step> | --number <n>> [options] |
| 20 | +``` |
| 21 | + |
| 22 | +where: |
| 23 | + |
| 24 | +- `<range>` defines the binning limits |
| 25 | +- Either `--interval` or `--number` specifies bin size (exactly one required) |
| 26 | + |
| 27 | +## Command Options |
| 28 | + |
| 29 | +| Option | Description | |
| 30 | +|--------|-------------| |
| 31 | +| `<range>` | Range for rebinning (required). Must have finite bounds. See [range specification]({{ "/commands/general-syntax#range-specification" | relative_url }}) for details. | |
| 32 | +| `--interval <step>` | Fixed bin width (mutually exclusive with `--number`). Must include units. | |
| 33 | +| `--number <n>` | Number of bins to create (mutually exclusive with `--interval`). | |
| 34 | +| `--axis <axis>` <br> `-x <axis>` | Axis column for binning (auto-inferred from range units if omitted). | |
| 35 | +| `--domain <domain>` | Domain in which to rebin (default: `reciprocal`). Options: `reciprocal`, `fourier`. | |
| 36 | +| `--fix-points` | Interpolate bin averages back to exact bin centers (preserves target axis values). | |
| 37 | + |
| 38 | +## Binning Method |
| 39 | + |
| 40 | +The command: |
| 41 | + |
| 42 | +1. Creates bin boundaries at half-intervals: `[range[0] - step/2, ..., range[1] + step/2]` |
| 43 | +2. Assigns each data point to a bin |
| 44 | +3. Computes the mean of all points in each bin (all columns) |
| 45 | +4. Optionally interpolates to exact bin centers if `--fix-points` is set |
| 46 | + |
| 47 | +## Fix Points Option |
| 48 | + |
| 49 | +- **Default (no `--fix-points`):** Bin centers are the mean axis values within each bin (may not align exactly with target grid) |
| 50 | +- **With `--fix-points`:** After averaging, cubic spline interpolation repositions points to exact bin centers |
| 51 | + |
| 52 | +Use `--fix-points` when you need bin centers at precise positions (e.g., for subsequent operations requiring exact alignment between files). |
| 53 | + |
| 54 | +## Examples |
| 55 | + |
| 56 | +```sh |
| 57 | +# Rebin energy axis to 1 eV intervals |
| 58 | +rebin 8000eV 9000eV --interval 1eV |
| 59 | + |
| 60 | +# Create exactly 100 bins in k-space |
| 61 | +rebin 2k 14k --number 100 |
| 62 | + |
| 63 | +# Rebin Fourier domain with fixed bin centers |
| 64 | +rebin 0A 5A --interval 0.1A --domain fourier --fix-points |
| 65 | + |
| 66 | +# Explicit axis specification |
| 67 | +rebin 0 1000 --interval 2 --axis E --domain reciprocal |
| 68 | +``` |
| 69 | + |
| 70 | +## Behavior |
| 71 | + |
| 72 | +Rebinning: |
| 73 | + |
| 74 | +- **Reduces noise** by averaging multiple points within each bin |
| 75 | +- **Downsamples** high-resolution data for faster processing |
| 76 | +- **Removes outliers** if most points in a bin are consistent |
| 77 | +- **Smooths** irregular step sizes into uniform intervals |
| 78 | + |
| 79 | +{: .warning } |
| 80 | +**Destructive operation:** Original data is replaced with binned averages. The original data file remains unchanged; only the in-memory dataset is modified. Data points outside the extended range `[range[0] - step/2, range[1] + step/2]` are discarded. |
| 81 | + |
| 82 | +## Use Cases |
| 83 | + |
| 84 | +- **Noise reduction:** Average out high-frequency noise while preserving overall shape |
| 85 | +- **Downsampling:** Reduce point count from oversampled scans |
| 86 | +- **Uniformity:** Convert variable-spacing scans to fixed intervals |
| 87 | +- **Pre-processing for averaging:** Align multiple scans to identical grids before merging |
| 88 | + |
| 89 | +## Tips and Best Practices |
| 90 | + |
| 91 | +1. **Choose appropriate bin size:** |
| 92 | + |
| 93 | + - Too small → minimal noise reduction |
| 94 | + - Too large → loss of spectral features |
| 95 | + - Typical: 0.5–2 eV for energy, 0.05–0.2 k⁻¹ for k-space |
| 96 | + |
| 97 | +2. **Check data spacing:** Bin width should be larger than original step size to achieve averaging |
| 98 | + |
| 99 | +3. **Use for noise, not upsampling:** Rebinning cannot increase resolution; use `interpolate` for upsampling (interpolation does not add information, only resamples existing data) |
| 100 | + |
| 101 | +4. **Edge effects:** Data near range boundaries may be lost if bins extend outside the data range |
| 102 | + |
| 103 | +## Comparison with Interpolate |
| 104 | + |
| 105 | +| Feature | `rebin` | `interpolate` | |
| 106 | +|---------|---------|---------------| |
| 107 | +| Method | Binning + averaging | Cubic spline fitting | |
| 108 | +| Noise reduction | Yes (averaging reduces noise) | No | |
| 109 | +| Outlier handling | Robust (majority vote per bin) | Sensitive (fits through all points) | |
| 110 | +| Use case | Noise reduction + downsampling | Resampling to new grid | |
| 111 | + |
| 112 | +**See also:** |
| 113 | + |
| 114 | +- [Data Manipulation overview]({{ "/commands/data-manipulation" | relative_url }}) |
| 115 | +- [Interpolate]({{ "/commands/data-manipulation/interpolate" | relative_url }}) |
| 116 | +- [General syntax]({{ "/commands/general-syntax" | relative_url }}) |
0 commit comments