From 3da7b54bd84ba3256ee0527841f9afb3ce39fcb6 Mon Sep 17 00:00:00 2001 From: Miles Date: Tue, 17 Dec 2024 18:21:50 +0900 Subject: [PATCH 1/2] redo pre-commit --- .gitignore | 1 + docker-compose.dev.yml | 1 + studio/app/common/dataclass/histogram.py | 10 +++---- studio/app/common/dataclass/line.py | 10 +++---- studio/app/common/dataclass/pie.py | 20 +++++--------- studio/app/common/dataclass/polar.py | 26 ++++++++++++------- .../wrappers/caiman/conda/caiman.yaml | 1 + .../caiman/conda/caiman_with_expdb.yaml | 3 ++- .../optinist/wrappers/expdb/conda/expdb.yaml | 1 + studio/config/docker/Dockerfile.dev | 18 ++++++++++++- 10 files changed, 55 insertions(+), 36 deletions(-) diff --git a/.gitignore b/.gitignore index 9ba7839d1..7effb7031 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ tensorflow-2.4.1-py3-none-any.whl !*.env.example process.lock +.conda/ diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index afcbdafd4..4ba79fc6a 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -27,6 +27,7 @@ services: working_dir: /app volumes: - .:/app + - ../optinist-docker-volumes/.conda/pkgs:/app/.conda/pkgs # optinist data outputs directories - ../optinist-docker-volumes/.snakemake/:/app/.snakemake diff --git a/studio/app/common/dataclass/histogram.py b/studio/app/common/dataclass/histogram.py index 0750c5f90..7d285e3f5 100644 --- a/studio/app/common/dataclass/histogram.py +++ b/studio/app/common/dataclass/histogram.py @@ -1,9 +1,8 @@ from typing import Optional +import matplotlib.pyplot as plt import numpy as np import pandas as pd -import plotly.express as px -import plotly.io as pio from studio.app.common.core.utils.filepath_creater import join_filepath from studio.app.common.core.utils.json_writer import JsonWriter @@ -38,8 +37,9 @@ def output_path(self) -> OutputPath: return OutputPath(path=self.json_path, type=OutputType.HISTOGRAM) def save_plot(self, output_dir): - fig = px.histogram(x=self.data[0], nbins=20) + plt.figure() + plt.hist(self.data[0], bins=20) plot_file = join_filepath([output_dir, f"{self.file_name}.png"]) - pio.write_image(fig, plot_file) - + plt.savefig(plot_file) + plt.close() save_thumbnail(plot_file) diff --git a/studio/app/common/dataclass/line.py b/studio/app/common/dataclass/line.py index cb90990ae..f72fb5c8b 100644 --- a/studio/app/common/dataclass/line.py +++ b/studio/app/common/dataclass/line.py @@ -1,8 +1,7 @@ from typing import Optional +import matplotlib.pyplot as plt import pandas as pd -import plotly.express as px -import plotly.io as pio from studio.app.common.core.utils.filepath_creater import join_filepath from studio.app.common.core.utils.json_writer import JsonWriter @@ -32,8 +31,9 @@ def output_path(self) -> OutputPath: def save_plot(self, output_dir): for i in range(len(self.data)): - fig = px.line(y=self.data[i], x=self.columns) + plt.figure() + plt.plot(self.columns, self.data[i]) plot_file = join_filepath([output_dir, f"{self.file_name}_{i}.png"]) - pio.write_image(fig, plot_file) - + plt.savefig(plot_file) + plt.close() save_thumbnail(plot_file) diff --git a/studio/app/common/dataclass/pie.py b/studio/app/common/dataclass/pie.py index 28184cee3..de1c3cde4 100644 --- a/studio/app/common/dataclass/pie.py +++ b/studio/app/common/dataclass/pie.py @@ -1,9 +1,8 @@ from typing import Optional +import matplotlib.pyplot as plt import numpy as np import pandas as pd -import plotly.graph_objects as go -import plotly.io as pio from studio.app.common.core.utils.filepath_creater import join_filepath from studio.app.common.core.utils.json_writer import JsonWriter @@ -39,17 +38,10 @@ def output_path(self) -> OutputPath: return OutputPath(path=self.json_path, type=OutputType.PIE) def save_plot(self, output_dir): - fig = go.Figure( - data=[ - go.Pie( - labels=self.columns, - values=self.data[0], - sort=False, - direction="clockwise", - ) - ] - ) + plt.figure(figsize=(8, 8)) # Optional: Adjust the figure size as needed + plt.pie(self.data[0], labels=self.columns, counterclock=False, startangle=90) + plt.axis("equal") # Equal aspect ratio ensures the pie chart is circular. plot_file = join_filepath([output_dir, f"{self.file_name}.png"]) - pio.write_image(fig, plot_file) - + plt.savefig(plot_file) + plt.close() save_thumbnail(plot_file) diff --git a/studio/app/common/dataclass/polar.py b/studio/app/common/dataclass/polar.py index bda973d23..fa430b645 100644 --- a/studio/app/common/dataclass/polar.py +++ b/studio/app/common/dataclass/polar.py @@ -1,8 +1,8 @@ from typing import Optional +import matplotlib.pyplot as plt +import numpy as np import pandas as pd -import plotly.express as px -import plotly.io as pio from studio.app.common.core.utils.filepath_creater import join_filepath from studio.app.common.core.utils.json_writer import JsonWriter @@ -33,14 +33,20 @@ def output_path(self) -> OutputPath: def save_plot(self, output_dir): for i in range(len(self.data)): - fig = px.line_polar( - r=self.data[i], - theta=self.columns, - direction="counterclockwise", - start_angle=0, - line_close=True, + # Convert theta to radians + theta = np.linspace(0, 2 * np.pi, len(self.columns)) + plt.figure() + ax = plt.subplot(111, polar=True) + ax.plot(theta, self.data[i]) + ax.set_theta_direction(-1) # Counterclockwise + ax.set_theta_offset(np.pi / 2.0) # Start angle at 0 + ax.plot( + [theta[-1], theta[0]], + [self.data[i][-1], self.data[i][0]], + linestyle="-", + linewidth=2, ) plot_file = join_filepath([output_dir, f"{self.file_name}_{i}.png"]) - pio.write_image(fig, plot_file) - + plt.savefig(plot_file) + plt.close() save_thumbnail(plot_file) diff --git a/studio/app/optinist/wrappers/caiman/conda/caiman.yaml b/studio/app/optinist/wrappers/caiman/conda/caiman.yaml index 7e49303bf..bbe919508 100644 --- a/studio/app/optinist/wrappers/caiman/conda/caiman.yaml +++ b/studio/app/optinist/wrappers/caiman/conda/caiman.yaml @@ -8,3 +8,4 @@ dependencies: - scikit-image=0.19.* - protobuf=3.20.* - caiman>=1.9.9, <=1.9.12 + - matplotlib diff --git a/studio/app/optinist/wrappers/caiman/conda/caiman_with_expdb.yaml b/studio/app/optinist/wrappers/caiman/conda/caiman_with_expdb.yaml index af841c5d7..45d373d6b 100644 --- a/studio/app/optinist/wrappers/caiman/conda/caiman_with_expdb.yaml +++ b/studio/app/optinist/wrappers/caiman/conda/caiman_with_expdb.yaml @@ -2,12 +2,13 @@ channels: - defaults - conda-forge dependencies: - - python=3.8 + - python=3.9 - cython - numpy=1.22.* - scikit-image=0.19.* - protobuf=3.20.* - caiman>=1.9.9, <=1.9.12 + - matplotlib # for expdb - gcc=12 diff --git a/studio/app/optinist/wrappers/expdb/conda/expdb.yaml b/studio/app/optinist/wrappers/expdb/conda/expdb.yaml index 06dfdcc6b..331420348 100644 --- a/studio/app/optinist/wrappers/expdb/conda/expdb.yaml +++ b/studio/app/optinist/wrappers/expdb/conda/expdb.yaml @@ -5,6 +5,7 @@ dependencies: - gcc=12 - numpy=1.23 - scipy=1.10 + - matplotlib - pip: - isx==1.0.* - pynwb==2.6.0 diff --git a/studio/config/docker/Dockerfile.dev b/studio/config/docker/Dockerfile.dev index d41117f72..3cb1b7d89 100644 --- a/studio/config/docker/Dockerfile.dev +++ b/studio/config/docker/Dockerfile.dev @@ -36,6 +36,23 @@ RUN mkdir -p /opt/miniforge && \ conda clean -y --tarballs ENV PATH $PATH:/opt/miniforge/bin +ENV CONDA_ALWAYS_COPY=1 + +# Setup conda dir +RUN mkdir -p /app/.conda/pkgs \ + && mkdir -p /app/.conda/envs \ + && chown -R optinist:www-data /app/.conda \ + && su optinist -c 'cat > /home/optinist/.condarc << EOF +pkgs_dirs: + - /app/.conda/pkgs +envs_dirs: + - /app/.conda/envs +channels: + - conda-forge + - defaults +channel_priority: flexible +EOF' + # setup cron RUN ln -snf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime && echo "Asia/Tokyo" > /etc/timezone && \ apt-get install --no-install-recommends -y cron rsyslog && \ @@ -111,4 +128,3 @@ USER optinist COPY studio/app/optinist/wrappers/caiman/run_download_model_files.sh ./ RUN bash run_download_model_files.sh && rm run_download_model_files.sh USER root - From 5a1069bc42d679eb9ed4d0f27c8c6103a4cd6a2a Mon Sep 17 00:00:00 2001 From: Miles Date: Thu, 19 Dec 2024 09:05:17 +0900 Subject: [PATCH 2/2] redo pre-commit --- studio/app/optinist/microscopes/OIRReader.py | 6 +++--- studio/app/optinist/wrappers/caiman/cnmf.py | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/studio/app/optinist/microscopes/OIRReader.py b/studio/app/optinist/microscopes/OIRReader.py index 90ec94115..36280c5ae 100644 --- a/studio/app/optinist/microscopes/OIRReader.py +++ b/studio/app/optinist/microscopes/OIRReader.py @@ -450,9 +450,9 @@ def _get_image_stacks(self) -> list: single_plane_buffer = np.ctypeslib.as_array(ctypes_buffer_ptr) # construct return value (each channel's stack) - result_channels_stacks[channel_no, serial_loops_index] = ( - single_plane_buffer - ) + result_channels_stacks[ + channel_no, serial_loops_index + ] = single_plane_buffer serial_loops_index += 1 frame_manager.release_image_body() diff --git a/studio/app/optinist/wrappers/caiman/cnmf.py b/studio/app/optinist/wrappers/caiman/cnmf.py index d511d3f28..e345867ca 100644 --- a/studio/app/optinist/wrappers/caiman/cnmf.py +++ b/studio/app/optinist/wrappers/caiman/cnmf.py @@ -154,6 +154,7 @@ def util_download_model_files(): with open(file_path, "wb") as f: f.write(response.content) + def mm_fun(A: np.ndarray, Y: np.ndarray) -> np.ndarray: """ This code is a port of the CaImAn-MATLAB function (mm_fun.m).