Skip to content

Commit

Permalink
Add logging to all biomero scripts by default. Update batch workflows…
Browse files Browse the repository at this point in the history
… script
  • Loading branch information
TorecLuik committed Feb 21, 2024
1 parent 2befc27 commit 3603b65
Show file tree
Hide file tree
Showing 8 changed files with 361 additions and 104 deletions.
35 changes: 30 additions & 5 deletions Example_Minimal_Slurm_Script.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import subprocess
from biomero import SlurmClient
import logging
import os
import sys

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -72,11 +74,11 @@ def runScript():

try:
scriptParams = client.getInputs(unwrap=True)
print(f"Params: {scriptParams}")
print(f"Validating slurm connection:\
logger.info(f"Params: {scriptParams}")
logger.info(f"Validating slurm connection:\
{slurmClient.validate()} for {slurmClient.__dict__}")

print(f"Running py cmd: {scriptParams[_PYCMD]}")
logger.info(f"Running py cmd: {scriptParams[_PYCMD]}")
print_result = []
cmdlist = []
if scriptParams[_RUNSLRM]:
Expand All @@ -93,10 +95,10 @@ def runScript():
# run a list of commands
for cmd in cmdlist:
results = slurmClient.run(cmd)
print(f"Ran slurm {results}")
logger.info(f"Ran slurm {results}")
except subprocess.CalledProcessError as e:
results = f"Error {e.__dict__}"
print(results)
logger.info(results)
finally:
print_result.append(f"{results.stdout}")
client.setOutput("Message", rstring("".join(print_result)))
Expand All @@ -105,4 +107,27 @@ def runScript():


if __name__ == '__main__':
# Some defaults from OMERO; don't feel like reading ice files.
# Retrieve the value of the OMERODIR environment variable
OMERODIR = os.environ.get('OMERODIR', '/opt/omero/server/OMERO.server')
LOGDIR = os.path.join(OMERODIR, 'var', 'log')
LOGFORMAT = "%(asctime)s %(levelname)-5.5s [%(name)40s] " \
"[%(process)d] (%(threadName)-10s) %(message)s"
# Added the process id
LOGSIZE = 500000000
LOGNUM = 9
log_filename = 'biomero.log'
# Create a stream handler with INFO level (for OMERO.web output)
stream_handler = logging.StreamHandler(sys.stdout)
stream_handler.setLevel(logging.INFO)
# Create DEBUG logging to rotating logfile at var/log
logging.basicConfig(level=logging.DEBUG,
format=LOGFORMAT,
handlers=[
stream_handler,
logging.handlers.RotatingFileHandler(
os.path.join(LOGDIR, log_filename),
maxBytes=LOGSIZE,
backupCount=LOGNUM)
])
runScript()
26 changes: 23 additions & 3 deletions data/SLURM_Get_Results.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,27 @@ def runScript():


if __name__ == '__main__':
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
stream=sys.stdout)
# Some defaults from OMERO; don't feel like reading ice files.
# Retrieve the value of the OMERODIR environment variable
OMERODIR = os.environ.get('OMERODIR', '/opt/omero/server/OMERO.server')
LOGDIR = os.path.join(OMERODIR, 'var', 'log')
LOGFORMAT = "%(asctime)s %(levelname)-5.5s [%(name)40s] " \
"[%(process)d] (%(threadName)-10s) %(message)s"
# Added the process id
LOGSIZE = 500000000
LOGNUM = 9
log_filename = 'biomero.log'
# Create a stream handler with INFO level (for OMERO.web output)
stream_handler = logging.StreamHandler(sys.stdout)
stream_handler.setLevel(logging.INFO)
# Create DEBUG logging to rotating logfile at var/log
logging.basicConfig(level=logging.DEBUG,
format=LOGFORMAT,
handlers=[
stream_handler,
logging.handlers.RotatingFileHandler(
os.path.join(LOGDIR, log_filename),
maxBytes=LOGSIZE,
backupCount=LOGNUM)
])
runScript()
25 changes: 25 additions & 0 deletions data/SLURM_Get_Update.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from omero.rtypes import rstring, robject, unwrap, wrap
from biomero import SlurmClient
import logging
import os
import sys

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -163,4 +165,27 @@ def check_job(slurmClient, message, slurm_job_id):


