pymakeplots 0.1.7__tar.gz → 0.2.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pymakeplots
3
- Version: 0.1.7
3
+ Version: 0.2.0
4
4
  Home-page: https://github.com/TimothyADavis/pymakeplots
5
5
  Author: Timothy A. Davis
6
6
  Author-email: DavisT@cardiff.ac.uk
@@ -47,6 +47,8 @@ class pymakeplots:
47
47
  self.moment1=None
48
48
  self.rms=None
49
49
  self.flat_cube=None
50
+ self.obj_ra_pix=None
51
+ self.obj_dec_pix=None
50
52
  self.pbcorr_cube=None
51
53
  self.spectralcube=None
52
54
  self.mask=None
@@ -301,21 +303,16 @@ class pymakeplots:
301
303
 
302
304
  def get_header_coord_arrays(self,hdr):
303
305
 
304
- y,x=self.spectralcube.spatial_coordinate_map
306
+ cd1=self.spectralcube.wcs.pixel_scale_matrix[0,0]*3600
307
+ cd2=self.spectralcube.wcs.pixel_scale_matrix[1,1]*3600
308
+ x1=((np.arange(1,hdr['NAXIS1']+1)-(hdr['NAXIS1']//2))*cd1)# + hdr['CRVAL1']
309
+ y1=((np.arange(1,hdr['NAXIS2']+1)-(hdr['NAXIS1']//2))*cd2)# + hdr['CRVAL2']
305
310
 
306
- x1=np.median(x[0:hdr['NAXIS2'],0:hdr['NAXIS1']],0).value
307
- y1=np.median(y[0:hdr['NAXIS2'],0:hdr['NAXIS1']],1).value
308
311
  v1=self.spectralcube.spectral_axis.value
309
312
 
310
313
  cd3= np.median(np.diff(v1))
311
- cd1= np.median(np.diff(x1))
312
-
313
- if np.any(np.diff(x1) > 359):
314
- # we have RA=0 wrap issue
315
- x1[x1 > 180]-=360
316
-
317
314
 
318
- return x1,y1,v1,np.abs(cd1*3600),cd3
315
+ return x1,y1,v1,np.abs(cd1),cd3
319
316
 
320
317
  def read_in_a_cube(self,path):
321
318
  self.spectralcube=SpectralCube.read(path).with_spectral_unit(u.km/u.s, velocity_convention='radio')#, rest_value=self.restfreq)
@@ -337,6 +334,8 @@ class pymakeplots:
337
334
  beamtab=False
338
335
 
339
336
  return cube, hdr, beamtab
337
+
338
+
340
339
 
341
340
  def read_primary_cube(self,cube):
342
341
 
@@ -356,23 +355,10 @@ class pymakeplots:
356
355
 
357
356
 
358
357
  self.xcoord,self.ycoord,self.vcoord,self.cellsize,self.dv = self.get_header_coord_arrays(hdr)
358
+ #breakpoint()
359
359
 
360
360
 
361
-
362
- try:
363
- self.obj_ra=hdr['OBSRA']
364
- self.obj_dec=hdr['OBSDEC']
365
- if (self.obj_ra > np.max(self.xcoord)) or (self.obj_ra < np.min(self.xcoord)) or (self.obj_dec < np.min(self.ycoord)) or (self.obj_dec > np.max(self.ycoord)):
366
- # obsra/dec given in the headers arent in the observed field! Fall back on medians.
367
- if not self.silent: print("OBSRA/OBSDEC keywords dont seem correct! Assuming galaxy centre is at pointing centre")
368
- self.obj_ra=np.median(self.xcoord)
369
- self.obj_dec=np.median(self.ycoord)
370
- except:
371
- self.obj_ra=np.median(self.xcoord)
372
- self.obj_dec=np.median(self.ycoord)
373
-
374
-
375
-
361
+
376
362
 
377
363
  if self.dv < 0:
378
364
  datacube = np.flip(datacube,axis=2)
@@ -386,23 +372,27 @@ class pymakeplots:
386
372
 
387
373
  def prepare_cubes(self):
388
374
 
389
- self.clip_cube()
375
+ self.centskycoord=self.spectralcube.wcs.celestial.pixel_to_world(self.xcoord.size//2,self.ycoord.size//2).transform_to('icrs')
376
+ self.x_skycent=self.centskycoord.ra.value
377
+ self.y_skycent=self.centskycoord.dec.value
378
+ if self.obj_ra == None:
379
+ self.obj_ra=self.x_skycent
380
+ if self.obj_dec == None:
381
+ self.obj_dec=self.y_skycent
382
+
383
+ refpos=SkyCoord(self.obj_ra*u.deg,self.obj_dec*u.deg)
384
+ xpix,ypix=self.spectralcube.wcs.celestial.world_to_pixel(refpos)
390
385
 
391
- self.mask_trim=self.smooth_mask(self.flat_cube_trim)
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
+
392
389
 
390
+ self.clip_cube(xoffsetarc,yoffsetarc)
391
+
392
+ self.mask_trim=self.smooth_mask(self.flat_cube_trim)
393
393
 
394
- #y,x=self.spectralcube.spatial_coordinate_map
395
- #sk=SkyCoord(x,y)
396
- # refpos=SkyCoord(self.obj_ra*u.deg,self.obj_dec*u.deg)
397
- # sx=SkyCoord(self.xcoord*u.deg,self.obj_dec*u.deg)
398
- # self.xc=sx.separation(refpos).to(u.arcsec).value #* np.cos(np.deg2rad(self.obj_dec)) + self.obj_ra
399
- # sy=SkyCoord(self.obj_ra*u.deg,self.ycoord*u.deg)
400
- # self.yc=sy.separation(refpos).to(u.arcsec).value #+ self.obj_dec
401
- #
402
- #
403
- # breakpoint()
404
- self.xc=(self.xcoord_trim-self.obj_ra)*(-1) * 3600. * np.cos(np.deg2rad(self.obj_dec))
405
- self.yc=(self.ycoord_trim-self.obj_dec) * 3600.
394
+
395
+
406
396
 
407
397
 
408
398
 
@@ -451,15 +441,16 @@ class pymakeplots:
451
441
  self.make_spec(axes=ax5,fits=fits)
452
442
 
453
443
  ### plotting PA on mom1
454
- ypv=self.yc
455
- xpv=self.yc*0.0
444
+ ypv=np.arange(-np.max(self.yc),np.max(self.yc),20)
445
+ xpv=ypv*0.0
456
446
  ang=self.posang
457
447
  c = np.cos(np.deg2rad(ang))
458
448
  s = np.sin(np.deg2rad(ang))
459
449
  x2 = c*xpv - s*ypv
460
450
  y2 = s*xpv + c*ypv
451
+ ax2.scatter(0,0,facecolors='none',edgecolors='k')
461
452
  ax2.plot(x2,y2,'k--')
462
-
453
+ #breakpoint()
463
454
 
464
455
  ###### make summary box
465
456
 
@@ -478,7 +469,7 @@ class pymakeplots:
478
469
 
479
470
 
480
471
  at2 = AnchoredText(thetext,
481
- loc='upper right', prop=dict(size=30,multialignment='right'), frameon=False,
472
+ loc='upper right', prop=dict(size=25,multialignment='right'), frameon=False,
482
473
  bbox_transform=textaxes.transAxes
483
474
  )
484
475
  textaxes.add_artist(at2)
@@ -531,7 +522,7 @@ class pymakeplots:
531
522
 
532
523
 
533
524
  if pdf:
534
- plt.savefig(self.galname+"_moment"+"".join(mom.astype(np.str))+".pdf", bbox_inches = 'tight')
525
+ plt.savefig(self.galname+"_moment"+"".join(mom.astype(str))+".pdf", bbox_inches = 'tight')
535
526
  plt.close()
536
527
  else:
537
528
  if not outsideaxis:
@@ -553,9 +544,9 @@ class pymakeplots:
553
544
 
554
545
 
555
546
  if np.log10(barlength_pc) > 3:
556
- label=(barlength_pc/1e3).astype(np.str)+ " kpc"
547
+ label=(barlength_pc/1e3).astype(str)+ " kpc"
557
548
  else:
558
- label=barlength_pc.astype(int).astype(np.str)+ " pc"
549
+ label=barlength_pc.astype(int).astype(str)+ " pc"
559
550
 
560
551
  asb = AnchoredSizeBar(ax.transData, barlength_arc, label, loc=loc, pad=0.25, borderpad=0.5, sep=5, frameon=False)
561
552
  ax.add_artist(asb)
@@ -564,7 +555,11 @@ class pymakeplots:
564
555
 
565
556
 
566
557
 
567
- def clip_cube(self):
558
+ def clip_cube(self,xoffsetarc,yoffsetarc):
559
+
560
+ #
561
+
562
+
568
563
 
569
564
  if self.chans2do == None:
570
565
  # use the mask to try and guess the channels with signal.
@@ -585,18 +580,19 @@ class pymakeplots:
585
580
  self.imagesize=[self.imagesize,self.imagesize]
586
581
 
587
582
 
588
- wx,=np.where((np.abs((self.xcoord-self.obj_ra)*3600.) <= self.imagesize[0]/np.cos(np.deg2rad(self.obj_dec))))
589
- wy,=np.where((np.abs((self.ycoord-self.obj_dec)*3600.) <= self.imagesize[1]))
590
- self.spatial_trim=[np.min(wx),np.max(wx),np.min(wy),np.max(wy)]
583
+ wx,=np.where(np.abs(self.xcoord-xoffsetarc) <= self.imagesize[0])
584
+ wy,=np.where(np.abs(self.ycoord-yoffsetarc) <= self.imagesize[1])
585
+ self.spatial_trim=[np.min(wx),np.max(wx),np.min(wy),np.max(wy)]
586
+
591
587
 
592
588
  if self.spatial_trim == None:
593
589
 
594
590
  mom0=(self.pbcorr_cube > self.rmsfac*self.rms).sum(axis=2)
595
591
  mom0[mom0>0]=1
596
592
 
597
- cumulative_x = np.nancumsum(mom0.sum(axis=1),dtype=np.float)
593
+ cumulative_x = np.nancumsum(mom0.sum(axis=1),dtype=float)
598
594
  cumulative_x /= np.nanmax(cumulative_x)
599
- cumulative_y = np.nancumsum(mom0.sum(axis=0),dtype=np.float)
595
+ cumulative_y = np.nancumsum(mom0.sum(axis=0),dtype=float)
600
596
  cumulative_y /= np.nanmax(cumulative_y)
601
597
 
602
598
  wx_low,=np.where(cumulative_x < 0.02)
@@ -616,7 +612,6 @@ class pymakeplots:
616
612
  self.spatial_trim = [np.clip(np.max(wx_low) - 2*beam_in_pix,0,self.xcoord.size),np.clip(np.min(wx_high) + 2*beam_in_pix,0,self.xcoord.size)\
617
613
  , np.clip(np.max(wy_low) - 2*beam_in_pix,0,self.ycoord.size), np.clip(np.min(wy_high) + 2*beam_in_pix,0,self.ycoord.size)]
618
614
 
619
- #breakpoint()
620
615
  #print(np.where(np.isclose(self.xcoord-self.obj_ra,0,atol=self.cellsize/3600)))
621
616
  self.flat_cube_trim=self.flat_cube[self.spatial_trim[0]:self.spatial_trim[1],self.spatial_trim[2]:self.spatial_trim[3],self.chans2do[0]:self.chans2do[1]]
622
617
  self.pbcorr_cube_trim=self.pbcorr_cube[self.spatial_trim[0]:self.spatial_trim[1],self.spatial_trim[2]:self.spatial_trim[3],self.chans2do[0]:self.chans2do[1]]
@@ -625,7 +620,8 @@ class pymakeplots:
625
620
  self.xcoord_trim=self.xcoord[self.spatial_trim[0]:self.spatial_trim[1]]
626
621
  self.ycoord_trim=self.ycoord[self.spatial_trim[2]:self.spatial_trim[3]]
627
622
  self.vcoord_trim=self.vcoord[self.chans2do[0]:self.chans2do[1]]
628
-
623
+ self.xc=(self.xcoord_trim-xoffsetarc)*(-1)
624
+ self.yc=(self.ycoord_trim-yoffsetarc)
629
625
 
630
626
 
631
627
 
@@ -643,11 +639,11 @@ class pymakeplots:
643
639
 
644
640
  def add_beam(self,ax):
645
641
  if self.all_axes_physical:
646
- ae = AnchoredEllipse(ax.transData, width=self.ang2kpctrans(self.bmaj), height=self.ang2kpctrans(self.bmin), angle=self.bpa,
642
+ ae = AnchoredEllipse(ax.transData, width=self.ang2kpctrans(self.bmaj), height=self.ang2kpctrans(self.bmin), angle=self.bpa+90,
647
643
  loc='lower left', pad=0.5, borderpad=0.4,
648
644
  frameon=False)
649
645
  else:
650
- ae = AnchoredEllipse(ax.transData, width=self.bmaj, height=self.bmin, angle=self.bpa,
646
+ ae = AnchoredEllipse(ax.transData, width=self.bmaj, height=self.bmin, angle=self.bpa+90,
651
647
  loc='lower left', pad=0.5, borderpad=0.4,
652
648
  frameon=False)
653
649
  ae.ellipse.set_edgecolor('black')
@@ -675,10 +671,10 @@ class pymakeplots:
675
671
  levs=np.linspace(0,1,10)
676
672
  mom0-=1
677
673
 
678
-
679
-
674
+ #mom0[mom0<minmom0]=np.nan
675
+ #breakpoint()
680
676
  im1=ax1.contourf(self.xc,self.yc,mom0.T,levels=levs,cmap=newcmp)
681
-
677
+ #im1=ax1.pcolormesh(self.xc,self.yc,mom0.T,cmap=newcmp,vmin=minmom0,vmax=maxmom0)
682
678
 
683
679
  if self.all_axes_physical:
684
680
  ax1.set_xlabel('RA offset (kpc)')
@@ -825,9 +821,9 @@ class pymakeplots:
825
821
 
826
822
  def write_fits(self,array,whichmoment):
827
823
  if self.fits == True:
828
- filename=self.galname+"_mom"+"".join(np.array([whichmoment]).astype(np.str))+".fits"
824
+ filename=self.galname+"_mom"+"".join(np.array([whichmoment]).astype(str))+".fits"
829
825
  else:
830
- filename=self.fits+"_mom"+"".join(np.array([whichmoment]).astype(np.str))+".fits"
826
+ filename=self.fits+"_mom"+"".join(np.array([whichmoment]).astype(str))+".fits"
831
827
 
832
828
 
833
829
  newhdu = fits.PrimaryHDU(array)
@@ -968,10 +964,10 @@ class pymakeplots:
968
964
 
969
965
  centpix_x=np.where(np.isclose(self.xc,0.0,atol=self.cellsize/1.9))[0]
970
966
  centpix_y=np.where(np.isclose(self.yc,0.0,atol=self.cellsize/1.9))[0]
971
-
967
+ #breakpoint()
972
968
 
973
969
 
974
- rotcube= rotateImage(self.pbcorr_cube_trim*self.mask_trim,90-self.posang,[centpix_x[0],centpix_y[0]])
970
+ rotcube= rotateImage(self.pbcorr_cube_trim*self.mask_trim,90-self.posang,[centpix_y[0],centpix_x[0]])
975
971
 
976
972
 
977
973
  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)
@@ -1046,7 +1042,7 @@ class pymakeplots:
1046
1042
  outsideaxis=1
1047
1043
  spec=self.pbcorr_cube[self.spatial_trim[0]:self.spatial_trim[1],self.spatial_trim[2]:self.spatial_trim[3],:].sum(axis=0).sum(axis=0)
1048
1044
  spec_mask=(self.pbcorr_cube_trim*self.mask_trim).sum(axis=0).sum(axis=0)
1049
-
1045
+ ylab="Unknown"
1050
1046
  #breakpoint()
1051
1047
  if (''.join(self.bunit.split())).lower() == "Jy/beam".lower():
1052
1048
 
@@ -1121,4 +1117,4 @@ class pymakeplots:
1121
1117
 
1122
1118
 
1123
1119
 
1124
-
1120
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pymakeplots
3
- Version: 0.1.7
3
+ Version: 0.2.0
4
4
  Home-page: https://github.com/TimothyADavis/pymakeplots
5
5
  Author: Timothy A. Davis
6
6
  Author-email: DavisT@cardiff.ac.uk
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
5
 
6
6
 
7
7
  setup(name='pymakeplots',
8
- version='0.1.7',
8
+ version='0.2.0',
9
9
  description='',
10
10
  url='https://github.com/TimothyADavis/pymakeplots',
11
11
  author='Timothy A. Davis',
File without changes
File without changes
File without changes