-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPZ-01-01-more-line-ratios.py
1911 lines (1617 loc) · 51.6 KB
/
PZ-01-01-more-line-ratios.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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
# ---
# jupyter:
# jupytext:
# formats: ipynb,py:light,md
# text_representation:
# extension: .py
# format_name: light
# format_version: '1.5'
# jupytext_version: 1.15.2
# kernelspec:
# display_name: Python 3 (ipykernel)
# language: python
# name: python3
# ---
# # Line ratios from saved moment images with PZ cube
#
# In this notebook, I will work with only pre-calculated line maps, which have already been extracted from the cube. The extraction process is carried out in the PZ-03 series of notebooks.
# +
from pathlib import Path
import numpy as np
from matplotlib import pyplot as plt
import seaborn as sns
from mpdaf.obj import Image
import regions
import sys
import pandas as pd
import cmasher as cmr
import pyneb as pn
sns.set_context("talk")
sns.set_color_codes()
# -
# ## Path to the root of this repo
ROOT = Path.cwd().parent.parent
# ## Calculate reddening from Balmer decrement
# Load the Hα and Hβ maps
imha = Image(str(ROOT / "data/ngc346-PZ-hi-6563-bin01-sum.fits"))
imhb = Image(str(ROOT / "data/ngc346-PZ-hi-4861-bin01-sum.fits"))
# ### Look at the raw Hα/Hβ ratio:
fig, ax = plt.subplots(figsize=(12, 12))
(imha / imhb).plot(vmin=2.7, vmax=3.7, cmap="gray", colorbar="v")
# So we see very little structure there, compared with in the ESO pipeline cube case. In priniciple, lighter means more extinction. There might be a hint of this at the bottom of the image, where we see possible signs of the foreground filament.
#
# But in other parts, we just see the stars (which have a different ratio because of photospheric absorption)
# ### PyNeb calculation of intrinsic Balmer decrement
hi = pn.RecAtom("H", 1)
# Calculate the theoretical Balmer decrement from PyNeb. Density and temperature from Valerdi:2019a
tem, den = 12500, 100
R0 = hi.getEmissivity(tem, den, wave=6563) / hi.getEmissivity(tem, den, wave=4861)
R0
# ### Look at correlation between Hα and Hβ in the faint limit
#
# To make thinks easier, I multiply the Hb values by R0 so we have a square plot. I zoom in on the faint parts:
imax = 100000
m = imha.data < imax
m = m & (R0 * imhb.data < imax)
m = m & ~imha.mask & ~imhb.mask
df = pd.DataFrame(
{
"ha": imha.data[m],
"hb": R0 * imhb.data[m],
}
)
g = sns.pairplot(
df,
kind="hist",
height=4,
corner=True,
)
g.axes[1, 0].axvline(0.0, color="r")
g.axes[1, 0].axhline(0.0, color="r")
g.axes[1, 0].plot([0, imax], [0, imax], "--", color="r")
g.axes[1, 0].plot([0, imax], [0, 0.9 * imax], "--", color="r", linewidth=1.4)
g.axes[1, 0].plot([0, imax], [0, 0.8 * imax], "--", color="r", linewidth=0.7)
g.fig.suptitle("Correlation between Ha and Hb brightness")
# So, the slope is not unity, meaning the extinction is not zero. But the intercept is zero, which is great. So nothing more to do,
# Now define some regions to take averages
boxes = {
"sw filament": regions.RegionBoundingBox(
iymin=20,
iymax=40,
ixmin=200,
ixmax=310,
),
"bow shock": regions.RegionBoundingBox(
iymin=165,
iymax=205,
ixmin=240,
ixmax=290,
),
"w filament": regions.RegionBoundingBox(
iymin=100,
iymax=130,
ixmin=25,
ixmax=55,
),
"c filament": regions.RegionBoundingBox(
iymin=195,
iymax=210,
ixmin=155,
ixmax=195,
),
}
# Plot on a better scale and show the regions:
# +
fig, ax = plt.subplots(figsize=(12, 12))
(imha / (imhb)).plot(
vmin=R0,
vmax=1.5 * R0,
scale="linear",
cmap="gray_r",
colorbar="v",
)
for box, c in zip(boxes.values(), "yrmgc"):
box.plot(
ax=ax,
lw=3,
edgecolor=c,
linestyle="dashed",
# facecolor=(1.0, 1.0, 1.0, 0.4),
fill=False,
)
# -
# We can see some very high extinction at in the S filaments. And some small increase in extinction in the main diagonal filament. This is probably limited having foreground emission to some extent.
#
# Look at average values in the sample boxes
for label, box in boxes.items():
(yslice, xslice), _ = box.get_overlap_slices(imha.shape)
ha = np.median(imha[yslice, xslice].data.data)
hb = np.median(imhb[yslice, xslice].data.data)
print(f"{label}: {ha/hb:.3f}")
# I tried mean and median, and it made very little difference. Lowest in the bow shock region; slightly higher in the west and central filaments. Even higher in the southwest filament.
# ### Equivalent widths
# *New 2024-04-23*
#imnii = Image(str(ROOT / "data/ngc346-PZ-nii-6583-bin01-sum.fits"))
imcont = Image(str(ROOT / "data/ngc346-PZ-cont-6312-mean.fits"))
# Turns out that we never extracted the N II red lines. And also, the closest continuum we have is S III
ewha = 1.25 * imha / imcont
# +
fig, ax = plt.subplots(figsize=(12, 12))
(ewha).plot(
vmin=0,
vmax=1000,
scale="linear",
cmap="gray_r",
colorbar="v",
)
for box, c in zip(boxes.values(), "yrmgc"):
box.plot(
ax=ax,
lw=3,
edgecolor=c,
linestyle="dashed",
# facecolor=(1.0, 1.0, 1.0, 0.4),
fill=False,
)
# -
for label, box in boxes.items():
(yslice, xslice), _ = box.get_overlap_slices(imha.shape)
ew = np.mean(ewha[yslice, xslice].data.data)
dew = np.std(ewha[yslice, xslice].data.data)
print(f"{label}: {ew:.3f} +/- {dew:.3f}")
# ### The reddening law
pn.RedCorr().getLaws()
# PyNeb does not seem to have anything specifically tailored to the SMC. The average SMC extinction law is supposedly simply $1/\lambda$.
#
# But, it is possible to get a SMC curve by using the "F99-like" option, which uses the curve of Fitzpatrick & Massa 1990, ApJS, 72, 163. This depends on $R_V$ and 6 other parameters (!!!). Most of the parameters only affect the UV part of the curve, which does not concern us.
#
# Then, we can use the average values of $R_V$ and the other parameters, which were fit by Gordon:2003l to SMC stars. This is $R_V = 2.74 \pm 0.13$.
#
# So here I compare that SMC curve with $1/\lambda$ and with the Clayton curve for Milky Way (but also adjusted to $R_V = 2.74$):
# +
def A_lam(wave):
return 4861.32 / wave
def my_X(wave, params=[]):
"""A_lam / E(B - V) ~ lam^-1"""
return A_lam(wave) / (A_lam(4400) - A_lam(5500))
rc = pn.RedCorr()
rc.UserFunction = my_X
rc.R_V = 2.74
rc.FitzParams = [-4.96, 2.26, 0.39, 0.6, 4.6, 1.0]
f, ax = plt.subplots(figsize=(10, 10))
rc.plot(laws=["user", "F99", "CCM89"], ax=ax)
ax.set(
xlim=[4000, 9300],
ylim=[-2.5, 1.0],
# xlim=[4000, 7000],
# ylim=[-1, 1],
)
# -
# So the Gordon curve is flatter in the blue, steeper in green, and flatter in red, as compared to $1/\lambda$.
rc = pn.RedCorr()
rc.R_V = 2.74
rc.FitzParams = [-4.96, 2.26, 0.39, 0.6, 4.6, 1.0]
rc.law = "F99"
# Test it out for the bow shock region:
rc.setCorr(obs_over_theo=3.123 / R0, wave1=6563.0, wave2=4861.0)
rc.E_BV, rc.cHbeta
# And for the highest extinction region
rc.setCorr(obs_over_theo=4.165 / R0, wave1=6563.0, wave2=4861.0)
rc.E_BV, rc.cHbeta
# So $E(B - V)$ varies from about 0.1 to about 0.35. This is similar to what is found for the stars.
# ### The reddening map
#
# We can now make a map of $E(B - V)$
R = imha / (imhb)
rc.setCorr(obs_over_theo=R.data / R0, wave1=6563.0, wave2=4861.0)
imEBV = R.copy()
imEBV.data = rc.E_BV
imEBV.mask = imha.mask | imhb.mask
fig, ax = plt.subplots(figsize=(12, 12))
imEBV.rebin(4).plot(
vmin=0.0,
vmax=1.0,
scale="linear",
cmap="magma_r",
colorbar="v",
)
# Looks like I would expect. Check values in the boxes:
for label, box in boxes.items():
yslice, xslice = box.slices
ebv = np.median(imEBV[yslice, xslice].data.data)
print(f"{label}: {ebv:.3f}")
# These seem the same as before. But we want to eliminate extreme values.
badpix = (imEBV.data > 1.0) | (imEBV.data < 0.0)
imEBV.mask = imEBV.mask | badpix
# Save it to a file:
imEBV.write(str(ROOT / "data/ngc346-PZ-reddening-E_BV.fits"), savemask="nan")
# Lots of regions are affected by the stellar absorption. There are apparent increases in reddening at the position of each star. This is not real, but is due to the photospheric absorption having more of an effect on Hb (mainly because the emission line is weaker).
#
# At some point, I am going to have to deal with that. But it is not an issue for the bow shock emission, since this is in an area free of stars. We should just use the median bow shock reddening of $E(B-V) = 0.097$ so that we don't introduce any extra noise.
# +
rc.E_BV = 0.097
wavs = np.arange(4600, 9300)
Alam = rc.E_BV * rc.X(wavs)
fig, ax = plt.subplots(figsize=(12, 5))
ax.plot(wavs, Alam)
ax.set(
xlabel="Wavelength, $\lambda$, Å",
ylabel="Extinction, $A_\lambda$, mag",
title=f"Extinction curve for $E(B - V) = {rc.E_BV:.3f}$",
)
sns.despine()
# -
# ## Calculate the [S III] temperature
im6312 = Image(str(ROOT / "data/ngc346-PZ-siii-6312-bin01-sum.fits"))
im9069 = Image(str(ROOT / "data/ngc346-PZ-siii-9069-bin01-sum.fits"))
cont6312 = Image(str(ROOT / "data/ngc346-PZ-cont-6312-mean.fits"))
# The raw ratio:
fig, ax = plt.subplots(figsize=(12, 12))
(im6312 / im9069).plot(vmin=0.08, vmax=0.15, cmap="gray", colorbar="v")
# That does not look too bad. But we will look at the joint distro anyway.
imax = 15000
slope = 0.1
m = im9069.data < imax
m = m & (im9069.data > -100)
m = m & (im6312.data < slope * imax)
m = m & ~im9069.mask & ~im6312.mask
df = pd.DataFrame(
{
"9069": im9069.data[m],
"6312": im6312.data[m],
}
)
# +
g = sns.pairplot(
df,
kind="hist",
height=4,
corner=True,
)
g.axes[1, 0].axvline(0.0, color="r")
g.axes[1, 0].axhline(0.0, color="r")
g.axes[1, 0].plot([0, imax], [0, slope * imax], "--", color="r")
g.fig.suptitle("Correlation between [S III] 9069 and 6312 brightness")
# -
# Nothing needs to get added to anything.
imax = 5000
slope = 0.1
x = im9069.data
y = im6312.data
m = x < imax
m = m & (x > -100)
m = m & (y < 1.2 * slope * imax)
m = m & ~im9069.mask & ~im6312.mask
df = pd.DataFrame(
{
"9069": x[m],
"6312": y[m],
}
)
# +
g = sns.pairplot(
df,
kind="hist",
height=4,
corner=True,
)
g.axes[1, 0].axvline(0.0, color="r")
g.axes[1, 0].axhline(0.0, color="r")
g.axes[1, 0].plot([0, imax], [0, slope * imax], "--", color="r")
g.axes[1, 0].plot([0, imax], [0, 1.2 * slope * imax], "--", color="r")
g.fig.suptitle("ZOOMED Correlation between [S III] 9069 and 6312 brightness")
# -
# Now we need to correct for reddening.
A9069 = rc.X(9069) * imEBV
im9069c = im9069.copy()
im9069c.data = im9069.data * 10 ** (0.4 * A9069.data)
A6312 = rc.X(6312) * imEBV
im6312c = im6312.copy()
im6312c.data = (im6312.data) * 10 ** (0.4 * A6312.data)
n = 1
fig, ax = plt.subplots(figsize=(12, 12))
(im6312c.rebin(n) / im9069c.rebin(n)).plot(
vmin=0.1, vmax=0.15, cmap="magma", colorbar="v"
)
n = 4
x = np.log10(im9069c.rebin(n).data)
y = np.log10(im6312c.rebin(n).data / im9069c.rebin(n).data)
m = (x > 3.0) & (x < 4.5)
m = m & (y > -1.05) & (y < -0.75)
m = m & ~im9069c.rebin(n).mask & ~im6312c.rebin(n).mask
df = pd.DataFrame(
{
"log10 9069": x[m],
"log 10 6312/9069": y[m],
}
)
g = sns.pairplot(
df,
kind="hist",
height=4,
corner=True,
)
# This is totally different from what we got from the ESO cube. This version is much more reliable, since with the other one we had no idea where the zeropoint was
# Now, make a mask of EW(6312). But first, we need to correct the zero point of the continuum.
# +
im6312_zero = 0.0
cont6312_zero = 0.0
imax = 600
x = im6312.data - im6312_zero
y = cont6312.data - cont6312_zero
m = x < imax
m = m & (x > 100)
m = m & (y < 300) & (y > 100)
m = m & ~cont6312.mask & ~im6312.mask
df = pd.DataFrame(
{
"6312": x[m],
"cont": y[m],
}
)
g = sns.pairplot(
df,
kind="hist",
height=4,
corner=True,
)
g.axes[1, 0].axvline(0.0, color="r")
g.axes[1, 0].axhline(0.0, color="r")
# -
fig, ax = plt.subplots(figsize=(10, 10))
ew6312 = 1.25 * (im6312 - im6312_zero) / (cont6312 - cont6312_zero)
ew6312.plot(vmin=1.0, vmax=5.0, scale="sqrt")
ax.contour(ew6312.data, levels=[0.5], colors="r", linewidths=3)
ax.contour(im9069.data, levels=[6000.0], colors="k", linewidths=1)
fixmask = (ew6312.data < 1.0) | (im9069.data < 3000.0)
fixmask = fixmask & (im6312c.data < 0.1 * im9069c.data)
fixmask = fixmask & (im6312c.data > 0.2 * im9069c.data)
iborder = 12
fixmask[:iborder, :] = True
fixmask[-iborder:, :] = True
fixmask[:, :iborder] = True
fixmask[:, -iborder:] = True
im6312c.mask = im6312c.mask | fixmask
n = 1
fig, ax = plt.subplots(figsize=(12, 12))
(im6312c.rebin(n) / im9069c.rebin(n)).plot(
vmin=0.1, vmax=0.15, cmap="magma", colorbar="v"
)
# Honestly, this looks identical to the last one. So I do not know what I am even doing here.
n = 4
x = np.log10(im9069c.rebin(n).data)
y = np.log10(im6312c.rebin(n).data / im9069c.rebin(n).data)
z = im9069c.rebin(n).data
m = (x > 2.5) & (x < 5.5)
m = m & (y > -1.1) & (y < -0.6)
m = m & ~im9069c.rebin(n).mask & ~im6312c.rebin(n).mask
df = pd.DataFrame(
{
"log10 9069": x[m],
"log 10 6312/9069": y[m],
}
)
kws = dict(weights=z[m], bins=30)
g = sns.pairplot(
df,
kind="hist",
height=4,
corner=True,
plot_kws=kws,
diag_kws=kws,
)
# ### Convert to actual temperatures with pyneb
s3 = pn.Atom("S", 3)
s3.getTemDen([0.1, 0.2], den=100.0, wave1=6300, wave2=9069)
r_s3_grid = np.linspace(0.05, 0.25, 201)
T_s3_grid = s3.getTemDen(r_s3_grid, den=100.0, wave1=6300, wave2=9069)
imT_siii = im6312c.clone(data_init=np.empty)
imT_siii.data[~fixmask] = np.interp(
im6312c.data[~fixmask] / im9069c.data[~fixmask],
r_s3_grid,
T_s3_grid,
left=np.nan,
right=np.nan,
)
# imT_siii.mask = imT_siii.mask | fixmask
# imT_siii.data[imT_siii.mask] = np.nan
fig, ax = plt.subplots(figsize=(12, 12))
imT_siii.rebin(2).plot(colorbar="v", cmap="hot", vmin=12000, vmax=16000)
badpix = ~np.isfinite(imT_siii.data)
imT_siii.mask = imT_siii.mask | badpix
imT_siii.write(str(ROOT / "data/ngc346-PZ-T-siii.fits"), savemask="nan")
# The rather disappointing conclusion of this is that the [S III] temperatures do vary from about 13 to 16 kK, but they don't show anything special at the bow shock, being about 13.7 +/- 0.4 kK there.
#
# If anything, the T is lower in the bow shock.
#
# Average over whole FOV is 14.2 +/- 0.8 kK after smoothing to eliminate the noise contribution. This implies $t^2 = 0.003$ in plane of sky, which is small.
# ## Calculate [O III]/[S III]
im5007 = Image(str(ROOT / "data/ngc346-PZ-oiii-5007-bin01-sum.fits"))
# Correct for extinction:
A5007 = rc.X(5007) * imEBV
im5007c = im5007.copy()
im5007c.data = im5007.data * 10 ** (0.4 * A5007.data)
median_EBV = np.median(imEBV[150:250, 200:300].data)
median_EBV
im5007cc = im5007.copy()
im5007cc.data = im5007.data * 10 ** (0.4 * rc.X(5007) * median_EBV)
im9069cc = im9069.copy()
im9069cc.data = im9069.data * 10 ** (0.4 * rc.X(9069) * median_EBV)
# Quick look:
fig, axes = plt.subplots(1, 2, sharey=True, figsize=(12, 6))
((im5007cc) / im9069cc).plot(
vmin=10,
vmax=55,
colorbar="v",
scale="linear",
cmap="Purples",
ax=axes[0],
)
((im5007c) / im9069c).plot(
vmin=10,
vmax=55,
colorbar="v",
scale="linear",
cmap="Purples",
ax=axes[1],
)
# The left panel is with a median reddening. The right panel is with a pixel-by-pixel reddening but that fails at the position of stars.
# Check zero points:
imax = 15000
imin = 2000
slope = 45
slope2 = 35
x = im9069cc.data
y = im5007cc.data
m = x < imax
m = m & (x > imin)
m = m & (y < slope * imax)
m = m & (y > slope * imin)
m = m & ~im9069c.mask & ~im5007c.mask
df = pd.DataFrame(
{
"9069": x[m],
"5007": y[m],
}
)
g = sns.pairplot(
df,
kind="hist",
height=4,
corner=True,
)
# g.axes[1, 0].axvline(0.0, color="r")
# g.axes[1, 0].axhline(0.0, color="r")
g.axes[1, 0].plot([0, imax], [0, slope * imax], "--", color="r")
g.axes[1, 0].plot([0, imax], [0, slope2 * imax], "--", color="r")
g.fig.suptitle("Correlation between [S III] 9069 and [O III] 5007 brightness")
slope = 45
slope2 = 35
x = im9069cc.data
y = im5007cc.data
m = x > imin
m = m & (y > 10 * x) & (y < 60 * x)
m = m & ~im9069cc.mask & ~im5007cc.mask
df = pd.DataFrame(
{
"log 9069": np.log10(x[m]),
"log 5007/9069": np.log10(y[m] / x[m]),
}
)
g = sns.pairplot(
df,
kind="hist",
height=4,
corner=True,
)
g.fig.suptitle("Correlation between [S III] 9069 and [O III] / [S III] ratio")
imR_oiii_siii = (im5007cc) / im9069cc
imR_oiii_siii.write(
str(ROOT / "data/ngc346-PZ-R-oiii-5007-siii-9069.fits"), savemask="nan"
)
# ## Calculate [O III] / Hβ
#
# This might be better since at least it is not affected by reddening.
imax = 60000
imin = 2000
slope = 5.0
slope2 = 6.0
x = imhb.data
y = im5007.data
m = x < imax
m = m & (x > imin)
m = m & (y < slope * imax)
m = m & (y > slope * imin)
m = m & ~imhb.mask & ~im5007.mask
df = pd.DataFrame(
{
"4861": x[m],
"5007": y[m],
}
)
g = sns.pairplot(
df,
kind="hist",
height=4,
corner=True,
)
g.axes[1, 0].plot([0, imax], [0, slope * imax], "--", color="r")
g.axes[1, 0].plot([0, imax], [0, slope2 * imax], "--", color="r")
g.fig.suptitle("Correlation between Hβ 4861 and [O III] 5007 brightness")
n = 1
x = imhb.rebin(n).data
y = im5007.rebin(n).data
m = (x > imin) & (y > x) & (y < 10 * x)
m = m & ~imhb.rebin(n).mask & ~im5007.rebin(n).mask
df = pd.DataFrame(
{
"log10(4861)": np.log10(x[m]),
"log10(5007 / 4861)": np.log10(y[m] / x[m]),
}
)
g = sns.pairplot(
df,
kind="hist",
height=4,
corner=True,
)
g.fig.suptitle("Correlation between Hβ 4861 and [O III] / Hβ ratio")
imR_oiii_hb = (im5007) / (imhb)
imR_oiii_hb.write(str(ROOT / "data/ngc346-PZ-R-oiii-5007-hi-4861.fits"), savemask="nan")
im4740 = Image(str(ROOT / "data/ngc346-PZ-ariv-4740-bin01-sum.fits"))
from astropy.convolution import convolve_fft
from astropy.convolution import Gaussian2DKernel
im = convolve_fft(im4740.data, Gaussian2DKernel(5.0))
fig, axes = plt.subplots(1, 2, sharey=True, figsize=(12, 6))
imR_oiii_siii.plot(
vmin=10,
vmax=55,
colorbar="v",
scale="linear",
ax=axes[0],
cmap="Purples",
)
imR_oiii_hb.plot(
vmin=2,
vmax=6.5,
colorbar="v",
scale="linear",
ax=axes[1],
cmap="Greens",
)
for ax in axes:
ax.contour(im, levels=[200, 250, 300], linewidths=1, colors="y")
axes[0].set_title("[O III] / [S III]")
axes[1].set_title("[O III] / Hβ")
# So, the bow shock shows up much better in [O III]/[S III] than it does in [O III]/Hb. This implies that it must be a lack of [S III], rather than an excess of [O III] that characterises the bow shock.
# ## Calculate He I / Hβ
#
# Let us see if this has a hole in it where the He II is coming from.
im5875 = Image(str(ROOT / "data/ngc346-PZ-hei-5875-bin01-sum.fits"))
im4922 = Image(str(ROOT / "data/ngc346-PZ-hei-4922-bin01-sum.fits"))
im5048 = Image(str(ROOT / "data/ngc346-PZ-hei-5048-bin01-sum.fits"))
fig, axes = plt.subplots(2, 2, sharey=True, figsize=(12, 12))
im5875.plot(ax=axes[0, 0], vmin=0, vmax=7500)
im4922.plot(ax=axes[0, 1], vmin=0, vmax=400)
(imhb).plot(ax=axes[1, 0], vmin=0, vmax=60000)
im5048.plot(ax=axes[1, 1], vmin=0, vmax=200)
axes[0, 0].set_title("He I 5875")
axes[0, 1].set_title("He I 4922")
axes[1, 0].set_title("H I 4861")
axes[1, 1].set_title("He I 5048")
# So 5875 is 10 to 100 times brighter than the other two. And it is almost identical to Hβ!
imax = 30000
imin = 1000
slope = 0.12
x = imhb.data
y = im5875.data
m = x < imax
m = m & (x > imin)
m = m & (y < slope * imax)
m = m & (y > imin * slope)
m = m & ~imhb.mask & ~im5875.mask
df = pd.DataFrame(
{
"4861": x[m],
"5875": y[m],
}
)
g = sns.pairplot(
df,
kind="hist",
height=4,
corner=True,
plot_kws=dict(weights=x[m], bins=200),
diag_kws=dict(weights=x[m], bins=200),
)
g.axes[1, 0].axvline(0.0, color="r")
g.axes[1, 0].axhline(0.0, color="r")
g.axes[1, 0].plot([0, imax], [0, slope * imax], "--", color="r")
g.fig.suptitle("Correlation between Hβ 4861 and He I 5875 brightness")
imax = 100000
imin = 1000
slope = 0.12
x = imhb.data
y = im5875.data
m = x < imax
m = m & (x > imin)
m = m & (y < slope * imax)
m = m & (y > imin * slope)
m = m & ~imhb.mask & ~im5875.mask
df = pd.DataFrame(
{
"4861": x[m],
"5875": y[m],
}
)
g = sns.pairplot(
df,
kind="hist",
height=4,
corner=True,
plot_kws=dict(weights=x[m], bins=200),
diag_kws=dict(weights=x[m], bins=200),
)
g.axes[1, 0].axvline(0.0, color="r")
g.axes[1, 0].axhline(0.0, color="r")
g.axes[1, 0].plot([0, imax], [0, slope * imax], "--", color="r")
g.fig.suptitle("Correlation between Hβ 4861 and He I 5875 brightness")
imR_hei_hb = im5875 / (imhb)
fig, ax = plt.subplots(figsize=(12, 12))
imR_hei_hb.plot(colorbar="v", cmap="gray", vmin=0.11, vmax=0.14)
red_R_hei_hb = imR_hei_hb.copy()
red_R_hei_hb.data = 10 ** (0.4 * imEBV.data * (rc.X(4861) - rc.X(5875)))
fig, ax = plt.subplots(figsize=(12, 12))
(imR_hei_hb / red_R_hei_hb).plot(colorbar="v", cmap="gray", vmin=0.1, vmax=0.115)
# So if we correct it for reddening, then lots of spurious structure disappears. But we are left with very little variation at all, except for at the mYSO and the top right corner, which both show low He I.
# ## Calculate He II / Hβ
#
#
im4686 = Image(str(ROOT / "data/ngc346-PZ-heii-4686-bin01-sum.fits"))
fig, ax = plt.subplots(figsize=(12, 12))
im4686.plot(colorbar="v", cmap="gray", vmin=0.0, vmax=300)
# +
imR_heii_hb = im4686 / imhb
fig, ax = plt.subplots(figsize=(12, 12))
imR_heii_hb.plot(colorbar="v", cmap="gray", vmin=-0.01, vmax=0.01)
# -
n = 2
xslice, yslice = slice(200, 300), slice(100, 250)
x = imR_heii_hb[yslice, xslice].rebin(n).data
y = (
imR_hei_hb[yslice, xslice].rebin(n).data
/ red_R_hei_hb[yslice, xslice].rebin(n).data
)
z = im4686[yslice, xslice].rebin(n).data
m = x < 0.03
m = m & (x > 0)
m = m & (y < 0.113)
m = m & (y > 0.103)
m = (
m
& ~imR_heii_hb[yslice, xslice].rebin(n).mask
& ~imR_hei_hb[yslice, xslice].rebin(n).mask
)
df = pd.DataFrame(
{
"4686 / 4861": x[m],
"5875 / 4861": y[m],
}
)
g = sns.pairplot(
df,
kind="hist",
height=4,
corner=True,
plot_kws=dict(weights=z[m], bins=30),
diag_kws=dict(weights=z[m], bins=30),
)
g.fig.suptitle("Correlation between He II / Hβ and He I / Hβ ratios")
# So there is a *tiny* change in 5875/4861 from 0.109 to 0.107 as 4686/4861 increases.
df["high"] = df["4686 / 4861"] > 0.005
df
sns.histplot(
data=df,
x="5875 / 4861",
hue="high",
multiple="dodge",
shrink=1.0,
stat="probability",
common_norm=False,
alpha=0.8,
bins=10,
)
# Try to remove the pattern noise
imR_heii_hb_fake = imR_heii_hb.copy()
m = imR_heii_hb_fake.data > 0.01
imR_heii_hb_fake.data[m] = np.nan
vv = np.nanmedian(imR_heii_hb_fake.data, axis=0, keepdims=True)
hh = np.nanmedian(imR_heii_hb_fake.data, axis=1, keepdims=True)
imR_heii_hb_fake.data = vv + hh
imR_heii_hb_fake.data -= np.nanmedian(vv + hh)
imR_heii_hb_c = imR_heii_hb.copy()
imR_heii_hb_c.data -= imR_heii_hb_fake.data
fig, axes = plt.subplots(2, 2, figsize=(12, 12))
imR_heii_hb_fake.plot(ax=axes[0, 0], colorbar="v", cmap="gray", vmin=-0.01, vmax=0.01)
(imR_hei_hb / red_R_hei_hb).plot(ax=axes[0, 1],
colorbar="v", cmap="gray",
vmin=0.1, vmax=0.115)
imR_heii_hb.plot(ax=axes[1, 0], colorbar="v", cmap="gray", vmin=-0.01, vmax=0.01)
imR_heii_hb_c.plot(ax=axes[1, 1], colorbar="v", cmap="gray", vmin=-0.01, vmax=0.01)
n = 2
xslice, yslice = slice(200, 300), slice(100, 250)
#xslice, yslice = slice(230, 300), slice(130, 220)
x = imR_heii_hb_c[yslice, xslice].rebin(n).data
y = (
imR_hei_hb[yslice, xslice].rebin(n).data
/ red_R_hei_hb[yslice, xslice].rebin(n).data
)
z = im4686[yslice, xslice].rebin(n).data
m = x < 0.03
m = m & (x > 0)
m = m & (y < 0.113)
m = m & (y > 0.103)
m = (
m
& ~imR_heii_hb[yslice, xslice].rebin(n).mask
& ~imR_hei_hb[yslice, xslice].rebin(n).mask
)
df = pd.DataFrame(
{
"4686 / 4861": x[m],
"5875 / 4861": y[m],
}
)
g = sns.pairplot(
df,
kind="hist",
height=4,
corner=True,
plot_kws=dict(weights=z[m], bins=10),
diag_kws=dict(weights=z[m], bins=10),
)
g.fig.suptitle("Correlation between He II / Hβ and He I / Hβ ratios")
df["high"] = df["4686 / 4861"] > 0.003
sns.histplot(
data=df,
x="5875 / 4861",
hue="high",
multiple="dodge",
shrink=1.0,
stat="probability",
common_norm=False,
alpha=0.8,
bins=10,
)
df["high"] = df["4686 / 4861"] > 0.003
sns.histplot(
data=df,
x="5875 / 4861",
hue="high",
#multiple="dodge",
shrink=1.0,
stat="probability",
cumulative=True,
common_norm=False,
alpha=0.8,
bins=1000,
element="step",
).axhline(0.5, linestyle="dotted", color="k")
# So, the depatterning improved the map but did not help with the statistics.
#
#
# ## Ratio of [Ar IV] / [Ar III]
im4711 = Image(str(ROOT / "data/ngc346-PZ-ariv-4711-bin01-sum.fits"))
im4740 = Image(str(ROOT / "data/ngc346-PZ-ariv-4740-bin01-sum.fits"))
im7171 = Image(str(ROOT / "data/ngc346-PZ-ariv-7171-bin01-sum.fits"))
im7237 = Image(str(ROOT / "data/ngc346-PZ-ariv-7237-bin01-sum.fits"))
im7263 = Image(str(ROOT / "data/ngc346-PZ-ariv-7263-bin01-sum.fits"))
im7136 = Image(str(ROOT / "data/ngc346-PZ-ariii-7136-bin01-sum.fits"))
fig, axes = plt.subplots(2, 2, sharey=True, figsize=(12, 12))
im4711.plot(ax=axes[0, 0], vmin=0, vmax=600)
im4740.plot(ax=axes[0, 1], vmin=0, vmax=450)
(im7171 + im7263).plot(ax=axes[1, 0], vmin=0, vmax=30)
im7136.plot(ax=axes[1, 1], vmin=0, vmax=4500)
axes[0, 0].set_title("[Ar IV] 4711 + He I 4713")
axes[0, 1].set_title("[Ar IV] 4740")
axes[1, 0].set_title("[Ar IV] 7171 + 7263")
axes[1, 1].set_title("[Ar III] 7136")
n = 8
fig, axes = plt.subplots(2, 2, sharey=True, figsize=(12, 12))
(im4711.rebin(n) / im4740.rebin(n)).plot(ax=axes[0, 0], vmin=0, vmax=2)
(im4740.rebin(n) / im7136.rebin(n)).plot(ax=axes[0, 1], vmin=0, vmax=0.1)
((im7171.rebin(n) + im7263.rebin(n)) / (im4740.rebin(n) + im4711.rebin(n))).plot(
ax=axes[1, 0], vmin=0, vmax=0.04