@@ -292,142 +292,17 @@ function Base.propertynames(model::RRTMGPModel, private::Bool = false)
292292 return private ? (names... , fieldnames (typeof (model))... ) : names
293293end
294294
295- """
296- lookup_tables(::AbstractRRTMGPMode, device, FloatType)
297-
298- Return a NamedTuple, containing
299- - RRTMGP lookup tables (varies by radiation mode)
300- - nbnd_lw
301- - nbnd_sw
302- - ngas_lw (absent for GrayRadiation)
303- - ngas_sw (absent for GrayRadiation)
304-
305- TODO:
306- - We should add type annotations for the data read from NC files as this will
307- improve inference and the return type of `lookup_tables`.
308- """
309- function lookup_tables end
310-
311- lookup_tables (
312- radiation_mode:: GrayRadiation ,
313- device:: ClimaComms.AbstractDevice ,
314- :: Type{FT} ,
315- ) where {FT} = (; lookups = (;), lu_kwargs = (; nbnd_lw = 1 , nbnd_sw = 1 ))
316-
317- function lookup_tables (
318- radiation_mode:: ClearSkyRadiation ,
319- device:: ClimaComms.AbstractDevice ,
320- :: Type{FT} ,
321- ) where {FT}
322- DA = ClimaComms. array_type (device)
323- # turn kwargs into a Dict, so that values can be dynamically popped from it
324-
325- artifact (t, b, n) =
326- NC. Dataset (RRTMGP. ArtifactPaths. get_lookup_filename (t, b)) do ds
327- getproperty (RRTMGP. LookUpTables, n)(ds, FT, DA)
328- end
329- lookup_lw, idx_gases_lw = artifact (:gas , :lw , :LookUpLW )
330-
331- nbnd_lw = RRTMGP. LookUpTables. get_n_bnd (lookup_lw)
332- ngas_lw = RRTMGP. LookUpTables. get_n_gases (lookup_lw)
333-
334- lookup_lw_aero, idx_aerosol_lw, idx_aerosize_lw =
335- if radiation_mode. aerosol_radiation
336- artifact (:aerosol , :lw , :LookUpAerosolMerra )
337- else
338- (nothing , nothing , nothing )
339- end
340-
341- lookup_sw, idx_gases_sw = artifact (:gas , :sw , :LookUpSW )
342-
343- nbnd_sw = RRTMGP. LookUpTables. get_n_bnd (lookup_sw)
344- ngas_sw = RRTMGP. LookUpTables. get_n_gases (lookup_sw)
345-
346- lookup_sw_aero, idx_aerosol_sw, idx_aerosize_sw =
347- if radiation_mode. aerosol_radiation
348- artifact (:aerosol , :sw , :LookUpAerosolMerra )
349- else
350- (nothing , nothing , nothing )
351- end
352-
353- lookups = (;
354- idx_aerosize_lw,
355- idx_aerosize_sw,
356- idx_aerosol_lw,
357- idx_aerosol_sw,
358- idx_gases_lw,
359- idx_gases_sw,
360- lookup_lw,
361- lookup_lw_aero,
362- lookup_sw,
363- lookup_sw_aero,
295+ get_radiation_method (m:: GrayRadiation ) = RRTMGP. GrayRadiation ()
296+ get_radiation_method (m:: ClearSkyRadiation ) =
297+ RRTMGP. ClearSkyRadiation (m. aerosol_radiation)
298+ get_radiation_method (m:: AllSkyRadiation ) =
299+ RRTMGP. AllSkyRadiation (m. aerosol_radiation, m. reset_rng_seed)
300+ get_radiation_method (m:: AllSkyRadiationWithClearSkyDiagnostics ) =
301+ RRTMGP. AllSkyRadiationWithClearSkyDiagnostics (
302+ m. aerosol_radiation,
303+ m. reset_rng_seed,
364304 )
365305
366- @assert RRTMGP. LookUpTables. get_n_gases (lookup_lw) ==
367- RRTMGP. LookUpTables. get_n_gases (lookup_sw)
368- @assert lookup_lw. p_ref_min == lookup_sw. p_ref_min
369- return (; lookups, lu_kwargs = (; nbnd_lw, ngas_lw, nbnd_sw, ngas_sw))
370- end
371-
372- function lookup_tables (
373- radiation_mode:: Union {
374- AllSkyRadiation,
375- AllSkyRadiationWithClearSkyDiagnostics,
376- },
377- device:: ClimaComms.AbstractDevice ,
378- :: Type{FT} ,
379- ) where {FT}
380- DA = ClimaComms. array_type (device)
381- # turn kwargs into a Dict, so that values can be dynamically popped from it
382-
383- artifact (t, b, n) =
384- NC. Dataset (RRTMGP. ArtifactPaths. get_lookup_filename (t, b)) do ds
385- getproperty (RRTMGP. LookUpTables, n)(ds, FT, DA)
386- end
387- lookup_lw, idx_gases_lw = artifact (:gas , :lw , :LookUpLW )
388- lookup_lw_cld = artifact (:cloud , :lw , :LookUpCld )
389- lookup_lw_aero, idx_aerosol_lw, idx_aerosize_lw =
390- if radiation_mode. aerosol_radiation
391- artifact (:aerosol , :lw , :LookUpAerosolMerra )
392- else
393- (nothing , nothing , nothing )
394- end
395- lookup_sw, idx_gases_sw = artifact (:gas , :sw , :LookUpSW )
396- lookup_sw_cld = artifact (:cloud , :sw , :LookUpCld )
397-
398- lookup_sw_aero, idx_aerosol_sw, idx_aerosize_sw =
399- if radiation_mode. aerosol_radiation
400- artifact (:aerosol , :sw , :LookUpAerosolMerra )
401- else
402- (nothing , nothing , nothing )
403- end
404-
405- nbnd_lw = RRTMGP. LookUpTables. get_n_bnd (lookup_lw)
406- ngas_lw = RRTMGP. LookUpTables. get_n_gases (lookup_lw)
407- nbnd_sw = RRTMGP. LookUpTables. get_n_bnd (lookup_sw)
408- ngas_sw = RRTMGP. LookUpTables. get_n_gases (lookup_sw)
409-
410- lookups = (;
411- idx_aerosize_lw,
412- idx_aerosize_sw,
413- idx_aerosol_lw,
414- idx_aerosol_sw,
415- idx_gases_lw,
416- idx_gases_sw,
417- lookup_lw,
418- lookup_lw_aero,
419- lookup_lw_cld,
420- lookup_sw,
421- lookup_sw_aero,
422- lookup_sw_cld,
423- )
424-
425- @assert RRTMGP. LookUpTables. get_n_gases (lookup_lw) ==
426- RRTMGP. LookUpTables. get_n_gases (lookup_sw)
427- @assert lookup_lw. p_ref_min == lookup_sw. p_ref_min
428- return (; lookups, lu_kwargs = (; nbnd_lw, ngas_lw, nbnd_sw, ngas_sw))
429- end
430-
431306"""
432307 RRTMGPModel(params; kwargs...)
433308
@@ -603,7 +478,8 @@ function _RRTMGPModel(
603478 pressures/temperatures are specified" )
604479 end
605480
606- (; lookups, lu_kwargs) = lookup_tables (radiation_mode, device, FT)
481+ radiation_method = get_radiation_method (radiation_mode)
482+ (; lookups, lu_kwargs) = RRTMGP. lookup_tables (grid_params, radiation_method)
607483 views = []
608484
609485 t = (views, domain_nlay)
0 commit comments