Skip to content
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

improved repr #26

Merged
merged 6 commits into from
Aug 6, 2020
Merged

improved repr #26

merged 6 commits into from
Aug 6, 2020

Conversation

tlambert03
Copy link
Owner

@tlambert03 tlambert03 commented Aug 3, 2020

closes #4
This is a start on improved reprs, as per #4 (leave out properties that are set to the default, summarize containers rather than recursively include their contents) plenty to discuss here...
here's an Image repr as it stands:

Image:0
   pixels=Pixels:0:0
      dimension_order='XYCZT'
      size_c=2
      size_t=2
      size_x=6
      size_y=4
      size_z=2
      type='uint8'
      bin_data=<8 Bin_Data>
      channels=<2 Channels>
      physical_size_x=10000.0
      physical_size_y=10000.0
      planes=<8 Planes>
   acquisition_date=2010-11-10 14:42:38
   annotation_ref=<4 Annotation_Ref>
   instrument_ref=Instrument:SpimSampleMicroscope1

   name=Spim Sample Tile 1 Angle 1
   objective_settings=Objective:1
      correction_collar=6.0
      medium='Oil'
   stage_label=StageLabel
      name=(1,1) of 1x2
      x=1.0
      y=1.0
previously...

😂

Image(pixels=Pixels(dimension_order=<DimensionOrder.XYCZT: 'XYCZT'>,
size_c=2, size_t=2, size_x=6, size_y=4, size_z=2, type=<PixelType.UINT8:
'uint8'>, big_endian=None,
bin_data=[BinData(value='/wCrzur//wB5oMPi/wBIbJO3AP8ePGCF', big_endian=False,
length=32, compression=<Compression.NONE: 'none'>),
BinData(value='/wCrzur//wB5oMPi/wBIbJO3AP8ePGCF', big_endian=False, length=32,
compression=<Compression.NONE: 'none'>),
BinData(value='/wCrzur//wB5oMPi/wBIbJO3AP8ePGCF', big_endian=False, length=32,
compression=<Compression.NONE: 'none'>),
BinData(value='/wCrzur//wB5oMPi/wBIbJO3AP8ePGCF', big_endian=False, length=32,
compression=<Compression.NONE: 'none'>),
BinData(value='/wCrzur//wB5oMPi/wBIbJO3AP8ePGCF', big_endian=False, length=32,
compression=<Compression.NONE: 'none'>),
BinData(value='/wCrzur//wB5oMPi/wBIbJO3AP8ePGCF', big_endian=False, length=32,
compression=<Compression.NONE: 'none'>),
BinData(value='/wCrzur//wB5oMPi/wBIbJO3AP8ePGCF', big_endian=False, length=32,
compression=<Compression.NONE: 'none'>),
BinData(value='/wCrzur//wB5oMPi/wBIbJO3AP8ePGCF', big_endian=False, length=32,
compression=<Compression.NONE: 'none'>)],
channels=[Channel(acquisition_mode=None, annotation_ref=[], color=-1,
contrast_method=None, detector_settings=None, emission_wavelength=None,
emission_wavelength_unit=<UnitsLength.NANOMETER: 'nm'>,
excitation_wavelength=None, excitation_wavelength_unit=<UnitsLength.NANOMETER:
'nm'>, filter_set_ref=None, fluor='Autofluorescence', id='Channel:0.0',
illumination_type=None, light_path=None, light_source_settings=None, name=None,
nd_filter=None, pinhole_size=None, pinhole_size_unit=<UnitsLength.MICROMETER:
'µm'>, pockel_cell_setting=None, samples_per_pixel=None),
Channel(acquisition_mode=None, annotation_ref=[], color=16711935,
contrast_method=None, detector_settings=None, emission_wavelength=None,
emission_wavelength_unit=<UnitsLength.NANOMETER: 'nm'>,
excitation_wavelength=None, excitation_wavelength_unit=<UnitsLength.NANOMETER:
'nm'>, filter_set_ref=None, fluor='Green-OME', id='Channel:0.1',
illumination_type=None, light_path=None, light_source_settings=None, name=None,
nd_filter=None, pinhole_size=None, pinhole_size_unit=<UnitsLength.MICROMETER:
'µm'>, pockel_cell_setting=None, samples_per_pixel=None)], id='Pixels:0:0',
interleaved=None, metadata_only=False, physical_size_x=10000.0,
physical_size_x_unit=<UnitsLength.MICROMETER: 'µm'>, physical_size_y=10000.0,
physical_size_y_unit=<UnitsLength.MICROMETER: 'µm'>, physical_size_z=None,
physical_size_z_unit=<UnitsLength.MICROMETER: 'µm'>, planes=[Plane(the_c=0,
the_t=0, the_z=0, annotation_ref=[], delta_t=None,
delta_t_unit=<UnitsTime.SECOND: 's'>, exposure_time=500.0,
exposure_time_unit=<UnitsTime.SECOND: 's'>, hash_sha1=None, position_x=None,
position_x_unit=<UnitsLength.REFERENCEFRAME: 'reference frame'>,
position_y=None, position_y_unit=<UnitsLength.REFERENCEFRAME: 'reference
frame'>, position_z=None, position_z_unit=<UnitsLength.REFERENCEFRAME:
'reference frame'>), Plane(the_c=1, the_t=0, the_z=0, annotation_ref=[],
delta_t=None, delta_t_unit=<UnitsTime.SECOND: 's'>, exposure_time=500.0,
exposure_time_unit=<UnitsTime.SECOND: 's'>, hash_sha1=None, position_x=None,
position_x_unit=<UnitsLength.REFERENCEFRAME: 'reference frame'>,
position_y=None, position_y_unit=<UnitsLength.REFERENCEFRAME: 'reference
frame'>, position_z=None, position_z_unit=<UnitsLength.REFERENCEFRAME:
'reference frame'>), Plane(the_c=0, the_t=0, the_z=1, annotation_ref=[],
delta_t=None, delta_t_unit=<UnitsTime.SECOND: 's'>, exposure_time=500.0,
exposure_time_unit=<UnitsTime.SECOND: 's'>, hash_sha1=None, position_x=None,
position_x_unit=<UnitsLength.REFERENCEFRAME: 'reference frame'>,
position_y=None, position_y_unit=<UnitsLength.REFERENCEFRAME: 'reference
frame'>, position_z=None, position_z_unit=<UnitsLength.REFERENCEFRAME:
'reference frame'>), Plane(the_c=1, the_t=0, the_z=1, annotation_ref=[],
delta_t=None, delta_t_unit=<UnitsTime.SECOND: 's'>, exposure_time=500.0,
exposure_time_unit=<UnitsTime.SECOND: 's'>, hash_sha1=None, position_x=None,
position_x_unit=<UnitsLength.REFERENCEFRAME: 'reference frame'>,
position_y=None, position_y_unit=<UnitsLength.REFERENCEFRAME: 'reference
frame'>, position_z=None, position_z_unit=<UnitsLength.REFERENCEFRAME:
'reference frame'>), Plane(the_c=0, the_t=1, the_z=0, annotation_ref=[],
delta_t=None, delta_t_unit=<UnitsTime.SECOND: 's'>, exposure_time=500.0,
exposure_time_unit=<UnitsTime.SECOND: 's'>, hash_sha1=None, position_x=None,
position_x_unit=<UnitsLength.REFERENCEFRAME: 'reference frame'>,
position_y=None, position_y_unit=<UnitsLength.REFERENCEFRAME: 'reference
frame'>, position_z=None, position_z_unit=<UnitsLength.REFERENCEFRAME:
'reference frame'>), Plane(the_c=1, the_t=1, the_z=0, annotation_ref=[],
delta_t=None, delta_t_unit=<UnitsTime.SECOND: 's'>, exposure_time=500.0,
exposure_time_unit=<UnitsTime.SECOND: 's'>, hash_sha1=None, position_x=None,
position_x_unit=<UnitsLength.REFERENCEFRAME: 'reference frame'>,
position_y=None, position_y_unit=<UnitsLength.REFERENCEFRAME: 'reference
frame'>, position_z=None, position_z_unit=<UnitsLength.REFERENCEFRAME:
'reference frame'>), Plane(the_c=0, the_t=1, the_z=1, annotation_ref=[],
delta_t=None, delta_t_unit=<UnitsTime.SECOND: 's'>, exposure_time=500.0,
exposure_time_unit=<UnitsTime.SECOND: 's'>, hash_sha1=None, position_x=None,
position_x_unit=<UnitsLength.REFERENCEFRAME: 'reference frame'>,
position_y=None, position_y_unit=<UnitsLength.REFERENCEFRAME: 'reference
frame'>, position_z=None, position_z_unit=<UnitsLength.REFERENCEFRAME:
'reference frame'>), Plane(the_c=1, the_t=1, the_z=1, annotation_ref=[],
delta_t=None, delta_t_unit=<UnitsTime.SECOND: 's'>, exposure_time=500.0,
exposure_time_unit=<UnitsTime.SECOND: 's'>, hash_sha1=None, position_x=None,
position_x_unit=<UnitsLength.REFERENCEFRAME: 'reference frame'>,
position_y=None, position_y_unit=<UnitsLength.REFERENCEFRAME: 'reference
frame'>, position_z=None, position_z_unit=<UnitsLength.REFERENCEFRAME:
'reference frame'>)], significant_bits=None, tiff_data_blocks=[],
time_increment=None, time_increment_unit=<UnitsTime.SECOND: 's'>),
acquisition_date=datetime.datetime(2010, 11, 10, 14, 42, 38),
annotation_ref=[AnnotationRef(id='Annotation:ExtraStageLabel:1:0'),
AnnotationRef(id='Annotation:SpimSet:1'),
AnnotationRef(id='Annotation:ObjectiveAdditions:1'),
AnnotationRef(id='Annotation:SystemSpecific:1')], description=None,
experiment_ref=None, experimenter_group_ref=None, experimenter_ref=None,
id='Image:0', imaging_environment=None,
instrument_ref=InstrumentRef(id='Instrument:SpimSampleMicroscope1'),
microbeam_manipulation_ref=[], name='Spim Sample Tile 1 Angle 1',
objective_settings=ObjectiveSettings(correction_collar=6.0, id='Objective:1',
medium=<Medium.OIL: 'Oil'>, refractive_index=None), roi_ref=[],
stage_label=StageLabel(name='(1,1) of 1x2', x=1.0,
x_unit=<UnitsLength.REFERENCEFRAME: 'reference frame'>, y=1.0,
y_unit=<UnitsLength.REFERENCEFRAME: 'reference frame'>, z=None,
z_unit=<UnitsLength.REFERENCEFRAME: 'reference frame'>))

