forked from google/neuroglancer
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/na 194 #15
Open
SimaoBolota-MetaCell
wants to merge
16
commits into
feature/transfer-function-shader-widget
Choose a base branch
from
feature/NA-194
base: feature/transfer-function-shader-widget
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature/na 194 #15
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f4749c1
WIP tests
SimaoBolota-MetaCell 8dd34d2
python test for Gain
SimaoBolota-MetaCell 78cc9d9
removing in progress tests
SimaoBolota-MetaCell 69e22e2
screenshot now taken only for canvas + 3d layout only
SimaoBolota-MetaCell 8463bf2
changed data source
SimaoBolota-MetaCell 2e661c8
fix(Python): gain default of 0 with exp change
seankmartin 529842a
Merge remote-tracking branch 'origin/feature/transfer-function-shader…
SimaoBolota-MetaCell 24caa03
changed test order
SimaoBolota-MetaCell e30fc74
.
SimaoBolota-MetaCell 375b487
removed debug sleep
SimaoBolota-MetaCell 5690715
test: go back to just 3d layout
seankmartin 470a0fb
NA-194 removed 2nd webdriver sync
SimaoBolota-MetaCell 3b2a8a3
fix(volume_rendering): Volume rendering fixes for max projection - pi…
seankmartin f805b54
feat: Add a transfer function shader widget (#582)
seankmartin 8aa9340
cleaned up test
SimaoBolota-MetaCell 97e6493
Merge branch 'master' into feature/NA-194
seankmartin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
# @license | ||
# Copyright 2020 Google Inc. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Tests basic screenshot functionality.""" | ||
|
||
import neuroglancer | ||
import numpy as np | ||
from time import sleep | ||
import pytest | ||
from selenium.webdriver.support.ui import WebDriverWait | ||
from selenium.webdriver.support import expected_conditions as EC | ||
from selenium.webdriver.common.by import By | ||
from PIL import Image | ||
import io | ||
|
||
|
||
|
||
URL = r"zarr://s3://aind-open-data/exaSPIM_653980_2023-08-10_20-08-29_fusion_2023-08-24/fused.zarr/" | ||
|
||
def add_render_panel(side="left", row=0, col=0): | ||
return neuroglancer.LayerSidePanelState( | ||
side=side, | ||
col=col, | ||
row=row, | ||
tab="rendering", | ||
tabs=["rendering", "source"], | ||
) | ||
|
||
|
||
no_gain_screenshot = None | ||
gain_screenshot = None | ||
|
||
@pytest.mark.timeout(600) | ||
def test_no_gain(webdriver): | ||
|
||
global no_gain_avg | ||
global no_gain_screenshot | ||
a = np.array([[[255]]], dtype=np.uint8) | ||
with webdriver.viewer.txn() as s: | ||
s.dimensions = neuroglancer.CoordinateSpace( | ||
names=["x", "y", "z", "t"], units=["nm", "nm", "um", "ms"], scales=[748, 748, 1, 1] | ||
) | ||
s.layers.append( | ||
name="a", | ||
layer=neuroglancer.ImageLayer( | ||
source = URL, | ||
panels=[add_render_panel()], | ||
shader=""" | ||
#uicontrol invlerp normalized(range=[0, 250], window=[0, 65535], clamp=true) | ||
void main() { | ||
emitGrayscale(normalized()); | ||
} | ||
""", | ||
volume_rendering=True, | ||
volumeRenderingDepthSamples=512, | ||
tool_bindings={ | ||
"A": neuroglancer.VolumeRenderingDepthSamplesTool(), | ||
"B": neuroglancer.VolumeRenderingGainTool(), | ||
} | ||
), | ||
) | ||
s.cross_section_scale = 1e-6 | ||
s.show_axis_lines = False | ||
s.position = [0.5, 0.5, 0.5] | ||
s.layers["brain"].volumeRenderingGain = 0 | ||
|
||
WebDriverWait(webdriver.driver, 60).until( | ||
EC.text_to_be_present_in_element((By.CSS_SELECTOR, '#neuroglancer-container > div > div:nth-child(2) > div.neuroglancer-side-panel-column > div.neuroglancer-side-panel > div.neuroglancer-tab-view.neuroglancer-layer-side-panel-tab-view > div.neuroglancer-stack-view > div > div:nth-child(6) > label > div.neuroglancer-render-scale-widget.neuroglancer-layer-control-control > div.neuroglancer-render-scale-widget-legend > div:nth-child(2)'), '16/16') | ||
) | ||
WebDriverWait(webdriver.driver, 60).until( | ||
lambda driver: driver.execute_script('return document.readyState') == 'complete' | ||
) | ||
print("Layer loaded") | ||
sleep(3) | ||
screenshot = webdriver.driver.get_screenshot_as_png() | ||
sleep(3) | ||
print("Screenshot taken") | ||
# Convert the screenshot to a NumPy array | ||
image = Image.open(io.BytesIO(screenshot)) | ||
no_gain_screenshot = np.array(image) | ||
assert no_gain_screenshot.size != 0, "Image is empty" | ||
# Check if the image contains valid pixel values | ||
assert np.all(no_gain_screenshot >= 0) and np.all(no_gain_screenshot <= 255), "Image contains invalid pixel values" | ||
no_gain_avg = np.mean(no_gain_screenshot) | ||
print('No Gain average pixel value:') | ||
print(no_gain_avg) | ||
|
||
|
||
|
||
@pytest.mark.timeout(600) | ||
def test_gain(webdriver): | ||
global gain_screenshot | ||
global gain_avg | ||
a = np.array([[[255]]], dtype=np.uint8) | ||
with webdriver.viewer.txn() as s: | ||
s.dimensions = neuroglancer.CoordinateSpace( | ||
names=["x", "y", "z", "t"], units=["nm", "nm", "um", "ms"], scales=[748, 748, 1, 1] | ||
) | ||
s.layers.append( | ||
name="a", | ||
layer=neuroglancer.ImageLayer( | ||
source = URL, | ||
panels=[add_render_panel()], | ||
shader=""" | ||
#uicontrol invlerp normalized(range=[0, 250], window=[0, 65535], clamp=true) | ||
void main() { | ||
emitGrayscale(normalized()); | ||
} | ||
""", | ||
volume_rendering=True, | ||
volumeRenderingDepthSamples=512, | ||
tool_bindings={ | ||
"A": neuroglancer.VolumeRenderingDepthSamplesTool(), | ||
"B": neuroglancer.VolumeRenderingGainTool(), | ||
} | ||
), | ||
) | ||
s.cross_section_scale = 1e-6 | ||
s.show_axis_lines = False | ||
s.position = [0.5, 0.5, 0.5] | ||
s.layers["brain"].volumeRenderingGain = 10 | ||
WebDriverWait(webdriver.driver, 60).until( | ||
lambda driver: driver.execute_script('return document.readyState') == 'complete' | ||
) | ||
sleep(3) | ||
print("Layer loaded") | ||
screenshot = webdriver.driver.get_screenshot_as_png() | ||
sleep(3) | ||
print("Screenshot taken") | ||
# Convert the screenshot to a NumPy array | ||
image = Image.open(io.BytesIO(screenshot)) | ||
gain_screenshot = np.array(image) | ||
assert gain_screenshot.size != 0, "Image is empty" | ||
# Check if the image contains valid pixel values | ||
assert np.all(gain_screenshot >= 0) and np.all(gain_screenshot <= 255), "Image contains invalid pixel values" | ||
gain_avg = np.mean(gain_screenshot) | ||
print('Gain average pixel value:') | ||
print(gain_avg) | ||
|
||
|
||
|
||
def test_gain_difference(): | ||
sleep(2) | ||
assert gain_avg > no_gain_avg, "The gain screenshot is not brighter than the no gain screenshot" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I can tell,
s.postion = blah
is what is causing the zoom look. I guesss.position
isn't always working