34
34
'meta_dir' : DEFAULT_META_DIR ,
35
35
}
36
36
37
- MAIN_KWARGS = {
38
- ** BASE_KWARGS ,
39
- 'extent' : 'full' ,
40
- 'satellite' : 'east' ,
37
+ MAIN_KWARGS = {** BASE_KWARGS , 'extent' : 'full' , 'satellite' : 'east' }
38
+
39
+ SURFRAD_KWARGS = {
40
+ ** MAIN_KWARGS ,
41
+ 'freq' : '15min' ,
42
+ 'spatial' : '4km' ,
41
43
}
42
44
43
45
BLEND_KWARGS = {
47
49
'main_dir' : '../' ,
48
50
}
49
51
50
- COLLECT_BLEND_KWARGS = {
51
- ** BASE_KWARGS ,
52
- 'extent' : 'full' ,
53
- }
52
+ COLLECT_BLEND_KWARGS = {** BASE_KWARGS , 'extent' : 'full' }
54
53
55
54
AGG_KWARGS = {
56
55
** BASE_KWARGS ,
62
61
'conus_freq' : '5min' ,
63
62
'final_freq' : '30min' ,
64
63
'n_chunks' : 32 ,
65
- 'source_priority' : ['conus' , 'full_disk ' ],
64
+ 'source_priority' : ['conus' , 'full_disc ' ],
66
65
}
67
66
68
67
COLLECT_AGG_KWARGS = {
@@ -102,14 +101,16 @@ class CreateConfigs:
102
101
standard CONUS / Full Disc runs."""
103
102
104
103
MAIN_RUN_NAME = '{basename}_{satellite}_{extent}_{year}_{spatial}_{freq}'
104
+ SURFRAD_RUN_NAME = '{basename}_{year}_surfrad'
105
105
BLEND_RUN_NAME = '{basename}_{extent}_{year}_blend'
106
106
AGG_RUN_NAME = '{basename}_{year}_aggregate'
107
107
COLLECT_AGG_RUN_NAME = '{basename}_{year}_collect_aggregate'
108
108
COLLECT_BLEND_RUN_NAME = '{basename}_{extent}_{year}_collect_blend'
109
109
110
110
@classmethod
111
- def _init_kwargs (cls , kwargs , default_kwargs ):
111
+ def init_kwargs (cls , kwargs = None , default_kwargs = None ):
112
112
"""Initialize config with default kwargs."""
113
+ default_kwargs = default_kwargs or {}
113
114
msg = f'kwargs must have a "year" key. Received { kwargs } .'
114
115
assert 'year' in kwargs , msg
115
116
config = copy .deepcopy (default_kwargs )
@@ -211,6 +212,7 @@ def _get_run_name(cls, config, run_type='main'):
211
212
{k : v for k , v in BASE_KWARGS .items () if k not in config }
212
213
)
213
214
pattern_dict = {
215
+ 'surfrad' : cls .SURFRAD_RUN_NAME ,
214
216
'main' : cls .MAIN_RUN_NAME ,
215
217
'blend' : cls .BLEND_RUN_NAME ,
216
218
'aggregate' : cls .AGG_RUN_NAME ,
@@ -227,7 +229,7 @@ def _get_run_name(cls, config, run_type='main'):
227
229
return pattern .format (** run_config )
228
230
229
231
@classmethod
230
- def _update_run_templates (cls , config ):
232
+ def _update_run_templates (cls , config , run_type = 'main' ):
231
233
"""Replace format keys and dictionary keys in config templates with
232
234
user input values."""
233
235
@@ -236,6 +238,17 @@ def _update_run_templates(cls, config):
236
238
f'{ pprint .pformat (config , indent = 2 )} '
237
239
)
238
240
241
+ config ['doy_range' ] = config .get (
242
+ 'doy_range' ,
243
+ ([1 , 367 ] if calendar .isleap (config ['year' ]) else [1 , 366 ]),
244
+ )
245
+ config ['start_doy' ], config ['end_doy' ] = (
246
+ config ['doy_range' ][0 ],
247
+ config ['doy_range' ][1 ],
248
+ )
249
+ config ['run_name' ] = cls ._get_run_name (config , run_type = run_type )
250
+ config ['out_dir' ] = os .path .join (config ['out_dir' ], config ['run_name' ])
251
+
239
252
template = (
240
253
PRE2018_CONFIG_TEMPLATE
241
254
if int (config ['year' ]) < 2018
@@ -263,6 +276,22 @@ def _update_run_templates(cls, config):
263
276
config_dict , cls ._get_config_file (config , 'pipeline' )
264
277
)
265
278
279
+ run_file = os .path .join (config ['out_dir' ], 'run.sh' )
280
+ with open (run_file , 'w' ) as f :
281
+ f .write ('python -m nsrdb.cli pipeline -c config_pipeline.json' )
282
+
283
+ logger .info (f'Saved run script: { run_file } .' )
284
+
285
+ @classmethod
286
+ def surfrad (cls , kwargs ):
287
+ """Get basic config template specified parameters replaced."""
288
+ config = cls .init_kwargs (kwargs , SURFRAD_KWARGS )
289
+ config ['extent_tag' ] = EXTENT_MAP ['extent_tag' ][config ['extent' ]]
290
+ config ['meta_file' ] = os .path .join (
291
+ config ['meta_dir' ], 'surfrad_meta.csv'
292
+ )
293
+ cls ._update_run_templates (config , run_type = 'surfrad' )
294
+
266
295
@classmethod
267
296
def main (cls , kwargs ):
268
297
"""Modify config files with specified parameters
@@ -273,7 +302,7 @@ def main(cls, kwargs):
273
302
Dictionary of parameters including year, basename, satellite,
274
303
extent, freq, spatial, meta_file, doy_range
275
304
"""
276
- config = cls ._init_kwargs (kwargs , MAIN_KWARGS )
305
+ config = cls .init_kwargs (kwargs , MAIN_KWARGS )
277
306
msg = (
278
307
'"extent" key not provided. Provide "extent" so correct input '
279
308
'data can be selected'
@@ -284,27 +313,8 @@ def main(cls, kwargs):
284
313
config ['meta_file' ] = cls ._get_meta (config )
285
314
config ['spatial' ], config ['freq' ] = cls ._get_res (config )
286
315
287
- config ['doy_range' ] = config .get (
288
- 'doy_range' ,
289
- ([1 , 367 ] if calendar .isleap (config ['year' ]) else [1 , 366 ]),
290
- )
291
-
292
- config ['start_doy' ], config ['end_doy' ] = (
293
- config ['doy_range' ][0 ],
294
- config ['doy_range' ][1 ],
295
- )
296
-
297
- config ['run_name' ] = cls ._get_run_name (config )
298
- config ['out_dir' ] = os .path .join (config ['out_dir' ], config ['run_name' ])
299
-
300
316
cls ._update_run_templates (config )
301
317
302
- run_file = os .path .join (config ['out_dir' ], 'run.sh' )
303
- with open (run_file , 'w' ) as f :
304
- f .write ('python -m nsrdb.cli pipeline -c config_pipeline.json' )
305
-
306
- logger .info (f'Saved run script: { run_file } .' )
307
-
308
318
@classmethod
309
319
def main_all (cls , kwargs ):
310
320
"""Modify config files for all domains with specified parameters.
@@ -463,7 +473,7 @@ def _get_agg_entry(cls, config, extent):
463
473
464
474
@classmethod
465
475
def _aggregate (cls , kwargs ):
466
- """Get config for conus and full disk high-resolution to low-resolution
476
+ """Get config for conus and full disc high-resolution to low-resolution
467
477
aggregation. This is then used as the input to `nsrdb.cli.aggregate`
468
478
469
479
Parameters
@@ -472,14 +482,14 @@ def _aggregate(cls, kwargs):
472
482
Dictionary with keys specifying the case for which to aggregate
473
483
files
474
484
"""
475
- config = cls ._init_kwargs (kwargs , AGG_KWARGS )
485
+ config = cls .init_kwargs (kwargs , AGG_KWARGS )
476
486
477
487
if config ['year' ] == 2018 :
478
488
data = NSRDB_2018
479
489
480
490
else :
481
491
data = {
482
- 'full_disk ' : cls ._get_agg_entry (config , extent = 'full' ),
492
+ 'full_disc ' : cls ._get_agg_entry (config , extent = 'full' ),
483
493
'conus' : cls ._get_agg_entry (config , extent = 'conus' ),
484
494
'final' : cls ._get_agg_entry (config , extent = 'final' ),
485
495
}
@@ -490,7 +500,7 @@ def _aggregate(cls, kwargs):
490
500
491
501
@classmethod
492
502
def aggregate (cls , kwargs ):
493
- """Get config for conus and full disk high-resolution to low-resolution
503
+ """Get config for conus and full disc high-resolution to low-resolution
494
504
aggregation. This is then used as the input to `nsrdb.cli.aggregate`
495
505
496
506
Parameters
@@ -521,7 +531,7 @@ def _blend(cls, kwargs):
521
531
Dictionary with keys specifying the case for which to blend data
522
532
files
523
533
"""
524
- config = cls ._init_kwargs (kwargs , BLEND_KWARGS )
534
+ config = cls .init_kwargs (kwargs , BLEND_KWARGS )
525
535
config ['map_col' ] = EXTENT_MAP ['map_col' ][config ['extent' ]]
526
536
config ['lon_seam' ] = EXTENT_MAP ['lon_seam' ][config ['extent' ]]
527
537
config ['meta_file' ] = cls ._get_meta (config , run_type = 'blend' )
@@ -599,7 +609,7 @@ def _collect_blend(cls, kwargs):
599
609
Dictionary with keys specifying the case for blend collection
600
610
"""
601
611
602
- config = cls ._init_kwargs (kwargs , COLLECT_BLEND_KWARGS )
612
+ config = cls .init_kwargs (kwargs , COLLECT_BLEND_KWARGS )
603
613
config ['meta_final' ] = cls ._get_meta (config , run_type = 'collect-blend' )
604
614
config ['collect_dir' ] = cls ._get_run_name (config , run_type = 'blend' )
605
615
config ['collect_tag' ] = config ['collect_dir' ].replace ('_blend' , '' )
@@ -650,7 +660,7 @@ def _collect_aggregate(cls, kwargs):
650
660
kwargs : dict
651
661
Dictionary with keys specifying the case for aggregation collection
652
662
"""
653
- config = cls ._init_kwargs (kwargs , COLLECT_AGG_KWARGS )
663
+ config = cls .init_kwargs (kwargs , COLLECT_AGG_KWARGS )
654
664
655
665
config ['meta_final' ] = cls ._get_meta (
656
666
config , run_type = 'collect-aggregate'
0 commit comments