Skip to content

Instantly share code, notes, and snippets.

@Miladiouss
Last active April 13, 2022 22:27
Show Gist options
  • Select an option

  • Save Miladiouss/fb06d9e08efdb24f8c8a45c8b6fea503 to your computer and use it in GitHub Desktop.

Select an option

Save Miladiouss/fb06d9e08efdb24f8c8a45c8b6fea503 to your computer and use it in GitHub Desktop.

Revisions

  1. Milad Pourrahmani revised this gist Apr 13, 2022. 1 changed file with 13 additions and 7 deletions.
    20 changes: 13 additions & 7 deletions astropy_quantities.py
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,30 @@
    # Science
    from astropy.units import Unit
    import numpy as np
    from astropy.units import Unit

    # Notebook
    from IPython.display import Markdown
    from IPython.core.interactiveshell import InteractiveShell
    InteractiveShell.ast_node_interactivity = "all"

    # Handy functions
    def Qshow(Q, sigfig=2, unit=None):
    def Qshow(Q, sigfig=2, unit=None, name=None):
    name = Q.info.name
    if unit is not None:
    Q = Q.to(unit)
    Q = Q.round(sigfig - int(np.log10(Q.value)))
    if Q.info.name is not None:
    output = Markdown(f'{Q.info.name} = {Q._repr_latex_()}')
    if sigfig is not None:
    q = Q.round(sigfig - int(np.log10(Q.value)))
    else:
    output = Markdown(f'{Q._repr_latex_()}')
    q = Q
    if name is not None:
    output = Markdown(f'{name} = {q._repr_latex_()}')
    else:
    output = Markdown(f'{q._repr_latex_()}')
    return output

    # Parameter
    density = 2 * Unit('g/cm^3')
    density = 1.23456e12 * Unit('g/cm^3')
    density.info.name = r'$\rho$'

    # Results
    Qshow(density)
  2. Milad Pourrahmani revised this gist Apr 13, 2022. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions astropy_quantities.py
    Original file line number Diff line number Diff line change
    @@ -8,8 +8,10 @@
    InteractiveShell.ast_node_interactivity = "all"

    # Handy functions
    def Qshow(Q, sigfig=2):
    Q.round(sigfig - int(np.log10(Q.value)))
    def Qshow(Q, sigfig=2, unit=None):
    if unit is not None:
    Q = Q.to(unit)
    Q = Q.round(sigfig - int(np.log10(Q.value)))
    if Q.info.name is not None:
    output = Markdown(f'{Q.info.name} = {Q._repr_latex_()}')
    else:
  3. Milad Pourrahmani created this gist Apr 13, 2022.
    22 changes: 22 additions & 0 deletions astropy_quantities.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    # Science
    from astropy.units import Unit
    import numpy as np

    # Notebook
    from IPython.display import Markdown
    from IPython.core.interactiveshell import InteractiveShell
    InteractiveShell.ast_node_interactivity = "all"

    # Handy functions
    def Qshow(Q, sigfig=2):
    Q.round(sigfig - int(np.log10(Q.value)))
    if Q.info.name is not None:
    output = Markdown(f'{Q.info.name} = {Q._repr_latex_()}')
    else:
    output = Markdown(f'{Q._repr_latex_()}')
    return output

    # Parameter
    density = 2 * Unit('g/cm^3')
    density.info.name = r'$\rho$'
    Qshow(density)