Skip to content

Commit

Permalink
Merge pull request #38 from SWxTREC/threshold-to-clip
Browse files Browse the repository at this point in the history
Change Threshold to Clip to Contour
  • Loading branch information
greglucas authored May 11, 2022
2 parents 538703f + 239d39d commit 8acde2a
Showing 1 changed file with 11 additions and 49 deletions.
60 changes: 11 additions & 49 deletions pvw/server/enlil.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ def __init__(self, dirname):
self.time_string = pvs.Text(registrationName='Time')
# Don't add in any text right now
self.time_string.Text = ""
# Need to keep track of whether the CME/Threshold should be visible
# so that we can hide 0 value returns
self._THRESHOLD_VISIBLE = False
# Keep track of satellite labels
self._sat_views = []

Expand All @@ -130,16 +127,13 @@ def __init__(self, dirname):
self.cme_contours.Isosurfaces = []
self.cme_contours.PointMergeMethod = 'Uniform Binning'

# Create a threshold that can be modified by the user
self.threshold_data = pvs.Threshold(registrationName='Threshold',
Input=self.data)
# We really only want a minimum value, so just set the maximum high
self.threshold_data.ThresholdRange = [10, 500]
# The quantity of interest
self.threshold_data.Scalars = ['CELLS', 'Density']
self.threshold = pvs.ResampleToImage(
registrationName='resampled_threshold',
Input=self.threshold_data)
# Create a threshold that can be modified by the user, we use
# two contours here instead because it looks a bit nicer.
self.threshold = pvs.Contour(registrationName='Threshold',
Input=self.data)
self.threshold.ContourBy = ['POINTS', 'Density']
self.threshold.Isosurfaces = [10, 50]
self.threshold.PointMergeMethod = 'Uniform Binning'

# Create a Longitude slice
self.lon_slice_data = pvs.Slice(
Expand Down Expand Up @@ -243,16 +237,11 @@ def _setup_views(self):
disp.LookupTable = bzLUT

disp = pvs.Show(self.threshold, self.view,
'UniformGridRepresentation')
'GeometryRepresentation')
self.displays[self.threshold] = disp
disp.Representation = 'Volume'
disp.Representation = 'Surface'
disp.ColorArrayName = ['POINTS', 'Bz']
disp.LookupTable = bzLUT
disp.OpacityArray = [None, '']
disp.OpacityTransferFunction = 'PiecewiseFunction'
disp.ScalarOpacityFunction = bzPWF
disp.ScalarOpacityUnitDistance = 0.02
disp.OpacityArrayName = [None, '']

# Latitude
disp = pvs.Show(self.lat_slice, self.view,
Expand Down Expand Up @@ -568,11 +557,6 @@ def change_visibility(self, obj, visibility):
else:
return ["Visibility can only be 'on' or 'off'"]

# Keep track of whether the Threshold variables are visible
if obj == "threshold":
self._THRESHOLD_VISIBLE = {"on": True, "off": False}[visibility]
self.update(None, None)

@exportRpc("pv.enlil.colorby")
def change_color_variable(self, name):
"""
Expand Down Expand Up @@ -722,8 +706,8 @@ def set_threshold(self, name, range):
"""
variable = VARIABLE_MAP[name]
# The quantity of interest
self.threshold_data.Scalars = ['CELLS', variable]
self.threshold_data.ThresholdRange = range
self.threshold.ContourBy = ['POINTS', variable]
self.threshold.Isosurfaces = range

@exportRpc("pv.enlil.set_contours")
def set_contours(self, name, values):
Expand Down Expand Up @@ -840,7 +824,6 @@ def toggle_satellites(self, visibility):
for sat in self._sat_views:
# Hide() / Show()
hide_show(sat, self.view)
self.update(None, None)

@exportRpc("pv.enlil.get_satellite_times")
def get_satellite_time(self, sat):
Expand Down Expand Up @@ -875,14 +858,7 @@ def get_satellite_data(self, sat):
def update(self, caller, event):
"""
Update function to call every time the time variable has changed.
The Threshold variables will ruin the view if they are shown and
there is no data present. So, if they are clicked "on" by the
frontend, but have no data we still want to force them to be hidden.
When they have data again, we want to show that value without needing
to click on/off by the user.
"""
pv_time = pvs.GetAnimationScene().TimeKeeper.Time
curr_time = self.get_current_time()
self.time_string.Text = curr_time.strftime("%Y-%m-%d %H:00")

Expand All @@ -892,20 +868,6 @@ def update(self, caller, event):
getattr(self, x).Center = self.evolutions[x].get_position(
curr_time)

if self._THRESHOLD_VISIBLE:
# NOTE: Only update pipeline if necessary, same as the CME
pvs.UpdatePipeline(time=pv_time, proxy=self.threshold_data)
# Get the variable associated with this threshold operation
# and see if it is present within CellData
var = self.threshold_data.Scalars[1]
if self.threshold.Input.CellData[var] is None:
pvs.Hide(self.threshold, self.view)
else:
pvs.Show(self.threshold, self.view)
else:
# Hide the Threshold
pvs.Hide(self.threshold, self.view)

# Update the rotation of the earth image
self.rotate_earth()
self.update_solar_image()
Expand Down

0 comments on commit 8acde2a

Please sign in to comment.