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

Adding metadata to a unyt_array or unyt_quantity #227

Open
gregsalvesen-work opened this issue May 20, 2022 · 1 comment
Open

Adding metadata to a unyt_array or unyt_quantity #227

gregsalvesen-work opened this issue May 20, 2022 · 1 comment

Comments

@gregsalvesen-work
Copy link

Can a unyt_array or unyt_quantity store metadata?

I like this feature in Astropy. For example, I can add information to a Quantity object Q using its info attribute like so:

# Add information (name, meta, description) to an Astropy Quantity Q
def add_info(Q, name=None, meta=None, description=None):
    if name: Q.info.name = name
    if meta: Q.info.meta = meta
    if description: Q.info.description = description
    return Q

This is handy for attaching a brief description to the object or a TeX-formatted string for axes labels.

@neutrinoceros
Copy link
Member

Sorry for the delay. I don't see much added value in supporting this in unyt.
unyt.Unit objects have a latex_representation method that already fills your needs (axis labels); you should be able to format a label from a unyt_quantity (q) as, for instance

label = "$%.2f %s$" % (q.v, q.units.latex_representation())

the matplotlib interface also helps with achieving this seamlessly.

Overall I currently don't think there's a need for this feature in unyt, and I'm inclined to close this ticket, but I'll give a chance to interested parties to voice their opinions.

@gregsalvesen-work, can you give an example of something this would enable that's not already cleanly achievable using existing interface ?

@jzuhone any opinion here ?

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

No branches or pull requests

2 participants