Skip to content

Commit

Permalink
Merge pull request #214 from lkluft/update-pyarts
Browse files Browse the repository at this point in the history
Update PyARTS
  • Loading branch information
lkluft committed Mar 26, 2023
2 parents e3a64d6 + 1f724e2 commit d6ff51f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 30 deletions.
8 changes: 4 additions & 4 deletions environment.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: konrad
channels:
- defaults
- conda-forge
- rttools
dependencies:
- python>=3.8
- python>=3.9
- jupyter-book
- matplotlib>=2.0.0
- netcdf4>=1.2.7
- numpy>1.22.0
- pyarts==2.5.4
- pyarts>=2.5.8
- pytest
- scipy>=0.19.0
- sphinx
Expand All @@ -17,5 +17,5 @@ dependencies:
- xarray>=0.9.1
- pip
- pip:
- git+https://github.com/atmtools/climt@rrtmg-only#egg=climt
- climt
- sympl>=0.4.0
61 changes: 36 additions & 25 deletions konrad/radiation/arts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import warnings
from os.path import join, dirname, isfile

import numpy as np
Expand Down Expand Up @@ -44,20 +45,25 @@ def __init__(self, ws=None, threads=None, nstreams=4, scale_vmr=True, verbosity=
self.ws.water_p_eq_agendaSet()
self.ws.gas_scattering_agendaSet()
self.ws.iy_main_agendaSet(option="Emission")
self.ws.iy_space_agendaSet()
self.ws.iy_surface_agendaSet()
self.ws.ppath_agendaSet(option="FollowSensorLosPath")
self.ws.ppath_step_agendaSet(option="GeometricPath")
self.ws.iy_space_agendaSet(option="CosmicBackground")
self.ws.iy_surface_agendaSet(option="UseSurfaceRtprop")

# Non reflecting surface
self.ws.VectorSetConstant(self.ws.surface_scalar_reflectivity, 1, 0.0)
self.ws.surface_rtprop_agendaSet(
option="Specular_NoPol_ReflFix_SurfTFromt_surface"
)

# Number of Stokes components to be computed
self.ws.IndexSet(self.ws.stokes_dim, 1)

self.ws.jacobianOff() # No jacobian calculation
self.ws.cloudboxOff() # Clearsky = No scattering

# Set Absorption Species
self.ws.abs_speciesSet(
species=[
"O2, O2-CIAfunCKDMT100",
"H2O, H2O-SelfContCKDMT252, H2O-ForeignContCKDMT252",
"H2O, H2O-SelfContCKDMT400, H2O-ForeignContCKDMT400",
"O3",
"CO2, CO2-CKDMT252",
"N2, N2-CIAfunCKDMT252, N2-CIArotCKDMT252",
Expand All @@ -67,35 +73,33 @@ def __init__(self, ws=None, threads=None, nstreams=4, scale_vmr=True, verbosity=
]
)

# Surface handling
self.ws.VectorSetConstant(self.ws.surface_scalar_reflectivity, 1, 0.0)
self.ws.surface_rtprop_agendaSet(
option="Specular_NoPol_ReflFix_SurfTFromt_surface",
)

# Read lookup table
abs_lookup = os.getenv(
"KONRAD_LOOKUP_TABLE", join(dirname(__file__), "data/abs_lookup.xml")
)

if not isfile(abs_lookup):
raise FileNotFoundError(
self.ws.abs_lookup_is_adapted.initialize_if_not()
if isfile(abs_lookup):
self.ws.abs_lines_per_speciesSetEmpty()
self.ws.ReadXML(self.ws.abs_lookup, abs_lookup)
self.ws.f_gridFromGasAbsLookup()
self.ws.abs_lookupAdapt()
self.ws.propmat_clearsky_agendaAuto(use_abs_lookup=1)

self.ws.jacobianOff() # No jacobian calculation
self.ws.cloudboxOff() # Clearsky = No scattering
self.ws.sensorOff() # No sensor properties
else:
warnings.warn(
"Could not find ARTS absorption lookup table.\n"
"To perform ARTS calculations you have to download the lookup "
"table at:\n\n https://doi.org/10.5281/zenodo.3885410\n\n"
"Afterwards, use the following environment variable to tell "
"konrad where to find it:\n\n"
" $ export KONRAD_LOOKUP_TABLE='/path/to/abs_lookup.xml'"
" $ export KONRAD_LOOKUP_TABLE='/path/to/abs_lookup.xml'",
UserWarning,
)

self.ws.abs_lines_per_speciesSetEmpty()
self.ws.ReadXML(self.ws.abs_lookup, abs_lookup)
self.ws.f_gridFromGasAbsLookup()
self.ws.abs_lookupAdapt()
self.ws.propmat_clearsky_agendaAuto(use_abs_lookup=1)

self.ws.sensorOff() # No sensor properties

# Set number of OMP threads
if threads is not None:
self.ws.SetNumberOfThreads(threads)
Expand Down Expand Up @@ -129,13 +133,17 @@ def calc_lookup_table(self, filename=None, fnum=2 ** 15, wavenumber=None):
self.ws.abs_lines_per_speciesReadSpeciesSplitCatalog(
basename="lines/"
)
self.ws.ReadXML(
self.ws.predefined_model_data,
"model/mt_ckd_4.0/H2O.xml"
)

# Set line shape and cut off.
self.ws.LegacyContinuaInit()
self.ws.abs_lines_per_speciesCompact() # Throw away lines outside f_grid
self.ws.abs_lines_per_speciesLineShapeType(self.ws.abs_lines_per_species, "VP")
self.ws.abs_lines_per_speciesNormalization(self.ws.abs_lines_per_species, "VVH")
self.ws.abs_lines_per_speciesCutoff(self.ws.abs_lines_per_species, "ByLine", 750e9)
self.ws.abs_lines_per_speciesTurnOffLineMixing()
self.ws.propmat_clearsky_agendaAuto(use_abs_lookup=0)

# Create a standard atmosphere
Expand Down Expand Up @@ -179,7 +187,7 @@ def calc_lookup_table(self, filename=None, fnum=2 ** 15, wavenumber=None):

# Run checks
self.ws.propmat_clearsky_agenda_checkedCalc()
self.ws.lbl_checked = 1 # self.ws.lbl_checkedCalc()
self.ws.lbl_checkedCalc()

# Calculate actual lookup table.
self.ws.abs_lookupCalc()
Expand Down Expand Up @@ -241,6 +249,9 @@ def set_atmospheric_state(self, atmosphere, t_surface):

def calc_spectral_irradiance_field(self, atmosphere, t_surface):
"""Calculate the spectral irradiance field."""
if not self.ws.abs_lookup_is_adapted.value.value:
raise Exception("Simulations without lookup table are not supported.")

self.set_atmospheric_state(atmosphere, t_surface)

# get the zenith angle grid and the integrations weights
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ install_requires =
[options.extras_require]
arts =
pyarts
pyarts>=2.5.8
docs =
jupyter-book
sphinx
Expand Down

0 comments on commit d6ff51f

Please sign in to comment.