spacr 0.3.68__tar.gz → 0.3.70__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {spacr-0.3.68/spacr.egg-info → spacr-0.3.70}/PKG-INFO +1 -1
- spacr-0.3.70/notebooks/old/.ipynb_checkpoints/Untitled1-checkpoint.ipynb +6 -0
- spacr-0.3.70/notebooks/old/.ipynb_checkpoints/trade_2025-checkpoint.ipynb +6 -0
- spacr-0.3.70/notebooks/old/Untitled1.ipynb +230 -0
- spacr-0.3.70/notebooks/old/trade_2025.ipynb +230 -0
- spacr-0.3.70/settings/measure_crop_settings.csv +48 -0
- {spacr-0.3.68 → spacr-0.3.70}/setup.py +1 -1
- {spacr-0.3.68 → spacr-0.3.70}/spacr/ml.py +25 -20
- {spacr-0.3.68 → spacr-0.3.70/spacr.egg-info}/PKG-INFO +1 -1
- {spacr-0.3.68 → spacr-0.3.70}/spacr.egg-info/SOURCES.txt +4 -0
- spacr-0.3.68/settings/measure_crop_settings.csv +0 -62
- {spacr-0.3.68 → spacr-0.3.70}/.readthedocs.yaml +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/LICENSE +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/MANIFEST.in +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/README.rst +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/deploy_docs.sh +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/requirements.txt +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/Makefile +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/doctrees/environment.pickle +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_modules/index.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_modules/spacr/app_annotate.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_modules/spacr/app_classify.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_modules/spacr/app_make_masks.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_modules/spacr/app_mask.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_modules/spacr/app_measure.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_modules/spacr/app_sequencing.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_modules/spacr/app_umap.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_modules/spacr/core.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_modules/spacr/deep_spacr.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_modules/spacr/graph_learning.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_modules/spacr/gui.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_modules/spacr/gui_core.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_modules/spacr/gui_elements.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_modules/spacr/gui_utils.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_modules/spacr/io.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_modules/spacr/logger.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_modules/spacr/measure.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_modules/spacr/plot.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_modules/spacr/sequencing.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_modules/spacr/settings.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_modules/spacr/sim.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_modules/spacr/timelapse.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_modules/spacr/utils.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_sources/index.rst.txt +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_sources/modules.rst.txt +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_sources/spacr.rst.txt +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/_sphinx_javascript_frameworks_compat.js +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/basic.css +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/css/badge_only.css +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/css/fonts/Roboto-Slab-Bold.woff +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/css/fonts/Roboto-Slab-Bold.woff2 +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/css/fonts/Roboto-Slab-Regular.woff +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/css/fonts/Roboto-Slab-Regular.woff2 +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/css/fonts/fontawesome-webfont.eot +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/css/fonts/fontawesome-webfont.svg +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/css/fonts/fontawesome-webfont.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/css/fonts/fontawesome-webfont.woff +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/css/fonts/fontawesome-webfont.woff2 +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/css/fonts/lato-bold-italic.woff +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/css/fonts/lato-bold-italic.woff2 +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/css/fonts/lato-bold.woff +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/css/fonts/lato-bold.woff2 +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/css/fonts/lato-normal-italic.woff +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/css/fonts/lato-normal-italic.woff2 +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/css/fonts/lato-normal.woff +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/css/fonts/lato-normal.woff2 +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/css/theme.css +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/doctools.js +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/documentation_options.js +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/file.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/jquery.js +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/js/badge_only.js +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/js/html5shiv-printshiv.min.js +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/js/html5shiv.min.js +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/js/theme.js +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/language_data.js +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/minus.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/plus.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/pygments.css +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/searchtools.js +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/_static/sphinx_highlight.js +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/genindex.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/index.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/modules.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/objects.inv +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/py-modindex.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/search.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/searchindex.js +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/_build/html/spacr.html +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/conf.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/index.rst +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/make.bat +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/modules.rst +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/docs/source/spacr.rst +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/environment.yaml +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/fonts/OpenSans-Regular.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/notebooks/.ipynb_checkpoints/4_spacr_annotate-checkpoint.ipynb +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/notebooks/1_spacr_generate_masks.ipynb +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/notebooks/2_spacr_generate_mesurments_crop_images.ipynb +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/notebooks/3a_spacr_machine_learning.ipynb +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/notebooks/3b_spacr_computer_vision.ipynb +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/notebooks/4_spacr_annotate.ipynb +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/notebooks/old/.ipynb_checkpoints/Untitled-checkpoint.ipynb +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/notebooks/old/.ipynb_checkpoints/figure_2-checkpoint.ipynb +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/notebooks/old/.ipynb_checkpoints/interperate_vision_classes-checkpoint.ipynb +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/notebooks/old/.ipynb_checkpoints/spacr_image_umap-checkpoint.ipynb +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/notebooks/old/.ipynb_checkpoints/submodule_1_frequency_analysis-checkpoint.ipynb +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/notebooks/old/Untitled.ipynb +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/notebooks/old/cv_scoring_nb.ipynb +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/notebooks/old/deep_learning_spacr.ipynb +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/notebooks/old/figure_2.ipynb +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/notebooks/old/figure_3-Copy1.ipynb +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/notebooks/old/figure_3.ipynb +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/notebooks/old/interperate_vision_classes.ipynb +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/notebooks/old/machine_learning_spacr_nb.ipynb +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/notebooks/old/spacr_0.1_all_settings_git.ipynb +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/notebooks/old/spacr_0.1_minimal.ipynb +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/notebooks/old/spacr_image_umap.ipynb +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/notebooks/submodules/submodule_1_frequency_analysis.ipynb +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/path/home/carruthers/datasets/plate1/measurements/measurements.db +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/path/home/carruthers/datasets/plate1/settings/measure_crop_settings.csv +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/path/settings/preprocess_generate_masks_settings.csv +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/requirements.txt +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/setup.cfg +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/setup_docs.sh +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/source/conf.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/source/index.rst +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/source/modules.rst +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/source/setup.rst +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/source/spacr.rst +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/__init__.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/__main__.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/app_annotate.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/app_classify.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/app_make_masks.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/app_mask.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/app_measure.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/app_sequencing.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/app_umap.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/cellpose.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/chat_bot.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/core.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/deep_spacr.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/gui.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/gui_core.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/gui_elements.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/gui_utils.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/io.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/logger.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/measure.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/mediar.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/openai.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/plot.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/.gitignore +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/LICENSE +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/README.md +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/SetupDict.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/config/baseline.json +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/config/mediar_example.json +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/config/pred/pred_mediar.json +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/config/step1_pretraining/phase1.json +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/config/step1_pretraining/phase2.json +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/config/step2_finetuning/finetuning1.json +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/config/step2_finetuning/finetuning2.json +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/config/step3_prediction/base_prediction.json +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/config/step3_prediction/ensemble_tta.json +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/core/BasePredictor.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/core/BaseTrainer.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/core/Baseline/Predictor.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/core/Baseline/Trainer.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/core/Baseline/__init__.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/core/Baseline/utils.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/core/MEDIAR/EnsemblePredictor.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/core/MEDIAR/Predictor.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/core/MEDIAR/Trainer.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/core/MEDIAR/__init__.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/core/MEDIAR/utils.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/core/__init__.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/core/utils.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/evaluate.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/generate_mapping.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/image/examples/img1.tiff +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/image/examples/img2.tif +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/image/failure_cases.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/image/mediar_framework.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/image/mediar_model.PNG +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/image/mediar_results.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/main.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/predict.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/requirements.txt +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/train_tools/__init__.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/train_tools/data_utils/__init__.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/train_tools/data_utils/custom/CellAware.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/train_tools/data_utils/custom/LoadImage.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/train_tools/data_utils/custom/NormalizeImage.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/train_tools/data_utils/custom/__init__.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/train_tools/data_utils/custom/modalities.pkl +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/train_tools/data_utils/datasetter.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/train_tools/data_utils/transforms.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/train_tools/data_utils/utils.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/train_tools/measures.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/train_tools/models/MEDIARFormer.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/train_tools/models/__init__.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/MEDIAR/train_tools/utils.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/data/lopit.csv +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/data/toxoplasma_metadata.csv +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/OFL.txt +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/OpenSans-Italic-VariableFont_wdth,wght.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/OpenSans-VariableFont_wdth,wght.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/README.txt +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans-Bold.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans-BoldItalic.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans-ExtraBold.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans-ExtraBoldItalic.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans-Italic.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans-Light.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans-LightItalic.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans-Medium.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans-MediumItalic.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans-Regular.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans-SemiBold.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans-SemiBoldItalic.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans_Condensed-Bold.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans_Condensed-BoldItalic.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans_Condensed-ExtraBold.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans_Condensed-ExtraBoldItalic.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans_Condensed-Italic.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans_Condensed-Light.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans_Condensed-LightItalic.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans_Condensed-Medium.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans_Condensed-MediumItalic.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans_Condensed-Regular.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans_Condensed-SemiBold.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans_Condensed-SemiBoldItalic.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans_SemiCondensed-Bold.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans_SemiCondensed-BoldItalic.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans_SemiCondensed-ExtraBold.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans_SemiCondensed-ExtraBoldItalic.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans_SemiCondensed-Italic.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans_SemiCondensed-Light.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans_SemiCondensed-LightItalic.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans_SemiCondensed-Medium.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans_SemiCondensed-MediumItalic.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans_SemiCondensed-Regular.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans_SemiCondensed-SemiBold.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/font/open_sans/static/OpenSans_SemiCondensed-SemiBoldItalic.ttf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/icons/abort.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/icons/annotate.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/icons/cellpose_all.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/icons/cellpose_masks.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/icons/classify.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/icons/convert.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/icons/default.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/icons/dna_matrix.mp4 +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/icons/download.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/icons/logo.pdf +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/icons/logo_spacr.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/icons/logo_spacr_1.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/icons/make_masks.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/icons/map_barcodes.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/icons/mask.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/icons/measure.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/icons/ml_analyze.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/icons/plaque.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/icons/recruitment.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/icons/regression.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/icons/run.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/icons/sequencing.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/icons/settings.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/icons/train_cellpose.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/icons/umap.png +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/images/plate1_E01_T0001F001L01A01Z01C02.tif +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/images/plate1_E01_T0001F001L01A02Z01C01.tif +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/resources/images/plate1_E01_T0001F001L01A03Z01C03.tif +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/sequencing.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/settings.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/sim.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/stats.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/submodules.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/timelapse.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/toxo.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/utils.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr/version.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr.egg-info/dependency_links.txt +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr.egg-info/entry_points.txt +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr.egg-info/requires.txt +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/spacr.egg-info/top_level.txt +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/tests/test_annotate_app.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/tests/test_core.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/tests/test_gui_classify_app.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/tests/test_gui_mask_app.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/tests/test_gui_measure_app.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/tests/test_gui_sim_app.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/tests/test_gui_utils.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/tests/test_io.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/tests/test_mask_app.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/tests/test_measure.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/tests/test_plot.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/tests/test_sim.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/tests/test_timelapse.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/tests/test_train.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/tests/test_umap.py +0 -0
- {spacr-0.3.68 → spacr-0.3.70}/tests/test_utils.py +0 -0
@@ -0,0 +1,230 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "code",
|
5
|
+
"execution_count": 11,
|
6
|
+
"id": "40424f6c",
|
7
|
+
"metadata": {},
|
8
|
+
"outputs": [],
|
9
|
+
"source": [
|
10
|
+
"import os\n",
|
11
|
+
"import json\n",
|
12
|
+
"import cv2\n",
|
13
|
+
"import numpy as np\n",
|
14
|
+
"import openai\n",
|
15
|
+
"from sklearn.model_selection import train_test_split\n",
|
16
|
+
"\n",
|
17
|
+
"\n",
|
18
|
+
"def prepare_data_for_finetuning(image_folder, test_size=0.2, output_file=\"fine_tune_dataset.jsonl\"):\n",
|
19
|
+
" \"\"\"\n",
|
20
|
+
" Prepares a dataset for fine-tuning GPT-4 using grayscale images and corresponding masks.\n",
|
21
|
+
"\n",
|
22
|
+
" Args:\n",
|
23
|
+
" image_folder (str): Path to the folder containing grayscale images and a \"masks\" subfolder.\n",
|
24
|
+
" test_size (float): Proportion of the dataset to include in the test split.\n",
|
25
|
+
" output_file (str): Output JSONL file for fine-tuning.\n",
|
26
|
+
" \n",
|
27
|
+
" Returns:\n",
|
28
|
+
" tuple: Paths to the training and testing datasets in JSONL format.\n",
|
29
|
+
" \"\"\"\n",
|
30
|
+
" def convert_to_16bit(image):\n",
|
31
|
+
" \"\"\"\n",
|
32
|
+
" Converts an image to 16-bit format.\n",
|
33
|
+
" \"\"\"\n",
|
34
|
+
" if image.dtype == np.uint8: # Convert 8-bit to 16-bit\n",
|
35
|
+
" image = cv2.normalize(image, None, 0, 65535, cv2.NORM_MINMAX, dtype=cv2.CV_16U)\n",
|
36
|
+
" elif image.dtype == np.float32: # Convert float32 to 16-bit\n",
|
37
|
+
" image = (image * 65535).clip(0, 65535).astype(np.uint16)\n",
|
38
|
+
" elif image.dtype != np.uint16: # Convert other types to 16-bit\n",
|
39
|
+
" image = cv2.normalize(image, None, 0, 65535, cv2.NORM_MINMAX, dtype=cv2.CV_16U)\n",
|
40
|
+
" return image\n",
|
41
|
+
"\n",
|
42
|
+
" images_path = [f for f in os.listdir(image_folder) if os.path.isfile(os.path.join(image_folder, f))]\n",
|
43
|
+
" masks_folder = os.path.join(image_folder, \"masks\")\n",
|
44
|
+
" data = []\n",
|
45
|
+
"\n",
|
46
|
+
" for image_file in images_path:\n",
|
47
|
+
" image_path = os.path.join(image_folder, image_file)\n",
|
48
|
+
" mask_path = os.path.join(masks_folder, image_file)\n",
|
49
|
+
" \n",
|
50
|
+
" if not os.path.exists(mask_path):\n",
|
51
|
+
" continue # Skip if mask does not exist\n",
|
52
|
+
" \n",
|
53
|
+
" # Load image and mask\n",
|
54
|
+
" image = cv2.imread(image_path, cv2.IMREAD_UNCHANGED)\n",
|
55
|
+
" mask = cv2.imread(mask_path, cv2.IMREAD_UNCHANGED)\n",
|
56
|
+
"\n",
|
57
|
+
" # Skip if images fail to load\n",
|
58
|
+
" if image is None or mask is None:\n",
|
59
|
+
" print(f\"Skipping {image_file}: Unable to load.\")\n",
|
60
|
+
" continue\n",
|
61
|
+
"\n",
|
62
|
+
" # Convert to 16-bit if necessary\n",
|
63
|
+
" image = convert_to_16bit(image)\n",
|
64
|
+
" mask = convert_to_16bit(mask)\n",
|
65
|
+
"\n",
|
66
|
+
" # Create a prompt-response pair\n",
|
67
|
+
" prompt = f\"Generate a mask for the grayscale image with dimensions {image.shape}.\"\n",
|
68
|
+
" completion = f\"The mask has been generated with specific contours and intensity ranges.\"\n",
|
69
|
+
" \n",
|
70
|
+
" # Append to the dataset\n",
|
71
|
+
" data.append({\"prompt\": prompt, \"completion\": completion})\n",
|
72
|
+
"\n",
|
73
|
+
" # Split the data\n",
|
74
|
+
" train_data, test_data = train_test_split(data, test_size=test_size, random_state=42)\n",
|
75
|
+
"\n",
|
76
|
+
" # Save the datasets\n",
|
77
|
+
" train_file = f\"train_{output_file}\"\n",
|
78
|
+
" test_file = f\"test_{output_file}\"\n",
|
79
|
+
" \n",
|
80
|
+
" with open(train_file, \"w\") as train_f:\n",
|
81
|
+
" for entry in train_data:\n",
|
82
|
+
" train_f.write(json.dumps(entry) + \"\\n\")\n",
|
83
|
+
" \n",
|
84
|
+
" with open(test_file, \"w\") as test_f:\n",
|
85
|
+
" for entry in test_data:\n",
|
86
|
+
" test_f.write(json.dumps(entry) + \"\\n\")\n",
|
87
|
+
"\n",
|
88
|
+
" return train_file, test_file\n",
|
89
|
+
"\n",
|
90
|
+
"\n",
|
91
|
+
"def fine_tune_gpt4(train_file, model=\"gpt-4\", epochs=4, learning_rate=1e-4):\n",
|
92
|
+
" \"\"\"\n",
|
93
|
+
" Fine-tunes GPT-4 using the prepared training dataset.\n",
|
94
|
+
"\n",
|
95
|
+
" Args:\n",
|
96
|
+
" train_file (str): Path to the training dataset in JSONL format.\n",
|
97
|
+
" model (str): Base GPT-4 model to fine-tune.\n",
|
98
|
+
" epochs (int): Number of epochs for fine-tuning.\n",
|
99
|
+
" learning_rate (float): Learning rate for fine-tuning.\n",
|
100
|
+
" \n",
|
101
|
+
" Returns:\n",
|
102
|
+
" str: Fine-tuned model ID.\n",
|
103
|
+
" \"\"\"\n",
|
104
|
+
" openai.api_key = os.getenv(\"OPENAI_API_KEY\")\n",
|
105
|
+
"\n",
|
106
|
+
" # Upload the training file\n",
|
107
|
+
" print(\"Uploading training file...\")\n",
|
108
|
+
" try:\n",
|
109
|
+
" with open(train_file, \"rb\") as f:\n",
|
110
|
+
" response = openai.File.create(file=f, purpose=\"fine-tune\")\n",
|
111
|
+
" training_file_id = response[\"id\"]\n",
|
112
|
+
" except Exception as e:\n",
|
113
|
+
" print(f\"Error uploading training file: {e}\")\n",
|
114
|
+
" return None\n",
|
115
|
+
"\n",
|
116
|
+
" # Fine-tune the model\n",
|
117
|
+
" print(\"Starting fine-tuning...\")\n",
|
118
|
+
" try:\n",
|
119
|
+
" fine_tune_response = openai.FineTune.create(\n",
|
120
|
+
" model=model,\n",
|
121
|
+
" training_file=training_file_id,\n",
|
122
|
+
" n_epochs=epochs,\n",
|
123
|
+
" learning_rate=learning_rate\n",
|
124
|
+
" )\n",
|
125
|
+
" fine_tune_id = fine_tune_response[\"id\"]\n",
|
126
|
+
" print(f\"Fine-tuning initiated with ID: {fine_tune_id}\")\n",
|
127
|
+
" return fine_tune_id\n",
|
128
|
+
" except Exception as e:\n",
|
129
|
+
" print(f\"Error during fine-tuning: {e}\")\n",
|
130
|
+
" return None\n",
|
131
|
+
"\n",
|
132
|
+
"\n",
|
133
|
+
"def save_fine_tuned_model(fine_tune_id, output_model_path):\n",
|
134
|
+
" \"\"\"\n",
|
135
|
+
" Saves the fine-tuned model to disk.\n",
|
136
|
+
"\n",
|
137
|
+
" Args:\n",
|
138
|
+
" fine_tune_id (str): The fine-tune ID returned after training.\n",
|
139
|
+
" output_model_path (str): Path to save the fine-tuned model.\n",
|
140
|
+
" \"\"\"\n",
|
141
|
+
" try:\n",
|
142
|
+
" fine_tune_details = openai.FineTune.retrieve(id=fine_tune_id)\n",
|
143
|
+
" fine_tuned_model = fine_tune_details[\"fine_tuned_model\"]\n",
|
144
|
+
" \n",
|
145
|
+
" with open(output_model_path, \"w\") as f:\n",
|
146
|
+
" f.write(fine_tuned_model)\n",
|
147
|
+
" print(f\"Fine-tuned model saved to: {output_model_path}\")\n",
|
148
|
+
" except Exception as e:\n",
|
149
|
+
" print(f\"Error saving fine-tuned model: {e}\")\n"
|
150
|
+
]
|
151
|
+
},
|
152
|
+
{
|
153
|
+
"cell_type": "code",
|
154
|
+
"execution_count": 12,
|
155
|
+
"id": "1cbc2b20",
|
156
|
+
"metadata": {},
|
157
|
+
"outputs": [
|
158
|
+
{
|
159
|
+
"name": "stdout",
|
160
|
+
"output_type": "stream",
|
161
|
+
"text": [
|
162
|
+
"Uploading training file...\n",
|
163
|
+
"Error uploading training file: \n",
|
164
|
+
"\n",
|
165
|
+
"You tried to access openai.File, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python for the API.\n",
|
166
|
+
"\n",
|
167
|
+
"You can run `openai migrate` to automatically upgrade your codebase to use the 1.0.0 interface. \n",
|
168
|
+
"\n",
|
169
|
+
"Alternatively, you can pin your installation to the old version, e.g. `pip install openai==0.28`\n",
|
170
|
+
"\n",
|
171
|
+
"A detailed migration guide is available here: https://github.com/openai/openai-python/discussions/742\n",
|
172
|
+
"\n",
|
173
|
+
"Error saving fine-tuned model: \n",
|
174
|
+
"\n",
|
175
|
+
"You tried to access openai.FineTune, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python for the API.\n",
|
176
|
+
"\n",
|
177
|
+
"You can run `openai migrate` to automatically upgrade your codebase to use the 1.0.0 interface. \n",
|
178
|
+
"\n",
|
179
|
+
"Alternatively, you can pin your installation to the old version, e.g. `pip install openai==0.28`\n",
|
180
|
+
"\n",
|
181
|
+
"A detailed migration guide is available here: https://github.com/openai/openai-python/discussions/742\n",
|
182
|
+
"\n"
|
183
|
+
]
|
184
|
+
}
|
185
|
+
],
|
186
|
+
"source": [
|
187
|
+
"image_folder = '/nas_mnt/carruthers/Einar/dsred/train'\n",
|
188
|
+
"test_size=0.1\n",
|
189
|
+
"\n",
|
190
|
+
"# Step 1: Prepare data\n",
|
191
|
+
"train_file, test_file = prepare_data_for_finetuning(image_folder)\n",
|
192
|
+
"\n",
|
193
|
+
"# Step 2: Fine-tune GPT-4\n",
|
194
|
+
"fine_tune_id = fine_tune_gpt4(train_file, epochs=3, learning_rate=5e-5)\n",
|
195
|
+
"\n",
|
196
|
+
"# Step 3: Save the fine-tuned model\n",
|
197
|
+
"save_fine_tuned_model(fine_tune_id, \"./fine_tuned_gpt4_mask_generator.txt\")\n"
|
198
|
+
]
|
199
|
+
},
|
200
|
+
{
|
201
|
+
"cell_type": "code",
|
202
|
+
"execution_count": null,
|
203
|
+
"id": "7ac25b4a",
|
204
|
+
"metadata": {},
|
205
|
+
"outputs": [],
|
206
|
+
"source": []
|
207
|
+
}
|
208
|
+
],
|
209
|
+
"metadata": {
|
210
|
+
"kernelspec": {
|
211
|
+
"display_name": "spacr",
|
212
|
+
"language": "python",
|
213
|
+
"name": "spacr"
|
214
|
+
},
|
215
|
+
"language_info": {
|
216
|
+
"codemirror_mode": {
|
217
|
+
"name": "ipython",
|
218
|
+
"version": 3
|
219
|
+
},
|
220
|
+
"file_extension": ".py",
|
221
|
+
"mimetype": "text/x-python",
|
222
|
+
"name": "python",
|
223
|
+
"nbconvert_exporter": "python",
|
224
|
+
"pygments_lexer": "ipython3",
|
225
|
+
"version": "3.9.19"
|
226
|
+
}
|
227
|
+
},
|
228
|
+
"nbformat": 4,
|
229
|
+
"nbformat_minor": 5
|
230
|
+
}
|
@@ -0,0 +1,230 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "code",
|
5
|
+
"execution_count": 2,
|
6
|
+
"id": "e7243b46",
|
7
|
+
"metadata": {},
|
8
|
+
"outputs": [],
|
9
|
+
"source": [
|
10
|
+
"import alpaca_trade_api as tradeapi\n",
|
11
|
+
"import pandas as pd\n",
|
12
|
+
"import numpy as np\n",
|
13
|
+
"from datetime import datetime, timedelta\n",
|
14
|
+
"from sklearn.ensemble import RandomForestRegressor\n",
|
15
|
+
"from sklearn.metrics import mean_squared_error\n",
|
16
|
+
"import matplotlib.pyplot as plt\n",
|
17
|
+
"\n",
|
18
|
+
"class StockTrader:\n",
|
19
|
+
" def __init__(self, alpaca_api_key, alpaca_secret_key, base_url='https://paper-api.alpaca.markets'):\n",
|
20
|
+
" # Initialize Alpaca API\n",
|
21
|
+
" self.api = tradeapi.REST(alpaca_api_key, alpaca_secret_key, base_url, api_version='v2')\n",
|
22
|
+
" self.model = None\n",
|
23
|
+
" self.test_mode = False\n",
|
24
|
+
"\n",
|
25
|
+
" def fetch_historical_data(self, symbol, start_date, end_date):\n",
|
26
|
+
" # Fetch historical daily bars\n",
|
27
|
+
" bars = self.api.get_bars(\n",
|
28
|
+
" symbol,\n",
|
29
|
+
" '1Day',\n",
|
30
|
+
" start=start_date.isoformat(),\n",
|
31
|
+
" end=end_date.isoformat()\n",
|
32
|
+
" ).df\n",
|
33
|
+
" bars = bars[bars['symbol'] == symbol]\n",
|
34
|
+
" return bars\n",
|
35
|
+
"\n",
|
36
|
+
" def prepare_features(self, data):\n",
|
37
|
+
" # Prepare features for the model\n",
|
38
|
+
" data['return'] = data['close'].pct_change()\n",
|
39
|
+
" data['volatility'] = data['close'].rolling(window=5).std()\n",
|
40
|
+
" data['momentum'] = data['close'] / data['close'].shift(5) - 1\n",
|
41
|
+
" data['ma5'] = data['close'].rolling(window=5).mean()\n",
|
42
|
+
" data['ma10'] = data['close'].rolling(window=10).mean()\n",
|
43
|
+
" data['ma_ratio'] = data['ma5'] / data['ma10']\n",
|
44
|
+
" data = data.dropna()\n",
|
45
|
+
" features = data[['return', 'volatility', 'momentum', 'ma_ratio']]\n",
|
46
|
+
" return features\n",
|
47
|
+
"\n",
|
48
|
+
" def train_model(self, symbol, start_date, end_date):\n",
|
49
|
+
" # Fetch and prepare data\n",
|
50
|
+
" data = self.fetch_historical_data(symbol, start_date, end_date)\n",
|
51
|
+
" features = self.prepare_features(data)\n",
|
52
|
+
" target = data['close'].shift(-1).dropna()\n",
|
53
|
+
" features = features.iloc[:-1] # Align features and target\n",
|
54
|
+
"\n",
|
55
|
+
" # Split into training and testing sets\n",
|
56
|
+
" split_index = int(len(features) * 0.8)\n",
|
57
|
+
" X_train, X_test = features[:split_index], features[split_index:]\n",
|
58
|
+
" y_train, y_test = target[:split_index], target[split_index:]\n",
|
59
|
+
"\n",
|
60
|
+
" # Train the model\n",
|
61
|
+
" self.model = RandomForestRegressor(n_estimators=100, random_state=42)\n",
|
62
|
+
" self.model.fit(X_train, y_train)\n",
|
63
|
+
"\n",
|
64
|
+
" # Evaluate the model\n",
|
65
|
+
" y_pred = self.model.predict(X_test)\n",
|
66
|
+
" mse = mean_squared_error(y_test, y_pred)\n",
|
67
|
+
" print(f\"Model trained. Test MSE: {mse:.4f}\")\n",
|
68
|
+
"\n",
|
69
|
+
" if self.test_mode:\n",
|
70
|
+
" self.backtest_strategy(X_test, y_test, y_pred)\n",
|
71
|
+
"\n",
|
72
|
+
" def backtest_strategy(self, X_test, y_test, y_pred):\n",
|
73
|
+
" # Simulate trading strategy based on predictions\n",
|
74
|
+
" initial_capital = 100000\n",
|
75
|
+
" positions = pd.DataFrame(index=X_test.index).fillna(0.0)\n",
|
76
|
+
" positions['signal'] = np.where(y_pred > X_test['return'], 1, -1)\n",
|
77
|
+
" positions['holdings'] = positions['signal'] * y_test\n",
|
78
|
+
"\n",
|
79
|
+
" portfolio = positions['holdings'].cumsum() * 100 # Assuming 100 shares per trade\n",
|
80
|
+
" portfolio += initial_capital\n",
|
81
|
+
"\n",
|
82
|
+
" # Plot the portfolio value over time\n",
|
83
|
+
" plt.figure(figsize=(10, 5))\n",
|
84
|
+
" plt.plot(portfolio)\n",
|
85
|
+
" plt.title('Backtested Portfolio Value')\n",
|
86
|
+
" plt.xlabel('Date')\n",
|
87
|
+
" plt.ylabel('Portfolio Value ($)')\n",
|
88
|
+
" plt.show()\n",
|
89
|
+
"\n",
|
90
|
+
" total_return = (portfolio.iloc[-1] - initial_capital) / initial_capital * 100\n",
|
91
|
+
" print(f\"Total return from backtesting: {total_return:.2f}%\")\n",
|
92
|
+
"\n",
|
93
|
+
" def predict(self, symbol):\n",
|
94
|
+
" # Predict the next day's closing price\n",
|
95
|
+
" end_date = datetime.now()\n",
|
96
|
+
" start_date = end_date - timedelta(days=60) # Get recent data for features\n",
|
97
|
+
" data = self.fetch_historical_data(symbol, start_date, end_date)\n",
|
98
|
+
" features = self.prepare_features(data)\n",
|
99
|
+
"\n",
|
100
|
+
" if features.empty:\n",
|
101
|
+
" print(\"Not enough data to make a prediction.\")\n",
|
102
|
+
" return\n",
|
103
|
+
"\n",
|
104
|
+
" latest_features = features.iloc[-1].values.reshape(1, -1)\n",
|
105
|
+
" predicted_price = self.model.predict(latest_features)[0]\n",
|
106
|
+
" current_price = data['close'].iloc[-1]\n",
|
107
|
+
" expected_return = (predicted_price - current_price) / current_price * 100\n",
|
108
|
+
"\n",
|
109
|
+
" print(f\"Predicted next closing price for {symbol}: ${predicted_price:.2f}\")\n",
|
110
|
+
" print(f\"Expected return: {expected_return:.2f}%\")\n",
|
111
|
+
"\n",
|
112
|
+
" return expected_return\n",
|
113
|
+
"\n",
|
114
|
+
" def execute_trade(self, symbol, expected_return, risk_tolerance=0.05):\n",
|
115
|
+
" # Decide whether to buy or sell based on expected return\n",
|
116
|
+
" if expected_return > risk_tolerance:\n",
|
117
|
+
" # Place a buy order\n",
|
118
|
+
" try:\n",
|
119
|
+
" self.api.submit_order(\n",
|
120
|
+
" symbol=symbol,\n",
|
121
|
+
" qty=10, # Number of shares to buy\n",
|
122
|
+
" side='buy',\n",
|
123
|
+
" type='market',\n",
|
124
|
+
" time_in_force='day'\n",
|
125
|
+
" )\n",
|
126
|
+
" print(f\"Placed a market buy order for {symbol}\")\n",
|
127
|
+
" except Exception as e:\n",
|
128
|
+
" print(f\"Error placing buy order: {e}\")\n",
|
129
|
+
" elif expected_return < -risk_tolerance:\n",
|
130
|
+
" # Place a sell order\n",
|
131
|
+
" try:\n",
|
132
|
+
" self.api.submit_order(\n",
|
133
|
+
" symbol=symbol,\n",
|
134
|
+
" qty=10, # Number of shares to sell\n",
|
135
|
+
" side='sell',\n",
|
136
|
+
" type='market',\n",
|
137
|
+
" time_in_force='day'\n",
|
138
|
+
" )\n",
|
139
|
+
" print(f\"Placed a market sell order for {symbol}\")\n",
|
140
|
+
" except Exception as e:\n",
|
141
|
+
" print(f\"Error placing sell order: {e}\")\n",
|
142
|
+
" else:\n",
|
143
|
+
" print(f\"No trade executed for {symbol}. Expected return does not meet risk tolerance.\")\n",
|
144
|
+
"\n",
|
145
|
+
" def run(self, symbol, test_mode=False):\n",
|
146
|
+
" self.test_mode = test_mode\n",
|
147
|
+
" start_date = datetime.now() - timedelta(days=365*2)\n",
|
148
|
+
" end_date = datetime.now() - timedelta(days=1)\n",
|
149
|
+
"\n",
|
150
|
+
" # Train the model\n",
|
151
|
+
" self.train_model(symbol, start_date, end_date)\n",
|
152
|
+
"\n",
|
153
|
+
" if not self.test_mode:\n",
|
154
|
+
" # Predict and trade\n",
|
155
|
+
" expected_return = self.predict(symbol)\n",
|
156
|
+
" if expected_return is not None:\n",
|
157
|
+
" self.execute_trade(symbol, expected_return)\n"
|
158
|
+
]
|
159
|
+
},
|
160
|
+
{
|
161
|
+
"cell_type": "code",
|
162
|
+
"execution_count": 3,
|
163
|
+
"id": "29ebde4b",
|
164
|
+
"metadata": {},
|
165
|
+
"outputs": [
|
166
|
+
{
|
167
|
+
"ename": "APIError",
|
168
|
+
"evalue": "Invalid format for parameter start: error parsing '2022-12-03T13:32:03.137224' as RFC3339 or 2006-01-02 time: parsing time \"2022-12-03T13:32:03.137224\": extra text: \"T13:32:03.137224\"",
|
169
|
+
"output_type": "error",
|
170
|
+
"traceback": [
|
171
|
+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
172
|
+
"\u001b[0;31mAPIError\u001b[0m Traceback (most recent call last)",
|
173
|
+
"Cell \u001b[0;32mIn[3], line 7\u001b[0m\n\u001b[1;32m 5\u001b[0m trader \u001b[38;5;241m=\u001b[39m StockTrader(alpaca_api_key, alpaca_secret_key)\n\u001b[1;32m 6\u001b[0m \u001b[38;5;66;03m# To backtest the model\u001b[39;00m\n\u001b[0;32m----> 7\u001b[0m \u001b[43mtrader\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mAAPL\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtest_mode\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m)\u001b[49m\n\u001b[1;32m 8\u001b[0m \u001b[38;5;66;03m# To predict and trade on current data\u001b[39;00m\n\u001b[1;32m 9\u001b[0m trader\u001b[38;5;241m.\u001b[39mrun(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mAAPL\u001b[39m\u001b[38;5;124m'\u001b[39m, test_mode\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m)\n",
|
174
|
+
"Cell \u001b[0;32mIn[2], line 142\u001b[0m, in \u001b[0;36mStockTrader.run\u001b[0;34m(self, symbol, test_mode)\u001b[0m\n\u001b[1;32m 139\u001b[0m end_date \u001b[38;5;241m=\u001b[39m datetime\u001b[38;5;241m.\u001b[39mnow() \u001b[38;5;241m-\u001b[39m timedelta(days\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1\u001b[39m)\n\u001b[1;32m 141\u001b[0m \u001b[38;5;66;03m# Train the model\u001b[39;00m\n\u001b[0;32m--> 142\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtrain_model\u001b[49m\u001b[43m(\u001b[49m\u001b[43msymbol\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstart_date\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mend_date\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 144\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtest_mode:\n\u001b[1;32m 145\u001b[0m \u001b[38;5;66;03m# Predict and trade\u001b[39;00m\n\u001b[1;32m 146\u001b[0m expected_return \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mpredict(symbol)\n",
|
175
|
+
"Cell \u001b[0;32mIn[2], line 41\u001b[0m, in \u001b[0;36mStockTrader.train_model\u001b[0;34m(self, symbol, start_date, end_date)\u001b[0m\n\u001b[1;32m 39\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mtrain_model\u001b[39m(\u001b[38;5;28mself\u001b[39m, symbol, start_date, end_date):\n\u001b[1;32m 40\u001b[0m \u001b[38;5;66;03m# Fetch and prepare data\u001b[39;00m\n\u001b[0;32m---> 41\u001b[0m data \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfetch_historical_data\u001b[49m\u001b[43m(\u001b[49m\u001b[43msymbol\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstart_date\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mend_date\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 42\u001b[0m features \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprepare_features(data)\n\u001b[1;32m 43\u001b[0m target \u001b[38;5;241m=\u001b[39m data[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mclose\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;241m.\u001b[39mshift(\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m)\u001b[38;5;241m.\u001b[39mdropna()\n",
|
176
|
+
"Cell \u001b[0;32mIn[2], line 18\u001b[0m, in \u001b[0;36mStockTrader.fetch_historical_data\u001b[0;34m(self, symbol, start_date, end_date)\u001b[0m\n\u001b[1;32m 16\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mfetch_historical_data\u001b[39m(\u001b[38;5;28mself\u001b[39m, symbol, start_date, end_date):\n\u001b[1;32m 17\u001b[0m \u001b[38;5;66;03m# Fetch historical daily bars\u001b[39;00m\n\u001b[0;32m---> 18\u001b[0m bars \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mapi\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_bars\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 19\u001b[0m \u001b[43m \u001b[49m\u001b[43msymbol\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 20\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m1Day\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 21\u001b[0m \u001b[43m \u001b[49m\u001b[43mstart\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstart_date\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43misoformat\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 22\u001b[0m \u001b[43m \u001b[49m\u001b[43mend\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mend_date\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43misoformat\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 23\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241m.\u001b[39mdf\n\u001b[1;32m 24\u001b[0m bars \u001b[38;5;241m=\u001b[39m bars[bars[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124msymbol\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m==\u001b[39m symbol]\n\u001b[1;32m 25\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m bars\n",
|
177
|
+
"File \u001b[0;32m~/anaconda3/envs/spacr/lib/python3.9/site-packages/alpaca_trade_api/rest.py:735\u001b[0m, in \u001b[0;36mREST.get_bars\u001b[0;34m(self, symbol, timeframe, start, end, adjustment, limit, feed, asof, sort)\u001b[0m\n\u001b[1;32m 724\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mget_bars\u001b[39m(\u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 725\u001b[0m symbol: Union[\u001b[38;5;28mstr\u001b[39m, List[\u001b[38;5;28mstr\u001b[39m]],\n\u001b[1;32m 726\u001b[0m timeframe: TimeFrame,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 733\u001b[0m sort: Optional[Sort] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 734\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m BarsV2:\n\u001b[0;32m--> 735\u001b[0m bars \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mlist\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_bars_iter\u001b[49m\u001b[43m(\u001b[49m\u001b[43msymbol\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 736\u001b[0m \u001b[43m \u001b[49m\u001b[43mtimeframe\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 737\u001b[0m \u001b[43m \u001b[49m\u001b[43mstart\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 738\u001b[0m \u001b[43m \u001b[49m\u001b[43mend\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 739\u001b[0m \u001b[43m \u001b[49m\u001b[43madjustment\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 740\u001b[0m \u001b[43m \u001b[49m\u001b[43mlimit\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 741\u001b[0m \u001b[43m \u001b[49m\u001b[43mfeed\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mfeed\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 742\u001b[0m \u001b[43m \u001b[49m\u001b[43masof\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43masof\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 743\u001b[0m \u001b[43m \u001b[49m\u001b[43msort\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43msort\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 744\u001b[0m \u001b[43m \u001b[49m\u001b[43mraw\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 745\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m BarsV2(bars)\n",
|
178
|
+
"File \u001b[0;32m~/anaconda3/envs/spacr/lib/python3.9/site-packages/alpaca_trade_api/rest.py:718\u001b[0m, in \u001b[0;36mREST.get_bars_iter\u001b[0;34m(self, symbol, timeframe, start, end, adjustment, limit, feed, asof, sort, raw)\u001b[0m\n\u001b[1;32m 697\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mget_bars_iter\u001b[39m(\u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 698\u001b[0m symbol: Union[\u001b[38;5;28mstr\u001b[39m, List[\u001b[38;5;28mstr\u001b[39m]],\n\u001b[1;32m 699\u001b[0m timeframe: TimeFrame,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 706\u001b[0m sort: Optional[Sort] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 707\u001b[0m raw\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m BarIterator:\n\u001b[1;32m 708\u001b[0m bars \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_data_get(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mbars\u001b[39m\u001b[38;5;124m'\u001b[39m, symbol,\n\u001b[1;32m 709\u001b[0m timeframe\u001b[38;5;241m=\u001b[39mtimeframe,\n\u001b[1;32m 710\u001b[0m adjustment\u001b[38;5;241m=\u001b[39madjustment,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 716\u001b[0m sort\u001b[38;5;241m=\u001b[39msort,\n\u001b[1;32m 717\u001b[0m )\n\u001b[0;32m--> 718\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m bar \u001b[38;5;129;01min\u001b[39;00m bars:\n\u001b[1;32m 719\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m raw:\n\u001b[1;32m 720\u001b[0m \u001b[38;5;28;01myield\u001b[39;00m bar\n",
|
179
|
+
"File \u001b[0;32m~/anaconda3/envs/spacr/lib/python3.9/site-packages/alpaca_trade_api/rest.py:594\u001b[0m, in \u001b[0;36mREST._data_get\u001b[0;34m(self, endpoint, symbol_or_symbols, api_version, endpoint_base, resp_grouped_by_symbol, page_limit, feed, asof, loc, **kwargs)\u001b[0m\n\u001b[1;32m 592\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m endpoint:\n\u001b[1;32m 593\u001b[0m path \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m/\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mendpoint\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\n\u001b[0;32m--> 594\u001b[0m resp \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdata_get\u001b[49m\u001b[43m(\u001b[49m\u001b[43mpath\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdata\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdata\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfeed\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mfeed\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 595\u001b[0m \u001b[43m \u001b[49m\u001b[43mapi_version\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mapi_version\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 596\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m resp_grouped_by_symbol:\n\u001b[1;32m 597\u001b[0m k \u001b[38;5;241m=\u001b[39m endpoint \u001b[38;5;129;01mor\u001b[39;00m endpoint_base\n",
|
180
|
+
"File \u001b[0;32m~/anaconda3/envs/spacr/lib/python3.9/site-packages/alpaca_trade_api/rest.py:274\u001b[0m, in \u001b[0;36mREST.data_get\u001b[0;34m(self, path, data, feed, api_version)\u001b[0m\n\u001b[1;32m 272\u001b[0m data \u001b[38;5;241m=\u001b[39m data \u001b[38;5;129;01mor\u001b[39;00m {}\n\u001b[1;32m 273\u001b[0m data[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mfeed\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m feed\n\u001b[0;32m--> 274\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 275\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mGET\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpath\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdata\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mbase_url\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mbase_url\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mapi_version\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mapi_version\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 276\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
|
181
|
+
"File \u001b[0;32m~/anaconda3/envs/spacr/lib/python3.9/site-packages/alpaca_trade_api/rest.py:222\u001b[0m, in \u001b[0;36mREST._request\u001b[0;34m(self, method, path, data, base_url, api_version)\u001b[0m\n\u001b[1;32m 220\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m retry \u001b[38;5;241m>\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[1;32m 221\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 222\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_one_request\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmethod\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mopts\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mretry\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 223\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m RetryException:\n\u001b[1;32m 224\u001b[0m retry_wait \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_retry_wait\n",
|
182
|
+
"File \u001b[0;32m~/anaconda3/envs/spacr/lib/python3.9/site-packages/alpaca_trade_api/rest.py:248\u001b[0m, in \u001b[0;36mREST._one_request\u001b[0;34m(self, method, url, opts, retry)\u001b[0m\n\u001b[1;32m 246\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m resp\u001b[38;5;241m.\u001b[39mstatus_code \u001b[38;5;129;01min\u001b[39;00m retry_codes \u001b[38;5;129;01mand\u001b[39;00m retry \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[1;32m 247\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m RetryException()\n\u001b[0;32m--> 248\u001b[0m \u001b[43mraise_api_error\u001b[49m\u001b[43m(\u001b[49m\u001b[43mresp\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mhttp_error\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 249\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m resp\u001b[38;5;241m.\u001b[39mtext \u001b[38;5;241m!=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m'\u001b[39m:\n\u001b[1;32m 250\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m resp\u001b[38;5;241m.\u001b[39mjson()\n",
|
183
|
+
"File \u001b[0;32m~/anaconda3/envs/spacr/lib/python3.9/site-packages/alpaca_trade_api/rest.py:83\u001b[0m, in \u001b[0;36mraise_api_error\u001b[0;34m(resp, http_error)\u001b[0m\n\u001b[1;32m 81\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m http_error \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 82\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmessage\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;129;01min\u001b[39;00m error:\n\u001b[0;32m---> 83\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m APIError(error, http_error) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 84\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m http_error \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n",
|
184
|
+
"\u001b[0;31mAPIError\u001b[0m: Invalid format for parameter start: error parsing '2022-12-03T13:32:03.137224' as RFC3339 or 2006-01-02 time: parsing time \"2022-12-03T13:32:03.137224\": extra text: \"T13:32:03.137224\""
|
185
|
+
]
|
186
|
+
}
|
187
|
+
],
|
188
|
+
"source": [
|
189
|
+
"if __name__ == '__main__':\n",
|
190
|
+
" alpaca_api_key = 'PKJATKYKR4NWCYALKL58'\n",
|
191
|
+
" alpaca_secret_key = '8aFRppO0HdabLAO8b05ZImUwSd0bEmv4hqpU0Hqs'\n",
|
192
|
+
"\n",
|
193
|
+
" trader = StockTrader(alpaca_api_key, alpaca_secret_key)\n",
|
194
|
+
" # To backtest the model\n",
|
195
|
+
" trader.run('AAPL', test_mode=True)\n",
|
196
|
+
" # To predict and trade on current data\n",
|
197
|
+
" trader.run('AAPL', test_mode=False)\n"
|
198
|
+
]
|
199
|
+
},
|
200
|
+
{
|
201
|
+
"cell_type": "code",
|
202
|
+
"execution_count": null,
|
203
|
+
"id": "77a1c83f",
|
204
|
+
"metadata": {},
|
205
|
+
"outputs": [],
|
206
|
+
"source": []
|
207
|
+
}
|
208
|
+
],
|
209
|
+
"metadata": {
|
210
|
+
"kernelspec": {
|
211
|
+
"display_name": "spacr",
|
212
|
+
"language": "python",
|
213
|
+
"name": "spacr"
|
214
|
+
},
|
215
|
+
"language_info": {
|
216
|
+
"codemirror_mode": {
|
217
|
+
"name": "ipython",
|
218
|
+
"version": 3
|
219
|
+
},
|
220
|
+
"file_extension": ".py",
|
221
|
+
"mimetype": "text/x-python",
|
222
|
+
"name": "python",
|
223
|
+
"nbconvert_exporter": "python",
|
224
|
+
"pygments_lexer": "ipython3",
|
225
|
+
"version": "3.9.19"
|
226
|
+
}
|
227
|
+
},
|
228
|
+
"nbformat": 4,
|
229
|
+
"nbformat_minor": 5
|
230
|
+
}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
Key,Value
|
2
|
+
src,D:\20240920-IRE1a-inhibitors_20240920_132333\plate1\test\merged
|
3
|
+
verbose,False
|
4
|
+
experiment,exp
|
5
|
+
test_mode,False
|
6
|
+
test_nr,10
|
7
|
+
channels,"[0, 1, 2, 3]"
|
8
|
+
save_measurements,True
|
9
|
+
radial_dist,True
|
10
|
+
calculate_correlation,True
|
11
|
+
manders_thresholds,"[15, 85, 95]"
|
12
|
+
homogeneity,True
|
13
|
+
homogeneity_distances,"[8, 16, 32]"
|
14
|
+
save_arrays,False
|
15
|
+
save_png,True
|
16
|
+
use_bounding_box,False
|
17
|
+
png_size,"[[224, 224]]"
|
18
|
+
png_dims,"[0, 1, 2]"
|
19
|
+
normalize,False
|
20
|
+
normalize_by,png
|
21
|
+
crop_mode,cell
|
22
|
+
dialate_pngs,False
|
23
|
+
dialate_png_ratios,"[1, 10]"
|
24
|
+
timelapse,False
|
25
|
+
timelapse_objects,cell
|
26
|
+
plot,False
|
27
|
+
n_jobs,6
|
28
|
+
cell_mask_dim,4
|
29
|
+
nucleus_mask_dim,5
|
30
|
+
pathogen_mask_dim,6
|
31
|
+
cytoplasm,True
|
32
|
+
uninfected,False
|
33
|
+
cell_min_size,8000
|
34
|
+
nucleus_min_size,2000
|
35
|
+
pathogen_min_size,500
|
36
|
+
cytoplasm_min_size,0
|
37
|
+
merge_edge_pathogen_cells,True
|
38
|
+
Paths,
|
39
|
+
General,
|
40
|
+
Cell,
|
41
|
+
Nucleus,
|
42
|
+
Pathogen,
|
43
|
+
Measurements,
|
44
|
+
Object Image,
|
45
|
+
Plot,
|
46
|
+
Test,
|
47
|
+
Timelapse,
|
48
|
+
Advanced,
|
@@ -1493,27 +1493,32 @@ def _calculate_similarity(df, features, col_to_compare, val1, val2):
|
|
1493
1493
|
# Add a small value to the diagonal elements for regularization
|
1494
1494
|
epsilon = 1e-5
|
1495
1495
|
inv_cov_matrix = np.linalg.inv(cov_matrix + np.eye(cov_matrix.shape[0]) * epsilon)
|
1496
|
-
|
1496
|
+
|
1497
1497
|
# Calculate similarity scores
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1498
|
+
def safe_similarity(func, row, control):
|
1499
|
+
try:
|
1500
|
+
return func(row, control)
|
1501
|
+
except Exception:
|
1502
|
+
return np.nan
|
1503
|
+
|
1504
|
+
# Calculate similarity scores
|
1505
|
+
try:
|
1506
|
+
df['similarity_to_pos_euclidean'] = df[features].apply(lambda row: safe_similarity(euclidean, row, pos_control), axis=1)
|
1507
|
+
df['similarity_to_neg_euclidean'] = df[features].apply(lambda row: safe_similarity(euclidean, row, neg_control), axis=1)
|
1508
|
+
df['similarity_to_pos_cosine'] = df[features].apply(lambda row: safe_similarity(cosine, row, pos_control), axis=1)
|
1509
|
+
df['similarity_to_neg_cosine'] = df[features].apply(lambda row: safe_similarity(cosine, row, neg_control), axis=1)
|
1510
|
+
df['similarity_to_pos_mahalanobis'] = df[features].apply(lambda row: safe_similarity(mahalanobis, row, pos_control, inv_cov_matrix), axis=1)
|
1511
|
+
df['similarity_to_neg_mahalanobis'] = df[features].apply(lambda row: safe_similarity(mahalanobis, row, neg_control, inv_cov_matrix), axis=1)
|
1512
|
+
df['similarity_to_pos_manhattan'] = df[features].apply(lambda row: safe_similarity(cityblock, row, pos_control), axis=1)
|
1513
|
+
df['similarity_to_neg_manhattan'] = df[features].apply(lambda row: safe_similarity(cityblock, row, neg_control), axis=1)
|
1514
|
+
df['similarity_to_pos_minkowski'] = df[features].apply(lambda row: safe_similarity(minkowski, row, pos_control, p=3), axis=1)
|
1515
|
+
df['similarity_to_neg_minkowski'] = df[features].apply(lambda row: safe_similarity(minkowski, row, neg_control, p=3), axis=1)
|
1516
|
+
df['similarity_to_pos_chebyshev'] = df[features].apply(lambda row: safe_similarity(chebyshev, row, pos_control), axis=1)
|
1517
|
+
df['similarity_to_neg_chebyshev'] = df[features].apply(lambda row: safe_similarity(chebyshev, row, neg_control), axis=1)
|
1518
|
+
df['similarity_to_pos_braycurtis'] = df[features].apply(lambda row: safe_similarity(braycurtis, row, pos_control), axis=1)
|
1519
|
+
df['similarity_to_neg_braycurtis'] = df[features].apply(lambda row: safe_similarity(braycurtis, row, neg_control), axis=1)
|
1520
|
+
except Exception as e:
|
1521
|
+
print(f"Error calculating similarity scores: {e}")
|
1517
1522
|
return df
|
1518
1523
|
|
1519
1524
|
def interperate_vision_model(settings={}):
|