Skip to content

Commit bd1888b

Browse files
committed
Docstring fixes and more compact variable names
1 parent a922e45 commit bd1888b

File tree

2 files changed

+75
-63
lines changed

2 files changed

+75
-63
lines changed

pysteps/cascade/bandpass_filters.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,26 @@
1111
The output of each filter function is a dictionary containing the following
1212
key-value pairs:
1313
14-
weights_1d 2d array of shape (n, r) containing 1d filter weights
15-
for each frequency band k=1,2,...,n
16-
weights_2d 3d array of shape (n, M, N) containing the 2d filter
17-
weights for each frequency band k=1,2,...,n
18-
central_freqs 1d array of shape n containing the central frequencies of
19-
the filters
14+
.. tabularcolumns:: |p{1.8cm}|L|
15+
16+
+-----------------+-----------------------------------------------------------+
17+
| Key | Value |
18+
+=================+===========================================================+
19+
| weights_1d | 2d array of shape (n, r) containing 1d filter weights |
20+
| | for each frequency band k=1,2,...,n |
21+
+-----------------+-----------------------------------------------------------+
22+
| weights_2d | 3d array of shape (n, M, N) containing the 2d filter |
23+
| | weights for each frequency band k=1,2,...,n |
24+
+-----------------+-----------------------------------------------------------+
25+
| central_freqs | 1d array of shape n containing the central frequencies of |
26+
| | the filters |
27+
+-----------------+-----------------------------------------------------------+
2028
2129
where r = int(max(N, M)/2)+1
2230
2331
The filter weights are assumed to be normalized so that for any Fourier
2432
wavenumber they sum to one.
33+
2534
"""
2635

2736
import numpy as np
@@ -36,8 +45,8 @@ def filter_uniform(shape, n):
3645
Parameters
3746
----------
3847
shape : int or tuple
39-
The dimensions (height, width) of the input field. If shape is an int, it
40-
assumes to be a square domain.
48+
The dimensions (height, width) of the input field. If shape is an int,
49+
it assumes to be a square domain.
4150
n : int
4251
Not used. Needed for compatibility with the filter interface.
4352
"""

pysteps/io/exporters.py

Lines changed: 58 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,55 @@
44
Each exporter method in this module has its own initialization function that
55
implements the following interface:
66
7-
initialize_forecast_exporter_xxx(filename, startdate, timestep, num_timesteps,
8-
shape, num_ens_members, metadata, incremental=None)
7+
initialize_forecast_exporter_xxx(filename, startdate, timestep, num_timesteps, \
8+
shape, num_ens_members, metadata, incremental=None)
99
10-
Parameters
11-
----------
12-
filename : str
13-
Name of the output file.
14-
startdate : datetime.datetime
15-
Start date of the forecast.
16-
timestep : int
17-
Time step of the forecast (minutes).
18-
num_timesteps : int
19-
Number of time steps in the forecast. This argument is ignored if
20-
incremental is set to 'timestep'.
21-
shape : tuple
22-
Two-element tuple defining the shape (height,width) of the forecast grids.
23-
num_ens_members : int
24-
Number of ensemble members in the forecast. This argument is ignored if
25-
incremental is set to 'member'.
26-
metadata : dict
27-
Metadata dictionary containing the projection,x1,x2,y1,y2 and unit
28-
attributes described in the documentation of pysteps.io.importers.
29-
incremental : {'timestep', 'member'}
30-
Allow incremental writing of datasets into the netCDF file. The
31-
available options are: 'timestep'=write a forecast or a forecast
32-
ensemble for a given time step or 'member'=write a forecast sequence
33-
for a given ensemble member.
10+
where xxx describes the file format. This function creates the file and writes
11+
the metadata. The datasets are written by calling export_forecast_dataset, and
12+
the file is closed by calling close_forecast_file.
3413
35-
Returns
36-
-------
37-
out : dict
38-
An exporter object that can be used with export_forecast_dataset to write
39-
datasets into the netCDF file.
14+
The arguments in the above are defined as follows:
15+
16+
.. tabularcolumns:: |p{2.3cm}|p{2.5cm}|L|
17+
18+
+-------------------+-------------------+------------------------------------------------+
19+
| Argument | Type/values | Description |
20+
+===================+===================+================================================+
21+
| filename | str | name of the output file |
22+
+-------------------+-------------------+------------------------------------------------+
23+
| startdate | datetime.datetime | start date of the forecast |
24+
+-------------------+-------------------+------------------------------------------------+
25+
| timestep | int | time step of the forecast (minutes) |
26+
+-------------------+-------------------+------------------------------------------------+
27+
| n_timesteps | int | number of time steps in the forecast |
28+
| | | this argument is ignored if incremental is |
29+
| | | set to 'timestep'. |
30+
+-------------------+-------------------+------------------------------------------------+
31+
| shape | tuple | two-element tuple defining the shape |
32+
| | | (height,width) of the forecast grids |
33+
+-------------------+-------------------+------------------------------------------------+
34+
| n_ens_members | int | number of ensemble members in the forecast |
35+
| | | this argument is ignored if incremental is |
36+
| | | set to 'member' |
37+
+-------------------+-------------------+------------------------------------------------+
38+
| metadata | dict | metadata dictionary containing the |
39+
| | | projection,x1,x2,y1,y2 and unit attributes |
40+
| | | described in the documentation of |
41+
| | | pysteps.io.importers |
42+
+-------------------+-------------------+------------------------------------------------+
43+
| incremental | {'timestep', | Allow incremental writing of datasets into |
44+
| | 'member'} | the netCDF file |
45+
| | | the available options are: |
46+
| | | 'timestep' = write a forecast or a |
47+
| | | forecast ensemble for a given time step |
48+
| | | 'member' = write a forecast sequence |
49+
| | | for a given ensemble member |
50+
+-------------------+-------------------+------------------------------------------------+
51+
52+
The return value is a dictionary containing an exporter object. This can be
53+
used with export_forecast_dataset to write datasets into the netCDF file.
4054
41-
where xxx describes the file format. This function creates the file and writes
42-
the metadata. The datasets are written by calling export_forecast_dataset, and
43-
the file is closed by calling close_forecast_file."""
55+
"""
4456

