the interest of as

the interest of as#

The as parameter enables you to change the name between the keyword given during the model dict definition for the corresponding output column in the resulting pandas.DataFrame.

Most importantly, it enables to handle func that have multiple outputs.

Here is an example

Say you want to draw random coordinates in the sky. These parameters are named right-ascension (ra) and declination (dec). To be consistent, it is best to draw them together in a function that returns both ra and dec.

import numpy as np
def random_radec(size=None, ra_range=[0,360], dec_range=[-90,90]):
    """ evenly distributed R.A. Dec. coordinates in the sky. """
    dec_sin_range = np.sin(np.asarray(dec_range)*np.pi/180)
    ra = np.random.uniform(*ra_range, size=size)
    dec = np.arcsin( np.random.uniform(*dec_sin_range, size=size) ) / (np.pi/180)
    return ra, dec

ra, dec = random_radec(100)

When building the model, as enables you to provide the name of each columns.

import modeldag

# model construction    
model = {"radec": {"func": random_radec, "as": ["ra","dec"]} }

# create the DAG
dag = modeldag.ModelDAG(model)
data = dag.draw(100)
data.head()
ra dec
0 125.161291 -31.772886
1 266.752659 -7.116863
2 278.030421 21.806067
3 121.902128 37.495262
4 139.622884 16.717280