-
Notifications
You must be signed in to change notification settings - Fork 0
/
mass_distr.py
37 lines (27 loc) · 980 Bytes
/
mass_distr.py
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
from utils import load_data, find_mass_fn
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import json
import sys
import os
with open('select.json') as f:
data = json.load(f)
lgmag, hgmag = 10, 18
for cluster_name, subdata in data.items():
iso_df, clu_df = load_data(cluster_name)
poly, main_seq = find_mass_fn(iso_df)
data[cluster_name]["mass_fn"] = list(poly)
int_poly = np.polyint(poly)
avg_mass = ((int_poly(hgmag) - int_poly(lgmag)) / (hgmag - lgmag))
xs = np.linspace(lgmag, hgmag, 100)
ys = poly(xs)
plt.scatter(main_seq['Gmag'], main_seq['Mass'], label="Actual Data")
plt.plot(xs, ys, label=f'${poly[0]:.3f}+{poly[1]:.3f}x+{poly[2]:.3f}x^2+{poly[3]:.3f}x^3$')
plt.title(f'{cluster_name}\'s Mass v Gmag Function \nAverage Mass = {avg_mass}')
plt.xlabel('Gmag')
plt.ylabel('Mass')
plt.legend()
plt.show()
with open('select.json', 'w') as f:
json.dump(data, f, indent=4)