-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_plot.py
More file actions
89 lines (77 loc) · 3.15 KB
/
cmd_plot.py
File metadata and controls
89 lines (77 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import matplotlib.pyplot as plt
import numpy as np
class Plotter:
def __init__(self):
pass
def band(self, band):
pass
def color(self, band1, band2):
pass
def plot_CCD(self, band1, band2, band3, band4, ax=None, **kwargs):
# Color-Color Diagram
if ax is None:
ax = plt.gca()
ax.scatter(self.color(band1, band2), self.color(band3, band4), **kwargs)
ax.set_xlabel(f'[{band1.upper()}] - [{band2.upper()}]')
ax.set_ylabel(f'[{band3.upper()}] - [{band4.upper()}]')
return ax
def plot_CMD(self, band1, band2, band3, ax=None, **kwargs):
# Color-Magnitude Diagram
if ax is None:
ax = plt.gca()
ax.scatter(self.color(band1, band2), self.band(band3), **kwargs)
ax.set_xlabel(f'[{band1.upper()}] - [{band2.upper()}]')
ax.set_ylabel(f'[{band3.upper()}]')
plt.gca().invert_yaxis()
return ax
def plot_MMD(self, band1, band2, ax=None, **kwargs):
# Magnitude-Magnitude Diagram
if ax is None:
ax = plt.gca()
ax.scatter(self.band(band1), self.band(band2), **kwargs)
ax.set_xlabel(f'[{band1.upper()}]')
ax.set_ylabel(f'[{band2.upper()}]')
plt.gca().invert_xaxis()
plt.gca().invert_yaxis()
return ax
def plot_CCCD(self, band1, band2, band3, band4, band5, band6, ax=None, **kwargs):
# Color-Color-Color Diagram
if ax is None:
ax = plt.gca()
im = ax.scatter(self.color(band1, band2), self.color(band3, band4), c=self.color(band5, band6), **kwargs)
ax.set_xlabel(f'[{band1.upper()}] - [{band2.upper()}]')
ax.set_ylabel(f'[{band3.upper()}] - [{band4.upper()}]')
plt.colorbar(im, ax=ax, label=f'[{band5.upper()}] - [{band6.upper()}]')
return ax
def plot_position(self, ax=None, **kwargs):
if ax is None:
ax = plt.gca()
im = ax.scatter(self.ra, self.dec, **kwargs)
ax.set_xlabel('Right Ascension')
ax.set_ylabel('Declination')
return im
def plot_contour_CCD(self, band1, band2, band3, band4, ax=None, bins=100, threshold=5, cmap='autumn_r', color='k', s=1):
import mpl_plot_templates as template
#x = np.array(self.color(band1, band2))
x = self.color(band1, band2)
x[x.mask] = np.nan
x = np.array(x)
#x[x>5] = np.nan
#y = np.array(self.color(band3, band4))
y = self.color(band3, band4)
y[y.mask] = np.nan
y = np.array(y)
#y[y>5] = np.nan
if ax is None:
ax = plt.subplot()
template.adaptive_param_plot(x, y, threshold=threshold, bins=bins, cmap=cmap, marker_color=color, markersize=s, axis=ax)
ax.set_xlabel(f'[{band1.upper()}] - [{band2.upper()}]')
ax.set_ylabel(f'[{band3.upper()}] - [{band4.upper()}]')
def get_region_mask(self, reg, wcs):
mask = np.zeros(len(self.catalog), dtype=bool)
for r in reg:
mask += r.contains(self.coords, wcs=wcs)
return mask
def table_region_mask(self, reg, wcs):
mask = self.get_region_mask(reg, wcs)
return self.catalog[mask]