pymakeplots 0.2.0__py3-none-any.whl → 0.2.1__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.
@@ -66,6 +66,7 @@ class pymakeplots:
66
66
  self.bardist=None
67
67
  self.rmsfac=3
68
68
  self.restfreq=None
69
+ self.repfreq=None
69
70
  self.obj_ra=None
70
71
  self.obj_dec=None
71
72
  self.imagesize=None
@@ -78,6 +79,10 @@ class pymakeplots:
78
79
  self.spatial_trim = None
79
80
  self.maxvdisp=None
80
81
  self.cliplevel=None
82
+ self.points2plot=None
83
+ self.pointingsra=None
84
+ self.pointingsdec=None
85
+ self.pointingsdiam=None
81
86
  self.fits=False
82
87
  self.pvdthick=5.
83
88
  self.flipped=False
@@ -170,8 +175,9 @@ class pymakeplots:
170
175
  sigma = 1.5 * self.bmaj / self.cellsize
171
176
  smooth_cube = ndimage.uniform_filter(cube, size=[sigma, sigma,4], mode='constant') # mode='nearest'
172
177
  newrms= self.rms_estimate(smooth_cube,0,1)
173
- self.cliplevel=newrms*self.rmsfac
174
- mask=(smooth_cube > self.cliplevel)
178
+ self.cliplevel=self.rms*self.rmsfac
179
+ self.maskcliplevel=newrms*self.rmsfac
180
+ mask=(smooth_cube > self.maskcliplevel)
175
181
  # print("Clip level:",((3e20*1.6014457E-20*91.9)/(self.bmaj*self.bmin))*self.cliplevel*self.dv)
176
182
  # import ipdb
177
183
  # ipdb.set_trace()
@@ -302,7 +308,8 @@ class pymakeplots:
302
308
  return np.nanstd(cube[quarterx*1:3*quarterx,1*quartery:3*quartery,chanstart:chanend])
303
309
 
304
310
  def get_header_coord_arrays(self,hdr):
305
-
311
+
312
+
306
313
  cd1=self.spectralcube.wcs.pixel_scale_matrix[0,0]*3600
307
314
  cd2=self.spectralcube.wcs.pixel_scale_matrix[1,1]*3600
