0

I am still a newbie in python and I need to use PyAstronomy module for writing a code. I want to call this function as an Input for another code:

def phaseAngle(pos, los='-z'):
    """
    Calculate the phase angle.

    Parameters
    ----------
    pos : array
        Either a one-dimensional array with xyz coordinate or a
        [3,N] array containing N xyz positions.
    los : LineOfSight object
        A `LineOfSight` object from the pyasl giving the line of
        sight.

    Returns
    -------
    Phase angle : The phase angle in degrees. Depending on the input,
        it returns a single value or an array. 
    """
    from PyAstronomy.pyasl import LineOfSight
    l = LineOfSight(los)
    if pos.shape == (3,):
        # It is a single value
        return numpy.arccos(numpy.sum(-pos * (-l.los)) /
                            numpy.sqrt(numpy.sum(pos**2))) / numpy.pi * 180.
    else:
        # It is an array of positions
        N = len(pos[::, 0])
        result = numpy.zeros(N)
        for i in smo.range(N):
            print(i, numpy.sum((-pos[i, ::]) * (-l.los)), pos[i, ::])
            result[i] = numpy.arccos(numpy.sum((-pos[i, ::]) * (-l.los)) /
                                     numpy.sqrt(numpy.sum(pos[i, ::]**2)))
        return result / numpy.pi * 180.

In the main code the inputs are entered this way by calling KeplerEllipse from pyasl:

...
from PyAstronomy import pyasl
...
ke = pyasl.KeplerEllipse(1.3, 2., e=0.5, Omega=70., i=10.0, w=110.0)

that works very well and gives the positions and velocities as the outputs. But I need to use this phase angle as another input. But, I don't know how to inverse the output and input of def phaseAngle(pos, los='-z') so that I use the phase angle as an input and add it to

ke = pyasl.KeplerEllipse(1.3, 2., e=0.5, Omega=70., i=10.0, w=110.0, ??? )
4
  • "But, I don't know how to inverse the output and input" -> I don't understand what you are saying here. What value do you need to be at the "???", an array, a line of sight, or a phase angle? Commented Jun 20, 2019 at 11:05
  • Why specifically do you believe that a function needs to be inverted? Commented Jun 20, 2019 at 11:06
  • I do not know PyAstronomy, but in Python "everything is an object" and you can inline or nest everything. So you should find out from the documentation what argument you want to modify and then just use the return value of the function phaseAngle as this particular argument value in KeplerEllipse... KeplerEllipse(..., arg=phaseAngle(...), ...) Commented Jun 20, 2019 at 11:13
  • @Neil at "???" I need the "phase angle". because in the def phaseAngle the return (output) is "phase angle" and not the input. Commented Jun 20, 2019 at 11:21

2 Answers 2

1

If the missing argument you are looking for is the phase angle then invoke the PhaseAngle function. As Sven says in the comments, in Python you can inline and nest pretty much at will. So:

ke = pyasl.KeplerEllipse(1.3, 2., e=0.5, Omega=70., i=10.0, w=110.0, phaseAngle(?, ?) )

You have to supply phase angle with pos argument, and los if you don't want the default. It'll spit out the phaseAngle, which will be inserted where you need the argument.

For debugging you can also pre-compute like so:

phase_angle = phaseAngle(?, ?) # Put in the pos and los arguments here

ke = pyasl.KeplerEllipse(1.3, 2., e=0.5, Omega=70., i=10.0, w=110.0, phase_angle)

I think this answers your questions? There is no inversion involved though. This is forward-direction function evaluation.

Sign up to request clarification or add additional context in comments.

Comments

0

If you have created:


    def func():
        pass

Then you will call it:


    func()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.