Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ def single_propmat_agenda(ws):

# %% Tests

assert np.allclose(geometric.flatten()[::21], [1.25796726e+02, -5.83741570e-04, -2.57391509e-03, 6.19248870e-01,
1.38784898e+02, 1.03384405e-01, -2.12491046e-02, -5.28908702e-01,
1.29721222e+02, -4.55868565e-04])
assert np.allclose(geometric.flatten()[::21], [1.25794774e+02, -5.83537876e-04, -2.57431876e-03, 6.19251463e-01,
1.38783126e+02, 1.03390335e-01, -2.12537252e-02, -5.28821722e-01,
1.29719019e+02, -4.56132270e-04])

assert np.allclose(refractive.flatten()[::21], [1.25859048e+02, -5.89636065e-04, -2.56081274e-03, 6.19103775e-01,
1.38852518e+02, 1.03195242e-01, -2.10922560e-02, -5.31804997e-01,
1.29761824e+02, -4.48001573e-04])
assert np.allclose(refractive.flatten()[::21], [1.25857198e+02, -5.89476000e-04, -2.56123378e-03, 6.19115458e-01,
1.38850488e+02, 1.03201081e-01, -2.10969520e-02, -5.31725056e-01,
1.29760585e+02, -4.48233446e-04])

assert not np.allclose(geometric, refractive)
50 changes: 25 additions & 25 deletions examples/2-clearsky-radiative-transfer/3-disort/2-clearsky-flux.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,36 +58,36 @@
).flatten()
/ np.array(
[
2.65924430e-15,
2.66162733e-15,
2.65924817e-15,
2.66163119e-15,
2.75440515e-15,
9.57958182e-18,
2.08076327e-17,
5.39749082e-16,
2.93074072e-15,
2.93357370e-15,
9.57958159e-18,
2.08074133e-17,
5.39728390e-16,
2.93074462e-15,
2.93357757e-15,
3.03918211e-15,
9.99616600e-18,
2.34511632e-17,
6.12773186e-16,
3.19264874e-15,
3.19665668e-15,
9.99616581e-18,
2.34509262e-17,
6.12752485e-16,
3.19265273e-15,
3.19666066e-15,
3.33784028e-15,
1.03768102e-17,
3.05943372e-17,
8.07853130e-16,
3.35251230e-15,
3.36075470e-15,
1.03768097e-17,
3.05940685e-17,
8.07832320e-16,
3.35251628e-15,
3.36075873e-15,
3.65036247e-15,
1.07209025e-17,
6.78926741e-17,
1.56163327e-15,
3.37235023e-15,
2.86992821e-15,
1.07209024e-17,
6.78924115e-17,
1.56161464e-15,
3.37235046e-15,
2.86992793e-15,
3.97673151e-15,
1.52446216e-15,
2.80896759e-15,
3.94566396e-15,
1.52446492e-15,
2.80896736e-15,
3.94566425e-15,
]
),
1,
Expand Down
46 changes: 29 additions & 17 deletions python/src/pyarts3/hitran.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
}


def gen_latest_molparam_map(molparam_txt_file=None):
def get_latest_molparam_map(molparam_txt_file=None):
""" Generates a version of latest_molparam_map used in hitran_species.cc

The variable is simply printed to stream with print() as the intent is
to use this output in ARTS directly. ARTS does not use AFGL notation
internally, but species names that are different from Hitran are mapped to
ARTS names in the output.
The variable is returned as a dictionary mapping species to a list of
isotopologues. Each isotopologue is represented as a list of four items:
[specnum, pos, isotopologue string, abundance]
1. specnum: HITRAN species number
2. pos: position index in HITRAN notation
3. isotopologue string: isotopologue identifier in HITRAN notation
4. abundance: natural abundance of the isotopologue
"""
def pos2char(ind):
""" Convert an isotoplogue index to a HITRAN char for that index """
Expand Down Expand Up @@ -45,24 +48,34 @@ def pos2char(ind):
spec = vec[0]
specnum = int(eval(vec[1]))
pos = 1
out [spec] = []
out[spec] = []
else:
out[spec].append([specnum, pos, vec[0], vec[1]])
pos += 1
return out