@jmuhlich
Copy link
Collaborator

jmuhlich commented Aug 4, 2020

I think this is really close to creating reprs that are basically executable Python code (except for the containers)! This kind of repr would go a long way in guiding new users down the right path for creating their own objects without even needing to consult the docs. This near-executable output might look like this for your example:

Image(
   id="Image:0",
   pixels=Pixels(
      id="Pixels:0:0",
      dimension_order="XYCZT",
      size_c=2,
      size_t=2,
      size_x=6,
      size_y=4,
      size_z=2,
      type="uint8",
      bin_data=<8 Bin_Data>,
      channels=<2 Channels>,
      physical_size_x=10000.0,
      physical_size_y=10000.0,
      planes=<8 Planes>,
   ),
   acquisition_date=datetime.fromisoformat("2010-11-10T14:42:38"),
   annotation_ref=<4 Annotation_Ref>,
   instrument_ref=InstrumentRef(id="Instrument:SpimSampleMicroscope1"),
   name="Spim Sample Tile 1 Angle 1",
   objective_settings=ObjectiveSettings(
      id="Objective:1",
      correction_collar=6.0,
      medium="Oil",
   ),
   stage_label=StageLabel(
      name="(1,1) of 1x2",
      x=1.0,
      y=1.0,
   ),
)

