Skip to content

Commit

Permalink
Merge pull request #203 from lkluft/fix-arts
Browse files Browse the repository at this point in the history
Fix ARTS interface
  • Loading branch information
lkluft authored Feb 11, 2022
2 parents a7badee + ce3d390 commit d1a9820
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
20 changes: 10 additions & 10 deletions konrad/atmosphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def from_atm_fields_compact(cls, atm_fields_compact):
[0] http://arts.mi.uni-hamburg.de/docserver-trunk/variables/atm_fields_compact
Parameters:
atm_fields_compact (typhon.arts.types.GriddedField4):
atm_fields_compact (pyarts.types.GriddedField4):
Compact set of atmospheric fields.
"""

Expand All @@ -117,17 +117,15 @@ def from_xml(cls, xmlfile):
Parameters:
xmlfile (str): Path to XML file.
"""
import pyarts

# Read the content of given XML file.
griddedfield = typhon.arts.xml.load(xmlfile)
griddedfield = pyarts.xml.load(xmlfile)

# Check if the XML file contains an atm_fields_compact (GriddedField4).
arts_type = typhon.arts.utils.get_arts_typename(griddedfield)
if arts_type != "GriddedField4":
raise TypeError(
'XML file contains "{}". Expected "GriddedField4".'.format(arts_type)
)
if not isinstance(griddedfield, pyarts.GriddedField4):
raise TypeError('XML file does not an "GriddedField4".')

return cls.from_atm_fields_compact(griddedfield, **kwargs)
return cls.from_atm_fields_compact(griddedfield)

@classmethod
def from_dict(cls, dictionary):
Expand Down Expand Up @@ -183,6 +181,8 @@ def _return_profile(ds, var, ts):

def to_atm_fields_compact(self):
"""Convert an atmosphere into an ARTS atm_fields_compact."""
import pyarts

# Store all atmosphere variables including geopotential height.
variables = self.atmosphere_variables + ["z"]

Expand All @@ -192,7 +192,7 @@ def to_atm_fields_compact(self):
]

# Create a GriddedField4.
atmfield = typhon.arts.types.GriddedField4()
atmfield = pyarts.types.GriddedField4()

# Set grids and their names.
atmfield.gridnames = ["Species", "Pressure", "Longitude", "Latitude"]
Expand Down
8 changes: 5 additions & 3 deletions konrad/radiation/arts.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def calc_lookup_table(self, filename=None, fnum=2 ** 15, wavenumber=None):
# Setup the lookup table calculation
self.ws.AtmFieldsAndParticleBulkPropFieldFromCompact()
self.ws.vmr_field.value = self.ws.vmr_field.value.clip(min=0.0)
self.ws.atmfields_checkedCalc(bad_partition_functions_ok=1)
self.ws.atmfields_checkedCalc()
self.ws.abs_lookupSetup(p_step=1.0) # Do not refine p_grid
self.ws.abs_t_pert = np.arange(-160, 61, 20)

Expand Down Expand Up @@ -226,6 +226,8 @@ def calc_lookup_table(self, filename=None, fnum=2 ** 15, wavenumber=None):

def set_atmospheric_state(self, atmosphere, t_surface):
"""Set and check the atmospheric fields."""
import pyarts

atm_fields_compact = atmosphere.to_atm_fields_compact()

# Scale dry-air VMRs with H2O and CO2 content.
Expand All @@ -247,7 +249,7 @@ def set_atmospheric_state(self, atmosphere, t_surface):
atm_fields_compact.scale(species, 1 - variable_vmrs)

# Compute the N2 VMR as a residual of the full atmosphere composition.
n2 = ty.arts.types.GriddedField3(
n2 = pyarts.types.GriddedField3(
grids=atm_fields_compact.grids[1:],
data=0.7808 * (1 - variable_vmrs),
)
Expand All @@ -269,7 +271,7 @@ def set_atmospheric_state(self, atmosphere, t_surface):
self.ws.z_field.value[0, 0, 0] = 0.0

# Perform configuration and atmosphere checks
self.ws.atmfields_checkedCalc(bad_partition_functions_ok=1)
self.ws.atmfields_checkedCalc()
self.ws.propmat_clearsky_agenda_checkedCalc()
self.ws.atmgeom_checkedCalc()
self.ws.cloudbox_checkedCalc()
Expand Down

0 comments on commit d1a9820

Please sign in to comment.