Skip to content

Commit

Permalink
remove hbp-related project upload functionality (ilastik#2901)
Browse files Browse the repository at this point in the history
not in use anymore.
  • Loading branch information
k-dominik authored Aug 28, 2024
1 parent 6e811fd commit 07e1078
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 106 deletions.
101 changes: 0 additions & 101 deletions ilastik/applets/batchProcessing/batchProcessingGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,110 +204,9 @@ def initAppletDrawerUi(self):
layout.addWidget(self.run_button)
layout.addWidget(self.cancel_button)

if ilastik.config.cfg["ilastik"].getboolean("hbp"):
from ilastik.workflows import PixelClassificationWorkflow

if isinstance(self.parentApplet.workflow(), PixelClassificationWorkflow):
layout.addWidget(QPushButton("Upload Project File to HBP", self, clicked=self._hbp_upload_project_file))

self._drawer = QWidget(parent=self)
self._drawer.setLayout(layout)

def _hbp_upload_project_file(self):
import io
import pathlib
import webbrowser
import h5py
import requests
import numpy

webbrowser.open_new_tab(ilastik.config.cfg["hbp"]["token_url"])
token, ok = QInputDialog.getText(self, "Client Token", "Paste your token from a browser window")
if not ok:
return

project_file = self.parentApplet.dataSelectionApplet.topLevelOperator.ProjectFile.value
filename = pathlib.Path(project_file.filename).name

role_index = self.parentApplet.dataSelectionApplet.topLevelOperator.DatasetRoles.value.index("Raw Data")
dataset_info = self.parentApplet.dataSelectionApplet.topLevelOperator.DatasetGroup[0][role_index].value

try:
num_channels = dataset_info.laneShape[dataset_info.axistags.channelIndex]
except IndexError:
num_channels = 1

orders = {
"GaussianSmoothing": 0,
"LaplacianOfGaussian": 2,
"GaussianGradientMagnitude": 1,
"DifferenceOfGaussians": 0,
"StructureTensorEigenvalues": 1,
"HessianOfGaussianEigenvalues": 2,
}

workflow = self.parentApplet.workflow()
opFeatureSelection = self.parentApplet.workflow().featureSelectionApplet.topLevelOperator

min_block_size = 0
compute_in_2d = False

for row, col in numpy.argwhere(opFeatureSelection.SelectionMatrix.value):
name = opFeatureSelection.FeatureIds.value[row]
sigma = opFeatureSelection.Scales.value[col]
min_block_size = max(min_block_size, int(3 * sigma + 0.5 * orders[name] + 0.5))
compute_in_2d |= opFeatureSelection.ComputeIn2d.value[col]

workflow.shell.projectManager.saveProject()

with io.BytesIO() as buf:
with h5py.File(buf, "w") as dest:

def partial_copy(name, obj):
if isinstance(obj, h5py.Group):
dest.create_group(name).attrs.update(obj.attrs)
elif isinstance(obj, h5py.Dataset) and name.startswith("Input Data/local_data"):
dest.create_dataset_like(name, obj).attrs.update(obj.attrs)
else:
dest.copy(obj, name)

project_file.visititems(partial_copy)

data = buf.getvalue()

try:
file_response = requests.post(
ilastik.config.cfg["hbp"]["upload_file_url"],
data=data,
headers={
"Authorization": f"Token {token}",
"Content-Disposition": f'attachment; filename="{filename}"',
},
timeout=10,
)
file_response.raise_for_status()
file_json = file_response.json()

project_response = requests.post(
ilastik.config.cfg["hbp"]["create_project_url"],
json={
"file": file_json["url"],
"num_channels": num_channels,
"min_block_size_z": 0 if compute_in_2d else min_block_size,
"min_block_size_y": min_block_size,
"min_block_size_x": min_block_size,
},
headers={"Authorization": f"Token {token}"},
timeout=10,
)
project_response.raise_for_status()
project_json = project_response.json()

webbrowser.open_new_tab(project_json["html_url"])

except requests.exceptions.RequestException as e:
QMessageBox.critical(self, "Network Error", str(e))

def run_export(self):
role_names = self.parentApplet.dataSelectionApplet.role_names

Expand Down
5 changes: 0 additions & 5 deletions ilastik/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@
[lazyflow]
threads: -1
total_ram_mb: 0
[hbp]
token_url: https://web.ilastik.org/token/
upload_file_url: https://web.ilastik.org/v1/files/
create_project_url: https://web.ilastik.org/v1/batch/projects/
"""


Expand Down

0 comments on commit 07e1078

Please sign in to comment.