Git Product home page Git Product logo

Comments (4)

caseywstark avatar caseywstark commented on July 4, 2024

I'm guessing you did something like import dimensionful as dm. In this case dm.yr is a Unit object, not a Quantity. Here's what I tried...

from dimensionful import Quantity, G, c
mdot = Quantity(1.0, "Msun") * G / c**3 / Quantity(1.0, "yr")
mdot.convert_to_cgs()
print mdot

1.56195933878e-13 (dimensionless)

In your script, it tries to divide the data of Mdot by yr. Do you have any suggestions for what it should do when that happens? I wasn't sure what to do.

from dimensionful.

petigura avatar petigura commented on July 4, 2024

Hey, Casey.

I'm guessing you did something like import dimensionful as dm. In this case dm.yr is a Unit object, not a Quantity. Here's what I tried...

from dimensionful import Quantity, G, c
mdot = Quantity(1.0, "Msun") * G / c**3 / Quantity(1.0, "yr")
mdot.convert_to_cgs()
print mdot

1.56195933878e-13 (dimensionless)

I see what I did. I was confusing year, the unit, with 1 year a dimensionful quantity.

In your script, it tries to divide the data of Mdot by yr. Do you have any suggestions for what it should do when that happens? I wasn't sure what to do.

I wouldn't try to guess what the user means. But an important choice is to decide whether we think of 1 year as a unit or just as a shorthand for 3.14e7 seconds.

Erik

from dimensionful.

petigura avatar petigura commented on July 4, 2024

How about this?

Why is this not simplifying in CGS

import dimensionful
reload(dimensionful)
m = 4_pi_dm.Quantity(1.0,"Msun")/dm.Quantity(20.0,"day")_dm.Quantity(1.0,"Rsun")__2 /dm.c
print m
print m.convert_to_cgs()
2.09584502195e-11 Msun_Rsun*_2_s/(cm*day)
None

from dimensionful.

caseywstark avatar caseywstark commented on July 4, 2024

Quantity.convert_to_cgs() always returns None.

m.convert_to_cgs()
print m

would do it.

There are several *_to_cgs methods of Quantity. Quantity.get_in_cgs() creates and returns a new Quantity, Quantity.convert_to_cgs() overwrites the attributes and has no return value, and Quantity.get_data_in_cgs() gets the conversion factor and returns the data multiplied to cgs only. Looking back at the docstrings, this is not totally obvious. I will make them more explicit.

from dimensionful.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.