cogeotiff / rio-tiler

User friendly Rasterio plugin to read raster datasets.
https://cogeotiff.github.io/rio-tiler/
BSD 3-Clause "New" or "Revised" License
514 stars 107 forks source link

v6.0 break key access to Model #631

Closed vincentsarago closed 1 year ago

vincentsarago commented 1 year ago
In [1]: from rio_tiler.io import Reader

In [2]: with Reader("tests/fixtures/cog.tif") as src:
   ...:     stats = src.statistics()
   ...: 

In [4]: stats
Out[4]: {'b1': BandStatistics(min=1.0, max=7872.0, mean=2107.524612053134, count=1045504.0, sum=2203425412.0, std=2271.0065537857326, median=2800.0, majority=1.0, minority=7072.0, unique=15.0, histogram=[[503460, 0, 0, 161792, 283094, 0, 0, 0, 87727, 9431], [1.0, 788.1, 1575.2, 2362.3, 3149.4, 3936.5, 4723.6, 5510.7, 6297.8, 7084.900000000001, 7872.0]], valid_percent=100.0, masked_pixels=0.0, valid_pixels=1045504.0, percentile_2=1.0, percentile_98=6896.0)}

In [5]: stats["b1"]
Out[5]: BandStatistics(min=1.0, max=7872.0, mean=2107.524612053134, count=1045504.0, sum=2203425412.0, std=2271.0065537857326, median=2800.0, majority=1.0, minority=7072.0, unique=15.0, histogram=[[503460, 0, 0, 161792, 283094, 0, 0, 0, 87727, 9431], [1.0, 788.1, 1575.2, 2362.3, 3149.4, 3936.5, 4723.6, 5510.7, 6297.8, 7084.900000000001, 7872.0]], valid_percent=100.0, masked_pixels=0.0, valid_pixels=1045504.0, percentile_2=1.0, percentile_98=6896.0)

In [6]: stats["b1"]["min"]
Out[6]: 1.0

In [7]: stats["b1"]["percentile_2"]
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-7-b3eef3df4f87> in <cell line: 1>()
----> 1 stats["b1"]["percentile_2"]

~/Dev/CogeoTiff/rio-tiler/rio_tiler/models.py in __getitem__(self, item)
     45     def __getitem__(self, item):
     46         """Access item like in Dict."""
---> 47         return self.__dict__[item]
     48 
     49 

KeyError: 'percentile_2'

In [8]: stats["b1"].__dict__
Out[8]: 
{'min': 1.0,
 'max': 7872.0,
 'mean': 2107.524612053134,
 'count': 1045504.0,
 'sum': 2203425412.0,
 'std': 2271.0065537857326,
 'median': 2800.0,
 'majority': 1.0,
 'minority': 7072.0,
 'unique': 15.0,
 'histogram': [[503460, 0, 0, 161792, 283094, 0, 0, 0, 87727, 9431],
  [1.0,
   788.1,
   1575.2,
   2362.3,
   3149.4,
   3936.5,
   4723.6,
   5510.7,
   6297.8,
   7084.900000000001,
   7872.0]],
 'valid_percent': 100.0,
 'masked_pixels': 0.0,
 'valid_pixels': 1045504.0}