Skip to content

Add createMosaic mutation and related functionality - #4012

Open
jbwexler wants to merge 4 commits into
OpenNeuroOrg:masterfrom
jbwexler:feat/mosaic
Open

Add createMosaic mutation and related functionality#4012
jbwexler wants to merge 4 commits into
OpenNeuroOrg:masterfrom
jbwexler:feat/mosaic

Conversation

@jbwexler

@jbwexler jbwexler commented Jul 9, 2026

Copy link
Copy Markdown

This sets up the basics for incorporating the bids-mosaic tool into openneuro:

  1. Adds a createMosaic mutation that runs bids-mosaic on a particular dataset/snapshot, saves the output pdf to /datalad/mosaics/<dataset>/<dataset>-<hexsha>_mosaic.pdf, and then triggers the updateMosaic mutation to update the database.
  2. Adds a boolean mosaic query within snapshot, indicating whether bids-mosaic has been run.

I haven't added any tests yet but happy to do so once everything else is ready to go.

I thought I would start with the basics here and then we can discuss whether we want to incorporate it within the UI and/or have it be auto-triggered. Another idea from @effigies was to keep the 2D images annexed in a separate branch so unchanged images don't have to be regenerated when running on a future snapshot (currently they get created in /tmp and then deleted).

@nellh nellh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments. This looks pretty good, if we're keeping the mosaics in the datasets volume we'd just need an endpoint to serve them (on_get for the mosaic handler would work) and a resolver for that. The advantage of moving them into a branch is we could reuse the git object endpoint to stream them but that might not be worth the added complexity.

Let's start with an admin tab button to trigger mosaic creation and automate if that seems to be working well?

lock = client.lock(f'mosaic-lock:{dataset_id}:{ref}', timeout=60 * 60 *4)
if await lock.acquire(blocking=False):
try:
out_dir_path = Path(f"/datalad/mosaics/{dataset_id}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use DATALAD_DATASET_PATH as this volume can be configured to be in different locations.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be resolved by 6f5a339.



@broker.task
async def create_mosaic(dataset_id, dataset_path, ref, cookies=None, user=''):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the ref isn't actually referenced for the mosaic being produced. It would be good to read from that version of the dataset.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking at validator.py for ideas on how to do this but it looks like ref doesn't get used there either. I can't tell if I'm missing something or if that's a bug.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was recently implemented in #3927

Comment on lines +11 to +16
export const mosaic = async (dataset, _, _context: GraphQLContext) => {
const cache = new CacheItem(
getRedis(),
CacheType.mosaic,
[dataset.id, dataset.revision],
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Redis cache here is pretty unnecessary for a single MongoDB query. I'd remove it to simplify this.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be resolved by 7f99a56.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants