def addmags(*mags):
tot = <NUM_LIT:0><EOL>uncs = []<EOL>for mag in mags:<EOL><INDENT>try:<EOL><INDENT>tot += <NUM_LIT:10>**(-<NUM_LIT>*mag)<EOL><DEDENT>except:<EOL><INDENT>m, dm = mag<EOL>f = <NUM_LIT:10>**(-<NUM_LIT>*m)<EOL>tot += f<EOL>unc = f * (<NUM_LIT:1> - <NUM_LIT:10>**(-<NUM_LIT>*dm))<EOL>uncs.append(unc)<EOL><DEDENT><DEDENT>totmag = -<NUM_LIT>*np.log10(tot)<EOL>if len(uncs) > <NUM_LIT:0>:<EOL><INDENT>f_unc = np.sqrt(np.array([u**<NUM_LIT:2> for u in uncs]).sum())<EOL>return totmag, -<NUM_LIT>*np.log10(<NUM_LIT:1> - f_unc/tot)<EOL><DEDENT>else:<EOL><INDENT>return totmag<EOL><DEDENT>
mags is either list of magnitudes or list of (mag, err) pairs