77import pystac
88from pystac import RelType , STACError , STACObjectType
99from pystac .asset import Asset
10+ from pystac .band import Band
1011from pystac .catalog import Catalog
1112from pystac .collection import Collection
1213from pystac .errors import DeprecatedWarning , ExtensionNotImplemented
@@ -106,6 +107,8 @@ class Item(STACObject):
106107 stac_extensions : List [str ]
107108 """List of extensions the Item implements."""
108109
110+ _bands : Optional [List [Band ]]
111+
109112 STAC_OBJECT_TYPE = STACObjectType .ITEM
110113
111114 def __init__ (
@@ -122,6 +125,7 @@ def __init__(
122125 collection : Optional [Union [str , Collection ]] = None ,
123126 extra_fields : Optional [Dict [str , Any ]] = None ,
124127 assets : Optional [Dict [str , Asset ]] = None ,
128+ bands : Optional [List [Band ]] = None ,
125129 ):
126130 super ().__init__ (stac_extensions or [])
127131
@@ -167,6 +171,8 @@ def __init__(
167171 for k , asset in assets .items ():
168172 self .add_asset (k , asset )
169173
174+ self ._bands = bands
175+
170176 def __repr__ (self ) -> str :
171177 return "<Item id={}>" .format (self .id )
172178
@@ -406,6 +412,16 @@ def get_derived_from(self) -> List[Item]:
406412 "Link failed to resolve. Use get_links instead."
407413 ) from e
408414
415+ @property
416+ def bands (self ) -> Optional [List [Band ]]:
417+ """Returns the bands set on this item."""
418+ return self ._bands
419+
420+ @bands .setter
421+ def bands (self , bands : Optional [List [Band ]]) -> None :
422+ """Sets the bands on this item."""
423+ self ._bands = bands
424+
409425 def to_dict (
410426 self , include_self_link : bool = True , transform_hrefs : bool = True
411427 ) -> Dict [str , Any ]:
@@ -442,6 +458,9 @@ def to_dict(
442458 for key in self .extra_fields :
443459 d [key ] = self .extra_fields [key ]
444460
461+ if self .bands is not None :
462+ d ["properties" ]["bands" ] = [band .to_dict () for band in self .bands ]
463+
445464 return d
446465
447466 def clone (self ) -> Item :
@@ -516,13 +535,20 @@ def from_dict(
516535 if k not in [* pass_through_fields , * parse_fields , * exclude_fields ]
517536 }
518537
538+ bands = properties .pop ("bands" , None )
539+ if bands is not None :
540+ deserialized_bands = [Band .from_dict (d ) for d in bands ]
541+ else :
542+ deserialized_bands = None
543+
519544 item = cls (
520545 ** {k : d .get (k ) for k in pass_through_fields }, # type: ignore
521546 datetime = datetime ,
522547 properties = properties ,
523548 extra_fields = extra_fields ,
524549 href = href ,
525550 assets = {k : Asset .from_dict (v ) for k , v in assets .items ()},
551+ bands = deserialized_bands ,
526552 )
527553
528554 for link in links :
0 commit comments