-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[python] Add export for MultiscaleImage
to SpatialData
#3355
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3355 +/- ##
==========================================
+ Coverage 85.66% 85.89% +0.22%
==========================================
Files 57 56 -1
Lines 6210 6166 -44
==========================================
- Hits 5320 5296 -24
+ Misses 890 870 -20
Flags with carried forward coverage won't be shown. Click here to find out more.
|
ed063d2
to
522282a
Compare
MultiscaleImage
to SpatialData
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, looks like this got merged while I was working on a review. I was about to give this code a shot, but will now do that from the main branch.
Still going to leave the other comments here as feedback
try: | ||
import xarray as xr | ||
except ImportError as err: | ||
warnings.warn("Experimental spatial exporter requires the spatialdatda package.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warnings.warn("Experimental spatial exporter requires the spatialdatda package.") | |
warnings.warn("Experimental spatial exporter requires the spatialdata package.") |
import spatialdata as sd | ||
from spatialdata.models.models import DataTree | ||
except ImportError as err: | ||
warnings.warn("Experimental spatial exporter requires the spatialdatda package.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warnings.warn("Experimental spatial exporter requires the spatialdatda package.") | |
warnings.warn("Experimental spatial exporter requires the spatialdata package.") |
patch = _str_to_int(split_version[2]) | ||
except ValueError as err: | ||
raise ValueError(f"Unable to parse version {version}.") from err | ||
print(f"Actual: {(major, minor, patch)} and Compare: {upper_bound}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print(f"Actual: {(major, minor, patch)} and Compare: {upper_bound}") |
def _version_less_than(version: str, upper_bound: Tuple[int, int, int]) -> bool: | ||
split_version = version.split(".") | ||
try: | ||
major = _str_to_int(split_version[0]) | ||
minor = _str_to_int(split_version[1]) | ||
patch = _str_to_int(split_version[2]) | ||
except ValueError as err: | ||
raise ValueError(f"Unable to parse version {version}.") from err | ||
print(f"Actual: {(major, minor, patch)} and Compare: {upper_bound}") | ||
return ( | ||
major < upper_bound[0] | ||
or (major == upper_bound[0] and minor < upper_bound[1]) | ||
or ( | ||
major == upper_bound[0] | ||
and minor == upper_bound[1] | ||
and patch < upper_bound[2] | ||
) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just as a heads up, tiledbsoma
has packaging
as a transient dependency. It comes with a robust version parser + even a version type: https://packaging.pypa.io/en/latest/version.html
It's mostly what we use for this kind of thing in scverse packages.
# of the DataTree. | ||
if _version_less_than(sd.__version__, (0, 2, 5)): | ||
return DataTree.from_dict( | ||
{f"scale{index}": image for index, image in enumerate(image_data_arrays)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add the "scale"
prefix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's what SpatialData uses: see https://github.com/scverse/spatialdata/blob/main/src/spatialdata/models/models.py#L256
try: | ||
import geopandas as gpd | ||
except ImportError as err: | ||
warnings.warn("Experimental spatial outgestor requires the geopandas package.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might make sense to import spatial data first, since geopandas is a hard dep there.
Then there isn't the UX of import
, hit missing dep error, install geopandas, import
, hit missing spatialdata
Add function to export a full
MultiscaleImage
to a SpatialDataImage2DModel
orImage3DModel
.Note: At the time of this PR, SpatialData is in the process of changing the multiscale image model to move from the legacy
xarray_datatree.datatree.DataTree
class to the newxarray.DataTree
model. This PR implements both versions and checks which to use based on the SpatialData version.