4
4
Each exporter method in this module has its own initialization function that
5
5
implements the following interface:
6
6
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)
9
9
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.
34
13
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.
40
54
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
+ """
44
56
45
57
import numpy as np
46
58
from datetime import datetime
57
69
58
70
# TODO: This is a draft version of the exporter. Revise the variable names and
59
71
# 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."""
73
76
if not netcdf4_imported :
74
77
raise Exception ("netCDF4 not imported" )
75
78
@@ -80,9 +83,9 @@ def initialize_forecast_exporter_netcdf(filename, startdate, timestep, num_times
80
83
raise ValueError ("unknown option %s: incremental must be 'timestep' or 'member'" % incremental )
81
84
82
85
if incremental == "timestep" :
83
- num_timesteps = None
86
+ n_timesteps = None
84
87
elif incremental == "member" :
85
- num_ens_members = None
88
+ n_ens_members = None
86
89
87
90
exporter = {}
88
91
@@ -98,8 +101,8 @@ def initialize_forecast_exporter_netcdf(filename, startdate, timestep, num_times
98
101
99
102
h ,w = shape
100
103
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 )
103
106
ncf .createDimension ("y" , size = h )
104
107
ncf .createDimension ("x" , size = w )
105
108
@@ -173,13 +176,13 @@ def initialize_forecast_exporter_netcdf(filename, startdate, timestep, num_times
173
176
174
177
var_ens_num = ncf .createVariable ("ens_number" , np .int , dimensions = ("ens_number" ,))
175
178
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 ))
177
180
var_ens_num .long_name = "ensemble member"
178
181
var_ens_num .units = ""
179
182
180
183
var_time = ncf .createVariable ("time" , np .int , dimensions = ("time" ,))
181
184
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 )]
183
186
var_time .long_name = "forecast time"
184
187
startdate_str = datetime .strftime (startdate , "%Y-%m-%d %H:%M:%S" )
185
188
var_time .units = "seconds since %s" % startdate_str
@@ -204,8 +207,8 @@ def initialize_forecast_exporter_netcdf(filename, startdate, timestep, num_times
204
207
exporter ["timestep" ] = timestep
205
208
exporter ["metadata" ] = metadata
206
209
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
209
212
exporter ["shape" ] = shape
210
213
211
214
return exporter
0 commit comments