def gen_latest_molparam_map(molparam_txt_file=None):
""" Generates a version of latest_molparam_map used in hitran_species.cc

print ('const HitranMap molparam_map{')
The variable is simply printed to stream with print() as the intent is
to use this output in ARTS directly. ARTS does not use AFGL notation
internally, but species names that are different from Hitran are mapped to
ARTS names in the output.
"""
out = get_latest_molparam_map(molparam_txt_file)
print('const HitranMap molparam_map{')
for spec in out:
print ('{',out[spec][0][0], ', { // ', spec, sep='')
print('{', out[spec][0][0], ', { // ', spec, sep='')
for isot in out[spec]:
isoname = f"{spec}-{isot[2]}"
if isoname in _HITRAN_TO_ARTS_NAMES:
isoname = _HITRAN_TO_ARTS_NAMES[isoname]
s,i = isoname.split('-')
print ('{', pos2char(isot[1]), ', {Species::find_species_index("', s, '", "', i, '"), ', isot[3], '}},', sep='')
print ('}},')
print ('};')


s, i = isoname.split('-')
print('{', pos2char(
isot[1]), ', {Species::find_species_index("', s, '", "', i, '"), ', isot[3], '}},', sep='')
print('}},')
print('};')


def gen_hitran_isotopologues(molparam_txt_file=None):
Expand Down Expand Up @@ -91,7 +104,7 @@ def gen_hitran_isotopologues(molparam_txt_file=None):
spec = vec[0]
specnum = int(eval(vec[1]))
pos = 1
out [spec] = []
out[spec] = []
else:
out[spec].append([specnum, vec[0], vec[3], vec[4]])
pos += 1
Expand All @@ -103,6 +116,5 @@ def gen_hitran_isotopologues(molparam_txt_file=None):
if isoname in _HITRAN_TO_ARTS_NAMES:
isoname = _HITRAN_TO_ARTS_NAMES[isoname]
spec, isotnum = isoname.split('-')
print(f'IsotopeRecord(fromShortName("{spec}"), "{isotnum}", {isot[3]}, {isot[2]}),')
print(f'IsotopeRecord("{spec}"_spec, "{isotnum}", {isot[3]}, {isot[2]}),')
print("/** AUTO-GENERATED FROM HITRAN **/")

42 changes: 34 additions & 8 deletions src/core/lbl/lbl_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,32 @@ Size count_zeeman_lines(
return x.second.count_zeeman_lines(pol);
});
}

std::vector<LineByLineCutoff> get_cutoff_types_and_values(
const std::unordered_map<QuantumIdentifier, lbl::band_data>& bands) {
constexpr LineByLineCutoff t{
.type = LineByLineCutoffType::None,
.value = std::numeric_limits<Numeric>::infinity(),
};
bool found_none = false;

std::vector<LineByLineCutoff> out;

for (auto& [key, band] : bands) {
switch (band.cutoff.type) {
case LineByLineCutoffType::None: found_none = true; break;
default:
if (stdr::none_of(out, Cmp::eq(band.cutoff)))
out.push_back(band.cutoff);

break;
};
}

if (found_none) out.push_back(t);

return out;
}
} // namespace lbl

