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

Add dataclass support #2

Open
dineshpinto opened this issue Apr 6, 2022 · 1 comment
Open

Add dataclass support #2

dineshpinto opened this issue Apr 6, 2022 · 1 comment

Comments

@dineshpinto
Copy link

dineshpinto commented Apr 6, 2022

dict is too opaque, pls add data class support

can devs do something??

here sample

from dataclasses import dataclass
from typing import List
from datetime import datetime, timedelta
import numpy as np

# The current data structure is:
# bigdict[time_idx][conc_nr][well_nr]['droplet geometry']

# Flattened into a dataclass:
# --------------------------
@dataclass
class ImageData:
    raw_image: str
    droplet_geometry: str
    droplet_status: bool
    conc_idx: int
    well_idx: int
    
    def gray_image(self) -> str:
        return "gray_image"

@dataclass
class Wells:
    image_data: ImageData

@dataclass
class Concentrations:
    wells: List[Wells]

@dataclass
class Images:
    concentrations: List[Concentrations]

# Sample code for testing:
# ------------------------   
TOTAL_WELLS = 2
TOTAL_CONCS = 3
dates = np.arange(
    datetime(2022, 4, 1), 
    datetime(2022, 4, 6), 
    timedelta(days=1)
).astype(datetime)

images = dict()

for date in dates:
    concentrations = []
    for conc_idx, conc in enumerate(range(TOTAL_CONCS)):
        wells = []
        for well_idx, well in enumerate(range(TOTAL_WELLS)):
            image_data = ImageData(
                raw_image="an_image.png", 
                droplet_geometry="round", 
                droplet_status=True, 
                conc_idx=conc_idx, 
                well_idx=well_idx
            )
            wells.append(Wells(image_data))
        concentrations.append(Concentrations(wells))
    images[date] = Images(concentrations=concentrations)
    
images[datetime(2022, 4, 2, 0, 0)].concentrations[2].wells[1].image_data

# Which returns:
# ImageData(raw_image='an_image.png', droplet_geometry='round', droplet_status=True, conc_idx=2, well_idx=1)
@cfsb618
Copy link
Owner

cfsb618 commented Apr 6, 2022

Thank you very much for your extensive suggestions.
Since I'm still learning the language, this is very helpfull.

I will try to implement classes and dataclasses as soon as I find time for it.
Thanks :)

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

No branches or pull requests

2 participants