Skip to content

feat: make Map implement MutableMapping interface #249

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

Merged
merged 8 commits into from
Mar 15, 2024
Merged

Conversation

tlambert03
Copy link
Owner

@tlambert03 tlambert03 commented Mar 14, 2024

closes #248 ... This PR makes ome_types.model.Map behave like a proper mutable mapping. so, it's much easier to cast to/from a dict object:

after this PR, you can do:

import ome_types
from ome_types.model import MapAnnotation

ome_test = ome_types.OME()

data = {
    "uiWidth": 1608,
    "uiWidthBytes": 3216,
    "uiHeight": "1608",
    "uiComp": "1",
}

ome_test.structured_annotations.extend([MapAnnotation(value=data)])
print(ome_test.model_dump(exclude_defaults=True))
print(ome_test.to_xml())

prints:

{
    "structured_annotations": {
        "map_annotations": [
            {
                "id": "Annotation:0",
                "value": {
                    "uiWidth": "1608",
                    "uiWidthBytes": "3216",
                    "uiHeight": "1608",
                    "uiComp": "1",
                },
                "kind": "mapannotation",
            }
        ]
    }
}

and

<OME xmlns="http://www.openmicroscopy.org/Schemas/OME/2016-06" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.openmicroscopy.org/Schemas/OME/2016-06 http://www.openmicroscopy.org/Schemas/OME/2016-06/ome.xsd">
  <StructuredAnnotations>
    <MapAnnotation ID="Annotation:0">
      <Value>
        <M K="uiWidth">1608</M>
        <M K="uiWidthBytes">3216</M>
        <M K="uiHeight">1608</M>
        <M K="uiComp">1</M>
      </Value>
    </MapAnnotation>
  </StructuredAnnotations>
</OME>

also note that you would be able to use standard dict-like methods to modify the Map object (like __getitem__, __setitem__, .get(), etc...)

Copy link

codecov bot commented Mar 14, 2024

Codecov Report

Attention: Patch coverage is 88.37209% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 86.72%. Comparing base (80d6a40) to head (6651747).

Files Patch % Lines
src/ome_types/_mixins/_map_mixin.py 90.00% 3 Missing ⚠️
src/ome_types/_mixins/_base_type.py 75.00% 1 Missing ⚠️
src/ome_types/_mixins/_validators.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #249      +/-   ##
==========================================
+ Coverage   86.66%   86.72%   +0.05%     
==========================================
  Files          24       25       +1     
  Lines        1200     1243      +43     
==========================================
+ Hits         1040     1078      +38     
- Misses        160      165       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

codspeed-hq bot commented Mar 14, 2024

CodSpeed Performance Report

Merging #249 will not alter performance

Comparing better-map (6651747) with main (80d6a40)

Summary

✅ 9 untouched benchmarks

@tlambert03 tlambert03 changed the title feat: better Map object feat: make Map implement MutableMapping interface Mar 14, 2024
@tlambert03
Copy link
Owner Author

cc @phisanti, how's this look to you?

I could also add this to ND2.ome_metadata as a full=True option to store all the metadata we can find

@phisanti
Copy link

Adding all the OME metadata directly in the nd2 would be very useful, save me one function in the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Appending elements to an OME object
2 participants