Skip to content

Commit f9f1602

Browse files
authored
Merge pull request #7 from DavidStirling/compat-4-2
Update 4.2.x branch
2 parents 0c8bc28 + acd0e70 commit f9f1602

File tree

30 files changed

+978
-297
lines changed

30 files changed

+978
-297
lines changed

.github/workflows/test.yml

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,67 @@
1+
name: run-core-tests
12
jobs:
2-
build:
3-
runs-on: ubuntu-latest
3+
test:
4+
name: Install and test Core
45
strategy:
56
max-parallel: 4
67
matrix:
7-
python-version: [3.8]
8+
os: [macos-11]
9+
python-version: [ 3.8, 3.9 ]
10+
fail-fast: false
11+
runs-on: ${{ matrix.os }}
12+
if: github.event.pull_request.draft == false
13+
env:
14+
CP_MYSQL_TEST_HOST: "127.0.0.1"
15+
CP_MYSQL_TEST_DB: "cellprofiler_test"
16+
CP_MYSQL_TEST_USER: "root"
17+
CP_MYSQL_TEST_PASSWORD: "None"
818
steps:
9-
- uses: actions/checkout@v1
10-
- name: Setup Python ${{ matrix.python-version }}
11-
uses: actions/setup-python@v1
12-
with:
13-
python-version: ${{ matrix.python-version }}
14-
- name: Installation
15-
run:
16-
|
17-
python -m pip install --upgrade pip
18-
pip install numpy
19-
pip install -e .[test]
20-
- name: Test
21-
run: pytest
22-
name: cellprofiler-core
23-
on: [push]
19+
- uses: actions/checkout@v2
20+
- name: Setup Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v1
22+
with:
23+
architecture: x64
24+
python-version: ${{ matrix.python-version }}
25+
- name: Get pip cache dir
26+
id: pip-cache-dir
27+
run: |
28+
echo "::set-output name=dir::$(pip cache dir)"
29+
- name: Cache pip
30+
uses: actions/cache@v3
31+
id: cache-pip
32+
with:
33+
path: ${{ steps.pip-cache-dir.outputs.dir }}
34+
key: ${{ runner.os }}-${{ env.pythonLocation }}-${{ hashFiles('**/setup.py') }}
35+
- name: Install java
36+
uses: actions/setup-java@v1
37+
with:
38+
java-version: '14.0.1' # The JDK version to make available on the path.
39+
java-package: jdk
40+
architecture: x64
41+
- name: Mac - Install and setup mysql
42+
if: startsWith(matrix.os, 'macos')
43+
env:
44+
LC_ALL: "en_US.UTF-8"
45+
run: |
46+
brew install mysql
47+
mysql.server start
48+
mysql --host=$CP_MYSQL_TEST_HOST --user=$CP_MYSQL_TEST_USER --execute="CREATE DATABASE $CP_MYSQL_TEST_DB;" --skip-password
49+
- name: Installation
50+
run:
51+
|
52+
pip install pyinstaller
53+
pip install --upgrade pip setuptools wheel
54+
pip install numpy>=1.20.1
55+
# git clone https://github.com/CellProfiler/CellProfiler.git ~/cellprofiler
56+
pip install -e .[test]
57+
# pip install -e ~/cellprofiler
58+
- name: Test
59+
run: pytest -k 'not test_load_objects and not test_load_single_object'
60+
on:
61+
pull_request:
62+
types: [opened, reopened, synchronize, ready_for_review, review_requested]
63+
push:
64+
branches:
65+
- 'master'
66+
workflow_dispatch:
67+

cellprofiler_core/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "4.2.1"
1+
__version__ = "4.2.6"

cellprofiler_core/analysis/_runner.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from ..preferences import get_plugin_directory
2828
from ..preferences import get_conserve_memory
2929
from ..preferences import get_temporary_directory
30+
from ..preferences import get_always_continue
3031
from ..preferences import preferences_as_dict
3132
from ..utilities.analysis import close_all_on_exec, start_daemon_thread
3233
from ..utilities.analysis import find_analysis_worker_source
@@ -664,6 +665,8 @@ def start_workers(cls, num=None):
664665
get_plugin_directory(),
665666
"--conserve-memory",
666667
str(get_conserve_memory()),
668+
"--always-continue",
669+
str(get_always_continue())
667670
]
668671
# stdin for the subprocesses serves as a deadman's switch. When
669672
# closed, the subprocess exits.

