Cia

  1"""
  2
  3This file will showcase how you can load collision-induced absorption (CIA)
  4data from arts-cat-data into the workspace and do the required setups to
  5perform a simple forward calculations using this data
  6
  7"""
  8
  9import pyarts
 10import numpy as np
 11import matplotlib.pyplot as plt
 12
 13# Initialize ARTS
 14ws = pyarts.workspace.Workspace()
 15
 16"""
 17
 18Download ARTS catalogs if they are not already present.
 19
 20"""
 21pyarts.cat.download.retrieve()
 22
 23"""
 24
 25Set ws.abs_species to the species tags that you wish to use.  CIA tags are
 26structured so that the main and secondary species are separated by the word
 27"CIA"
 28
 29This example sets up self CIA by molecular oxygen
 30
 31CIA is not just self-induced but can occur between two different molecules.  In
 32this case you can change the tag to read something like "O2-CIA-N2", though
 33you must ensure that there also exists another N2 species in your ws.abs_species
 34as this is the only way to pass the volume mixing ratio of the atmosphere into
 35ARTS
 36
 37"""
 38ws.abs_speciesSet(species=["O2-CIA-O2"])
 39
 40"""
 41
 42Loads all CIA data from a given folder.  This command expects the file
 43"cia/O2-CIA-O2.xml" to be found either by relative local path or in the
 44user-defined search paths.
 45
 46"""
 47ws.abs_cia_dataReadSpeciesSplitCatalog(basename="cia/")
 48
 49
 50"""
 51
 52This example does not deal with line-by-line absorption at all.  We must still
 53ensure that the line-by-line catalog has the correct size and that it has been
 54set so that our automatic agenda routine can do its work
 55
 56"""
 57ws.abs_lines_per_speciesSetEmpty()
 58
 59"""
 60
 61You should generally always call this after you are done setting up your
 62ws.abs_species and ws.abs_lines_per_species.  It will deal with the internal
 63ARTS setup for you.  Note that the flag use_abs_lookup=1 can be passed to this
 64method call to set up the agenda for USING the the lookup-table.  Without the
 65flag, ARTS should be configured correctly to either COMPUTE the lookup-table
 66or to compute the absorption on-the-fly
 67
 68In this case, it turns out that the temparature extrapolation is not enough
 69for a tropical atmosphere scenario below, so we extend it a small bit.  Play
 70with this "T_extrapolfac" value to see the relevant error message
 71
 72"""
 73ws.propmat_clearsky_agendaAuto(T_extrapolfac=1)
 74
 75"""
 76
 77Compute absorption
 78
 79Now we can use the propmat_clearsky_agenda to compute the absorption of O2-66.
 80We can also use this agenda in more complicated setups that might require
 81absorption calculations, but that is for other examples
 82
 83To just execute the agenda we need to still define its both its inputs and the
 84inputs required to initialize the propagation matrix
 85
 86"""
 87
 88ws.jacobian_quantities = []  # No derivatives
 89ws.select_abs_species = []  # All species
 90ws.f_grid = pyarts.arts.convert.wavelen2freq(np.linspace(6900e-9, 5900e-9, 1001))
 91ws.rtp_mag = []  # No magnetic field
 92ws.rtp_los = []  # No particular LOS
 93ws.rtp_pressure = 1e5  # At 1 bar
 94ws.rtp_temperature = 295  # At room temperature
 95ws.rtp_nlte = pyarts.arts.EnergyLevelMap()  # No NLTE
 96ws.rtp_vmr = [0.21]  # At 21% atmospheric Oxygen
 97ws.stokes_dim = 1  # Unpolarized
 98
 99# Call the agenda with inputs above
100ws.AgendaExecute(a=ws.propmat_clearsky_agenda)
101
102# Plot the absorption of this example
103plt.figure(1)
104plt.clf()
105plt.plot(
106    1e9 * pyarts.arts.convert.freq2wavelen(ws.f_grid.value),
107    ws.propmat_clearsky.value.data.flatten(),
108)
109plt.xlabel("Wavelength [nm]")
110plt.ylabel("Absorption [1/m]")
111plt.title("O2-CIA-O2 absorption from examples/arts-cat-data/cia/cia.py")
112
113"""
114That's it!  You are done and have reached the end of this example.  Everything
115below here is just to ensure that ARTS does not break in the future.  It can
116be safely ignored
117
118"""
119# Save test results
120# ws.propmat_clearsky.value.data.savexml("cia_test_result.xml", type="ascii")
121
122# test that we are still OK
123propmat_clearsky_agenda = pyarts.arts.Tensor4()
124propmat_clearsky_agenda.readxml("cia_test_result.xml")
125assert np.allclose(
126    propmat_clearsky_agenda, ws.propmat_clearsky.value.data
127), "O2 Absorption has changed"