Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ave map fa rv weighted by av #73

Merged
merged 8 commits into from
Jul 30, 2024
Merged
36 changes: 31 additions & 5 deletions megabeast/tools/make_naive_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
pix_size=10.0,
verbose=False,
median=False,
chi2mincut=False):
chi2mincut=False,
weigh_by_av=False):

"""
Make the naive maps by directly averaging the BEAST results for all the
stars in each pixel. Does not account for completeness, hence naive maps!
Expand All @@ -38,7 +40,12 @@
calculate the median of the BEAST results (instead of the mean)

chi2mincut : int (default=None)
place a chi2min cut on the BEAST results
place a chi2min cut on the BEAST results. Gives the max threshold.

weigh_by_av : bool (default=False)
weigh R(V) and f_A by A(V) to determinе R(V) and f_A of the total column
of dust in a pixel (as opposed to finding a simple average across a pixel)

"""

# type of statistic (make a commandline parameter later)
Expand Down Expand Up @@ -80,6 +87,8 @@

# setup arrary to store summary stats per pixel
sum_stats = ["Av", "Rv", "f_A", "logT", "M_act", "logA"]
print("summary stats", sum_stats)

Check warning on line 90 in megabeast/tools/make_naive_maps.py

View check run for this annotation

Codecov / codecov/patch

megabeast/tools/make_naive_maps.py#L90

Added line #L90 was not covered by tests

n_sum = len(sum_stats)
summary_stats = np.zeros((n_y + 1, n_x + 1, n_sum + 1), dtype=float)
summary_sigmas = np.zeros((n_y + 1, n_x + 1, n_sum), dtype=float)
Expand All @@ -102,13 +111,24 @@
print(i, j, len(tindxs))
for k, cur_stat in enumerate(sum_stats):
values = cat[cur_stat + "_" + stat_type][tindxs]
values_foreach_pixel[cur_stat][i, j] = values
summary_stats[j, i, k] = np.average(values)
summary_sigmas[j, i, k] = np.std(values, ddof=1) / math.sqrt(len(values))

# weigh R(V) and f_A by A(V)
if weigh_by_av and ("Rv" in cur_stat or "f_A" in cur_stat):

Check warning on line 116 in megabeast/tools/make_naive_maps.py

View check run for this annotation

Codecov / codecov/patch

megabeast/tools/make_naive_maps.py#L116

Added line #L116 was not covered by tests
# get Av values
av_values = cat["Av" + "_" + stat_type][tindxs]
values_foreach_pixel[cur_stat][i, j] = values / av_values
weights = av_values

Check warning on line 120 in megabeast/tools/make_naive_maps.py

View check run for this annotation

Codecov / codecov/patch

megabeast/tools/make_naive_maps.py#L118-L120

Added lines #L118 - L120 were not covered by tests
else:
values_foreach_pixel[cur_stat][i, j] = values
weights = None

Check warning on line 123 in megabeast/tools/make_naive_maps.py

View check run for this annotation

Codecov / codecov/patch

megabeast/tools/make_naive_maps.py#L122-L123

Added lines #L122 - L123 were not covered by tests

if median:
summary_stats[j, i, k] = np.median(values)
xabs = abs(values - np.median(values)) ** 2.
summary_sigmas[j, i, k] = np.sqrt(np.median(xabs)) / math.sqrt(len(values))
else:
summary_stats[j, i, k] = np.average(values, weights=weights)
summary_sigmas[j, i, k] = np.std(values, ddof=1) / math.sqrt(len(values))

Check warning on line 131 in megabeast/tools/make_naive_maps.py

View check run for this annotation

Codecov / codecov/patch

megabeast/tools/make_naive_maps.py#L130-L131

Added lines #L130 - L131 were not covered by tests

master_header = w.to_header()
# Now, write the maps to disk
Expand Down Expand Up @@ -157,6 +177,12 @@
parser.add_argument(
"--median", default=False, type=bool, help="find the median of the values"
)
parser.add_argument(

Check warning on line 180 in megabeast/tools/make_naive_maps.py

View check run for this annotation

Codecov / codecov/patch

megabeast/tools/make_naive_maps.py#L180

Added line #L180 was not covered by tests
"--chi2mincut", default=False, type=int, help="max chi2min threshold to place on results"
)
parser.add_argument(

Check warning on line 183 in megabeast/tools/make_naive_maps.py

View check run for this annotation

Codecov / codecov/patch

megabeast/tools/make_naive_maps.py#L183

Added line #L183 was not covered by tests
"--weigh_by_av", default=False, type=bool, help="weigh R(V) or f_A by A(V)"
)
args = parser.parse_args()

# call the function
Expand Down
Loading