namespace {
Expand Down Expand Up @@ -354,11 +380,11 @@ std::string std::formatter<lbl::band_data>::to_string(
"Line shape: "sv,
v.lineshape,
"; Cutoff: "sv,
v.cutoff == LineByLineCutoffType::None
v.cutoff.type == LineByLineCutoffType::None
? "<off>"s
: std::format("{} at {}",
v.cutoff,
to_educational_string_frequency(v.cutoff_value)),
v.cutoff.type,
to_educational_string_frequency(v.cutoff.value)),
"; Lines: ["sv,
v.lines,
']');
Expand All @@ -367,7 +393,7 @@ std::string std::formatter<lbl::band_data>::to_string(
const auto sep = tags.sep();

std::string out =
tags.vformat(v.lineshape, sep, v.cutoff, sep, v.cutoff_value);
tags.vformat(v.lineshape, sep, v.cutoff.type, sep, v.cutoff.value);

if (not tags.short_str) {
out += tags.vformat(sep, v.lines);
Expand All @@ -390,9 +416,9 @@ void xml_io_stream<AbsorptionBand>::write(std::ostream& os,
"lineshape",
String{toString(data.lineshape)},
"cutoff_type",
String{toString(data.cutoff)},
String{toString(data.cutoff.type)},
"cutoff_value",
data.cutoff_value,
data.cutoff.value,
"nelem",
static_cast<Index>(data.lines.size()));
tag.write_to_stream(os);
Expand All @@ -418,9 +444,9 @@ void xml_io_stream<AbsorptionBand>::read(std::istream& is,
data.lineshape = to<LineByLineLineshape>(tag);

open_tag.get_attribute_value("cutoff_type", tag);
data.cutoff = to<LineByLineCutoffType>(tag);
data.cutoff.type = to<LineByLineCutoffType>(tag);

open_tag.get_attribute_value("cutoff_value", data.cutoff_value);
open_tag.get_attribute_value("cutoff_value", data.cutoff.value);

open_tag.get_attribute_value("nelem", nelem);
data.lines.resize(0);
Expand Down
38 changes: 29 additions & 9 deletions src/core/lbl/lbl_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,30 @@ struct line {
friend std::istream& operator>>(std::istream& is, line& x);
};

struct LineByLineCutoff {
LineByLineCutoffType type{LineByLineCutoffType::None};

Numeric value{std::numeric_limits<Numeric>::infinity()};

constexpr bool operator==(const LineByLineCutoff& other) const {
if (type != other.type) return false;
switch (type) {
case LineByLineCutoffType::None: return true;
case LineByLineCutoffType::ByLine: return value == other.value;
}
}

constexpr bool operator!=(const LineByLineCutoff& other) const {
return not(*this == other);
}
};

struct band_data {
std::vector<line> lines{};

LineByLineLineshape lineshape{LineByLineLineshape::VP_LTE};

LineByLineCutoffType cutoff{LineByLineCutoffType::None};

Numeric cutoff_value{std::numeric_limits<Numeric>::infinity()};
LineByLineCutoff cutoff{};

template <typename T>
[[nodiscard]] auto& operator[](this T&& self, const std::integral auto& i) {
Expand Down Expand Up @@ -238,9 +254,9 @@ struct band_data {

[[nodiscard]] constexpr Numeric get_cutoff_frequency() const {
using enum LineByLineCutoffType;
switch (cutoff) {
switch (cutoff.type) {
case None: return std::numeric_limits<Numeric>::infinity();
case ByLine: return cutoff_value;
case ByLine: return cutoff.value;
}
return -1;
}
Expand Down Expand Up @@ -375,16 +391,20 @@ std::vector<flat_band_data> flatter_view(
Filter filter) {
std::vector<flat_band_data> off{};
off.reserve(bands.size());

Size prev_size = 0;
for (auto& [key, band] : bands) {
if (filter(key, band)) {
const Size size = off.empty() ? 0
: (off.back().prev_size +
off.back().band.count_zeeman_lines(pol));
off.emplace_back(size, key, band);
prev_size += off.empty() ? 0 : off.back().band.count_zeeman_lines(pol);
off.emplace_back(prev_size, key, band);
}
}

return off;
}

std::vector<LineByLineCutoff> get_cutoff_types_and_values(
const std::unordered_map<QuantumIdentifier, lbl::band_data>& bands);
} // namespace lbl

//! Support hashing of line keys
Expand Down
12 changes: 6 additions & 6 deletions src/core/lbl/lbl_fwd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ void lte::adapt() try {

if (shapes.size() == 0) continue;

voigt::lte::band_shape b{std::move(shapes), band.cutoff_value};
switch (band.cutoff) {
voigt::lte::band_shape b{std::move(shapes), band.cutoff.value};
switch (band.cutoff.type) {
case LineByLineCutoffType::ByLine:
cutoff_this.resize(b.lines.size());
b(cutoff_this);
Expand Down Expand Up @@ -123,8 +123,8 @@ void lte_mirror::adapt() {

if (shapes.size() == 0) continue;

voigt::lte_mirror::band_shape b{std::move(shapes), band.cutoff_value};
switch (band.cutoff) {
voigt::lte_mirror::band_shape b{std::move(shapes), band.cutoff.value};
switch (band.cutoff.type) {
case LineByLineCutoffType::ByLine:
cutoff_this.resize(b.lines.size());
b(cutoff_this);
Expand Down Expand Up @@ -177,8 +177,8 @@ void nlte::adapt() {

if (shapes.size() == 0) continue;

voigt::nlte::band_shape b{std::move(shapes), band.cutoff_value};
switch (band.cutoff) {
voigt::nlte::band_shape b{std::move(shapes), band.cutoff.value};
switch (band.cutoff.type) {
case LineByLineCutoffType::ByLine:
cutoff_this.resize(b.lines.size());
b(cutoff_this);
Expand Down
Loading
Loading