Skip to content

Update how databroker and tiled-bluesky-plugins is imported so that searchCatalog works#172

Merged
pbeaucage merged 8 commits intomainfrom
Issue170_UpdateDatabrokerImports
Jan 27, 2025
Merged

Update how databroker and tiled-bluesky-plugins is imported so that searchCatalog works#172
pbeaucage merged 8 commits intomainfrom
Issue170_UpdateDatabrokerImports

Conversation

@PriyankaKetkarBNL
Copy link
Collaborator

Addresses issue #171

Replaced databroker imports with bluesky-tiled-plugins
Added alternative method to load scan in case databroker, etc. does not work and only a container of UIDs is available
Fixed package name
Copy link
Collaborator

@pbeaucage pbeaucage left a comment

Choose a reason for hiding this comment

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

See individual comments for changes needed.

Comment on lines +574 to +576
catalogString = str(self.c)
if "Catalog" in catalogString: run = self.c[int(run)]
if "Container" in catalogString: ## Alternative method to load scan in case databroker, etc. does not work and only a container of UIDs is available
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use an actual form of type checking if you are going to do this, not just casting to a string... isinstance() would be the most appropriate way, see line 573 of this file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure that this actually gets you as far as you'd think, by the way. If you don't have the Bluesky tiled types you won't have a bunch of convenience methods that loadRun uses later (i.e, the resulting object won't be a BlueskyRun but some other native-tiled type, probably a DatasetClient) so that will fail. Probably best to just fail early if dependencies aren't installed/importable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see. I mostly had done this for NEXAFS reduction, but not RSoXS, so I have reverted that change to be safe.

import tiled
import dask
from databroker.queries import RawMongo, Key, FullText, Contains, Regex
from bluesky_tiled_plugins.queries import RawMongo, Key, FullText, Contains, Regex
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will, of course, break old installs or installs that don't force the dependencies to update. For now, I'd use a try/except to support both import sources.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

pyproject.toml Outdated
"databroker[all]>=2.0.0b10",
"bluesky-tiled-plugins",
"bottleneck"
## TODO: tiled, databroker, and bottleneck probably can be deleted for data from December 2024 onwards, but need to check if this harms backwards compatibility
Copy link
Collaborator

Choose a reason for hiding this comment

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

Proper place for this kind of future reminder is an issue, not a comment in a file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done. Made Issue # 176: #176

@pbeaucage pbeaucage linked an issue Jan 21, 2025 that may be closed by this pull request
catalogString = str(self.c)
if "Catalog" in catalogString: run = self.c[int(run)]
if "Container" in catalogString: ## Alternative method to load scan in case databroker, etc. does not work and only a container of UIDs is available
ScanUID = np.array(self.c.search(Key("scan_id") == int(run)))[0]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Few things here:

  • no need to cast run to int because this whole block only runs if isinstance(run,int)
  • I'm not sure this needs to be done via a np.array, in general this kind of casting is not best practice.. doesn't c.search return a Container? I didn't even realize Containers could be cast to arrays. Better route would be c.search(...).keys()[0] which iirc should give you a string.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense, and I'll keep an eye for other instances. For now, I have reverted this change, as it might cause more harm than fix.

@pbeaucage
Copy link
Collaborator

As a general suggestion, it's best practice to both use a descriptive PR title and to delete the default name for a commit so the top line message is useful, i.e, "change import source for Tiled types" not "Update SST1RSoXSDB.py".

@PriyankaKetkarBNL PriyankaKetkarBNL changed the title Issue170 update databroker imports Update how databroker and tiled-bluesky-plugins is imported so that searchCatalog works Jan 27, 2025
@PriyankaKetkarBNL
Copy link
Collaborator Author

I have made updates based on the suggested changes, and I also tested the same blocks of code detailed in Issue #171. Let me know if you think anything else is needed before merging.

Copy link
Collaborator

@pbeaucage pbeaucage left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@pbeaucage pbeaucage merged commit 6657973 into main Jan 27, 2025
16 checks passed
@pbeaucage pbeaucage deleted the Issue170_UpdateDatabrokerImports branch January 27, 2025 16:08
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.

Bug: searchCatalog no longer works due to databroker bug Bug: upgrades to bluesky, tiled, etc. resulted in inability to load catalog of scan IDs

2 participants