4557
import numpy as np
4658
from datetime import datetime
@@ -57,19 +69,10 @@
5769

5870
# TODO: This is a draft version of the exporter. Revise the variable names and
5971
# the structure of the file if necessary.
60-
def initialize_forecast_exporter_netcdf(filename, startdate, timestep, num_timesteps,
61-
shape, num_ens_members, metadata,
62-
incremental=None):
63-
"""Initialize a netCDF forecast exporter.
64-
65-
Parameters
66-
----------
67-
See the module docstring.
68-
69-
Returns
70-
-------
71-
See the module docstring.
72-
"""
72+
def initialize_forecast_exporter_netcdf(filename, startdate, timestep,
73+
n_timesteps, shape, n_ens_members,
74+
metadata, incremental=None):
75+
"""Initialize a netCDF forecast exporter."""
7376
if not netcdf4_imported:
7477
raise Exception("netCDF4 not imported")
7578

@@ -80,9 +83,9 @@ def initialize_forecast_exporter_netcdf(filename, startdate, timestep, num_times
8083
raise ValueError("unknown option %s: incremental must be 'timestep' or 'member'" % incremental)
8184

8285
if incremental == "timestep":
83-
num_timesteps = None
86+
n_timesteps = None
8487
elif incremental == "member":
85-
num_ens_members = None
88+
n_ens_members = None
8689

8790
exporter = {}
8891

@@ -98,8 +101,8 @@ def initialize_forecast_exporter_netcdf(filename, startdate, timestep, num_times
98101

99102
h,w = shape
100103

101-
ncf.createDimension("ens_number", size=num_ens_members)
102-
ncf.createDimension("time", size=num_timesteps)
104+
ncf.createDimension("ens_number", size=n_ens_members)
105+
ncf.createDimension("time", size=n_timesteps)
103106
ncf.createDimension("y", size=h)
104107
ncf.createDimension("x", size=w)
105108

@@ -173,13 +176,13 @@ def initialize_forecast_exporter_netcdf(filename, startdate, timestep, num_times
173176

174177
var_ens_num = ncf.createVariable("ens_number", np.int, dimensions=("ens_number",))
175178
if incremental != "member":
176-
var_ens_num[:] = list(range(1, num_ens_members+1))
179+
var_ens_num[:] = list(range(1, n_ens_members+1))
177180
var_ens_num.long_name = "ensemble member"
178181
var_ens_num.units = ""
179182

180183
var_time = ncf.createVariable("time", np.int, dimensions=("time",))
181184
if incremental != "timestep":
182-
var_time[:] = [i*timestep*60 for i in range(1, num_timesteps+1)]
185+
var_time[:] = [i*timestep*60 for i in range(1, n_timesteps+1)]
183186
var_time.long_name = "forecast time"
184187
startdate_str = datetime.strftime(startdate, "%Y-%m-%d %H:%M:%S")
185188
var_time.units = "seconds since %s" % startdate_str
@@ -204,8 +207,8 @@ def initialize_forecast_exporter_netcdf(filename, startdate, timestep, num_times
204207
exporter["timestep"] = timestep
205208
exporter["metadata"] = metadata
206209
exporter["incremental"] = incremental
207-
exporter["num_timesteps"] = num_timesteps
208-
exporter["num_ens_members"] = num_ens_members
210+
exporter["num_timesteps"] = n_timesteps
211+
exporter["num_ens_members"] = n_ens_members
209212
exporter["shape"] = shape
210213

211214
return exporter

0 commit comments

Comments
 (0)