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

DM-22073: Add support for writing matplotlib figures #205

Merged
merged 1 commit into from Nov 19, 2019

Conversation

leeskelvin
Copy link
Contributor

No description provided.

Copy link
Member

@timj timj left a comment

Choose a reason for hiding this comment

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

This looks good although I do have some comments for improvements to the tests.

It is a bit annoying that butler.get can't work but it is important that butler.getUri is tested.

import os
import shutil

import matplotlib
Copy link
Member

Choose a reason for hiding this comment

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

Please protect the matplotlib import and skip the tests if matplotlib is not available. daf_butler should not require matplotlib.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this resolved? I agree that it's important.

Copy link
Contributor

Choose a reason for hiding this comment

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

(It looks resolved, given the new try block for the import of matplotlib, but I haven't been able to test it in practice.)

Copy link
Member

Choose a reason for hiding this comment

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

It's hard for any of us to test it, I think, because we all use conda enviroments that always need to have matplotlib for other reasons. But I'm pretty confident what was merged will work.

"""Interface for writing matplotlib figures.
"""

extension = '.png'
Copy link
Member

Choose a reason for hiding this comment

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

Please use double quotes in daf_butler to be consistent with the rest of the code base.

universe=butler.registry.dimensions)
butler.registry.registerDatasetType(datasetType)
pyplot.imshow(np.random.randn(3, 4))
butler.put(pyplot.gcf(), datasetType)
Copy link
Member

Choose a reason for hiding this comment

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

@TallJimbo does this work without a DataId because the dataset type has no dimensions?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, exactly.

Copy link
Member

Choose a reason for hiding this comment

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

I think that since this code could be seen as providing example usage that we should not be relying on the super special case here of datasetType and datasetRef being interchangeable. Please receive the ref from the butler.put here and then use it later in the getUri and later butler methods below. This all works because there are no dimensions but we don't want to give the impression that it's going to work more generally.

ref = butler.put(...)
parsed = ...(butler.getUri(ref))
...
butler.datasetExists(ref)

etc.

# predicting the filename path based on test run
self.assertTrue(
filecmp.cmp(
os.path.join(self.root, 'testrun', datasetType.name,
Copy link
Member

Choose a reason for hiding this comment

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

I think I would prefer it if this path was constructed from calling butler.getUri since then you aren't relying on knowing how the file name was constructed within the datastore.

Copy link
Member

Choose a reason for hiding this comment

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

That's what we tried first, but annoyingly filecmp apparently can't handle file:// prefixes, and it occurred to me that actual usage would look more like this, but perhaps with users explicitly defining the template so they'd know where to look in general, rather than asking the butler where to look each time.

Do you have an incantation handy for how to get that file:// prefix off gracefully?

Copy link
Member

Choose a reason for hiding this comment

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

You can either use ButlerURI or you can go for the standard option of:

parsed = urllib.parse.urlparse(uri)

and then use parsed.path.

file.name,
shallow=True
)
)
Copy link
Member

Choose a reason for hiding this comment

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

Please add calls to butler.datasetExists and butler.remove so that we can check that these PNG images are being treated like a normal dataset. Also try to do a butler.get and check that it fails with with self.assertRaises.

@TallJimbo
Copy link
Member

TallJimbo commented Nov 15, 2019

@leeskelvin, I'm going to let you take the lead on addressing these comments, but please find me for more pair-programming if you want help with anything.

@leeskelvin leeskelvin force-pushed the tickets/DM-22073 branch 7 times, most recently from 7c004c5 to 06755d1 Compare November 18, 2019 20:57
@leeskelvin leeskelvin merged commit 8cb7c8f into master Nov 19, 2019
@leeskelvin leeskelvin deleted the tickets/DM-22073 branch November 19, 2019 00:29
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.

None yet

4 participants