Scientific Programming
153 subscribers
158 photos
30 videos
138 files
442 links
Tutorials and applications from scientific programming

https://github.com/Ziaeemehr
Download Telegram
Python examples for beginners.πŸ“ŒπŸ“Œ.pdf
418.2 KB
Python 100 programs.
Partial functions allow us to fix a certain number of arguments of a function and generate a new function

from functools import partial

def add(a, b, c):
return 100 * a + 10 * b + c

# A partial function with b = 1 and c = 2
add_part = partial(add, c = 2, b = 1)

# Calling partial function, input is a
print(add_part(3))
πŸ‘2
Post-doctoral in Marseille.

Project Title: Higher-order interactions in human brain networks supporting causal learning
I have a package let's call it my_package in python. how to implement a function to call it like my_package.tests() to run all tests?


## Create a tests Module

1. In your my_package directory, create a new directory called tests.
2. Inside the tests directory, create an empty __init__.py file to make it a Python package.
3. Create a new Python file, e.g., test_suite.py, where you will define your test suite.

## Define the tests() Function

1. In the test_suite.py file, import the necessary testing framework (e.g., unittest or `pytest`).
2. Define a function called tests() that will run all the tests in your package.

Here's an example using the unittest framework:


import unittest
from . import test_module1, test_module2

def tests():
suite = unittest.TestSuite()
suite.addTests(unittest.TestLoader().loadTestsFromModule(test_module1))
suite.addTests(unittest.TestLoader().loadTestsFromModule(test_module2))

runner = unittest.TextTestRunner(verbosity=2)
runner.run(suite)


test_module1.py is something like this:


import unittest
import numpy as np

class test_module_add(unittest.TestCase):
def test_add(self):
self.assertEqual(np.add(1, 2), 3)


In this example, the tests() function creates a TestSuite object, adds tests from the test_module1 and test_module2 modules, and then runs the test suite using a TextTestRunner.

## Import the tests() Function

1. In your my_package/__init__.py file, import the tests() function from the test_suite.py file:


from .tests.test_suite import tests


Now, you can call the tests() function from your package like this:


import my_package
my_package.tests()


This will run all the tests in your my_package package.
Pre-commit:

The pre-commit package is a tool used in software development to manage and maintain code quality. It allows developers to set up and run a series of checks on their code before committing it to version control systems like Git. These checks can include formatting, syntax, style, and even running tests to ensure that the code meets predefined standards and doesn't introduce any errors or bugs. By catching issues early in the development process, pre-commit helps to ensure that the codebase remains clean, consistent, and maintainable.

how to install and set up:
https://pre-commit.com/

you need to put a .pre-commit-config.yaml at the root of your project.
then just run to check and correct over all files:

bash
pre-commit install
pre-commit run --all-files
Scientific Programming
Pre-commit: The pre-commit package is a tool used in software development to manage and maintain code quality. It allows developers to set up and run a series of checks on their code before committing it to version control systems like Git. These checks can…
An example of configuration file:

yaml
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.3
hooks:
- id: ruff
- id: ruff-format
args: [--diff]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: mixed-line-ending
args: [--fix=lf]
- id: trailing-whitespace
I had trouble installing R and 'tidyverse' on Ubuntu because the standard repositories offer older versions of R, which caused some packages not to install properly.
This resolved the issue:

Link
How to remove jupyter notebook metadata/output before tracking with git?

There are several method including git filter approuch, git hooks and using nbstripout. I use the filter since looked cleaner to me.

bash

# Add this to your local .git/config
[filter "strip-notebook-output"]
clean = "jupyter nbconvert --ClearOutputPreprocessor.enabled=False --ClearMetadataPreprocessor.enabled=True --to=notebook --stdin --stdout --log-level=ERROR"
# Create a .gitattributes file in your directory with notebooks, with this content:
*.ipynb filter=strip-notebook-output

to remove the output change
--ClearOutputPreprocessor.enabled=True
.
it lunches each time ADD changes of the notebook.
πŸ‘1
πŸ“–Software Engineering for Data Scientists
From Notebooks to Scalable Systems

Catherine_Nelson

Definitely useful book to fill the gap between researchers and software engineers.
πŸ‘2
Forwarded from Microsoft Copilot
You are invited to Microsoft Copilot AI assistant!

Copilot is your one-stop destination within Telegram for answers, advice, and fun conversations.✨

Click on this link to start: Chat with Copilot
Lazy Predict Library in Python for Machine Learning

Lazy Predict is a Python library designed to simplify and accelerate predictive modeling projects. It offers a user-friendly, efficient approach to making predictions, requiring minimal effort to install and use. This open-source tool, released under the MIT license, is ideal for data science and machine learning tasks.

Key benefits of Lazy Predict include its ability to streamline data pre-processing, model tuning, and result evaluation. It also provides features for model selection and hyperparameter optimization, helping users achieve better outcomes with their machine learning models. By leveraging Lazy Predict, you can enhance your predictive modeling process and achieve more accurate results efficiently.

GeeksforGeeks
GitHub
πŸ‘1
Perplexity has added a nice feature of attaching PDF and ask from it. Just upload your pdf through (+) and ask question.
How to download part of a GitHub repository? for example one folder.

Sometimes a Repository could be very large and you only need part of it.

1. Go to https://download-directory.github.io/
2. Enter the URL of the GitHub repository folder you want to download in the input field.
3. Press Enter, and the folder will be downloaded as a ZIP file.

There are also other methods using git command or GitHub Desktop, but this one seems easier.
πŸ‘1