Skip to content

Commit

Permalink
Remove output from Visualization
Browse files Browse the repository at this point in the history
In addition, now libsplash writes output to a file `.libsplash.log` in
the current directory, rather than printing to stdout.
  • Loading branch information
dmentipl committed Sep 4, 2019
1 parent a55ade0 commit 33fef0f
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 158 deletions.
6 changes: 2 additions & 4 deletions plonk/core/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ def extra_quantity(self, quantity, sph_type=None, **kwargs):
quantities = self.available_extra_quantities

if quantity not in [element for tupl in quantities for element in tupl]:
print(f'{quantity} not available')
return None
raise ValueError(f'{quantity} not available')

if quantity in ('e', 'eccentricity'):
gravitational_constant = constants.gravitational_constant / (
Expand All @@ -227,8 +226,7 @@ def _density_from_smoothing_length(self, hfact=1.2):
if self.particles._can_compute_density:
return self.mass * (hfact / np.abs(self.particles.arrays['h'])) ** 3
else:
print(f'Cannot compute density on {self.particles}')
return None
raise ValueError(f'Cannot compute density on {self.particles}')

def _mass_from_itype(self):
return self.header['massoftype'][self.particles.arrays['itype'][:] - 1]
Expand Down
3 changes: 1 addition & 2 deletions plonk/core/particles.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ def extra_quantity(self, quantity, mass=None, **kwargs):
require_mass = False

if quantity not in [element for tupl in quantities for element in tupl]:
print(f'{quantity} not available')
return None
raise ValueError(f'{quantity} not available')

if quantity in ['r', 'spherical radius']:
data = (self.arrays['xyz'],)
Expand Down
30 changes: 4 additions & 26 deletions plonk/visualization/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,13 +509,11 @@ def set_particle_type(self, particle_types):
particle_types = set(particle_types)

if not particle_types.issubset(self._available_particle_types):
print(f'Some of particle type {particle_types} not available')
return
raise ValueError(f'Some of particle type {particle_types} not available')

if hasattr(self, '_particle_types'):
if particle_types == self._particle_types:
print(f'Particle types {particle_types} already plotted')
return
raise ValueError(f'Particle types {particle_types} already plotted')

self._particle_types = particle_types
self._particle_mask = np.logical_or.reduce(
Expand All @@ -540,19 +538,17 @@ def set_image_size(self, extent=None, size=None):

if extent is not None:
if np.all(extent == self._extent):
print(f'Image window size already = {extent}')
return
raise ValueError(f'Image window size already = {extent}')
self._extent = tuple(extent)
if self._initialized:
self._make_plot()
return

if size is not None:
if np.all(size == np.abs(self._extent)):
print(
raise ValueError(
'Image window size already = ' f'(-{size}, {size}, -{size}, {size})'
)
return
self._extent = (-size, size, -size, size)
if self._initialized:
self._make_plot()
Expand Down Expand Up @@ -635,11 +631,6 @@ def _render_image(self):
else:
raise ValueError('Cannot determine scalar data')

if self._render_label is not None:
print(f'Rendering scalar field "{self._render_label}" using Splash')
else:
print(f'Rendering scalar field using Splash')

image_data = scalar_interpolation(
self._xyz,
self._h,
Expand Down Expand Up @@ -741,11 +732,6 @@ def _vector_image(self):
else:
raise ValueError('Cannot determine vector data')

if self._vector_label is not None:
print(f'Plotting vector field "{self._vector_label}" using Splash')
else:
print(f'Plotting vector field using Splash')

vector_data = vector_interpolation(
self._xyz,
self._h,
Expand Down Expand Up @@ -871,7 +857,6 @@ def rotate_frame(self, axis, angle):
np.all(np.array(axis) == self._options.rotation.rotation_axis)
and angle == self._options.rotation.rotation_angle
):
print(f'Frame already has the specified rotation')
return

if axis is not None and angle is not None:
Expand All @@ -881,13 +866,6 @@ def rotate_frame(self, axis, angle):
else:
raise ValueError('Must specify by axis and angle for rotation')

print(
f'Rotating {angle*180/np.pi:.0f} deg around '
f'[{axis[0]:.2f},'
f' {axis[1]:.2f},'
f' {axis[2]:.2f}]'
)

if self._initialized:
self._make_plot()

Expand Down
31 changes: 19 additions & 12 deletions splash/fortran/interpolate3D_opacity.f90
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ module interpolate3D_opacity
use interpolation, only:weight_sink
implicit none

integer, private :: iunit = 10
character(len=21), private :: output_file = '.libsplash.log'

contains
!--------------------------------------------------------------------------
! $Id: interpolate3D_opacity.f90,v 1.16 2007/11/20 17:05:35 dprice Exp $
Expand Down Expand Up @@ -106,25 +109,27 @@ subroutine interp3D_proj_opacity(x,y,z,pmass,npmass,hh,weight,dat,zorig,itype,np
integer(kind=selected_int_kind(12)) :: iprogress
!#endif

open(iunit, file=output_file, position='append')

datsmooth = 0.
term = 0.
brightness = 0.
print "(1x,a)",'ray tracing from particles to pixels...'
write (iunit, "(1x,a)") 'ray tracing from particles to pixels...'
if (pixwidth.le.0.) then
print "(a)",'interpolate3D_opacity: error: pixel width <= 0'
write (iunit, "(a)") 'interpolate3D_opacity: error: pixel width <= 0'
return
endif
if (any(hh(1:npart).le.tiny(hh))) then
print*,'interpolate3D_opacity: warning: ignoring some or all particles with h < 0'
write (iunit, *) 'interpolate3D_opacity: warning: ignoring some or all particles with h < 0'
endif
!--check that npmass is sensible
if (npmass.lt.1 .or. npmass.gt.npart) then
print*,'interpolate3D_opacity: ERROR in input number of particle masses '
write (iunit, *) 'interpolate3D_opacity: ERROR in input number of particle masses '
return
endif
!--these values for npmass are not sensible but the routine will still work
if (npmass.ne.1 .and. npmass.ne.npart) then
print*,'WARNING: interpolate3D_opacity: number of particle masses input =',npmass
write (iunit, *) 'WARNING: interpolate3D_opacity: number of particle masses input =',npmass
endif

if (abs(dscreenfromobserver).gt.tiny(dscreenfromobserver)) then
Expand All @@ -148,8 +153,8 @@ subroutine interp3D_proj_opacity(x,y,z,pmass,npmass,hh,weight,dat,zorig,itype,np
!--average particle mass
pmassav = sum(pmass(1:npmass))/real(npmass)
rkappatemp = pi*hav*hav/(pmassav*coltable(0))
print*,'average h = ',hav,' average mass = ',pmassav
print "(1x,a,f6.2,a)",'typical surface optical depth is ~',rkappatemp/rkappa,' smoothing lengths'
write (iunit, *) 'average h = ',hav,' average mass = ',pmassav
write (iunit, "(1x,a,f6.2,a)") 'typical surface optical depth is ~',rkappatemp/rkappa,' smoothing lengths'
!
!--print a progress report if it is going to take a long time
! (a "long time" is, however, somewhat system dependent)
Expand Down Expand Up @@ -340,20 +345,22 @@ subroutine interp3D_proj_opacity(x,y,z,pmass,npmass,hh,weight,dat,zorig,itype,np
!--get ending CPU time
!
if (nsink > 99) then
print*,'rendered ',nsink,' sink particles'
write (iunit, *) 'rendered ',nsink,' sink particles'
elseif (nsink > 0) then
print "(1x,a,i2,a)",'rendered ',nsink,' sink particles'
write (iunit, "(1x,a,i2,a)") 'rendered ',nsink,' sink particles'
endif
call cpu_time(t_end)
t_used = t_end - t_start
if (t_used.gt.60.) then
itmin = int(t_used/60.)
tsec = t_used - (itmin*60.)
print "(1x,a,i4,a,f5.2,1x,a)",'completed in',itmin,' min ',tsec,'s'
write (iunit, "(1x,a,i4,a,f5.2,1x,a)") 'completed in',itmin,' min ',tsec,'s'
else
print "(1x,a,f5.2,1x,a)",'completed in ',t_used,'s'
write (iunit, "(1x,a,f5.2,1x,a)") 'completed in ',t_used,'s'
endif
if (zcut.lt.huge(zcut)) print*,'slice contains ',nused,' of ',npart,' particles'
if (zcut.lt.huge(zcut)) write (iunit, *) 'slice contains ',nused,' of ',npart,' particles'

close(iunit)

return

Expand Down
Loading

0 comments on commit 33fef0f

Please sign in to comment.