← Back to team overview

python-quantities-developers team mailing list archive

Re: Welcome

 

I think I'll need an example to understand what you mean.

I had a quick look at quantizer (what does the name mean?), and I think
creating quantities should be done like:

result[i].view(type=Quantity),
result[i].dimensionality = handler_quantities.dimensionality

which would require changes to the dimensionality property. Calling the
Quantity constructor makes an additional copy of the data, calling view just
converts the object type.

I'm still a little unsettled about rescaling other for addition and
subtraction. I already mentioned it being arbitrary to select one set of
units over the other, but also it is not consistent with multiplication and
division, which do not rescale other. I would really prefer to not rescale,
introducing such ambiguity is bound to lead to problems down the road.

Darren

On Sat, Jan 3, 2009 at 4:33 AM, John Salvatier <jsalvatier@xxxxxxxxx> wrote:

> I worked on the wrapper function generator a bit, and I got it working well
> with a basic case (scipy.integration.quad), but I have run up against
> something rather tricky. The way it works now is that all arguments are
> simplified (rescaled to their base units) and then recast as ndarrays. The
> simplification is necessary so that if the base function adds two quantities
> together (in say a fortran module where they will be treated as ndarrays)
> the units work out. The problem comes up when the user passes an object that
> the base function will call a member function from and return a quantity
> (maybe this is totally contrived). Since we don't have access to the object
> we can't perpare it to be used in the base_function (simplifying etc.).
>
> I don't know if this is fixable, but perhaps you have and idea.
>
> John
>
>
> On Fri, Jan 2, 2009 at 4:35 PM, John Salvatier <jsalvatier@xxxxxxxxx>wrote:
>
>> I added the ability to add quantities with different (but reconcilable)
>> units.
>>
>> I also started playing around with a way to create wrapper functions for
>> functions that you want to have work correctly with Quantities. It currently
>> works like this:
>>
>> from quantities import *
>>
>> from scipy.integrate import quad
>>
>> def integrate_units(function, x1, x2):
>>     return (function(x1) * x2,function(x1) * x2)
>>
>> #generate a wrapper function
>> integrator =  quantitizer( quad, integrate_units)
>>
>> #try it out
>> func = lambda x: x
>>
>> #integrate f(x) = x between 1 and 5 m
>> print integrator(func, 1 * m, 5 * m)
>>
>> See the __doc__ for quantitizer for a little bit of detail.
>>
>> I'll push the changes out a bit later.
>>
>> John
>>
>> On Fri, Jan 2, 2009 at 4:29 PM, Darren Dale <dsdale24@xxxxxxxxx> wrote:
>>
>>> Welcome to the python-quantities-developers mailing list!
>>>
>>> _______________________________________________
>>> Mailing list: https://launchpad.net/~python-quantities-developers<https://launchpad.net/%7Epython-quantities-developers>
>>> Post to     : python-quantities-developers@xxxxxxxxxxxxxxxxxxx
>>> Unsubscribe : https://launchpad.net/~python-quantities-developers<https://launchpad.net/%7Epython-quantities-developers>
>>> More help   : https://help.launchpad.net/ListHelp
>>>
>>>
>>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~python-quantities-developers<https://launchpad.net/%7Epython-quantities-developers>
> Post to     : python-quantities-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~python-quantities-developers<https://launchpad.net/%7Epython-quantities-developers>
> More help   : https://help.launchpad.net/ListHelp
>
>

References