Skip to content

How to plot normalized rgb by time? #76

Closed Answered by zxdawn
zxdawn asked this question in Q&A
Discussion options

You must be logged in to vote

Well, it's easier than I thought:

def normalize(da, stretch=1):
    min_val = np.quantile(da, 1-stretch)
    max_val = np.quantile(da, stretch)
    da_norm = np.clip((da - min_val) / (max_val - min_val), 0, 1)

    return da_norm


rgb = xr.apply_ufunc(normalize,
                     ds_rgb.isel(time=slice(0, 5)).to_array(name="rgb"),
                     exclude_dims=set(('variable', 'y', 'x')),
                     input_core_dims=[['variable', 'y', 'x']],
                     output_core_dims=[['variable', 'y', 'x']],
                     vectorize=True,
                     )

I can create a PR for this.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@aazuspan
Comment options

@zxdawn
Comment options

Answer selected by zxdawn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants