sciapy.level2.scia_akm.read_akm()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 26
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 4.3145

Importance

Changes 0
Metric Value
cc 2
eloc 6
nop 3
dl 0
loc 26
ccs 1
cts 6
cp 0.1666
crap 4.3145
rs 10
c 0
b 0
f 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