# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python [conda root]
#     language: python
#     name: conda-root-py
# ---

# +
from astropy.io import fits
import numpy as np
from IPython.display import HTML

data = fits.open('../photoParallax/photoParallaxAnderson17Mini.fits')
train = data[1].data
test = np.load('dusttgas.npy')
# -

train.dtype.names

testColor = test[0]

testEBV = test[1]

import matplotlib.pyplot as plt
# %matplotlib inline

# +
absMag = train['M_J']
color = train['J_Ks']

colorMid = 0.625
colorDel = 0.15
colorMin = colorMid - colorDel
colorMax = colorMid + colorDel
absMagMid = -1.0
absMagDel = 0.5
absMagMin = absMagMid - absMagDel
absMagMax = absMagMid + absMagDel


redclump = (color < colorMax) & (color > colorMin) & (absMag < absMagMax) & (absMag > absMagMin)

rgb = (color > 0.5) & (absMag < 3.)
lms = (color > 0.5) & (absMag > 3.)
ums = (color < 0.5)
# -

c1 = '#a6cee3'
c2 = '#1f78b4'
c3 = '#b2df8a'
c4 = '#33a02c'

HTML('<img src="playwithdata.png">')

# +
plt.figure(figsize=(10,10))
plt.scatter(color[rgb], absMag[rgb], s=1, lw=0, c=c1, alpha=0.1, zorder=0, rasterized=True)
plt.scatter(color[lms], absMag[lms], s=1, lw=0, c=c2, alpha=0.1, zorder=1, rasterized=True)
plt.scatter(color[ums], absMag[ums], s=1, lw=0, c=c3, alpha=0.1, zorder=2, rasterized=True)
plt.scatter(color[redclump], absMag[redclump], s=1, lw=0, c=c4, alpha=0.1, zorder=3, rasterized=True)

#plt.scatter(train['J_Ks'], train['M_J'], s=0.1, alpha=0.01, rasterized=True)
plt.ylim(6, -6)
plt.xlim(-0.5, 1.5)
plt.xlabel(r'$(J-K_s)^C$', fontsize=20)
plt.ylabel(r'$M_J^C$', fontsize=20)

# +
plt.figure(figsize=(10,10))
plt.scatter(testColor[rgb], testEBV[rgb], s=1, lw=0, c=c1, alpha=0.1, zorder=0, rasterized=True)
plt.scatter(testColor[lms], testEBV[lms], s=1, lw=0, c=c2, alpha=0.1, zorder=1, rasterized=True)
plt.scatter(testColor[ums], testEBV[ums], s=1, lw=0, c=c3, alpha=0.1, zorder=2, rasterized=True)
plt.scatter(testColor[redclump], testEBV[redclump], s=1, lw=0, c=c4, alpha=0.1, zorder=3, rasterized=True)

#plt.scatter(train['J_Ks'], train['M_J'], s=0.1, alpha=0.01, rasterized=True)
plt.ylim(-1, 2)
plt.xlim(-0.5, 1.5)
plt.xlabel(r'$(J-K_s)^C$', fontsize=20)
plt.ylabel(r'$E(B-V)$', fontsize=20)
plt.scatter(testColor, testEBV, s=0.1, alpha=0.01, rasterized=True)

# +
n_frames = 30
n_points = len(color)
# %matplotlib osx
frames = np.zeros((2,n_points,n_frames))
fig = plt.figure(figsize=(10,10))
#random start and end points to test 
firstx = color
firsty = absMag/-2.5
lastx = testColor
lasty = testEBV

for i in range(n_points):
    frames[0,i,:] = np.linspace(firstx[i],lastx[i],n_frames)
    frames[1,i,:] = np.linspace(firsty[i],lasty[i],n_frames)

#make intermediate date points, slow
#frames[0,:,i] = np.linspace(firstx[i],lastx[i],n_frames)
#frames[1,:,i] = np.linspace(firsty[i],lasty[i],n_frames)

#make frames  
for i in range(n_frames):
    fig.clf()
    #plt.figure(figsize=(10,10))
    plt.scatter(frames[0,:,i][rgb], frames[1,:,i][rgb], s=1, lw=0, c=c1, alpha=0.1, zorder=0, rasterized=True)
    plt.scatter(frames[0,:,i][lms], frames[1,:,i][lms], s=1, lw=0, c=c2, alpha=0.1, zorder=1, rasterized=True)
    plt.scatter(frames[0,:,i][ums], frames[1,:,i][ums], s=1, lw=0, c=c3, alpha=0.1, zorder=2, rasterized=True)
    plt.scatter(frames[0,:,i][redclump], frames[1,:,i][redclump], s=1, lw=0, c=c4, alpha=0.1, zorder=3, rasterized=True)

    if i < n_frames/2.: 
        ylabel=r'$M_J^c$'
        xlabel=r'$(J-K_s)^c$'
    else:
        ylabel = r'$E(B-V)$'
        xlabel = r'$(J-K_s)^c_P$'
    #plt.scatter(frames[0,:,i],frames[1,:,i],s=1, lw=0, c=c3, alpha=0.1, zorder=2, rasterized=True)
    #plt.ylim(6, -6)
    plt.xlabel(xlabel, fontsize=20)
    plt.ylabel(ylabel, fontsize=20)
    plt.xlim(-0.5, 1.5)
    fig.savefig('mlInterp_{0:03d}.png'.format(i))

# +
import imageio
import numpy as np

images = []
#frames = np.arange(0,30)
frames = np.concatenate((np.arange(0, 30), np.zeros(30) + 29))
#addframes = np.zeros(100) + 29

for i in list(frames):
    filename = 'mlInterp_{0}.png'.format('%03d' % i)
    images.append(imageio.imread(filename))
imageio.mimsave('mlInterp.gif', images)

# -

HTML('<img src="mlInterp.gif">')



StarcoderdataJupyterScriptsDedupFiltered