<jupyter_start><jupyter_text>Generate a spectral type, HST mags relation Using spex templates/standards<jupyter_code>splat.initializeStandards()
#1.visualize dupuy relation
sp_grid=np.arange(20, 38)
js = [spe.typeToMag(splat.typeToNum(x),'2MASS J',set='dupuy') for x in sp_grid]
hs= [spe.typeToMag(splat.typeToNum(x),'2MASS H',set='dupuy') for x in sp_grid]
#transform dupuy relation into HST mags
def get_abs_hst_mag(spt, flt):
    #using splat filtermag
    sp = splat.STDS_DWARF_SPEX[spt]
    sp.fluxCalibrate('2MASS J',float(sp.j_2mass))
    mag, mag_unc = splat.filterMag(sp, flt)
    #calculate the mag of the standard in J and H
    magj, mag_unck = splat.filterMag(sp,'2MASS J')
    magh, mag_unck = splat.filterMag(sp,'2MASS H')
    #calculate the offset between HST filters and 2mass filters
    offsetj=magj-mag
    offset2=magh-mag
    return [splat.filterMag(sp, 'NICMOS {}'.format(k)) for k in ['F110W', 'F140W', 'F160W']]
abs_hstmags=[get_abs_hst_mag(splat.typeToNum(x)) for x in  sp_grid]<jupyter_output><empty_output><jupyter_text>Generate apparent HST magsUsing candidates?<jupyter_code>ds=np.logspace(-1, 4, 1000)
def get_app_hst_mag(dist, absmag):
    ##returns apparent HST mag given distance and absolute mag
    return np.log10(dist-1)*5+absmag
app_hstmags=[]
for m in np.array(abs_hstmags)[:,:, 0]:
    app_hstmags.append([get_app_hst_mag(ds, x) for x in  m])<jupyter_output><empty_output><jupyter_text>Visualization<jupyter_code>fig, ax=plt.subplots(ncols=5, sharey=True, figsize=(13, 3))
ax[0].plot(np.array(js)[:,0], sp_grid)
ax[1].plot(np.array(hs)[:,0], sp_grid)

ax[0].set_xlabel('abs J')
ax[1].set_xlabel('abs H')
ax[0].set_ylabel('SpT')

ax[2].plot(np.array(abs_hstmags)[:,:, 0][:,0], sp_grid, '.')
ax[3].plot(np.array(abs_hstmags)[:,:, 0][:,1], sp_grid, '.')
ax[4].plot(np.array(abs_hstmags)[:,:, 0][:,2], sp_grid, '.')

ax[2].set_xlabel('abs F110W')
ax[3].set_xlabel('abs F140W')
ax[4].set_xlabel('abs F160W')



p4=fit_polynomial( sp_grid, np.array(abs_hstmags)[:,:, 0][:,0], n=3)
ax[2].plot(p4(sp_grid), sp_grid)


p5=fit_polynomial(sp_grid, np.array(abs_hstmags)[:,:, 0][:,1], n=3)
ax[3].plot(p5(sp_grid), sp_grid)

p6=fit_polynomial( sp_grid, np.array(abs_hstmags)[:,:, 0][:,2], n=3)
ax[4].plot(p6(sp_grid), sp_grid)

plt.tight_layout()


fig, ax=plt.subplots(ncols=3, figsize=(12, 3), sharex=True)
for a in ax:
    a.invert_yaxis()
    a.set_xscale('log')
for i in np.arange(0, 18):
    ax[0].plot(ds, np.array(app_hstmags)[i][0], color='#0074D9', alpha=0.4)
    ax[1].plot(ds, np.array(app_hstmags)[i][1],  color='#0074D9', alpha=0.4)
    ax[2].plot(ds, np.array(app_hstmags)[i][2],  color='#0074D9', alpha=0.4)

ax[0].set_xlabel('distance (pc)')
ax[1].set_xlabel('distance (pc)')
ax[2].set_xlabel('distance (pc)')