cellprofiler_core/constants/measurement.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
IMAGE = "Image"
66
EXPERIMENT = "Experiment"
77
RELATIONSHIP = "Relationship"
8+
DB_TEMP = "ExportToDb"
89
NEIGHBORS = "Neighbors"
910
OBJECT = "Object"
1011
disallowed_object_names = [IMAGE, EXPERIMENT, RELATIONSHIP]
@@ -33,6 +34,7 @@
3334
OBJECT_NUMBER = "ObjectNumber"
3435
GROUP_NUMBER = "Group_Number" # 1-based group index
3536
GROUP_INDEX = "Group_Index" # 1-based index within group
37+
GROUP_LENGTH = "Group_Length"
3638
R_FIRST_IMAGE_NUMBER = IMAGE_NUMBER + "_" + "First"
3739
R_FIRST_OBJECT_NUMBER = OBJECT_NUMBER + "_" + "First"
3840
R_SECOND_IMAGE_NUMBER = IMAGE_NUMBER + "_" + "Second"

cellprofiler_core/constants/pipeline.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
IMAGE_NUMBER = "ImageNumber"
44
GROUP_NUMBER = "Group_Number"
55
GROUP_INDEX = "Group_Index"
6+
GROUP_LENGTH = "Group_Length"
67
CURRENT = "Current"
78
NUMBER_OF_IMAGE_SETS = "NumberOfImageSets"
89
NUMBER_OF_MODULES = "NumberOfModules"

cellprofiler_core/image/abstract_image/file/_file_image.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def __set_image(self):
301301
c=self.channel,
302302
series=self.series,
303303
index=self.index,
304-
rescale=self.rescale,
304+
rescale=self.rescale if isinstance(self.rescale, bool) else False,
305305
wants_max_intensity=True,
306306
channel_names=channel_names,
307307
z=self.z_index,
@@ -325,7 +325,7 @@ def __set_image(self):
325325
c=channel,
326326
series=series,
327327
index=index,
328-
rescale=self.rescale,
328+
rescale=self.rescale if isinstance(self.rescale, bool) else False,
329329
wants_max_intensity=True,
330330
channel_names=channel_names,
331331
z=self.z_index,
@@ -341,6 +341,7 @@ def __set_image(self):
341341
path_name=self.get_pathname(),
342342
file_name=self.get_filename(),
343343
scale=self.scale,
344+
channelstack=img.ndim == 3 and img.shape[-1]>3
344345
)
345346
if img.ndim == 3 and len(channel_names) == img.shape[2]:
346347
self.__image.channel_names = list(channel_names)

cellprofiler_core/image/abstract_image/file/url/_color_image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ def provide_image(self, image_set):
2626
image = URLImage.provide_image(self, image_set)
2727

2828
if image.pixel_data.ndim == image.dimensions:
29-
image.pixel_data = skimage.color.gray2rgb(image.pixel_data, alpha=False)
29+
image.pixel_data = skimage.color.gray2rgb(image.pixel_data)
3030

3131
return image

cellprofiler_core/image/abstract_image/file/url/_objects_image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ def get_indexes(self, url):
8686

8787
def get_image_volume(self):
8888
imdata = self.__data
89-
planes = [] # newplanes = numpy.zeros_like(test2)
89+
planes = []
9090
for planeid in range(imdata.shape[0]):
91-
planes.append(convert_image_to_objects(imdata[planeid]).astype(numpy.int32))
91+
planes.append(imdata[planeid].astype(numpy.int32))
9292
imdata = numpy.stack(planes)
9393

