tiled icon indicating copy to clipboard operation
tiled copied to clipboard

Enhancements to the directory tree

Open danielballan opened this issue 4 years ago • 11 comments

  • [x] By default, strip file extension from node name. That is, a.tif becomes a. Rationale: the file extension is not part of the "name". (Windows hides it by default.) Including it makes it confusing to do things like http://.../thing.xlsx?format=csv. This does create the possibility of name collisions, but if you have example.tiff and example.json next to each other, they are likely related --- part of the same "data" --- and need a special Adapter to deal with. #49
  • [ ] Add a configurable function that, given a full path to a directory, returns a metadata dict. (The default will always return an empty dict.)
  • [x] Add a configurable function that, given a full path to a directory, returns a mimetype or None. If it returns None, that means, "Crawl into this subdirectory." If it returns a mimetype, that means, "I recognize this as a {TIFF sequence, Zarr directory, TileDB directory} with internal structure than an Adapter shoudl manage. Do not crawl any further. We might want to make this a list of functions to make it easy to extend default behavior. https://github.com/bluesky/tiled/pull/62

Developed in a phone conversation with @tacaswell

danielballan avatar Aug 04 '21 02:08 danielballan

Add a configurable function that, given a full path to a directory, returns a metadata dict.

Currently is there no way to add metadata for a node without re-writing the adapter and referencing it in a yml config?

For example, I have a lot of directories, and each has some tiff files and one json file. I would like to use the json file for that directory's metadata.

J-avery32 avatar Jul 27 '22 19:07 J-avery32

Correct. I think what you want here is similar to what we added in #259 — a way to extend the existing behavior without having to rewrite a bunch of stuff.

danielballan avatar Jul 27 '22 22:07 danielballan

I think the feature you need is subdirectory_handler. Does each directory map to a single (3-dimensional) array, comprised off all the TIFFs stacked up, with a dictionary of metadata attached? If so, it should be fit your use case as is. See

https://github.com/bluesky/tiled/blob/34ede8a48bf3c9c901acc6ae7db3f12fbe2d0f2b/tiled/adapters/tiff.py#L178

and the (rough) documentation

https://blueskyproject.io/tiled/explanations/scaling-down.html

If the structure you need is more complex than that, we should talk about how to extend subdirectory_handler to enable it.

danielballan avatar Jul 29 '22 17:07 danielballan

@J-avery32 Does subdirectory_handler address your use case?

danielballan avatar Aug 08 '22 12:08 danielballan

I'm not sure. How am I supposed to hook this up to read the json file in that directory? Or are you suggesting that I rewrite the Tiff adapter? Even if I re wrote the tiff adapter I don't see any way to give my new subdirectory_handler to tiled to use. Also I will be offline until Friday.

J-avery32 avatar Aug 09 '22 03:08 J-avery32

Ah! Never mind I think it does fit my use case. I will try it out and let you know.

J-avery32 avatar Aug 09 '22 03:08 J-avery32

How am I supposed to pass subdirectory_handler to tiled? Is there a hook in the yml for that or am I supposed to create a new DirectoryAdapter: https://blueskyproject.io/tiled/reference/generated/tiled.adapters.files.DirectoryAdapter.html?highlight=subdirectory_handler

J-avery32 avatar Aug 09 '22 03:08 J-avery32

You can create a config file that call a method which will load the right adapter. An example of a config file could be:

trees:
  - tree: files
    path: /
    args:
      directory: files/
      subdirectory_handler: module:subdirectory_handler_method

To run the config file with tiled you can use (https://blueskyproject.io/tiled/how-to/configuration.html): tiled serve config my_config_file.yml

jmaruland avatar Aug 09 '22 14:08 jmaruland

I think it might be what I want. Originally I had each tiff file be its own separate node but hadn't considered joining it into a single 3 dimensional array. However, there are some csv files in these directories as well which are important. If I were to turn each directory into a 3 dimensional array then it seems that these csv files would disappear.

If there was a way to avoid that issue with the CSVs then this will work.

J-avery32 avatar Aug 12 '22 20:08 J-avery32

@J-avery32 In #511 there are some changes that may be of interest:

  1. The feature whereby Tiled automatically updates when the file system changes is now opt in. You need to add --watch to tiled serve directory ... to engage it.
  2. The aforementioned subdirectory_handler is gone, in favor of an approach that is both easier to explain and more powerful. I think this is the way to handle "TIFF with associated JSON". Your use case may be a good way to test that and motivate a new documentation page to illustrate it. Can you expand a little on what your directories of files look like?

danielballan avatar Jul 21 '23 12:07 danielballan

I'll get back to you on this, but it will take me a bit to go back through my old stuff and remember what I was trying to do.

J-avery32 avatar Jul 28 '23 00:07 J-avery32

I'm going to close this now, as I think the use case of "node backed by heterogeneous files" is now addressed nicely.

Docs on how this works at a low level (in the database) are here: https://blueskyproject.io/tiled/explanations/catalog.html#data-source-asset-relation

danielballan avatar May 10 '24 14:05 danielballan