codecov-commenter: # [Codecov](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/51?src=pr&el=h1) Report
> Merging [#51](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/51?src=pr&el=desc) into [master](https://codecov.io/gh/dlr-eoc/ukis-pysat/commit/39b43d24edb8be6f3eb9738b9f4f8d8bdd6cd8e8&el=desc) will **decrease** coverage by `0.11%`.
> The diff coverage is `95.45%`.

[![Impacted file tree graph](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/51/graphs/tree.svg?width=650&height=150&src=pr&token=6LYPGRGMXV)](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/51?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master      #51      +/-   ##
==========================================
- Coverage   93.65%   93.54%   -0.12%     
==========================================
  Files           8        8              
  Lines         725      728       +3     
==========================================
+ Hits          679      681       +2     
- Misses         46       47       +1     
```

| Flag | Coverage Δ | |
|---|---|---|
| #unittests | `93.54% <95.45%> (-0.12%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/51?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [ukis\_pysat/raster.py](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/51/diff?src=pr&el=tree#diff-dWtpc19weXNhdC9yYXN0ZXIucHk=) | `92.63% <95.23%> (-0.49%)` | :arrow_down: |
| [tests/test\_raster.py](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/51/diff?src=pr&el=tree#diff-dGVzdHMvdGVzdF9yYXN0ZXIucHk=) | `99.21% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/51?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/51?src=pr&el=footer). Last update [39b43d2...4a97077](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/51?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index c3f20aa..d15c395 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -27,7 +27,8 @@ Fixed
 
 Changed
 *******
-- ``raster.Image()``: update of init signature to be less confusing #41
+- ``raster.Image()``: update of init signature to be less confusing #41 #50
+
 
 [0.4.0]  (2020-06-05)
 ----------------------
diff --git a/ukis_pysat/raster.py b/ukis_pysat/raster.py
index 59483a0..e0ac79c 100644
--- a/ukis_pysat/raster.py
+++ b/ukis_pysat/raster.py
@@ -40,40 +40,43 @@ class Image:
             self.dimorder = dimorder
         else:
             raise TypeError("dimorder for bands or channels must be either 'first' or 'last'.")
-        try:
+
+        if isinstance(data, rasterio.io.DatasetReader):
+            self.dataset = data
+            self.crs = self.dataset.crs
+            self.transform = self.dataset.transform
+            self.__arr = self.dataset.read()
+
+        elif isinstance(data, str):
             self.dataset = rasterio.open(data)
             self.crs = self.dataset.crs
             self.transform = self.dataset.transform
             self.__arr = self.dataset.read()
-        except (TypeError, AttributeError):
-            if isinstance(data, rasterio.io.DatasetReader):
-                self.dataset = data
-                self.crs = self.dataset.crs
-                self.transform = self.dataset.transform
-                self.__arr = self.dataset.read()
-            elif isinstance(data, np.ndarray):
-                if crs is None:
-                    raise TypeError("if dataset is of type np.ndarray crs must not be None")
-                if transform is None:
-                    raise TypeError("if dataset is of type np.ndarray transform must not be None")
-                meta = {"dtype": data.dtype, "count": data.shape[0], "crs": crs, "driver": "GTiff"}
+
+        elif isinstance(data, np.ndarray):
+            if crs is None:
+                raise TypeError("if dataset is of type np.ndarray crs must not be None")
+            if transform is None:
+                raise TypeError("if dataset is of type np.ndarray transform must not be None")
+            if dimorder == "first":
                 self.__arr = data
-                self.transform = transform
-                self.dataset = self.__update_dataset(meta).open()
-                self.crs = self.dataset.crs
-                self.transform = self.dataset.transform
             else:
-                raise TypeError("dataset must be of type str, rasterio.io.DatasetReader or np.ndarray")
+                self.__arr = reshape_as_raster(data)
+            meta = {"dtype": self.__arr.dtype, "count": self.__arr.shape[0], "crs": crs, "driver": "GTiff"}
+            self.transform = transform
+            self.dataset = self.__update_dataset(meta).open()
+            self.crs = self.dataset.crs
+            self.transform = self.dataset.transform
+        else:
+            raise TypeError("dataset must be of type rasterio.io.DatasetReader, str or np.ndarray")
 
     @property
     def arr(self):
         """array property"""
         if self.dimorder == "first":
             return self.__arr
-        elif self.dimorder == "last":
-            return reshape_as_image(self.__arr)
         else:
-            raise AttributeError("dimorder for bands or channels must be either 'first' or 'last'.")
+            return reshape_as_image(self.__arr)
 
     def get_valid_data_bbox(self, nodata=0):
         """bounding box covering the input array's valid data pixels.
@@ -90,7 +93,7 @@ class Image:
         :param bbox: bounding box of type tuple or Shapely Polygon
         :param crop: bool, see rasterio.mask. Optional, (default: True)
         :param pad: pads image, should only be used when bbox.bounds extent img.bounds, optional (default: False)
-        :param mode: str, how to pad, see rasterio.pad. Optional (default: 'constant') 
+        :param mode: str, how to pad, see rasterio.pad. Optional (default: 'constant')
         :param constant_values: nodata value, padding should be filled with, optional (default: 0)
         """
         # TODO https://github.com/mapbox/rasterio/issues/995

Array dimorder not considered anymore when creating Image from array
When creating an Image instance from an array, the array dimorder is not considered anymore. 
diff --git a/tests/test_raster.py b/tests/test_raster.py
index ea32ae0..b09158a 100644
--- a/tests/test_raster.py
+++ b/tests/test_raster.py
@@ -96,7 +96,7 @@ class DataTest(unittest.TestCase):
         self.assertEqual(img_first.arr.shape, (1, 385, 502))
         img_first.close()
 
-        img_last = Image(np.ones((1, 385, 502)), dimorder="last", crs=self.img.crs, transform=self.img.transform)
+        img_last = Image(np.ones((385, 502, 1)), dimorder="last", crs=self.img.crs, transform=self.img.transform)
         self.assertEqual(img_last.arr.shape, (385, 502, 1))
         img_last.close()
 

pip install -e .[complete]
parse_log_pytest
requirements.txt
pytest
apt-get update apt-get install -y gcc
3.7
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
affine==2.4.0
appdirs==1.4.4
attrs==24.2.0
certifi @ file:///croot/certifi_1671487769961/work/certifi
chardet==3.0.4
click==7.1.2
click-plugins==1.1.1
cligj==0.7.2
dask==2.14.0
decopatch==1.4.10
exceptiongroup==1.2.2
Fiona==1.8.22
geographiclib==2.0
geojson==3.2.0
geomet==1.1.0
geopy==2.4.1
html2text==2020.1.16
idna==2.10
importlib-metadata==6.7.0
iniconfig==2.0.0
landsatxplore==0.6
makefun==1.15.6
munch==4.0.0
numpy==1.18.5
packaging==24.0
pandas==1.0.5
Pillow==7.1.2
pluggy==1.2.0
pyfields==1.1.5
pylandsat==0.4
pyparsing==3.1.4
pyproj==2.6.1.post1
pytest==7.4.4
python-dateutil==2.8.2
pytz==2025.2
rasterio==1.1.8
requests==2.23.0
rio-mucho==1.0.0
rio-toa==0.3.0
sentinelsat==0.14
Shapely==1.7.1
six==1.17.0
snuggs==1.4.7
tomli==2.0.1
toolz==0.12.1
tqdm==4.67.1
typing_extensions==4.7.1
-e git+https://github.com/dlr-eoc/ukis-pysat.git@39b43d24edb8be6f3eb9738b9f4f8d8bdd6cd8e8#egg=ukis_pysat
urllib3==1.25.11
utm==0.5.0
valid8==5.1.2
zipp==3.15.0

name: ukis-pysat
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2022.12.7=py37h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=22.3.1=py37h06a4308_0
  - python=3.7.16=h7a1cb2a_0
  - readline=8.2=h5eee18b_0
  - setuptools=65.6.3=py37h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.38.4=py37h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - affine==2.4.0
      - appdirs==1.4.4
      - attrs==24.2.0
      - chardet==3.0.4
      - click==7.1.2
      - click-plugins==1.1.1
      - cligj==0.7.2
      - dask==2.14.0
      - decopatch==1.4.10
      - exceptiongroup==1.2.2
      - fiona==1.8.22
      - geographiclib==2.0
      - geojson==3.2.0
      - geomet==1.1.0
      - geopy==2.4.1
      - html2text==2020.1.16
      - idna==2.10
      - importlib-metadata==6.7.0
      - iniconfig==2.0.0
      - landsatxplore==0.6
      - makefun==1.15.6
      - munch==4.0.0
      - numpy==1.18.5
      - packaging==24.0
      - pandas==1.0.5
      - pillow==7.1.2
      - pluggy==1.2.0
      - pyfields==1.1.5
      - pylandsat==0.4
      - pyparsing==3.1.4
      - pyproj==2.6.1.post1
      - pytest==7.4.4
      - python-dateutil==2.8.2
      - pytz==2025.2
      - rasterio==1.1.8
      - requests==2.23.0
      - rio-mucho==1.0.0
      - rio-toa==0.3.0
      - sentinelsat==0.14
      - shapely==1.7.1
      - six==1.17.0
      - snuggs==1.4.7
      - tomli==2.0.1
      - toolz==0.12.1
      - tqdm==4.67.1
      - typing-extensions==4.7.1
      - urllib3==1.25.11
      - utm==0.5.0
      - valid8==5.1.2
      - zipp==3.15.0
prefix: /opt/conda/envs/ukis-pysat

tests/test_raster.py::DataTest::test_arr
tests/test_raster.py::DataTest::test__lookup_bands tests/test_raster.py::DataTest::test_dimorder_error tests/test_raster.py::DataTest::test_dn2toa tests/test_raster.py::DataTest::test_get_dask_array tests/test_raster.py::DataTest::test_get_subset tests/test_raster.py::DataTest::test_get_tiles tests/test_raster.py::DataTest::test_get_valid_data_bbox tests/test_raster.py::DataTest::test_init tests/test_raster.py::DataTest::test_init_fail_invalid_dataset tests/test_raster.py::DataTest::test_init_fail_invalid_path tests/test_raster.py::DataTest::test_init_with_array tests/test_raster.py::DataTest::test_init_with_arry_fail_missing_crs tests/test_raster.py::DataTest::test_init_with_arry_fail_missing_crs_and_transform tests/test_raster.py::DataTest::test_init_with_arry_fail_missing_transform tests/test_raster.py::DataTest::test_mask_image tests/test_raster.py::DataTest::test_warp tests/test_raster.py::DataTest::test_write_to_file
CHANGELOG.rst ukis_pysat/raster.py
CHANGELOG.rst ukis_pysat/raster.py