<jupyter_start><jupyter_text>Megapipe transformationsThe transformations can be found in [this page](https://www.cadc-ccda.hia-iha.nrc-cnrc.gc.ca/en/megapipe/docs/filt.html).<jupyter_code>plt.figure(figsize=(6,6))
plt.hlines(0, -2, 3)
plt.vlines(0, -2, 2)

plt.scatter(
    mb_data[idx,4][mask] - mb_data[idx,6][mask],
    unions_data['g'][mask] - mb_data[idx,4][mask],
    c='red', s=1, alpha=0.5,
)

plt.ylim(-2, 2)
plt.xlim(-1, 3)
plt.ylabel('CFHT - UNIONS g band')
plt.xlabel('CFHT, g - r band')
plt.title('g - r band', fontsize=20)
plt.show()


def linear_correction(x):
    # SDSS -> CFIS new filters
    return -0.067*x

def inv_linear_correction(y):
    # SDSS -> CFIS old filters
    return (-1/0.153)*y


plt.figure(figsize=(6,6))
plt.hlines(0, -2, 3)
plt.vlines(0, -2, 2)

plt.scatter(
    mb_data[idx,4][mask] - mb_data[idx,6][mask],
    unions_data['g'][mask] - mb_data[idx,4][mask],
    c='red', s=1, alpha=0.5,
)

plt.scatter(
    mb_data[idx,4][mask] - mb_data[idx,6][mask],
    linear_correction(mb_data[idx,4][mask] - mb_data[idx,6][mask]),
    c='blue', s=1, alpha=0.5,
)

plt.ylim(-2, 2)
plt.xlim(-1, 3)
plt.ylabel('UNIONS - CFHT g band')
plt.xlabel('CFHT, g - r band')
plt.title('g - r band', fontsize=20)
plt.show()


plt.figure(figsize=(6,6))
plt.hlines(0, -2, 3)
plt.vlines(0, -2, 2)

plt.scatter(
    inv_linear_correction(linear_correction(mb_data[idx,4][mask] - mb_data[idx,6][mask])),
    unions_data['g'][mask] - mb_data[idx,4][mask],
    c='red', s=1, alpha=0.5,
)

plt.ylim(-2, 2)
plt.xlim(-1, 3)
plt.ylabel('UNIONS - CFHT g band')
plt.xlabel('corrected CFHT, g - r band')
plt.title('g - r band', fontsize=20)
plt.show()


"""
g_new
(g-r)_sdss
g_old


g_new= m * (g-r)_sdss + b


g_old = m1 * (g-r)_sdss +b1


1/m (g_new - b) = 1/m1 (g_old - b1)

if b=b1=0:
g_new = g_old * (m/m1)

m = -0.067
m1 = -0.153

g_new = m/m1 * (g_old - b1) + b


"""


def g_new_2_g_old(g_old, b, b1):
    m = -0.067
    m1 = -0.153
    
    return (g_old - b1) * (m/m1) + b
    




plt.figure(figsize=(6,6))
plt.hlines(0, -2, 3)
plt.vlines(0, -2, 2)

plt.scatter(
    inv_linear_correction(mb_data[idx,4][mask] - mb_data[idx,6][mask]),
    unions_data['g'][mask],
    c='red', s=1, alpha=0.5,
)


straight_line = np.linspace(15,28, num=200)
plt.scatter(
    straight_line,
    straight_line,
    c='blue', s=1, alpha=0.5,
)

plt.ylim(15,28)
plt.xlim(15,28)
plt.xlabel('CFHT g band')
plt.ylabel('UNIONS g band')
plt.title('g band', fontsize=20)
plt.show()<jupyter_output><empty_output><jupyter_text>New session<jupyter_code># mb_data[idx,6][mask] # r band
# mb_data[idx,4][mask] # g band

def g_band_CFHTLens_2_SDSS(g, r):
    
    diff = g-r
    g_SDSS = 0.014 + 0.133 * diff + 0.032 * diff**2 + g
    
    return g_SDSS
    
def g_band_UNIONS_2_SDSS(g, r):
    
    diff = g-r
    g_SDSS = -0.002 + 0.046 * diff + 0.023 * diff**2 + g
    
    return g_SDSS


def z_band_CFHTLens_2_SDSS(i, z):
    
    diff = i-z
    g_SDSS = 0.014 + 0.133 * diff + 0.032 * diff**2 + g
    
    return g_SDSS
    
def z_band_UNIONS_2_SDSS(i, z):
    
    diff = i-z
    g_SDSS = -0.002 + 0.046 * diff + 0.023 * diff**2 + g
    
    return g_SDSS
    

plt.figure(figsize=(6,6))
# plt.hlines(0, -2, 3)
# plt.vlines(0, -2, 2)


g_SDSS_from_CFHTLens = g_band_CFHTLens_2_SDSS(g=mb_data[idx,4][mask], r=mb_data[idx,6][mask])
g_SDSS_from_UNIONS = g_band_UNIONS_2_SDSS(g=unions_data['g'][mask], r=unions_data['r'][mask])


plt.scatter(
    g_SDSS_from_CFHTLens,
    g_SDSS_from_UNIONS - g_SDSS_from_CFHTLens,
    c='red', s=1, alpha=0.5,
    label='with correction',
)

plt.scatter(
    mb_data[idx,4][mask],
    unions_data['g'][mask] - mb_data[idx,4][mask],
    c='green', s=1, alpha=0.5,
    label='Without correction',
)


# straight_line = np.linspace(16,28, num=200)
# plt.scatter(
#     straight_line,
#     straight_line,
#     c='blue', s=1, alpha=0.5,
# )

plt.legend()

plt.ylim(-2,2)
plt.xlim(15,28)
plt.xlabel('g band (from CFHTLens)')
plt.ylabel('g band (from UNIONS)')
plt.title('g band', fontsize=20)
plt.show()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup