codecov-commenter: # [Codecov](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/83?src=pr&el=h1) Report
> Merging [#83](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/83?src=pr&el=desc) into [master](https://codecov.io/gh/dlr-eoc/ukis-pysat/commit/e8e6b22a0f92b769086a8352d6e544a6f5c10ae6?el=desc) will **increase** coverage by `0.04%`.
> The diff coverage is `100.00%`.

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

```diff
@@            Coverage Diff             @@
##           master      #83      +/-   ##
==========================================
+ Coverage   93.55%   93.59%   +0.04%     
==========================================
  Files           8        8              
  Lines         776      781       +5     
==========================================
+ Hits          726      731       +5     
  Misses         50       50              
```

| Flag | Coverage Δ | |
|---|---|---|
| #unittests | `93.59% <100.00%> (+0.04%)` | :arrow_up: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/83?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [tests/test\_raster.py](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/83/diff?src=pr&el=tree#diff-dGVzdHMvdGVzdF9yYXN0ZXIucHk=) | `99.38% <100.00%> (+0.01%)` | :arrow_up: |
| [ukis\_pysat/raster.py](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/83/diff?src=pr&el=tree#diff-dWtpc19weXNhdC9yYXN0ZXIucHk=) | `92.98% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/83?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/83?src=pr&el=footer). Last update [e8e6b22...0de82f3](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/83?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 a614feb..c3055ce 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -16,9 +16,13 @@ something was changed
 [master]  (2020-**-**)
 ----------------------
 
+[0.6.1]  (2020-08-31)
+----------------------
+
 Added
 *****
 - ``file``: added to_ESA_date() function #80
+- ``raster``: added nodata value upon dataset creation with numpy arrays #82
 
 
 [0.6.0]  (2020-08-28)
diff --git a/ukis_pysat/__init__.py b/ukis_pysat/__init__.py
index b5d7c28..98eb676 100644
--- a/ukis_pysat/__init__.py
+++ b/ukis_pysat/__init__.py
@@ -1,1 +1,1 @@
-__version__ = "0.6.0"
+__version__ = "0.6.1"
diff --git a/ukis_pysat/raster.py b/ukis_pysat/raster.py
index 2676c25..4a43303 100644
--- a/ukis_pysat/raster.py
+++ b/ukis_pysat/raster.py
@@ -30,12 +30,14 @@ class Image:
 
     da_arr = None
 
-    def __init__(self, data, dimorder="first", crs=None, transform=None):
+    def __init__(self, data, dimorder="first", crs=None, transform=None, nodata=None):
         """
         :param data: rasterio.io.DatasetReader or path to raster or np.ndarray of shape (bands, rows, columns)
         :param dimorder: Order of channels or bands 'first' or 'last' (default: 'first')
         :param crs: Coordinate reference system used when creating form array. If 'data' is np.ndarray this is required (default: None)
         :param transform: Affine transformation mapping the pixel space to geographic space. If 'data' is np.ndarray this is required (default:None)
+        :param nodata: nodata value used when creating form array, optional (default: None)
+
         """
         if dimorder in ("first", "last"):
             self.dimorder = dimorder
@@ -60,7 +62,7 @@ class Image:
             else:
                 self.__arr = reshape_as_raster(data)
             self.dataset = None
-            self.__update_dataset(crs, transform)
+            self.__update_dataset(crs, transform, nodata=nodata)
         else:
             raise TypeError("dataset must be of type rasterio.io.DatasetReader, str or np.ndarray")
 

Nodata values not available when creating dataset from array
Creating an `Image.dataset` from a numpy array produces a rasterio dataset with the following metadata:

```
meta = {
    "driver": "GTiff",
    "dtype": self.__arr.dtype,
    "nodata": nodata,
    "height": self.__arr.shape[-2],
    "width": self.__arr.shape[-1],
    "count": self.__arr.shape[0],
    "crs": crs,
    "transform": transform,
}
```

The instance `nodata` is given as an argument of the method: `__update_dataset(self, crs, transform, nodata=None)`. However, `nodata` is not handed upon function call `self.__update_dataset(crs, transform)` which leaves the new dataset with no nodata value.

Suggest to introduce a nodata value when creating datasets from arrays such as `self.__update_dataset(crs, transform, nodata=nodata)`. This requires handing the nodata value to the instantiation of the Image class `__init__(self, data, dimorder="first", crs=None, transform=None, nodata=None)` if usage is desired.
diff --git a/tests/test_raster.py b/tests/test_raster.py
index d996f6c..2802070 100644
--- a/tests/test_raster.py
+++ b/tests/test_raster.py
@@ -109,6 +109,13 @@ class DataTest(unittest.TestCase):
         self.assertEqual(img_last.arr.shape, (385, 502, 1))
         img_last.close()
 
+    def test_arr_nodata(self):
+        array = np.ones((3, 385, 502))
+
+        with Image(array, crs=self.img.dataset.crs, transform=self.img.dataset.transform, nodata=0.0) as img_nodata:
+            self.assertEqual(img_nodata.dataset.nodata, 0.0)
+            self.assertEqual(img_nodata.dataset.nodatavals, (0.0, 0.0, 0.0))
+
     def test_set_array(self):
         img = Image(TEST_FILE, dimorder="last")
         img.arr = img.arr + 1

pip install -e .[complete]
parse_log_pytest
requirements.txt
pytest
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.4
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@e8e6b22a0f92b769086a8352d6e544a6f5c10ae6#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.4
      - 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_nodata
tests/test_raster.py::DataTest::test__lookup_bands tests/test_raster.py::DataTest::test_arr tests/test_raster.py::DataTest::test_context 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_set_array tests/test_raster.py::DataTest::test_set_array_error tests/test_raster.py::DataTest::test_warp tests/test_raster.py::DataTest::test_write_to_file
CHANGELOG.rst ukis_pysat/raster.py ukis_pysat/__init__.py
CHANGELOG.rst ukis_pysat/raster.py ukis_pysat/__init__.py