| Total Complexity | 2 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Coverage | 50% |
| Changes | 0 | ||
| 1 | # -*- coding: utf-8 -*- |
||
| 2 | # vim:fileencoding=utf-8 |
||
| 3 | # |
||
| 4 | # Copyright (c) 2018 Stefan Bender |
||
| 5 | # |
||
| 6 | # This file is part of sciapy. |
||
| 7 | # sciapy is free software: you can redistribute it or modify it |
||
| 8 | # under the terms of the GNU General Public License as published by |
||
| 9 | # the Free Software Foundation, version 2. |
||
| 10 | # See accompanying LICENSE file or http://www.gnu.org/licenses/gpl-2.0.html. |
||
| 11 | 1 | """SCIAMACHY level 2 averaging kernel interface |
|
| 12 | """ |
||
| 13 | 1 | from __future__ import print_function |
|
| 14 | |||
| 15 | 1 | import numpy as np |
|
| 16 | 1 | import xarray as xr |
|
| 17 | |||
| 18 | |||
| 19 | 1 | def read_akm(filename, nalt, nlat): |
|
| 20 | """Read SCIAMACHY level 2 averaging kernels into numpy array |
||
| 21 | |||
| 22 | Supports plain ascii (text) tables using :func:`numpy.genfromtxt` |
||
| 23 | and netcdf files using :mod:`xarray`. |
||
| 24 | |||
| 25 | Parameters |
||
| 26 | ---------- |
||
| 27 | filename: str |
||
| 28 | Filename of the averaging kernel elements |
||
| 29 | nalt: int |
||
| 30 | Number of altitude bins of the retrieval |
||
| 31 | nlat: int |
||
| 32 | Number of latitude bins of the retrieval |
||
| 33 | |||
| 34 | Returns |
||
| 35 | ------- |
||
| 36 | akm: numpy.ndarray of shape (nalt, nlat, nalt, nlat) |
||
| 37 | The averaging kernel matrix elements. |
||
| 38 | """ |
||
| 39 | try: |
||
| 40 | akm = np.genfromtxt(filename) |
||
| 41 | except UnicodeDecodeError: |
||
| 42 | # most probably a netcdf file |
||
| 43 | akm = xr.open_dataarray(filename).data |
||
| 44 | return akm.reshape(nalt, nlat, nalt, nlat) |
||
| 45 |