@tlambert03
Copy link
Owner Author

yep, love that... will work towards it.

@tlambert03
Copy link
Owner Author

updated... some examples:

Image(
   id='Image:0',
   name='Spim Sample Tile 1 Angle 1',
   pixels=Pixels(
      id='Pixels:0:0',
      dimension_order='XYCZT',
      size_c=2,
      size_t=2,
      size_x=6,
      size_y=4,
      size_z=2,
      type='uint8',
      bin_data=[<8 Bin_Data>],
      channels=[<2 Channels>],
      physical_size_x=10000.0,
      physical_size_y=10000.0,
      planes=[<8 Planes>]
   ),
   acquisition_date=datetime.fromisoformat('2010-11-10T14:42:38'),
   annotation_ref=[<4 Annotation_Ref>],
   instrument_ref=InstrumentRef(
      id='Instrument:SpimSampleMicroscope1'
   ),
   objective_settings=ObjectiveSettings(
      id='Objective:1',
      correction_collar=6.0,
      medium='Oil'
   ),
   stage_label=StageLabel(
      name='(1,1) of 1x2',
      x=1.0,
      y=1.0
   )
)

OME(
   images=[<4 Images>],
   instruments=[<1 Instruments>],
   structured_annotations=[<7 Structured_Annotations>]
)

Instrument(
   id='Instrument:SpimSampleMicroscope1',
   detectors=[<1 Detectors>],
   light_source_group=[<2 Light_Source_Group>],
   microscope=Microscope(
      manufacturer='OME-Sample',
      model='Spim-Sample',
      serial_number='SPIM-1',
      type='Other'
   ),
   objectives=[<3 Objectives>]
)

Laser(
   id='LightSource:1',
   manufacturer='OME-Sample',
   model='Laser Mk1',
   serial_number='LASER-1',
   laser_medium='GaAs',
   type='Semiconductor',
   wavelength=448.0
)

Copy link
Collaborator

@jmuhlich jmuhlich left a comment

Choose a reason for hiding this comment

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

Nice! The extra square brackets around the containers looks weird but I understand it communicates that they're lists.

@codecov-commenter
Copy link

codecov-commenter commented Aug 6, 2020

Codecov Report

Merging #26 into master will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #26      +/-   ##
==========================================
- Coverage   95.20%   95.18%   -0.02%     
==========================================
  Files           1        1              
  Lines         396      436      +40     
==========================================
+ Hits          377      415      +38     
- Misses         19       21       +2     
Impacted Files Coverage Δ
src/ome_autogen.py 95.18% <100.00%> (-0.02%) ⬇️

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 4c667ff...93449d0. Read the comment docs.

@tlambert03 tlambert03 merged commit 78ca963 into master Aug 6, 2020
@tlambert03 tlambert03 deleted the repr branch August 6, 2020 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve __repr__
3 participants