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
  7Note that this example presumes that you have set the environment variable
  8ARTS_DATA_PATH to contain a path to a local copy of both arts-cat-data and
  9arts-xml-data before you import pyarts.  Please check that this is the case
 10if the example does not work for you.  You can easily check if this path is
 11set by adding the following two lines at the top of this pyarts-controlfile:
 12
 13```
 14import os
 15print(os.environ.get("ARTS_DATA_PATH"))
 16```
 17
 18"""
 19
 20import pyarts
 21import numpy as np
 22import matplotlib.pyplot as plt
 23
 24# Initialize ARTS
 25ws = pyarts.workspace.Workspace()
 26
 27"""
 28
 29Set ws.abs_species to the species tags that you wish to use.  CIA tags are
 30structured so that the main and secondary species are separated by the word
 31"CIA"
 32
 33This example sets up self CIA by molecular oxygen
 34
 35CIA is not just self-induced but can occur between two different molecules.  In
 36this case you can change the tag to read something like "O2-CIA-N2", though
 37you must ensure that there also exists another N2 species in your ws.abs_species
 38as this is the only way to pass the volume mixing ratio of the atmosphere into
 39ARTS
 40
 41"""
 42ws.absorption_speciesSet(species=["O2-CIA-O2"])
 43
 44"""
 45
 46Loads all CIA data from a given folder.  This command expects the file
 47"cia/O2-CIA-O2.xml" to be found either by relative local path or in the
 48user-defined search paths.
 49
 50"""
 51ws.absorption_cia_dataReadSpeciesSplitCatalog(basename="cia/")
 52
 53
 54"""
 55
 56This example does not deal with line-by-line absorption at all.  We must still
 57ensure that the line-by-line catalog has the correct size and that it has been
 58set so that our automatic agenda routine can do its work
 59
 60"""
 61ws.absorption_bands = []
 62
 63"""
 64
 65You should generally always call this after you are done setting up your
 66ws.abs_species and ws.abs_lines_per_species.  It will deal with the internal
 67ARTS setup for you.  Note that the flag use_abs_lookup=1 can be passed to this
 68method call to set up the agenda for USING the the lookup-table.  Without the
 69flag, ARTS should be configured correctly to either COMPUTE the lookup-table
 70or to compute the absorption on-the-fly
 71
 72In this case, it turns out that the temparature extrapolation is not enough
 73for a tropical atmosphere scenario below, so we extend it a small bit.  Play
 74with this "T_extrapolfac" value to see the relevant error message
 75
 76"""
 77ws.propagation_matrix_agendaAuto(T_extrapolfac=1)
 78
 79"""
 80
 81Compute absorption
 82
 83Now we can use the propagation_matrix_agenda to compute the absorption of O2-66.
 84We can also use this agenda in more complicated setups that might require
 85absorption calculations, but that is for other examples
 86
 87To just execute the agenda we need to still define its both its inputs and the
 88inputs required to initialize the propagation matrix
 89
 90"""
 91
 92ws.jacobian_targets = pyarts.arts.JacobianTargets()
 93ws.frequency_grid = pyarts.arts.convert.wavelen2freq(np.linspace(6900e-9, 5900e-9, 1001))
 94ws.atmospheric_point.temperature = 295  # At room temperature
 95ws.atmospheric_point.pressure = 1e5  # At 1 bar
 96ws.atmospheric_point[ws.absorption_species[0]] = 0.21  # At 21% atmospheric Oxygen
 97ws.ray_path_point # No particular POSLOS
 98
 99# Call the agenda with inputs above
100ws.propagation_matrix_agendaExecute()
101
102# Plot the absorption of this example
103plt.figure(1)
104plt.clf()
105plt.plot(
106    1e9 * pyarts.arts.convert.freq2wavelen(ws.frequency_grid.value),
107    ws.propagation_matrix[:, 0],
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.propagation_matrix.savexml("cia_test_result.xml", type="ascii")
121
122# test that we are still OK
123propagation_matrix_agenda = \
124    pyarts.arts.PropmatVector.fromxml("cia_test_result.xml")
125assert np.allclose(
126    propagation_matrix_agenda, ws.propagation_matrix
127), "O2 Absorption has changed"