9494
image = Image(

cellprofiler_core/measurement/_measurements.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333
from ..constants.measurement import C_PATH_NAME
3434
from ..constants.measurement import C_SERIES
3535
from ..constants.measurement import C_URL
36+
from ..constants.measurement import DB_TEMP
3637
from ..constants.measurement import EXPERIMENT
3738
from ..constants.measurement import GROUP_INDEX
3839
from ..constants.measurement import GROUP_NUMBER
40+
from ..constants.measurement import GROUP_LENGTH
3941
from ..constants.measurement import IMAGE
4042
from ..constants.measurement import IMAGE_NUMBER
4143
from ..constants.measurement import K_CASE_SENSITIVE
@@ -364,6 +366,15 @@ def set_group_index(self, group_index):
364366

365367
group_index = property(get_group_index, set_group_index)
366368

369+
def get_group_length(self):
370+
"""The group length of the current image group"""
371+
return self.get_current_image_measurement(GROUP_LENGTH)
372+
373+
def set_group_length(self, group_length):
374+
self.add_image_measurement(GROUP_LENGTH, group_length)
375+
376+
group_length = property(get_group_length, set_group_length)
377+
367378
def get_groupings(self, features):
368379
"""Return groupings of image sets based on feature values
369380
@@ -741,7 +752,7 @@ def clear(self):
741752
def get_object_names(self):
742753
"""The list of object names (including Image) that have measurements
743754
"""
744-
return [x for x in self.hdf5_dict.top_level_names() if x != RELATIONSHIP]
755+
return [x for x in self.hdf5_dict.top_level_names() if x not in (DB_TEMP, RELATIONSHIP)]
745756

746757
object_names = property(get_object_names)
747758

@@ -1295,6 +1306,7 @@ def write_image_sets(self, fd_or_file, start=None, stop=None):
12951306
to_save = [
12961307
GROUP_NUMBER,
12971308
GROUP_INDEX,
1309+
GROUP_LENGTH
12981310
]
12991311
to_save_prefixes = [
13001312
C_URL,
@@ -1733,11 +1745,20 @@ def set_grouping_tags(self, grouping_tags):
17331745
data = json.dumps(grouping_tags)
17341746
self.add_experiment_measurement(M_GROUPING_TAGS, data)
17351747

1736-
def get_grouping_tags(self):
1748+
def get_grouping_tags_or_metadata(self):
17371749
"""Get the metadata tags that were used to group the image set
17381750
17391751
"""
17401752
if not self.has_feature(EXPERIMENT, M_GROUPING_TAGS,):
17411753
return self.get_metadata_tags()
17421754

17431755
return json.loads(self.get_experiment_measurement(M_GROUPING_TAGS))
1756+
1757+
def get_grouping_tags_only(self):
1758+
"""Get the metadata tags that were used to group the image set,
1759+
and only those, not metadata instead
1760+
"""
1761+
if not self.has_feature(EXPERIMENT, M_GROUPING_TAGS,):
1762+
return []
1763+
1764+
return json.loads(self.get_experiment_measurement(M_GROUPING_TAGS))

cellprofiler_core/module/_module.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import abc
2+
import logging
23
import sys
34
import uuid
45

@@ -106,12 +107,15 @@ def from_dict(self, settings: list, attributes: dict):
106107
self.wants_pause = attributes["wants_pause"]
107108
self.svn_version = attributes["svn_version"]
108109
self.enabled = attributes["enabled"]
109-
self.variable_revision_number = attributes["variable_revision_number"]
110110
self.module_path = attributes["module_path"]
111111
self.module_name = attributes["module_name"]
112112
setting_values = [setting["value"] for setting in settings]
113+
if attributes["variable_revision_number"] > self.variable_revision_number:
114+
logging.warning(f"Loaded module '{self.module_name}' is from a newer version of CellProfiler - "
115+
f"v{attributes['variable_revision_number']}, current version is "
116+
f"v{self.variable_revision_number}. Settings may load incorrectly.")
113117
self.set_settings_from_values(
114-
setting_values, self.variable_revision_number, self.module_path
118+
setting_values, attributes['variable_revision_number'], self.module_path
115119
)
116120

117121
@abc.abstractmethod

0 commit comments

Comments
 (0)