def test_heterogeneous_single(modes_all_single, components, bin_set, path_to_ussa76_approx_data): """ Unit tests for a HeterogeneousAtmosphere with a single component. """ # Construct succeeds if components == "molecular": if eradiate.mode().has_flags(ModeFlags.ANY_MONO): component = MolecularAtmosphere.ussa1976(absorption_data_sets={ "us76_u86_4": path_to_ussa76_approx_data }, ) elif eradiate.mode().has_flags(ModeFlags.ANY_CKD): component = MolecularAtmosphere.afgl_1986() else: pytest.skip(f"unsupported mode '{eradiate.mode().id}'") atmosphere = HeterogeneousAtmosphere(molecular_atmosphere=component) else: component = ParticleLayer() atmosphere = HeterogeneousAtmosphere(particle_layers=[component]) # Produced kernel dict can be loaded ctx = KernelDictContext(spectral_ctx=CKDSpectralContext(bin_set=bin_set)) assert atmosphere.kernel_dict(ctx).load()
def test_heterogeneous_multi(modes_all_single, bin_set, path_to_ussa76_approx_data): """ Unit tests for a HeterogeneousAtmosphere with multiple (2+) components. """ # Construct succeeds if eradiate.mode().has_flags(ModeFlags.ANY_MONO): molecular_atmosphere = MolecularAtmosphere.ussa1976( absorption_data_sets={"us76_u86_4": path_to_ussa76_approx_data}, ) elif eradiate.mode().has_flags(ModeFlags.ANY_CKD): molecular_atmosphere = MolecularAtmosphere.afgl_1986() else: pytest.skip(f"unsupported mode '{eradiate.mode().id}'") atmosphere = HeterogeneousAtmosphere( molecular_atmosphere=molecular_atmosphere, particle_layers=[ParticleLayer() for _ in range(2)], ) # Radiative property metadata are correct ctx = KernelDictContext(spectral_ctx=CKDSpectralContext(bin_set=bin_set)) # Kernel dict production succeeds assert atmosphere.kernel_phase(ctx) assert atmosphere.kernel_media(ctx) assert atmosphere.kernel_shapes(ctx) # Produced kernel dict can be loaded kernel_dict = atmosphere.kernel_dict(ctx) assert kernel_dict.load()
def test_heterogeneous_blend_switches(mode_mono): # Rayleigh-only atmosphere + particle layer combination works assert HeterogeneousAtmosphere( molecular_atmosphere=MolecularAtmosphere.ussa1976(has_absorption=False, has_scattering=True), particle_layers=[ParticleLayer()], ) # Purely absorbing atmosphere + particle layer combination is not allowed with pytest.raises(ValueError): HeterogeneousAtmosphere( molecular_atmosphere=MolecularAtmosphere.ussa1976( has_absorption=True, has_scattering=False), particle_layers=[ParticleLayer()], )
def test_molecular_atmosphere_default(mode_mono, tmpdir, ussa76_approx_test_absorption_data_set): """Default MolecularAtmosphere constructor produces a valid kernel dictionary.""" spectral_ctx = SpectralContext.new(wavelength=550.0) ctx = KernelDictContext(spectral_ctx=spectral_ctx) atmosphere = MolecularAtmosphere(absorption_data_sets=dict( us76_u86_4=ussa76_approx_test_absorption_data_set)) assert KernelDict.from_elements(atmosphere, ctx=ctx).load() is not None
def test_heterogeneous_scale(mode_mono, path_to_ussa76_approx_data): ctx = KernelDictContext() d = HeterogeneousAtmosphere( molecular_atmosphere=MolecularAtmosphere.ussa1976( absorption_data_sets={"us76_u86_4": path_to_ussa76_approx_data}, ), particle_layers=[ParticleLayer() for _ in range(2)], scale=2.0, ).kernel_dict(ctx) assert d["medium_atmosphere"]["scale"] == 2.0 assert d.load()
def test_molecular_atmosphere_afgl_1986( mode_mono, tmpdir, afgl_1986_test_absorption_data_sets, ): """MolecularAtmosphere 'afgl_1986' constructor produces a valid kernel dictionary.""" spectral_ctx = SpectralContext.new(wavelength=550.0) ctx = KernelDictContext(spectral_ctx=spectral_ctx) atmosphere = MolecularAtmosphere.afgl_1986( absorption_data_sets=afgl_1986_test_absorption_data_sets) assert KernelDict.from_elements(atmosphere, ctx=ctx).load() is not None
def test_onedim_experiment_ckd(mode_ckd, bin_set): """ OneDimExperiment with heterogeneous atmosphere in CKD mode can be created. """ ctx = KernelDictContext(spectral_ctx=CKDSpectralContext(bin_set=bin_set)) exp = OneDimExperiment( atmosphere=HeterogeneousAtmosphere( molecular_atmosphere=MolecularAtmosphere.afgl_1986()), surface={"type": "lambertian"}, measures={ "type": "distant", "id": "distant_measure" }, ) assert exp.kernel_dict(ctx=ctx).load()
def test_molecular_atmosphere_switches(mode_mono): # Absorption can be deactivated atmosphere = MolecularAtmosphere(has_absorption=False) ctx = KernelDictContext() assert np.all(atmosphere.eval_radprops(ctx.spectral_ctx).sigma_a == 0.0) # Scattering can be deactivated atmosphere = MolecularAtmosphere(has_scattering=False) ctx = KernelDictContext() assert np.all(atmosphere.eval_radprops(ctx.spectral_ctx).sigma_s == 0.0) # At least one must be active with pytest.raises(ValueError): MolecularAtmosphere(has_absorption=False, has_scattering=False)
def test_onedim_measure_inside_atmosphere(mode_mono): ctx = KernelDictContext() atm = HeterogeneousAtmosphere( molecular_atmosphere=MolecularAtmosphere.afgl_1986()) s1 = eradiate.scenes.measure.MultiDistantMeasure() s2 = eradiate.scenes.measure.PerspectiveCameraMeasure(origin=[1, 1, 1], target=[0, 0, 0]) s3 = eradiate.scenes.measure.MultiRadiancemeterMeasure( origins=[[1, 1, 1], [0, 0, 1000000]], directions=[[0, 0, -1], [0, 0, -1]]) assert not measure_inside_atmosphere(atm, s1, ctx) assert measure_inside_atmosphere(atm, s2, ctx) with pytest.raises(ValueError): measure_inside_atmosphere(atm, s3, ctx)
def test_molecular_atmosphere_scale(mode_mono): ctx = KernelDictContext() d = MolecularAtmosphere(scale=2.0).kernel_dict(ctx) assert d["medium_atmosphere"]["scale"] == 2.0 assert d.load()