Skip to content
This repository was archived by the owner on Dec 1, 2025. It is now read-only.

add size getters to the AICSImage class#38

Merged
toloudis merged 2 commits into
masterfrom
feature/dimension-getters
Oct 28, 2019
Merged

add size getters to the AICSImage class#38
toloudis merged 2 commits into
masterfrom
feature/dimension-getters

Conversation

@toloudis

Copy link
Copy Markdown
Collaborator

I added size getters to AICSImage. TODO eventually one day we should get the dimensions initialized from metadata rather than having to load the entire file. :)

@codecov-io

codecov-io commented Oct 26, 2019

Copy link
Copy Markdown

Codecov Report

Merging #38 into master will increase coverage by 0.18%.
The diff coverage is 94%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #38      +/-   ##
=========================================
+ Coverage   87.61%   87.8%   +0.18%     
=========================================
  Files          27      27              
  Lines        1066    1099      +33     
=========================================
+ Hits          934     965      +31     
- Misses        132     134       +2
Impacted Files Coverage Δ
aicsimageio/tests/test_aics_image.py 100% <100%> (ø) ⬆️
aicsimageio/aics_image.py 95.31% <88.88%> (-2.47%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b22b59d...85a486c. Read the comment docs.

Comment thread aicsimageio/aics_image.py
return_dims=self.dims)
return self._data

def size(self, dims: str = "STCZYX"):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really smart implementation :)

Comment thread README.md
Comment on lines +42 to +53
# Image dimension sizes can be obtained via properties:
im.size_z # returns the size of the Z dimension. X,Y,Z,C,T, and S supported.

# Image dimensions can also be obtained as a tuple in two ways:
im.size("ZYX") # returns a tuple containing the Z, Y, and X sizes only
im.get_image_data(out_orientation="ZYX").shape # returns same as above

# Image metadata is stored in `metadata` attribute
im.metadata # returns whichever metadata parser best suites the file format
im.metadata # returns whichever metadata parser best suits the file format

# Subsets or transposes of the image data can be requested:
im.get_image_data(out_orientation="ZYX") # returns a 3d data block containing only the ZYX dimensions

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this to the README!

@heeler heeler left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work.
I'm thinking now that my comment might be better for readers like pylibczi as opposed to in the aicsimage parent class. I forgot that we're locked to 6 dims when I wrote the comment.

Comment thread aicsimageio/aics_image.py
Comment on lines +146 to +198
@property
def size_x(self):
"""
Returns
-------
Returns the x size
"""
return self.size("X")[0]

@property
def size_y(self):
"""
Returns
-------
Returns the y size
"""
return self.size("Y")[0]

@property
def size_z(self):
"""
Returns
-------
Returns the z size
"""
return self.size("Z")[0]

@property
def size_c(self):
"""
Returns
-------
Returns the c size
"""
return self.size("C")[0]

@property
def size_t(self):
"""
Returns
-------
Returns the t size
"""
return self.size("T")[0]

@property
def size_s(self):
"""
Returns
-------
Returns the s size
"""
return self.size("S")[0]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the functionality but might I suggest

    def __init__(self):
        self.pattern = re.compile(r'size_([A-z])$')

    def __getattr__(self, attr_name):
        match = re.match(self.pattern, attr_name)
        if match:
            return self.size(match.group(1))[0]
        else:
            raise AttributeError(f'No such attribute: {attr_name}')

    def size(self, dims: str = "STCZYX"):
        upper_dims = dims.upper()
        if len(dims) != len(set(dims).intersection(set(self.dims))):
            print("Dimension not present in data!")
            return tuple([0])
        return tuple([self.data.shape[self.dims.index(dim)] for dim in upper_dims])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of thing is popular in ruby but I'd not sure how it's thought of in python

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will definitely take your cue about making sure to convert to upper, and assert that the requested dims are valid. But I'm not sure I understand the ruby comment. What is the thing that's popular in ruby?

@toloudis toloudis merged commit 78a5898 into master Oct 28, 2019
@toloudis toloudis deleted the feature/dimension-getters branch October 28, 2019 23:19
evamaxfield pushed a commit that referenced this pull request Oct 29, 2019
* add size getters to the AICSImage class

* add some extra validation to the size() function, and a couple extra tests
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants