diff --git a/tests/models/test_measurements.py b/tests/models/test_measurements.py index 6d52b2aa..4deea82d 100644 --- a/tests/models/test_measurements.py +++ b/tests/models/test_measurements.py @@ -83,7 +83,31 @@ def test_measurements_attributes(measurer, ptf_datastore, test_config): m.flux_apertures[m.best_aperture] = original_flux new_im.zp.dzp = original_zp_err - # TODO: add test for limiting magnitude (issue #143) + #test for limiting magnitude + srcList = ptf_datastore.sources + limMagEst, snrs, mags, grad, intercept = srcList.estimate_lim_mag(aperture=1) + + #Skip the lim mag test if using PSF photometry (i.e. if limMagEst==None) + if limMagEst != None: + #if interactive testing enabled, make and save a Magnitude vs SNR plot + if os.getenv('INTERACTIVE') is not None: + xdata = np.linspace(np.log(3),np.log(20),1000) + plt.plot(snrs,mags,linewidth=0,marker='o',c='midnightblue') + plt.plot(xdata, grad * xdata + intercept, c='firebrick') + plt.xlabel('log SNR') + plt.ylabel('magnitude') + plt.title('Limiting magntiude = {:.2f} mag'.format(limMagEst)) + ymin,ymax = plt.gca().get_ylim() + plt.vlines(x=np.log(5),ymin=ymin,ymax=ymax) + plt.hlines(y=limMagEst,xmin=np.log(3),xmax=np.log(20)) + plt.xlim(np.log(3),np.log(20)) + plt.ylim(ymin,ymax) + plt.savefig('plots/snr_mag_plot.png') + plt.show() + + #check the limiting magnitude is consistent with previous runs + assert limMagEst == pytest.approx(20.668, abs=0.05) + def test_filtering_measurements(ptf_datastore):