ax[0].set_ylabel('F110W')
ax[1].set_ylabel('F140W')
ax[2].set_ylabel('F160W')
plt.tight_layout()<jupyter_output><empty_output><jupyter_text>Using my sample to map to SNR and sigma_error on app mags<jupyter_code>cands=wisps.datasets['candidates']
#some reformatting
obs_F110W=np.array(np.apply_along_axis(list, 0,cands.F110.str.replace('nan', '-999').apply(eval).values))
obs_F140W=np.array(np.apply_along_axis(list, 0,cands.F140.str.replace('nan', '-999').apply(eval).values))
obs_F160W=np.array(np.apply_along_axis(list, 0,cands.F160.str.replace('nan', '-999').apply(eval).values))
obs_F160W[obs_F160W < -90.0]=np.nan
obs_F140W[obs_F140W < -90.0]=np.nan
obs_F110W[obs_F110W < -90.0]=np.nan
snrs=cands.snr1.values
fig, ax=plt.subplots(ncols=3, figsize=(12, 3))

mags=np.linspace(10, 27, 100)

for a in ax:
    #a.invert_yaxis()
    a.set_xlim([15, 25])
    a.set_ylabel(r'$\sigma^2_{mag}$')
    a.set_yscale('log')
ax[0].plot(obs_F110W[:,0], obs_F110W[:,1], '.')
ax[1].plot(obs_F140W[:,0], obs_F140W[:,1], '.')
ax[2].plot(obs_F160W[:,0], obs_F160W[:,1], '.')

ax[0].set_xlabel('F110W')
ax[1].set_xlabel('F140W')
ax[2].set_xlabel('F160W')
plt.tight_layout()
fig, ax=plt.subplots(ncols=3, figsize=(12, 3))

for a in ax:
    a.set_ylabel(r'log SNR-J')
    a.set_xlim([15, 27])
    #a.set_ylim([0, 500])

ax[0].plot(obs_F110W[:,0], np.log10(snrs), '.')
ax[1].plot(obs_F140W[:,0], np.log10(snrs), '.')
ax[2].plot(obs_F160W[:,0], np.log10(snrs), '.')

nonnans110=dropnans(obs_F110W[:,0])
p0=fit_polynomial(obs_F110W[:,0][nonnans110], np.log10(snrs[nonnans110]), n=1)
ax[0].plot(mags, p0(mags))

nonnans140=dropnans(obs_F140W[:,0])
p1=fit_polynomial(obs_F140W[:,0][nonnans140], np.log10(snrs[nonnans140]), n=1)
ax[1].plot(mags, p1(mags))

nonnans160=dropnans(obs_F160W[:,0])
p2=fit_polynomial(obs_F160W[:,0][nonnans160], np.log10(snrs[nonnans160]), n=1)
ax[2].plot(mags, p2(mags))

ax[0].set_xlabel('F110W')
ax[1].set_xlabel('F140W')
ax[2].set_xlabel('F160W')
plt.tight_layout()

plt.savefig(wisps.OUTPUT_FIGURES+'/snr_fits.pdf')
polrealtions={'snr_F110W':p0, 'snr_F140W':p1, 'snr_F160W':p2, \
             'sp_F110W':p4, 'sp_F140W':p5, 'sp_F160W':p6}
import pickle
with open(wisps.OUTPUT_FILES+'/polynomial_relations.pkl', 'wb') as file:
    pickle.dump(polrealtions,file)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2080364212193191, 'fraction_numerical': 0.07581155977830561, 'mean_word_length': 6.785824345146379, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '136531', 'license': 'MIT', 'n_tokens_mistral': 2592, 'n_tokens_neox': 2410, 'n_words': 324, 'path': 'notebooks/.ipynb_checkpoints/simulations3-checkpoint.ipynb', 'repo_name': 'caganze/WISPS', 'size': '5052'}