308
315
  x1=((np.arange(1,hdr['NAXIS1']+1)-(hdr['NAXIS1']//2))*cd1)# + hdr['CRVAL1']
@@ -311,6 +318,7 @@ class pymakeplots:
311
318
  v1=self.spectralcube.spectral_axis.value
312
319
 
313
320
  cd3= np.median(np.diff(v1))
321
+
314
322
 
315
323
  return x1,y1,v1,np.abs(cd1),cd3
316
324
 
@@ -332,7 +340,7 @@ class pymakeplots:
332
340
  beamtab=Beam(major=np.max(beamvals)*u.deg,minor=np.min(beamvals)*u.deg,pa=self.spectralcube.header['bpa']*u.deg)
333
341
  except:
334
342
  beamtab=False
335
-
343
+ self.repfreq=np.median(self.spectralcube.with_spectral_unit(u.GHz).spectral_axis)
336
344
  return cube, hdr, beamtab
337
345
 
338
346
 
@@ -369,7 +377,15 @@ class pymakeplots:
369
377
 
370
378
  self.rms= self.rms_estimate(datacube,self.linefree_chans_start,self.linefree_chans_end)
371
379
  return datacube
372
-
380
+
381
+ def calc_offset(self,ra,dec):
382
+ refpos=SkyCoord(ra,dec)
383
+ xpix,ypix=self.spectralcube.wcs.celestial.world_to_pixel(refpos)
384
+ #self.xcentpix,self.ycentpix= xpix,ypix
385
+ xoffsetarc=np.interp(xpix,np.arange(self.xcoord.size),self.xcoord)
386
+ yoffsetarc=np.interp(ypix,np.arange(self.ycoord.size),self.ycoord)
387
+ return xpix,ypix,xoffsetarc,yoffsetarc
388
+
373
389
  def prepare_cubes(self):
374
390
 
375
391
  self.centskycoord=self.spectralcube.wcs.celestial.pixel_to_world(self.xcoord.size//2,self.ycoord.size//2).transform_to('icrs')
@@ -380,12 +396,19 @@ class pymakeplots:
380
396
  if self.obj_dec == None:
381
397
  self.obj_dec=self.y_skycent
382
398
 
383
- refpos=SkyCoord(self.obj_ra*u.deg,self.obj_dec*u.deg)
384
- xpix,ypix=self.spectralcube.wcs.celestial.world_to_pixel(refpos)
385
-
386
- xoffsetarc=np.interp(xpix,np.arange(self.xcoord.size),self.xcoord)
387
- yoffsetarc=np.interp(ypix,np.arange(self.ycoord.size),self.ycoord)
388
399
 
400
+ xpix,ypix,xoffsetarc,yoffsetarc=self.calc_offset(self.obj_ra*u.deg,self.obj_dec*u.deg)
401
+ self.xcentpix,self.ycentpix= xpix,ypix
402
+
403
+
404
+ ### want to overplot the pointings
405
+ if self.pointingsra != None:
406
+ pointingposes=SkyCoord(self.pointingsra,self.pointingsdec,frame='icrs',unit=(u.hourangle,u.deg))
407
+ _,_,pointoffsetx,pointoffsety=self.calc_offset(pointingposes.ra,pointingposes.dec)
408
+ self.points2plot=np.zeros((len(pointoffsetx),3))
409
+ self.points2plot[:,0]=pointoffsetx-xoffsetarc
410
+ self.points2plot[:,1]=pointoffsety-yoffsetarc
411
+ self.points2plot[:,2]=self.pointingsdiam.value
389
412
 
390
413
  self.clip_cube(xoffsetarc,yoffsetarc)
391
414
 
@@ -404,6 +427,8 @@ class pymakeplots:
404
427
  if self.all_axes_physical:
405
428
  self.xc=self.ang2kpctrans(self.xc)
406
429
  self.yc=self.ang2kpctrans(self.yc)
430
+ if self.pointingsra != None:
431
+ self.points2plot=self.ang2kpctrans(self.points2plot)
407
432
 
408
433
 
409
434
 
@@ -441,7 +466,7 @@ class pymakeplots:
441
466
  self.make_spec(axes=ax5,fits=fits)
442
467
 
443
468
  ### plotting PA on mom1
444
- ypv=np.arange(-np.max(self.yc),np.max(self.yc),20)
469
+ ypv=np.arange(-np.max(self.yc),np.max(self.yc),self.cellsize)
445
470
  xpv=ypv*0.0
446
471
  ang=self.posang
447
472
  c = np.cos(np.deg2rad(ang))
@@ -701,6 +726,29 @@ class pymakeplots:
701
726
 
702
727
 
703
728
  self.add_beam(ax1)
729
+
730
+ if np.any(self.points2plot != None):
731
+ naca=0
732
+ nalma=0
733
+ for xp,yp,diam in self.points2plot:
734
+ if diam/np.min(self.points2plot[:,2])>1.7:
735
+ ls=':' #aca
736
+ if naca ==0:
737
+ label='ACA'
738
+ else:
739
+ label=None
740
+ naca+=1
741
+ else:
742
+ ls='--' #12m
743
+ if nalma ==0:
744
+ label='12m'
745
+ else:
746
+ label=None
747
+ nalma+=1
748
+ circle2 = plt.Circle((xp, yp), diam/2., color='k',ls=ls, fill=False,alpha=0.2,label=label)
749
+ ax1.add_patch(circle2)
750
+ ax1.legend(frameon=False,loc='upper left',fontsize='x-small',markerscale=0.5)
751
+
704
752
  if self.make_square:
705
753
  ax1.set_xlim(np.min([self.xc[0],self.yc[0]]),np.max([self.xc[-1],self.yc[-1]]))
706
754
  ax1.set_ylim(np.min([self.xc[0],self.yc[0]]),np.max([self.xc[-1],self.yc[-1]]))
@@ -725,7 +773,7 @@ class pymakeplots:
725
773
  mom1=mom0.copy()*np.nan
726
774
  mom1[mom0 != 0.0] = (((self.pbcorr_cube_trim*self.mask_trim)*self.vcoord_trim).sum(axis=2))[mom0 != 0.0]/mom0[mom0 != 0.0]
727
775
 
728
-
776
+
729
777
  vticks=np.linspace((-1)*np.ceil(np.max(np.abs(self.vcoord_trim-self.vsys))/10.)*10.,np.ceil(np.max(np.abs(self.vcoord_trim-self.vsys))/10.)*10.,5)
730
778
 
731
779
  im1=ax1.contourf(self.xc,self.yc,mom1.T-self.vsys,levels=self.vcoord_trim-self.vsys,cmap=sauron,vmin=vticks[0],vmax=vticks[-1])
@@ -860,8 +908,8 @@ class pymakeplots:
860
908
  newhdu.header['CUNIT2']=self.spectralcube.header['CUNIT2']
861
909
  newhdu.header['BMAJ']=self.bmaj/3600.
862
910
  newhdu.header['BMIN']=self.bmin/3600.
863
- newhdu.header['BPA']=self.bpa/3600.
864
- newhdu.header['MOMCLIP']=(self.cliplevel, self.bunit+' km/s')
911
+ newhdu.header['BPA']=self.bpa
912
+ newhdu.header['MOMCLIP']=(self.maskcliplevel, self.bunit+' km/s')
865
913
  newhdu.header['VSYS']=(self.vsys,'km/s')
866
914
  newhdu.header['comment'] = 'Moment map created with pymakeplots'
867
915
 
@@ -881,7 +929,7 @@ class pymakeplots:
881
929
  filename=self.galname+"_pvd.fits"
882
930
  else:
883
931
  filename=self.fits+"_pvd.fits"
884
-
932
+
885
933
  newhdu = fits.PrimaryHDU(pvd)
886
934
  newhdu.header['CRPIX1']=1
887
935
  newhdu.header['CRVAL1']=xx[0]
@@ -895,10 +943,10 @@ class pymakeplots:
895
943
  newhdu.header['CUNIT2']='km/s'
896
944
  newhdu.header['BMAJ']=self.bmaj/3600.
897
945
  newhdu.header['BMIN']=self.bmin/3600.
898
- newhdu.header['BPA']=self.bpa/3600.
946
+ newhdu.header['BPA']=self.bpa
899
947
  newhdu.header['PVDANGLE']=(self.posang,'deg')
900
948
  newhdu.header['PVDTHICK']=(self.pvdthick,'pixels')
901
- newhdu.header['MOMCLIP']=(self.cliplevel, self.bunit+' km/s')
949
+ newhdu.header['MOMCLIP']=(self.maskcliplevel, self.bunit+' km/s')
902
950
  newhdu.header['VSYS']=(self.vsys,'km/s')
903
951
  newhdu.header['comment'] = 'Moment map created with pymakeplots'
904
952
  newhdu.header['BUNIT'] = self.bunit+' km/s'
@@ -906,7 +954,7 @@ class pymakeplots:
906
954
  newhdu.writeto(filename,overwrite=True)
907
955
 
908
956
  def make_pvd(self,axes=None,fits=False,pdf=False):
909
-
957
+ self.fits=fits
910
958
  if np.any(self.xc) == None:
911
959
  self.prepare_cubes()
912
960
 
@@ -934,13 +982,14 @@ class pymakeplots:
934
982
  else:
935
983
  print("Downsampling the observed moment one in PA estimate for speed. Set `useallpixels` to override.")
936
984
  mom1[np.isfinite(mom1) == False] = self.vsys
937
- interper = interpolate.interp2d(self.xc,self.yc,mom1-self.vsys,bounds_error=False,fill_value=np.nan)
985
+ #breakpoint()
986
+ interper = interpolate.RegularGridInterpolator((self.xc,self.yc),(mom1-self.vsys).T,bounds_error=False,fill_value=np.nan)
938
987
  x=np.linspace(np.min(self.xc),np.max(self.xc),50)
939
988
  y=np.linspace(np.min(self.yc),np.max(self.yc),50)
940
- v= interper(x,y)
941
989
  xv, yv = np.meshgrid(x,y)
990
+ v= interper((xv,yv))
942
991
  x,y,v = xv.flatten(),yv.flatten(),v.flatten()
943
-
992
+
944
993
  self.posang,_,_ = fit_kinematic_pa(x[np.isfinite(v)],y[np.isfinite(v)],v[np.isfinite(v)],nsteps=36,plot=False,quiet=True)
945
994
 
946
995
  if np.sin(np.deg2rad((self.posang+45)*2)) > 0:
@@ -964,10 +1013,10 @@ class pymakeplots:
964
1013
 
965
1014
  centpix_x=np.where(np.isclose(self.xc,0.0,atol=self.cellsize/1.9))[0]
966
1015
  centpix_y=np.where(np.isclose(self.yc,0.0,atol=self.cellsize/1.9))[0]
967
- #breakpoint()
1016
+
968
1017
 
969
1018
 
970
- rotcube= rotateImage(self.pbcorr_cube_trim*self.mask_trim,90-self.posang,[centpix_y[0],centpix_x[0]])
1019
+ rotcube= rotateImage(self.pbcorr_cube_trim*self.mask_trim,90-self.posang,[centpix_x[0],centpix_y[0]])
971
1020
 
972
1021
 
973
1022
  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)
@@ -1004,13 +1053,16 @@ class pymakeplots:
1004
1053
 
1005
1054
  if self.all_axes_physical:
1006
1055
  axes.set_xlabel('Offset (kpc)')
1056
+ secaxy = axes.secondary_xaxis('top', functions=(self.ang2kpctrans_inv, self.ang2kpctrans))
1057
+ secaxy.set_xlabel('Offset (")')
1007
1058
  else:
1008
1059
  axes.set_xlabel('Offset (")')
1009
-
1060
+ secaxy = axes.secondary_xaxis('top', functions=(self.ang2kpctrans, self.ang2kpctrans_inv))
1061
+ secaxy.set_xlabel('Offset (kpc)')
1062
+
1010
1063
  axes.set_ylabel('Velocity (km s$^{-1}$)')
1011
1064
 
1012
- secaxy = axes.secondary_xaxis('top', functions=(self.ang2kpctrans, self.ang2kpctrans_inv))
1013
- secaxy.set_xlabel('Offset (kpc)')
1065
+
1014
1066
 
1015
1067
  secax = axes.secondary_yaxis('right', functions=(self.vsystrans, self.vsystrans_inv))
1016
1068
  secax.set_ylabel(r'V$_{\rm offset}$ (km s$^{-1}$)')
@@ -1020,7 +1072,7 @@ class pymakeplots:
1020
1072
 
1021
1073
  if self.gal_distance != None and not self.all_axes_physical:
1022
1074
  self.scalebar(axes,loc=loc2)
1023
-
1075
+
1024
1076
  if self.fits:
1025
1077
  self.write_pvd_fits(pvdaxis,vaxis,pvd.T)
1026
1078
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pymakeplots
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Home-page: https://github.com/TimothyADavis/pymakeplots
5
5
  Author: Timothy A. Davis
6
6
  Author-email: DavisT@cardiff.ac.uk
@@ -12,8 +12,8 @@ Classifier: Operating System :: OS Independent
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE.md
14
14
  Requires-Dist: numpy
15
- Requires-Dist: matplotlib (>3.3.1)
16
- Requires-Dist: scipy
15
+ Requires-Dist: matplotlib >3.3.1
16
+ Requires-Dist: scipy >=1.14.0
17
17
  Requires-Dist: astropy
18
18
  Requires-Dist: spectral-cube
19
19
  Requires-Dist: radio-beam
@@ -0,0 +1,9 @@
1
+ pymakeplots/__init__.py,sha256=PLKnIm6rIKYjH_b6L9UBCFtv1lKt5GItdBKDbSOhuMU,87
2
+ pymakeplots/pymakeplots.py,sha256=EIeZH1brAg5d9QM9QqaViXFBBDDVCRDWnK1hKZ6ofXg,45950
3
+ pymakeplots/sauron_colormap.py,sha256=8APka-_L432wyICcHcySjk3qmjNOynb3iDjjlMuUTU0,4448
4
+ pymakeplots-0.2.1.dist-info/LICENSE.md,sha256=qtvmvajOPCad_5HMY5u49hldzBIXz7tbHbuGSG_HE5o,1077
5
+ pymakeplots-0.2.1.dist-info/METADATA,sha256=GGL0jJnyhIuv9bmggds2jNoWRTPbXyPU-cQ4jlJJ_3M,1847
6
+ pymakeplots-0.2.1.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
7
+ pymakeplots-0.2.1.dist-info/top_level.txt,sha256=KgG17vI_D6BsiKRe_81UU5709tXc6Ha7gx1IwjA7ur8,12
8
+ pymakeplots-0.2.1.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
9
+ pymakeplots-0.2.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.38.4)
2
+ Generator: setuptools (70.3.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,9 +0,0 @@
1
- pymakeplots/__init__.py,sha256=PLKnIm6rIKYjH_b6L9UBCFtv1lKt5GItdBKDbSOhuMU,87
2
- pymakeplots/pymakeplots.py,sha256=-QBfg3BnC6I3RuGh9nFpfHXTQHNmGP8FsgboBCQ3cxk,43686
3
- pymakeplots/sauron_colormap.py,sha256=8APka-_L432wyICcHcySjk3qmjNOynb3iDjjlMuUTU0,4448
4
- pymakeplots-0.2.0.dist-info/LICENSE.md,sha256=qtvmvajOPCad_5HMY5u49hldzBIXz7tbHbuGSG_HE5o,1077
5
- pymakeplots-0.2.0.dist-info/METADATA,sha256=-bZdjlHzVwuuEnhWLyWoCJeNtFUCVNymSPe-yhETRmo,1840
6
- pymakeplots-0.2.0.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
7
- pymakeplots-0.2.0.dist-info/top_level.txt,sha256=KgG17vI_D6BsiKRe_81UU5709tXc6Ha7gx1IwjA7ur8,12
8
- pymakeplots-0.2.0.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
9
- pymakeplots-0.2.0.dist-info/RECORD,,