GithubHelp home page GithubHelp logo

Comments (5)

oruebel avatar oruebel commented on July 17, 2024

I'd like to be able to add data from an existing zarr store, with the same compression it used originally, in an efficient way

It would be useful if you could provide a code example of how you are copying the data right now or pseudo-code to show more specifically which kind of data you need to copy. E.g., Is this for individual datasets you want to copy or is this for more complex structures, e.g., an entire ElectricalSeries in NWB?

Brainstorming: Some ideas for implementing the requested feature

For individual datasets, e.g. ElectricalSeries.data, I think this could be done either:

  1. By explicitly specifying it by wrapping with ZarrDataIO. We would need to enhance ZarrDataIO to allow us to specify that the source Zarr dataset should be copied using the copy_store approach. Similar to how we have a ZarrDataIO.from_h5py_dataset we could then also have a ZarrDataIO.from_zarr_array method. I think this approach should not be too complicated to implement.
  2. By enhancing the logic in ZarrIO.write_dataset to automatically detect that we need to copy a Zarr dataset to use copy_store instead.
  3. Some combination of 1 and 2, where the logic in 2 would consist of automatically wrapping with ZarrDataIO

For whole groups, e.g., an entire ElectricalSeries , I believe this is something we would need to do define logic in ZarrIO.write_group to detect that a whole Builder needs to be copied. However, I'm not sure right now what the logic needs to look like to detect this case from the Builder.

from hdmf-zarr.

bjhardcastle avatar bjhardcastle commented on July 17, 2024

Right, sorry. I was talking about individual datasets.

Doing something like this works, and the zarr data are not read eagerly, which is great:

import datetime

import pynwb
import zarr

nwb = pynwb.NWBFile(
    session_id='test',
    session_description='test',
    identifier='12345',
    session_start_time=(
        datetime.datetime.now()
    ),
    processing=[
        pynwb.TimeSeries(
            name='running_speed',
            data=zarr.open('s3://test/running_speed.zarr'),
            unit='m/s',
            rate=60.0,
            starting_time=0.0,
        )
    ],
)

If the intermediate zarr data were written with some optimized chunking/compression config, I'd just like to include the data as-is, rather than re-do the compression on write to NWB-zarr.

from hdmf-zarr.

oruebel avatar oruebel commented on July 17, 2024

Thanks for the clarification and helpful example. In that case I would propose the following approach:

  1. Add a bool flag copy_zarr_store to ZarrDataIO
  2. Update ZarrIO.write_dataset to use zarr.convenience.copy_store to copy the data if the data is wrapped in ZarrDataIO and copy_zarr_store is set to true
  3. Optional: Add a static factory method ZarrIO.from_zarr_store(...) to wrap and existing zarr dataset with copy_zarr_store=True set. But I don't think this is needed here because it really doesn't save much.

With this, your example would change to:

pynwb.TimeSeries(
            name='running_speed',
            data=ZarrDataIO(data=zarr.open('s3://test/running_speed.zarr'), copy_zarr_store=True)
            ...

from hdmf-zarr.

oruebel avatar oruebel commented on July 17, 2024

@bjhardcastle is this something you are interested in contributing a PR for?

from hdmf-zarr.

bjhardcastle avatar bjhardcastle commented on July 17, 2024

@oruebel Yes potentially, just not sure when I'll get time to work on it.

from hdmf-zarr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.