pymakeplots 0.2.4__py3-none-any.whl → 0.2.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pymakeplots/pymakeplots.py +121 -17
- {pymakeplots-0.2.4.dist-info → pymakeplots-0.2.6.dist-info}/METADATA +4 -1
- pymakeplots-0.2.6.dist-info/RECORD +9 -0
- pymakeplots-0.2.4.dist-info/RECORD +0 -9
- {pymakeplots-0.2.4.dist-info → pymakeplots-0.2.6.dist-info}/LICENSE.md +0 -0
- {pymakeplots-0.2.4.dist-info → pymakeplots-0.2.6.dist-info}/WHEEL +0 -0
- {pymakeplots-0.2.4.dist-info → pymakeplots-0.2.6.dist-info}/top_level.txt +0 -0
- {pymakeplots-0.2.4.dist-info → pymakeplots-0.2.6.dist-info}/zip-safe +0 -0
pymakeplots/pymakeplots.py
CHANGED
|
@@ -9,8 +9,9 @@ import matplotlib.pyplot as plt
|
|
|
9
9
|
import matplotlib
|
|
10
10
|
from pymakeplots.sauron_colormap import sauron
|
|
11
11
|
from mpl_toolkits.axes_grid1 import make_axes_locatable
|
|
12
|
-
from matplotlib.patches import Ellipse,Rectangle, Arrow
|
|
12
|
+
from matplotlib.patches import Ellipse,Rectangle, Arrow, FancyArrowPatch
|
|
13
13
|
from matplotlib import cm
|
|
14
|
+
from matplotlib.text import Text
|
|
14
15
|
from matplotlib.colors import ListedColormap, LinearSegmentedColormap
|
|
15
16
|
from matplotlib.offsetbox import AnchoredText,AuxTransformBox, AnchoredOffsetbox
|
|
16
17
|
from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar,AnchoredDirectionArrows
|
|
@@ -54,12 +55,16 @@ class pymakeplots:
|
|
|
54
55
|
self.pbcorr_cube=None
|
|
55
56
|
self.spectralcube=None
|
|
56
57
|
self.mask=None
|
|
58
|
+
self.masksmoothing=0
|
|
59
|
+
self.maskdilating=0
|
|
57
60
|
self.flat_cube_trim=None
|
|
58
61
|
self.pbcorr_cube_trim=None
|
|
59
62
|
self.mask_trim=None
|
|
63
|
+
self.pbcliplevel=None
|
|
60
64
|
self.bmaj=None
|
|
61
65
|
self.rotate=rotate
|
|
62
66
|
self.smoothmask_spatial=1.5
|
|
67
|
+
self.smoothmask_velocity=4
|
|
63
68
|
self.bmin=None
|
|
64
69
|
self.bpa=None
|
|
65
70
|
self.xcoord,self.ycoord,self.vcoord = None, None, None
|
|
@@ -96,6 +101,7 @@ class pymakeplots:
|
|
|
96
101
|
self.suppress_subbeam_artifacts=False
|
|
97
102
|
self.mom1_cmap=sauron
|
|
98
103
|
self.mom2_cmap=sauron
|
|
104
|
+
self.pb_radial_cut=False
|
|
99
105
|
#self.wcs=None
|
|
100
106
|
|
|
101
107
|
if (cube != None)&(pb==None)&(cube_flat==None):
|
|
@@ -183,11 +189,25 @@ class pymakeplots:
|
|
|
183
189
|
:return: (ndarray) mask to apply to the un-clipped cube
|
|
184
190
|
"""
|
|
185
191
|
sigma = self.smoothmask_spatial * self.bmaj / self.cellsize
|
|
186
|
-
smooth_cube = ndimage.uniform_filter(cube, size=[sigma, sigma,
|
|
192
|
+
smooth_cube = ndimage.uniform_filter(cube, size=[sigma, sigma,self.smoothmask_velocity], mode='constant') # mode='nearest'
|
|
187
193
|
newrms= self.rms_estimate(smooth_cube,0,1)
|
|
188
|
-
self.cliplevel=self.rms*self.rmsfac
|
|
194
|
+
self.cliplevel=self.rms*self.rmsfac
|
|
195
|
+
|
|
196
|
+
if self.pb_radial_cut or self.pbcliplevel!=None:
|
|
197
|
+
np.seterr(all='ignore')
|
|
198
|
+
pb=np.divide(self.flat_cube_trim,self.pbcorr_cube_trim)#,where=self.pbcorr_cube_trim!=0)
|
|
199
|
+
|
|
189
200
|
self.maskcliplevel=newrms*self.rmsfac
|
|
190
|
-
|
|
201
|
+
|
|
202
|
+
if self.pb_radial_cut:
|
|
203
|
+
mask=(smooth_cube > np.divide(self.maskcliplevel,np.abs(pb),where=pb!=0))
|
|
204
|
+
else:
|
|
205
|
+
mask=(np.abs(smooth_cube) > self.maskcliplevel)
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
if self.pbcliplevel!=None:
|
|
210
|
+
mask[pb<self.pbcliplevel]=False
|
|
191
211
|
|
|
192
212
|
if self.suppress_subbeam_artifacts:
|
|
193
213
|
label,cnt=ndimage.label(mask)#.sum(axis=2))
|
|
@@ -195,6 +215,52 @@ class pymakeplots:
|
|
|
195
215
|
beampix=(self.bmaj*self.bmin)/(self.cellsize**2)
|
|
196
216
|
for thelabel in lab[0:-1][hist<(beampix*self.suppress_subbeam_artifacts)]:
|
|
197
217
|
mask[label == thelabel]=False
|
|
218
|
+
#maskorig=mask.copy()
|
|
219
|
+
if self.masksmoothing>0:
|
|
220
|
+
expand_by_npix=self.masksmoothing
|
|
221
|
+
print(expand_by_npix)
|
|
222
|
+
# structure = np.zeros([3, expand_by_npix * 2 + 1, expand_by_npix * 2 + 1])
|
|
223
|
+
# Y, X = np.ogrid[:expand_by_npix * 2 + 1, :expand_by_npix * 2 + 1]
|
|
224
|
+
# R = np.sqrt((X - expand_by_npix) ** 2 + (Y - expand_by_npix) ** 2)
|
|
225
|
+
# structure[1, :] = R <= expand_by_npix
|
|
226
|
+
# mask = ndimage.binary_dilation(mask, iterations=1, structure=structure)
|
|
227
|
+
#breakpoint()
|
|
228
|
+
mask = ndimage.binary_dilation(mask, iterations=expand_by_npix,axes=(0,1,2))
|
|
229
|
+
|
|
230
|
+
'''
|
|
231
|
+
r=np.linspace(1,0,self.masksmoothing+1,endpoint=False)[1:]
|
|
232
|
+
facs=np.exp(-((r-1)**2/(2*(0.33)**2)))
|
|
233
|
+
|
|
234
|
+
maskorig=mask.copy()
|
|
235
|
+
struct1 = ndimage.generate_binary_structure(2, 1)
|
|
236
|
+
for i,fac in enumerate(facs):
|
|
237
|
+
mask2 = ndimage.grey_dilation(maskorig.astype(float), (int(i+1),int(i+1),0), mode='constant') #
|
|
238
|
+
mask=np.fmax(mask,mask2*facs[i])
|
|
239
|
+
'''
|
|
240
|
+
#
|
|
241
|
+
#
|
|
242
|
+
#from kinms import KinMS
|
|
243
|
+
#from astropy.convolution import convolve
|
|
244
|
+
#psf=KinMS.makebeam(1,32, 32, [self.masksmoothing,self.masksmoothing,0])
|
|
245
|
+
|
|
246
|
+
#for i in range(0,mask.shape[2]):
|
|
247
|
+
# mask[:, :, i] = convolve(mask[:, :, i], psf) #binary
|
|
248
|
+
#mask=mask.astype(float)
|
|
249
|
+
#for i in range(0,mask.shape[2]):
|
|
250
|
+
# mask[:, :, i] = convolve(mask[:, :, i], psf) #smooth
|
|
251
|
+
#mask[mask<maskorig]=maskorig[mask<maskorig]
|
|
252
|
+
#mask=np.fmax(mask,maskorig)
|
|
253
|
+
#mask = ndimage.uniform_filter(mask.astype(float), size=[self.masksmoothing,self.masksmoothing,0], mode='constant') #
|
|
254
|
+
#print(mask.sum())
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
#mask = ndimage.gaussian_filter(mask.astype(float), [self.masksmoothing,self.masksmoothing,0], mode='constant') #
|
|
259
|
+
#if self.maskdilating != 0:
|
|
260
|
+
# mask=ndimage.grey_dilation(mask.astype(float), size=(np.round(self.maskdilating).astype(int),np.round(self.maskdilating).astype(int),0))
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
#breakpoint()
|
|
198
264
|
|
|
199
265
|
return mask
|
|
200
266
|
|
|
@@ -366,6 +432,7 @@ class pymakeplots:
|
|
|
366
432
|
hdr=scube.header
|
|
367
433
|
cube = np.squeeze(scube.filled_data[:,:,:].T).value #squeeze to remove singular stokes axis if present
|
|
368
434
|
cube[np.isfinite(cube) == False] = 0.0
|
|
435
|
+
|
|
369
436
|
try:
|
|
370
437
|
beamtab=scube.beam
|
|
371
438
|
except:
|
|
@@ -377,7 +444,13 @@ class pymakeplots:
|
|
|
377
444
|
beamvals=[scube.header['bmaj'],scube.header['bmin']]
|
|
378
445
|
beamtab=Beam(major=np.max(beamvals)*u.deg,minor=np.min(beamvals)*u.deg,pa=self.spectralcube.header['bpa']*u.deg)
|
|
379
446
|
except:
|
|
380
|
-
beamtab=False
|
|
447
|
+
beamtab=False
|
|
448
|
+
|
|
449
|
+
if beamtab.major.value ==0:
|
|
450
|
+
### MeerKAT style beams
|
|
451
|
+
beamvals=[np.mean([scube.header['bmaj1'],scube.header['bmaj3826']]),np.mean([scube.header['bmin1'],scube.header['bmin3826']])]
|
|
452
|
+
beamtab=Beam(major=np.max(beamvals)*u.deg,minor=np.min(beamvals)*u.deg,pa=np.mean([scube.header['bpa1'],scube.header['bpa3826']])*u.deg)
|
|
453
|
+
|
|
381
454
|
if primary:
|
|
382
455
|
self.spectralcube=scube
|
|
383
456
|
self.repfreq=np.median(self.spectralcube.with_spectral_unit(u.GHz).spectral_axis)
|
|
@@ -705,11 +778,14 @@ class pymakeplots:
|
|
|
705
778
|
|
|
706
779
|
def add_beam(self,ax):
|
|
707
780
|
aux_tr_box = AuxTransformBox(ax.transData)
|
|
708
|
-
|
|
781
|
+
if self.rotate!=None:
|
|
782
|
+
rotang=self.rotate
|
|
783
|
+
else:
|
|
784
|
+
rotang=0
|
|
709
785
|
if self.all_axes_physical:
|
|
710
|
-
aux_tr_box.add_artist(Ellipse((0, 0), width=self.ang2kpctrans(self.bmaj), height=self.ang2kpctrans(self.bmin), angle=self.bpa+90,edgecolor='black',facecolor='none',linewidth=1.5))
|
|
786
|
+
aux_tr_box.add_artist(Ellipse((0, 0), width=self.ang2kpctrans(self.bmaj), height=self.ang2kpctrans(self.bmin), angle=self.bpa+90+rotang,edgecolor='black',facecolor='none',linewidth=1.5))
|
|
711
787
|
else:
|
|
712
|
-
aux_tr_box.add_artist(Ellipse((0, 0), width=self.bmaj, height=self.bmin, angle=self.bpa+90,edgecolor='black',facecolor='none',linewidth=1.5))
|
|
788
|
+
aux_tr_box.add_artist(Ellipse((0, 0), width=self.bmaj, height=self.bmin, angle=self.bpa+90+rotang,edgecolor='black',facecolor='none',linewidth=1.5))
|
|
713
789
|
box = AnchoredOffsetbox(child=aux_tr_box, loc='lower left', pad=0.5, borderpad=0.4,frameon=False)
|
|
714
790
|
ax.add_artist(box)
|
|
715
791
|
|
|
@@ -761,7 +837,31 @@ class pymakeplots:
|
|
|
761
837
|
|
|
762
838
|
rotmat=np.array([[np.cos(np.deg2rad(self.rotate)),-np.sin(np.deg2rad(self.rotate))],[np.sin(np.deg2rad(self.rotate)),np.cos(np.deg2rad(self.rotate))]])
|
|
763
839
|
dx1,dx2=np.dot(rotmat,np.array([0,length2use]))
|
|
764
|
-
|
|
840
|
+
if (dx1 <0)&(dx2<0):
|
|
841
|
+
#lower left quadrant
|
|
842
|
+
startx,starty= np.abs(dx1), np.abs(dx2)
|
|
843
|
+
endx,endy=0,0
|
|
844
|
+
ha='right'
|
|
845
|
+
if (dx1 <0)&(dx2>0):
|
|
846
|
+
#upper left quadrant
|
|
847
|
+
startx,starty= 0,0
|
|
848
|
+
endx,endy= dx1,dx2
|
|
849
|
+
ha='right'
|
|
850
|
+
if (dx1 >0)&(dx2>0):
|
|
851
|
+
#upper right quadrant
|
|
852
|
+
startx,starty= 0,0
|
|
853
|
+
endx,endy= dx1, dx2
|
|
854
|
+
ha='left'
|
|
855
|
+
if (dx1 >0)&(dx2<0):
|
|
856
|
+
#lower right quadrant
|
|
857
|
+
startx,starty= -np.abs(dx1), np.abs(dx2)
|
|
858
|
+
endx,endy=0,0
|
|
859
|
+
ha='left'
|
|
860
|
+
|
|
861
|
+
aux_tr_box.add_artist(Text(endx,endy,'N',color='k',ha=ha,fontsize='small',va='center'))
|
|
862
|
+
aux_tr_box.add_artist(FancyArrowPatch((startx,starty), (endx,endy),
|
|
863
|
+
mutation_scale=100,color='k',arrowstyle='->,head_length=0.1, head_width=0.05'))
|
|
864
|
+
|
|
765
865
|
box = AnchoredOffsetbox(child=aux_tr_box, loc=loc, frameon=False)
|
|
766
866
|
ax.add_artist(box)
|
|
767
867
|
#ax.text(3, y + 0.05, bracketstyle, ha="center", va="bottom", fontsize=14)
|
|
@@ -1139,9 +1239,10 @@ class pymakeplots:
|
|
|
1139
1239
|
centpix_y=np.where(np.isclose(self.yc,0.0,atol=self.cellsize/1.9))[0]
|
|
1140
1240
|
|
|
1141
1241
|
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1242
|
+
if self.posang!=0:
|
|
1243
|
+
rotcube= rotateImage(self.pbcorr_cube_trim*self.mask_trim,90-self.posang,[centpix_x[0],centpix_y[0]])
|
|
1244
|
+
else:
|
|
1245
|
+
rotcube=self.pbcorr_cube_trim*self.mask_trim
|
|
1145
1246
|
|
|
1146
1247
|
pvd=rotcube[:,np.array(rotcube.shape[1]//2-self.pvdthick).astype(int):np.array(rotcube.shape[1]//2+self.pvdthick).astype(int),:].sum(axis=1)
|
|
1147
1248
|
|
|
@@ -1227,14 +1328,17 @@ class pymakeplots:
|
|
|
1227
1328
|
|
|
1228
1329
|
mask2d=self.mask_trim.sum(axis=2).reshape((self.mask_trim.shape[0],self.mask_trim.shape[1],1)).astype(bool)
|
|
1229
1330
|
mask2d=ndimage.binary_dilation(mask2d,iterations=2)
|
|
1230
|
-
|
|
1231
|
-
|
|
1331
|
+
if self.bunit == "K":
|
|
1332
|
+
spec=np.nanmean(self.pbcorr_cube[self.spatial_trim[0]:self.spatial_trim[1],self.spatial_trim[2]:self.spatial_trim[3],:],axis=(0,1))*1e3
|
|
1333
|
+
spec_mask=np.nanmean((self.pbcorr_cube_trim*self.mask_trim),axis=(0,1))*1e3
|
|
1334
|
+
else:
|
|
1335
|
+
spec=(self.pbcorr_cube[self.spatial_trim[0]:self.spatial_trim[1],self.spatial_trim[2]:self.spatial_trim[3],:]*mask2d).sum(axis=0).sum(axis=0)
|
|
1336
|
+
spec_mask=(self.pbcorr_cube_trim*self.mask_trim).sum(axis=0).sum(axis=0)
|
|
1232
1337
|
|
|
1233
|
-
|
|
1338
|
+
|
|
1234
1339
|
ylab="Unknown"
|
|
1235
1340
|
|
|
1236
1341
|
if (''.join(self.bunit.split())).lower() == "Jy/beam".lower():
|
|
1237
|
-
|
|
1238
1342
|
spec*=1/self.beam_area()
|
|
1239
1343
|
spec_mask*=1/self.beam_area()
|
|
1240
1344
|
|
|
@@ -1245,7 +1349,7 @@ class pymakeplots:
|
|
|
1245
1349
|
else:
|
|
1246
1350
|
ylab="Flux Density (Jy)"
|
|
1247
1351
|
if self.bunit == "K":
|
|
1248
|
-
ylab="Brightness Temp. (
|
|
1352
|
+
ylab="Brightness Temp. (mK)"
|
|
1249
1353
|
|
|
1250
1354
|
if nsum:
|
|
1251
1355
|
spec=np.append(running_mean(spec,nsum),spec[-1])
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pymakeplots
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.6
|
|
4
4
|
Home-page: https://github.com/TimothyADavis/pymakeplots
|
|
5
5
|
Author: Timothy A. Davis
|
|
6
6
|
Author-email: DavisT@cardiff.ac.uk
|
|
@@ -19,6 +19,9 @@ Requires-Dist: spectral-cube
|
|
|
19
19
|
Requires-Dist: radio-beam
|
|
20
20
|
Requires-Dist: pafit
|
|
21
21
|
|
|
22
|
+
# pymakeplots
|
|
23
|
+
<img style="float:top,right" src="https://github.com/TimothyADavis/pymakeplots/blob/master/NGC1684_allplots.png">
|
|
24
|
+
|
|
22
25
|
[](https://www.python.org/downloads/release/python-382/) [](https://badge.fury.io/py/pymakeplots)
|
|
23
26
|
|
|
24
27
|
A python module for making publication quality plots and output datafiles (including moment zero, one, two, PVD's and spectra) from interferometric datacubes.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
pymakeplots/__init__.py,sha256=PLKnIm6rIKYjH_b6L9UBCFtv1lKt5GItdBKDbSOhuMU,87
|
|
2
|
+
pymakeplots/pymakeplots.py,sha256=pnPm6IBGsydY5QTYdmmpqdZnznR7kyt_e_5DYVwQ0Fw,56827
|
|
3
|
+
pymakeplots/sauron_colormap.py,sha256=8APka-_L432wyICcHcySjk3qmjNOynb3iDjjlMuUTU0,4448
|
|
4
|
+
pymakeplots-0.2.6.dist-info/LICENSE.md,sha256=qtvmvajOPCad_5HMY5u49hldzBIXz7tbHbuGSG_HE5o,1077
|
|
5
|
+
pymakeplots-0.2.6.dist-info/METADATA,sha256=SiNH7cgb8pdcm6GEUeLDTJJjYcI7fRBIEkWuqDnUwaA,1976
|
|
6
|
+
pymakeplots-0.2.6.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
|
|
7
|
+
pymakeplots-0.2.6.dist-info/top_level.txt,sha256=KgG17vI_D6BsiKRe_81UU5709tXc6Ha7gx1IwjA7ur8,12
|
|
8
|
+
pymakeplots-0.2.6.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
9
|
+
pymakeplots-0.2.6.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
pymakeplots/__init__.py,sha256=PLKnIm6rIKYjH_b6L9UBCFtv1lKt5GItdBKDbSOhuMU,87
|
|
2
|
-
pymakeplots/pymakeplots.py,sha256=qDG7pwhiUprjVvSqQzPt6PyU-W_BJGGf-pZTsN3kK6U,52065
|
|
3
|
-
pymakeplots/sauron_colormap.py,sha256=8APka-_L432wyICcHcySjk3qmjNOynb3iDjjlMuUTU0,4448
|
|
4
|
-
pymakeplots-0.2.4.dist-info/LICENSE.md,sha256=qtvmvajOPCad_5HMY5u49hldzBIXz7tbHbuGSG_HE5o,1077
|
|
5
|
-
pymakeplots-0.2.4.dist-info/METADATA,sha256=7IC9lbVFzP8BVTdzsci1b7w1T39TytxqVyNWmk-9TAE,1847
|
|
6
|
-
pymakeplots-0.2.4.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
|
|
7
|
-
pymakeplots-0.2.4.dist-info/top_level.txt,sha256=KgG17vI_D6BsiKRe_81UU5709tXc6Ha7gx1IwjA7ur8,12
|
|
8
|
-
pymakeplots-0.2.4.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
9
|
-
pymakeplots-0.2.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|