Skip to content

Commit bb2b2cf

Browse files
committed
Added disc_on kwarg through cli to all_sky
1 parent 8a55011 commit bb2b2cf

File tree

3 files changed

+56
-37
lines changed

3 files changed

+56
-37
lines changed

nsrdb/all_sky/all_sky.py

+25-24
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
def all_sky(alpha, aod, asymmetry, cloud_type, cld_opd_dcomp, cld_reff_dcomp,
5050
ozone, solar_zenith_angle, ssa, surface_albedo, surface_pressure,
5151
time_index, total_precipitable_water, cloud_fill_flag=None,
52-
variability_kwargs=None, scale_outputs=True, farmsdni=True):
52+
variability_kwargs=None, scale_outputs=True, disc_on=False):
5353
"""Calculate the all-sky irradiance.
5454
Updated by Yu Xie on 3/29/2023 to compute DNI by FARMS-DNI.
5555
@@ -109,8 +109,8 @@ def all_sky(alpha, aod, asymmetry, cloud_type, cld_opd_dcomp, cld_reff_dcomp,
109109
nsrdb.all_sky.utilities.cloud_variability for kwarg definitions.
110110
scale_outputs : bool
111111
Flag to safely scale and dtype convert output arrays.
112-
farmsdni : bool
113-
Compute cloudy-sky DNI using FARMS-DNI (True) or DISC (False).
112+
disc_on : bool
113+
Compute cloudy-sky DNI using FARMS-DNI (False) or DISC (True).
114114
115115
Returns
116116
-------
@@ -163,16 +163,15 @@ def all_sky(alpha, aod, asymmetry, cloud_type, cld_opd_dcomp, cld_reff_dcomp,
163163

164164
# use FARMS to calculate cloudy GHI
165165
ghi, dni_farmsdni, _ = farms(tau=cld_opd_dcomp,
166-
cloud_type=cloud_type,
167-
cloud_effective_radius=cld_reff_dcomp,
168-
solar_zenith_angle=solar_zenith_angle,
169-
radius=radius,
170-
Tuuclr=Tuuclr,
171-
Ruuclr=rest_data.Ruuclr,
172-
Tddclr=rest_data.Tddclr,
173-
Tduclr=rest_data.Tduclr,
174-
albedo=surface_albedo,
175-
)
166+
cloud_type=cloud_type,
167+
cloud_effective_radius=cld_reff_dcomp,
168+
solar_zenith_angle=solar_zenith_angle,
169+
radius=radius,
170+
Tuuclr=Tuuclr,
171+
Ruuclr=rest_data.Ruuclr,
172+
Tddclr=rest_data.Tddclr,
173+
Tduclr=rest_data.Tduclr,
174+
albedo=surface_albedo)
176175

177176
# merge the clearsky and cloudy irradiance into all-sky irradiance
178177
ghi = merge_rest_farms(rest_data.ghi, ghi, cloud_type)
@@ -182,16 +181,13 @@ def all_sky(alpha, aod, asymmetry, cloud_type, cld_opd_dcomp, cld_reff_dcomp,
182181
ghi = cloud_variability(ghi, rest_data.ghi, cloud_type,
183182
**variability_kwargs)
184183

185-
# calculate the DNI using the DISC model
186-
dni = disc(ghi, solar_zenith_angle, doy=time_index.dayofyear.values,
187-
pressure=surface_pressure)
188-
189184
# merge the clearsky and cloudy irradiance into all-sky irradiance
190-
#
191-
if farmsdni:
192-
dni = merge_rest_farms(rest_data.dni, dni_farmsdni, cloud_type)
193-
else:
185+
if disc_on:
186+
dni = disc(ghi, solar_zenith_angle, doy=time_index.dayofyear.values,
187+
pressure=surface_pressure)
194188
dni = merge_rest_farms(rest_data.dni, dni, cloud_type)
189+
else:
190+
dni = merge_rest_farms(rest_data.dni, dni_farmsdni, cloud_type)
195191

196192
# make a fill flag where bad data exists in the GHI irradiance
197193
fill_flag = make_fill_flag(ghi, rest_data.ghi, cloud_type, missing_props,
@@ -239,7 +235,7 @@ def all_sky(alpha, aod, asymmetry, cloud_type, cld_opd_dcomp, cld_reff_dcomp,
239235
return output
240236

241237

242-
def all_sky_h5(f_source, rows=slice(None), cols=slice(None)):
238+
def all_sky_h5(f_source, rows=slice(None), cols=slice(None), disc_on=False):
243239
"""Run all-sky from .h5 files.
244240
245241
Parameters
@@ -251,6 +247,8 @@ def all_sky_h5(f_source, rows=slice(None), cols=slice(None)):
251247
Subset of rows to run.
252248
cols : slice
253249
Subset of columns to run.
250+
disc_on : bool
251+
Compute cloudy sky dni with disc model or farms-dni model.
254252
255253
Returns
256254
-------
@@ -275,6 +273,7 @@ def all_sky_h5(f_source, rows=slice(None), cols=slice(None)):
275273
all_sky_input = {dset: source[dset, rows, cols]
276274
for dset in ALL_SKY_ARGS}
277275
all_sky_input['time_index'] = source.time_index[rows].tz_convert(None)
276+
all_sky_input['disc_on'] = disc_on
278277

