Skip to content

Commit 5401277

Browse files
committed
Add type annotations in phyvars module
1 parent fc7d5c8 commit 5401277

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

stagpy/phyvars.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,22 @@
55
be computed from other variables.
66
"""
77

8+
from __future__ import annotations
89
from operator import attrgetter
910
from types import MappingProxyType
11+
import typing
1012

1113
from . import processing
1214
from .datatypes import Varf, Varr, Vart
1315

16+
if typing.TYPE_CHECKING:
17+
from typing import Mapping, Callable, List
18+
from .datatypes import Field, Rprof, Tseries
19+
from ._step import Step
20+
from .stagyydata import StagyyData, _Scales
1421

15-
FIELD = MappingProxyType({
22+
23+
FIELD: Mapping[str, Varf] = MappingProxyType({
1624
'T': Varf('Temperature', 'K'),
1725
'v1': Varf('x Velocity', 'm/s'),
1826
'v2': Varf('y Velocity', 'm/s'),
@@ -44,11 +52,11 @@
4452
'prim': Varf('Primordial layer', '1'),
4553
})
4654

47-
FIELD_EXTRA = MappingProxyType({
55+
FIELD_EXTRA: Mapping[str, Callable[[Step], Field]] = MappingProxyType({
4856
'stream': processing.stream_function,
4957
})
5058

51-
FIELD_FILES = MappingProxyType({
59+
FIELD_FILES: Mapping[str, List[str]] = MappingProxyType({
5260
't': ['T'],
5361
'vp': ['v1', 'v2', 'v3', 'p'],
5462
'c': ['c'],
@@ -66,7 +74,7 @@
6674
'prm': ['prim'],
6775
})
6876

69-
FIELD_FILES_H5 = MappingProxyType({
77+
FIELD_FILES_H5: Mapping[str, List[str]] = MappingProxyType({
7078
'Temperature': ['T'],
7179
'Velocity': ['v1', 'v2', 'v3'],
7280
'Dynamic_Pressure': ['p'],
@@ -92,7 +100,7 @@
92100
'Primordial': ['prim'],
93101
})
94102

95-
SFIELD = MappingProxyType({
103+
SFIELD: Mapping[str, Varf] = MappingProxyType({
96104
'topo_top': Varf('Topography at top', 'm'),
97105
'topo_bot': Varf('Topography at bottom', 'm'),
98106
'geoid_top': Varf('Geoid at top', 'm'),
@@ -106,7 +114,7 @@
106114
'crust': Varf('Crustal thickness', 'm'),
107115
})
108116

109-
SFIELD_FILES = MappingProxyType({
117+
SFIELD_FILES: Mapping[str, List[str]] = MappingProxyType({
110118
'cs': ['topo_bot', 'topo_top'],
111119
'g': ['geoid_bot', 'geoid_top'],
112120
'csg': ['topo_g_bot', 'topo_g_top'],
@@ -115,7 +123,7 @@
115123
'cr': ['crust'],
116124
})
117125

118-
SFIELD_FILES_H5 = MappingProxyType({
126+
SFIELD_FILES_H5: Mapping[str, List[str]] = MappingProxyType({
119127
'BottomTopography': ['topo_bot'],
120128
'SurfaceTopography': ['topo_top'],
121129
'BottomGeoid': ['geoid_bot'],
@@ -130,7 +138,7 @@
130138
})
131139

132140

133-
RPROF = MappingProxyType({
141+
RPROF: Mapping[str, Varr] = MappingProxyType({
134142
'r': Varr('Radial coordinate', 'Radius', 'm'),
135143
'Tmean': Varr('Temperature', 'Temperature', 'K'),
136144
'Tmin': Varr('Min temperature', 'Temperature', 'K'),
@@ -199,7 +207,7 @@
199207
'advasc': Varr('Upward advection', 'Heat flux', 'W/m2'),
200208
})
201209

202-
RPROF_EXTRA = MappingProxyType({
210+
RPROF_EXTRA: Mapping[str, Callable[[Step], Rprof]] = MappingProxyType({
203211
'dr': processing.delta_r,
204212
'diff': processing.diff_prof,
205213
'diffs': processing.diffs_prof,
@@ -213,7 +221,7 @@
213221
})
214222

215223

216-
TIME = MappingProxyType({
224+
TIME: Mapping[str, Vart] = MappingProxyType({
217225
't': Vart('Time', 'Time', 's'),
218226
'ftop': Vart('Heat flux at top', 'Heat flux', 'W/m2'),
219227
'fbot': Vart('Heat flux at bottom', 'Heat flux', 'W/m2'),
@@ -245,14 +253,14 @@
245253
'botT_val': Vart('Temperature at bottom', 'Temperature', 'K'),
246254
})
247255

248-
TIME_EXTRA = MappingProxyType({
256+
TIME_EXTRA: Mapping[str, Callable[[StagyyData], Tseries]] = MappingProxyType({
249257
'dt': processing.dtime,
250258
'dTdt': processing.dt_dt,
251259
'ebalance': processing.ebalance,
252260
'mobility': processing.mobility,
253261
})
254262

255-
REFSTATE = MappingProxyType({
263+
REFSTATE: Mapping[str, Varr] = MappingProxyType({
256264
'z': Varr('z position', 'z position', 'm'),
257265
'T': Varr('Temperature', 'Temperature', 'K'),
258266
'rho': Varr('Density', 'Density', 'kg/m3'),
@@ -263,7 +271,7 @@
263271
'grav': Varr('Gravity', 'Gravity', 'm/s2'),
264272
})
265273

266-
SCALES = MappingProxyType({
274+
SCALES: Mapping[str, Callable[[_Scales], float]] = MappingProxyType({
267275
'm': attrgetter('length'),
268276
'kg/m3': attrgetter('density'),
269277
'K': attrgetter('temperature'),

0 commit comments

Comments
 (0)