Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions datamint/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from .endpoints import (
AnnotationsApi,
AnnotationWorklistApi,
ChannelsApi,
DatasetsInfoApi,
DeployModelApi,
InferenceApi,
Expand All @@ -29,7 +28,6 @@ class Api:
'projects': ProjectsApi,
'resources': ResourcesApi,
'annotations': AnnotationsApi,
'channels': ChannelsApi,
'users': UsersApi,
'datasets': DatasetsInfoApi,
'models': ModelsApi,
Expand Down Expand Up @@ -176,10 +174,6 @@ def resources(self) -> ResourcesApi:
def annotations(self) -> AnnotationsApi:
return self._get_endpoint('annotations')

@property
def channels(self) -> ChannelsApi:
return self._get_endpoint('channels')

@property
def users(self) -> UsersApi:
return self._get_endpoint('users')
Expand Down
2 changes: 0 additions & 2 deletions datamint/api/endpoints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from .annotations_api import AnnotationsApi
from .annotationsets_api import AnnotationWorklistApi
from .channels_api import ChannelsApi
from .datasetsinfo_api import DatasetsInfoApi
from .deploy_model_api import DeployModelApi
from .inference_api import InferenceApi
Expand All @@ -13,7 +12,6 @@
__all__ = [
'AnnotationWorklistApi',
'AnnotationsApi',
'ChannelsApi',
'DatasetsInfoApi',
'DeployModelApi',
'InferenceApi',
Expand Down
31 changes: 0 additions & 31 deletions datamint/api/endpoints/channels_api.py

This file was deleted.

29 changes: 28 additions & 1 deletion datamint/api/endpoints/resources_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from pydicom import config as pydicom_config
from tqdm.auto import tqdm

from datamint.entities import Project, Resource
from datamint.entities import Channel, Project, Resource
from datamint.entities.annotations import AnnotationType
from datamint.entities.annotations.annotation import Annotation
from datamint.exceptions import ItemNotFoundError, ServerError, ValidationError
Expand Down Expand Up @@ -1400,6 +1400,33 @@ def get_not_annotated(self,
all_items.extend(items)
return [self._init_entity_obj(**item) for item in all_items]

def list_channels(self,
limit: int | None = None,
**kwargs) -> list[Channel]:
"""List upload channels.

A channel is a grouping over resources (set via ``upload_channel``
at upload time).

Args:
limit: Maximum number of channels to return.
**kwargs: Additional query parameters forwarded to the endpoint
(e.g. ``project_name``).

Returns:
List of Channel instances.
"""
params = {k: v for k, v in kwargs.items() if v is not None}
items_gen = self._make_request_with_pagination('GET',
f'/{self.endpoint_base}/channels',
return_field='channels',
limit=limit,
params=params or None)
all_items = []
for _, items in items_gen:
all_items.extend(items)
return [Channel(**item) for item in all_items]

def rank_resources(self,
resources: Sequence[Resource],
score_fn: Callable[[Resource], float | None],
Expand Down
16 changes: 8 additions & 8 deletions datamint/entities/channel.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@

from pydantic import BaseModel, ConfigDict

from datamint.entities.base_entity import BaseEntity


class ChannelResourceData(BaseModel):
"""Represents resource data within a channel.

Attributes:
created_by: Email of the user who created the resource.
customer_id: UUID of the customer.
Expand All @@ -23,25 +21,27 @@ class ChannelResourceData(BaseModel):
resource_mimetype: str


class Channel(BaseEntity):
class Channel(BaseModel):
"""Represents a channel containing multiple resources.

A channel is a collection of resources grouped together,
typically for batch processing or organization purposes.

Attributes:
channel_name: Name identifier for the channel.
resource_data: List of resources contained in this channel.
deleted: Whether the channel has been marked as deleted.
created_at: Timestamp when the channel was created.
updated_at: Timestamp when the channel was last updated.
"""
channel_name: str
model_config = ConfigDict(extra='allow')

channel_name: str | None = None
resource_data: list[ChannelResourceData]
deleted: bool = False
created_at: str | None = None
updated_at: str | None = None

def get_resource_ids(self) -> list[str]:
"""Get list of all resource IDs in this channel."""
return [resource.resource_id for resource in self.resource_data] if self.resource_data else []
return [resource.resource_id for resource in self.resource_data] if self.resource_data else []
19 changes: 5 additions & 14 deletions docs/source/client_api_content.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ The |ApiClass| class provides access to different endpoint handlers:
+------------------------+--------------------------------------------------+
| ``api.projects`` | Organize resources into projects |
+------------------------+--------------------------------------------------+
| ``api.channels`` | Group resources by category |
+------------------------+--------------------------------------------------+
| ``api.models`` | Register and manage ML models |
+------------------------+--------------------------------------------------+
| ``api.deploy`` | Deploy models |
Expand Down Expand Up @@ -439,23 +437,16 @@ available with calls such as ``dataset.split(train=0.8, val=0.2, seed=42)``.
Working with Channels
---------------------

Organize resources with channels
++++++++++++++++++++++++++++++++
A channel is just a grouping over resources, set via ``upload_channel`` at
upload time (see ``datamint upload --channel``).

.. code-block:: python

# List all channels
channels = api.channels.get_list()
# List channels (optionally scoped to a project)
channels = api.resources.list_channels(project_name="MyProject")

# Create a new channel
api.channels.create(name="CT Scans", description="CT scan images")

# List channels with resources
for channel in channels:
print(channel.name, channel.resource_count)

# Delete a channel
api.channels.delete(channel)
print(channel.channel_name, len(channel.get_resource_ids()))

See also the tutorial notebooks: `upload_data.ipynb <https://github.com/SonanceAI/datamint-python-api/blob/main/notebooks/upload_data.ipynb>`_

Expand Down
8 changes: 0 additions & 8 deletions docs/source/datamint.api.endpoints.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ Annotations API
:undoc-members:
:show-inheritance:

Channels API
------------

.. automodule:: datamint.api.endpoints.channels_api
:members:
:undoc-members:
:show-inheritance:

Users API
---------

Expand Down
1 change: 0 additions & 1 deletion notebooks/01_getting_started/01_upload_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"- `api.resources` - Resource management (upload, download, etc.)\n",
"- `api.projects` - Project management and collaboration\n",
"- `api.annotations` - Annotation handling and segmentations\n",
"- `api.channels` - Channel organization\n",
"- `api.users` - User management\n",
"\n",
"Make sure you've run `datamint config` in your terminal first."
Expand Down
18 changes: 0 additions & 18 deletions tests/test_entity_pickling.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from datamint.entities.annotations.base_geometry import BaseGeometryAnnotation
from datamint.entities.annotations.base_segmentation import BaseSegmentationAnnotation
from datamint.entities.base_entity import BaseEntity, BaseEntityModel
from datamint.entities.channel import Channel, ChannelResourceData
from datamint.entities.datasetinfo import DatasetInfo
from datamint.entities.deployjob import DeployJob
from datamint.entities.inferencejob import InferenceJob
Expand Down Expand Up @@ -141,22 +140,6 @@ def _make_box_annotation() -> BoxAnnotation:
)


def _make_channel() -> Channel:
return Channel(
id='channel-1',
channel_name='uploads',
resource_data=[
ChannelResourceData(
created_by='tester@datamint.io',
customer_id='customer-1',
resource_id='resource-1',
resource_file_name='scan.png',
resource_mimetype='image/png',
)
],
)


def _make_dataset_info() -> DatasetInfo:
return DatasetInfo(
id='dataset-1',
Expand Down Expand Up @@ -336,7 +319,6 @@ def _make_sliced_video_resource() -> SlicedVideoResource:
_ENTITY_FACTORIES: dict[type[object], Factory] = {
Annotation: _make_annotation,
BoxAnnotation: _make_box_annotation,
Channel: _make_channel,
DatasetInfo: _make_dataset_info,
DICOMResource: _make_dicom_resource,
DeployJob: _make_deploy_job,
Expand Down
Loading