Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dimension slicing utility #68

Open
pp-mo opened this issue Apr 3, 2024 · 0 comments
Open

Dimension slicing utility #68

pp-mo opened this issue Apr 3, 2024 · 0 comments

Comments

@pp-mo
Copy link
Owner

pp-mo commented Apr 3, 2024

Found myself writing this just to use it.
It's pretty simple ...

slicedim_name = "time"
slicedim_len = 2
ncds.dimensions[slicedim_name].size = slicedim_len
for var in ncds.variables.values():
    if slicedim_name in var.dimensions:
        (i_slicedim,) = [
            i for i, name in enumerate(var.dimensions)
            if name == slicedim_name
        ]
        slices = [slice(None) for dim in var.dimensions]
        slices[i_slicedim] = slice(0, slicedim_len)
        var.data = var.data[tuple(slices)]

Probably wants to be slightly generalised.
Maybe control with a map dim_name: dim_slice
Then new dim length can be deduced for any-old input slice something like
dim.size = da.zeros(dim.size)[dim_slice].shape[0]
(using dask to avoid actually making an array)

N.B. goes in a 'utilities' space : cf #64

@pp-mo pp-mo mentioned this issue Apr 3, 2024
6 tasks
@pp-mo pp-mo moved this to In Progress in release 0.2 Jun 10, 2024
@pp-mo pp-mo linked a pull request Jun 10, 2024 that will close this issue
6 tasks
@pp-mo pp-mo moved this from In Progress to Possibles in release 0.2 Jun 10, 2024
@pp-mo pp-mo moved this from Possibles to In Progress in release 0.2 Dec 23, 2024
@pp-mo pp-mo moved this from In Progress to Possibles in release 0.2 Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Possibles
Development

Successfully merging a pull request may close this issue.

1 participant