279278
try:
280279
out = all_sky(**all_sky_input)
@@ -286,7 +285,7 @@ def all_sky_h5(f_source, rows=slice(None), cols=slice(None)):
286285

287286

288287
def all_sky_h5_parallel(f_source, rows=slice(None), cols=slice(None),
289-
col_chunk=10, max_workers=None):
288+
col_chunk=10, max_workers=None, disc_on=False):
290289
"""Run all-sky from .h5 files.
291290
292291
Parameters
@@ -304,6 +303,8 @@ def all_sky_h5_parallel(f_source, rows=slice(None), cols=slice(None),
304303
significantly faster.
305304
max_workers : int | None
306305
Number of workers to run in parallel.
306+
disc_on : bool
307+
Compute cloudy sky dni with disc model or farms-dni model.
307308
308309
Returns
309310
-------
@@ -361,7 +362,7 @@ def all_sky_h5_parallel(f_source, rows=slice(None), cols=slice(None),
361362

362363
loggers = ['farms', 'nsrdb', 'rest2', 'rex']
363364
with SpawnProcessPool(max_workers=max_workers, loggers=loggers) as exe:
364-
futures = {exe.submit(all_sky_h5, f_source, rows=rows,
365+
futures = {exe.submit(all_sky_h5, f_source, rows=rows, disc_on=disc_on,
365366
cols=c_slices_all[c]): c for c in c_range}
366367

367368
for future in as_completed(futures):

nsrdb/cli.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -930,8 +930,11 @@ def ml_cloud_fill(ctx, date, fill_all, model_path, col_chunk, max_workers):
930930
help='Chunking method to run all sky one column chunk at a time '
931931
'to reduce memory requirements. This is an integer specifying '
932932
'how many columns to work on at one time.')
933+
@click.option('--disc_on', '-do', type=bool, required=False, default=False,
934+
help='Whether to run compute cloudy sky dni with the disc model '
935+
'(True) or the farms-dni model (False).')
933936
@click.pass_context
934-
def all_sky(ctx, i_chunk, col_chunk):
937+
def all_sky(ctx, i_chunk, col_chunk, disc_on):
935938
"""Run allsky for a single chunked file"""
936939

937940
name = ctx.obj['NAME']
@@ -945,9 +948,9 @@ def all_sky(ctx, i_chunk, col_chunk):
945948
log_file = 'all_sky/all_sky_{}.log'.format(i_chunk)
946949
fun_str = 'NSRDB.run_all_sky'
947950
arg_str = ('"{}", {}, "{}", freq="{}", i_chunk={}, col_chunk={}, '
948-
'log_file="{}", log_level="{}", job_name="{}"'
951+
'disc_on={}, log_file="{}", log_level="{}", job_name="{}"'
949952
.format(out_dir, year, nsrdb_grid, nsrdb_freq, i_chunk,
950-
col_chunk, log_file, log_level, name))
953+
col_chunk, disc_on, log_file, log_level, name))
951954
if var_meta is not None:
952955
arg_str += ', var_meta="{}"'.format(var_meta)
953956
ctx.obj['IMPORT_STR'] = 'from nsrdb.nsrdb import NSRDB'
@@ -964,8 +967,11 @@ def all_sky(ctx, i_chunk, col_chunk):
964967
help='Chunking method to run all sky one column chunk at a time '
965968
'to reduce memory requirements. This is an integer specifying '
966969
'how many columns to work on at one time.')
970+
@click.option('--disc_on', '-do', type=bool, required=False, default=False,
971+
help='Whether to run compute cloudy sky dni with the disc model '
972+
'(True) or the farms-dni model (False).')
967973
@click.pass_context
968-
def daily_all_sky(ctx, date, col_chunk):
974+
def daily_all_sky(ctx, date, col_chunk, disc_on):
969975
"""Run allsky for a single day using daily data model output files as
970976
source data"""
971977

@@ -979,10 +985,10 @@ def daily_all_sky(ctx, date, col_chunk):
979985

980986
log_file = 'all_sky/all_sky_{}.log'.format(date)
981987
fun_str = 'NSRDB.run_daily_all_sky'
982-
arg_str = ('"{}", {}, "{}", "{}", freq="{}", col_chunk={}, '
988+
arg_str = ('"{}", {}, "{}", "{}", freq="{}", col_chunk={}, disc_on={}, '
983989
'log_file="{}", log_level="{}", job_name="{}"'
984990
.format(out_dir, year, nsrdb_grid, date, nsrdb_freq, col_chunk,
985-
log_file, log_level, name))
991+
disc_on, log_file, log_level, name))
986992
if var_meta is not None:
987993
arg_str += ', var_meta="{}"'.format(var_meta)
988994
ctx.obj['IMPORT_STR'] = 'from nsrdb.nsrdb import NSRDB'

nsrdb/nsrdb.py

+19-7
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,8 @@ def ml_cloud_fill(cls, out_dir, date, fill_all=False,
14051405
def run_all_sky(cls, out_dir, year, grid, freq='5min', var_meta=None,
14061406
col_chunk=10, rows=slice(None), cols=slice(None),
14071407
max_workers=None, log_level='DEBUG',
1408-
log_file='all_sky.log', i_chunk=None, job_name=None):
1408+
log_file='all_sky.log', i_chunk=None, job_name=None,
1409+
disc_on=False):
14091410
"""Run the all-sky physics model from collected .h5 files
14101411
14111412
Parameters
@@ -1442,6 +1443,9 @@ def run_all_sky(cls, out_dir, year, grid, freq='5min', var_meta=None,
14421443
Enumerated file index if running on site chunk.
14431444
job_name : str
14441445
Optional name for pipeline and status identification.
1446+
disc_on : bool
1447+
Compute cloudy sky dni with the disc model (True) or the farms-dni
1448+
model (False)
14451449
"""
14461450
t0 = time.time()
14471451
nsrdb = cls(out_dir, year, grid, freq=freq, var_meta=var_meta)
@@ -1476,10 +1480,10 @@ def run_all_sky(cls, out_dir, year, grid, freq='5min', var_meta=None,
14761480
if max_workers != 1:
14771481
out = all_sky_h5_parallel(f_source, rows=rows, cols=cols,
14781482
max_workers=max_workers,
1479-
col_chunk=col_chunk)
1483+
col_chunk=col_chunk, disc_on=disc_on)
14801484
else:
14811485
out = all_sky_h5(f_source, rows=rows, cols=cols,
1482-
col_chunk=col_chunk)
1486+
col_chunk=col_chunk, disc_on=disc_on)
14831487

14841488
logger.info('Finished all-sky. Writing to: {}'.format(f_out))
14851489
with Outputs(f_out, mode='a') as f:
@@ -1511,7 +1515,8 @@ def run_daily_all_sky(cls, out_dir, year, grid, date, freq='5min',
15111515
var_meta=None, col_chunk=500,
15121516
rows=slice(None), cols=slice(None),
15131517
max_workers=None, log_level='DEBUG',
1514-
log_file='all_sky.log', job_name=None):
1518+
log_file='all_sky.log', job_name=None,
1519+
disc_on=False):
15151520
"""Run the all-sky physics model from daily data model output files.
15161521
15171522
Parameters
@@ -1549,6 +1554,9 @@ def run_daily_all_sky(cls, out_dir, year, grid, date, freq='5min',
15491554
File to log to. Will be put in output directory.
15501555
job_name : str
15511556
Optional name for pipeline and status identification.
1557+
disc_on : bool
1558+
Compute cloudy sky dni with the disc model (True) or the farms-dni
1559+
model (False)
15521560
"""
15531561
t0 = time.time()
15541562
assert len(str(date)) == 8
@@ -1564,9 +1572,9 @@ def run_daily_all_sky(cls, out_dir, year, grid, date, freq='5min',
15641572
if max_workers != 1:
15651573
out = all_sky_h5_parallel(f_source, rows=rows, cols=cols,
15661574
max_workers=max_workers,
1567-
col_chunk=col_chunk)
1575+
col_chunk=col_chunk, disc_on=disc_on)
15681576
else:
1569-
out = all_sky_h5(f_source, rows=rows, cols=cols)
1577+
out = all_sky_h5(f_source, rows=rows, cols=cols, disc_on=disc_on)
15701578

15711579
logger.info('Finished all-sky compute.')
15721580
for dset, arr in out.items():
@@ -1597,7 +1605,7 @@ def run_daily_all_sky(cls, out_dir, year, grid, date, freq='5min',
15971605
def run_full(cls, date, grid, freq, var_meta=None, factory_kwargs=None,
15981606
fill_all=False, model_path=None, dist_lim=1.0,
15991607
max_workers=None, low_mem=False,
1600-
log_file=None, log_level='INFO'):
1608+
log_file=None, log_level='INFO', disc_on=False):
16011609
"""Run the full nsrdb pipeline in-memory using serial compute.
16021610
16031611
Parameters
@@ -1648,6 +1656,9 @@ def run_full(cls, date, grid, freq, var_meta=None, factory_kwargs=None,
16481656
initialized.
16491657
log_file : str
16501658
File to log to. Will be put in output directory.
1659+
disc_on : bool
1660+
Compute cloudy sky dni with the disc model (True) or the farms-dni
1661+
model (False)
16511662
16521663
Returns
16531664
-------
@@ -1693,6 +1704,7 @@ def run_full(cls, date, grid, freq, var_meta=None, factory_kwargs=None,
16931704
if k in ALL_SKY_ARGS}
16941705
all_sky_inputs['time_index'] = data_model.nsrdb_ti
16951706
all_sky_inputs['scale_outputs'] = False
1707+
all_sky_inputs['disc_on'] = disc_on
16961708
logger.info('Running NSRDB All-Sky.')
16971709
all_sky_out = all_sky(**all_sky_inputs)
16981710
for k, v in all_sky_out.items():

0 commit comments

Comments
 (0)