Coder Social home page Coder Social logo

fmi-faim / ipa-project-template Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 2.0 3.61 MB

Copier template for image processing & analysis projects.

Home Page: https://fmi-faim.github.io/ipa-project-template/

License: MIT License

Jinja 88.33% Shell 11.67%

ipa-project-template's People

Contributors

csoneson avatar imagejan avatar oole avatar pre-commit-ci[bot] avatar tibuch avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

oole csoneson

ipa-project-template's Issues

Keep an up-to-date .pre-commit-config.yaml in template subdir

Our current pre-commit.ci workflow updates the .pre-commit-config.yaml in the repository root, but doesn't check the file inside the template subfolder.

Also, we should consider using ruff (both check and format), remove redundant others (e.g. black), and maybe add a ruff.toml to the project template (if we want to deviate from defaults).

Use pixi in template

We should replace the miniforge/conda environments in the template with pixi.

Minimize logging boilerplate

The current code to create a logger is redundant and takes quite some space:

def _create_logger(name: str) -> logging.Logger:
"""
Create logger which logs to <timestamp>-<name>.log inside the current
working directory.
Parameters
----------
name
Name of the logger instance.
"""
logger = logging.Logger(name.capitalize())
now = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
handler = logging.FileHandler(f"{now}-{name}.log")
handler.setLevel(logging.INFO)
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger

Identical duplicates

def _create_logger(name: str) -> logging.Logger:
"""
Create logger which logs to <timestamp>-<name>.log inside the current
working directory.
Parameters
----------
name
Name of the logger instance.
"""
logger = logging.Logger(name.capitalize())
now = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
handler = logging.FileHandler(f"{now}-{name}.log")
handler.setLevel(logging.INFO)
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger

def _create_logger(name: str) -> logging.Logger:
"""
Create logger which logs to <timestamp>-<name>.log inside the current
working directory.
Parameters
----------
name
Name of the logger instance.
"""
logger = logging.Logger(name.capitalize())
now = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
handler = logging.FileHandler(f"{now}-{name}.log")
handler.setLevel(logging.INFO)
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger

I think we could improve this by migrating it into some utility function, so we can import create_logger and call create_logger(name) from any ipa step.
In addition, I'd like to use a basic decorator to have the function arguments logged by default (along the lines of https://ankitbko.github.io/blog/2021/04/logging-in-python/):

my_logger = create_logger(name="processing")

@log(logger=my_logger)
def run_processing(input_dir: str, output_dir: str):
	# do some processing
	my_logger.info("Done!")

... which would log the values of input_dir and output_dir, without having to put extra code into the run_processing function.

@tibuch what do you think?

Check available space in pixi cache_dir before proceeding

To prevent usage of the project code without initializing (i.e. running init.sh at the beginning of your session), we could introduce a task that checks for a minimum available space in the cache_dir folder of the pixi configuration, and warns the user if they're running with a "wrong" cache directory.

For example, this bash snippet gives the current free space on the file system where cache_dir is located:

pixi info --json | grep -o '"cache_dir": "[^"]*' | grep -o '[^"]*$' | tr -d '\n' | xargs -0 -I {} df -P {} | tail -1 | awk '{print $4}'

We could use this - or a (platform-independent) Python equivalent from a minimal environment in pixi - to fail early if there's not enough space available. What do you think, @tibuch?

Consider unifying config.yml across steps

Having a single config.yml for all steps of a workflow would have several benefits:

  • Avoid redundant definition of common arguments (e.g., zarr plate directory, project folder, etc.).
  • Reuse the config file for possible (prefect, nextflow, ...) workflows/pipelines built across all steps.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.