if __name__ == '__main__':
# Some defaults from OMERO; don't feel like reading ice files.
# Retrieve the value of the OMERODIR environment variable
OMERODIR = os.environ.get('OMERODIR', '/opt/omero/server/OMERO.server')
LOGDIR = os.path.join(OMERODIR, 'var', 'log')
LOGFORMAT = "%(asctime)s %(levelname)-5.5s [%(name)40s] " \
"[%(process)d] (%(threadName)-10s) %(message)s"
# Added the process id
LOGSIZE = 500000000
LOGNUM = 9
log_filename = 'biomero.log'
# Create a stream handler with INFO level (for OMERO.web output)
stream_handler = logging.StreamHandler(sys.stdout)
stream_handler.setLevel(logging.INFO)
# Create DEBUG logging to rotating logfile at var/log
logging.basicConfig(level=logging.DEBUG,
format=LOGFORMAT,
handlers=[
stream_handler,
logging.handlers.RotatingFileHandler(
os.path.join(LOGDIR, log_filename),
maxBytes=LOGSIZE,
backupCount=LOGNUM)
])
runScript()
26 changes: 25 additions & 1 deletion data/_SLURM_Image_Transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
zip file for download, then exports it to SLURM.
@author Torec Luik
@version 0.0.4
@version 1.5.0
"""

import shutil
Expand All @@ -48,6 +48,7 @@
import Image
from biomero import SlurmClient
import logging
import sys

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -711,4 +712,27 @@ def run_script():


if __name__ == "__main__":
# Some defaults from OMERO; don't feel like reading ice files.
# Retrieve the value of the OMERODIR environment variable
OMERODIR = os.environ.get('OMERODIR', '/opt/omero/server/OMERO.server')
LOGDIR = os.path.join(OMERODIR, 'var', 'log')
LOGFORMAT = "%(asctime)s %(levelname)-5.5s [%(name)40s] " \
"[%(process)d] (%(threadName)-10s) %(message)s"
# Added the process id
LOGSIZE = 500000000
LOGNUM = 9
log_filename = 'biomero.log'
# Create a stream handler with INFO level (for OMERO.web output)
stream_handler = logging.StreamHandler(sys.stdout)
stream_handler.setLevel(logging.INFO)
# Create DEBUG logging to rotating logfile at var/log
logging.basicConfig(level=logging.DEBUG,
format=LOGFORMAT,
handlers=[
stream_handler,
logging.handlers.RotatingFileHandler(
os.path.join(LOGDIR, log_filename),
maxBytes=LOGSIZE,
backupCount=LOGNUM)
])
run_script()
25 changes: 25 additions & 0 deletions init/SLURM_Init_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from omero.rtypes import rstring, unwrap
from biomero import SlurmClient
import logging
import os
import sys

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -61,4 +63,27 @@ def runScript():


if __name__ == '__main__':
# Some defaults from OMERO; don't feel like reading ice files.
# Retrieve the value of the OMERODIR environment variable
OMERODIR = os.environ.get('OMERODIR', '/opt/omero/server/OMERO.server')
LOGDIR = os.path.join(OMERODIR, 'var', 'log')
LOGFORMAT = "%(asctime)s %(levelname)-5.5s [%(name)40s] " \
"[%(process)d] (%(threadName)-10s) %(message)s"
# Added the process id
LOGSIZE = 500000000
LOGNUM = 9
log_filename = 'biomero.log'
# Create a stream handler with INFO level (for OMERO.web output)
stream_handler = logging.StreamHandler(sys.stdout)
stream_handler.setLevel(logging.INFO)
# Create DEBUG logging to rotating logfile at var/log
logging.basicConfig(level=logging.DEBUG,
format=LOGFORMAT,
handlers=[
stream_handler,
logging.handlers.RotatingFileHandler(
os.path.join(LOGDIR, log_filename),
maxBytes=LOGSIZE,
backupCount=LOGNUM)
])
runScript()
29 changes: 27 additions & 2 deletions workflows/SLURM_CellPose_Segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

from __future__ import print_function
import omero
import os
import sys
from omero.grid import JobParams
from omero.rtypes import rstring, unwrap
import omero.scripts as omscripts
Expand All @@ -38,7 +40,7 @@ def runScript():

params = JobParams()
params.authors = ["Torec Luik"]
params.version = "0.0.4"
params.version = "1.5.0"
params.description = f'''Script to run CellPose on slurm cluster.
First run the {_IMAGE_EXPORT_SCRIPT} script to export your data
to the cluster.
Expand All @@ -51,7 +53,7 @@ def runScript():
Connection ready? {slurmClient.validate()}
'''
params.name = 'Slurm Cellpose Segmentation'
params.contact = 't.t.luik@amsterdamumc.nl'
params.contact = 'cellularimaging@amsterdamumc.nl'
params.institutions = ["Amsterdam UMC"]
params.authorsInstitutions = [[1]]

Expand Down Expand Up @@ -174,4 +176,27 @@ def runScript():


if __name__ == '__main__':
# Some defaults from OMERO; don't feel like reading ice files.
# Retrieve the value of the OMERODIR environment variable
OMERODIR = os.environ.get('OMERODIR', '/opt/omero/server/OMERO.server')
LOGDIR = os.path.join(OMERODIR, 'var', 'log')
LOGFORMAT = "%(asctime)s %(levelname)-5.5s [%(name)40s] " \
"[%(process)d] (%(threadName)-10s) %(message)s"
# Added the process id
LOGSIZE = 500000000
LOGNUM = 9
log_filename = 'biomero.log'
# Create a stream handler with INFO level (for OMERO.web output)
stream_handler = logging.StreamHandler(sys.stdout)
stream_handler.setLevel(logging.INFO)
# Create DEBUG logging to rotating logfile at var/log
logging.basicConfig(level=logging.DEBUG,
format=LOGFORMAT,
handlers=[
stream_handler,
logging.handlers.RotatingFileHandler(
os.path.join(LOGDIR, log_filename),
maxBytes=LOGSIZE,
backupCount=LOGNUM)
])
runScript()
Loading

0 comments on commit 3603b65

Please sign in to comment.