question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Order in which units are presented

See original GitHub issue

Hi,

I have a quantity x that I would like to be presented in units of erg/(s Hz) or erg s^-1 Hz^-1, as opposed to erg/(Hz s) or erg Hz^-1 s^-1 because of how it looks when rendered in latex, among other reasons. I cannot seem to figure out a way to accomplish this – is this possible to do? And if so, how?

Another possible solution to my problem is getting the * or \times symbol to appear when the unit appears in LaTeX, i.e. erg/(Hz*s). Can that be done?

Thank you very much.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
smithis7commented, Jul 6, 2021

I think this works albeit a little brute force:

>>> from astropy import units as u
>>> myunit = u.def_unit('myunit', u.Unit('erg/(s Hz)'), format={'generic': 'erg/(s Hz)'})  # add your own formatting
>>> x = 1 * myunit
>>> x
<Quantity 1. erg/(s Hz)>
>>> x.to(u.erg)
<Quantity 1. erg>

p.s. You can then register it into astropy.units with u.add_enabled_units([myunit]).

This is perfect – the place we are using this for is hidden pretty deep in our code, so this will do exactly what we need it to do (no need to make it look pretty). Thank you very much!

0reactions
pllimcommented, Jul 6, 2021

Glad to hear! 😸

Read more comments on GitHub >

github_iconTop Results From Across the Web

SI Unit rules and style conventions checklist
Only units of the SI and those units recognized for use with the SI are used to express the values of quantities. Equivalent...
Read more >
Order unit - Wikipedia
An order unit is an element of an ordered vector space which can be used to bound all elements from above. In this...
Read more >
Units of the rate constant (video) - Khan Academy
The units of the rate constant, k, depend on the overall reaction order. The units of k for a zero- order reaction are...
Read more >
Lesson I: The Metric System and SI Units
The metric system is based upon powers of ten, which is convenient because: A measurement in the metric system that is represented by...
Read more >
Given below are some common units of mass. The correct ...
Given below are some common units of mass. The correct order of these units arranged in ascending order is-. mg, kg, dag, cg,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found