Skip to content

Commit

Permalink
CK and LBL RT working (#6)
Browse files Browse the repository at this point in the history
-fixed LBL rt
-added functionality to generate and use correlated k RT
-added surface class and new functions, but not well organized yet
  • Loading branch information
cometz95 authored and chengcli committed Jun 14, 2024
1 parent 121bf4f commit 092e2bf
Show file tree
Hide file tree
Showing 35 changed files with 2,288 additions and 445 deletions.
71 changes: 71 additions & 0 deletions doc/README-opacity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Instruction on generating opacity

## Files required
1. atmospheric profile, e.g. `jupiter.atm`
2. opacity definition file, e.g. `jupiter.yaml`

## Atmospheric profile
The atmospheric profile is a text file with named columns. The particular order of the columns is not important,
except for the first column, which is assumed to be an index of the vertical levels.
The vertical level index starts from 1 at the bottom of the atmosphere and progresses upwards.
The rest of the columns are altitude, pressure, temperature, and gas mole fractions.
The following names are required to be present in the file:

- 'IDX': index of the layer
- 'ALT': altitude (km)
- 'PRE': pressure (mbar)
- 'TEM': temperature (K)

If no units are provided, the code assumes `km` for altitude, `mbar` for pressure, and `K` for temperature.
It is possible to use different units by specifying them after the name of the column
(without spaces), and enclosed in square brackets, e.g. 'ALT[km]'. The code will convert the units automatically to SI units.
The recognized units are: `km`, `m`, `cm`, `bar`, `Pa`, `hPa`, `mbar`, `pa`, `hpa`, `K`

Following the required columns, the file can contain any number of additional columns with gas mole fractions.
The names of the columns should correspond to the names of the gases in the opacity definition file.
The units of the mole fractions are by default in `ppmv` (parts per million by volume), but it is possible to specify
different units by enclosing them in square brackets, e.g. 'H2[ppbv]' or `H2[1]`, where `1` is the unitless mole fraction.
The recognized units are: `ppmv`, `ppbv`, `ppm`, `ppb`, `mol/mol`, `1`

It is required that the atmospheric profile file contains all the gases that are defined in the opacity definition file.
The gases that are not present in the atmospheric profile are assumed to be radiatively inactive.
The mean molecular weight of the atmosphere is calculated based on the pressure and
altitude levels in the atmospheric profile.

Here is an example of an atmospheric profile file for Jupiter:
```text
# Sample atmospheric profile for Jupiter
IDX ALT[km] PRE[mbar] TEM[K] H2[ppmv] He[ppmv] CH4[ppmv]
1 -315.8 6289.6 294.2 861993 136001 1809
2 -310.2 5501.5 282.4 861993 136001 1809
```

You may add comments to the file by starting the line with `#`.
Any text after the `#` symbol wil be ignored.

We provide a python script `atm_profile_utils.py` that parses the atmospheric profile file and returns the data in a dictionary.
The dictionary contains the following keys:
- 'IDX': index of the layer
- 'ALT': altitude (m)
- 'PRE': pressure (Pa)
- 'TEM': temperature (K)
and additional keys for the names of the gases present in the file.
The entries are numpy arrays with the column data in SI units.
The script checks the units of the columns and converts them to SI units if necessary.
It will raise an error if the units are not recognized or the file format is incorrect.

The script can be used as follows:
```python
from atm_profile_utils import read_atm_profile
data = read_atm_profile('jupiter.atm')
```

Or you can use the script as a command line tool:
```bash
python3 atm_profile_utils.py -i [input_file] -o [output_file] -u [units]
```
where `[input_file]` is the name of the input atmospheric profile file, `[output_file]` is the name of the output file,
The format of the input file is determined by the extension of the file name.
Currently, the script supports `.atm`, `.txt` and `.nc` file formats.

## Generate line-by-line opacity using RFM
4 changes: 2 additions & 2 deletions examples/2024-CMetz-amars/amars.inp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ dt = 5.E1

<time>
cfl_number = 0.9 # The Courant, Friedrichs, & Lewy (CFL) Number
nlim = -1 # cycle limit
nlim = 1 # cycle limit
tlim = 1.E7 # time limit
xorder = 5 # horizontal reconstruction order
integrator = rk3 # integration method

<mesh>
nx1 = 128 # Number of zones in X1-direction
x1min = 0. # minimum value of X1
x1max = 50.E3 # maximum value of X1
x1max = 20.E3 # maximum value of X1
ix1_bc = reflecting # inner-X1 boundary flag
ox1_bc = reflecting # outer-X1 boundary flag

Expand Down
62 changes: 62 additions & 0 deletions examples/2024-CMetz-amars/amarsw-ck.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
opacity-sources:
- name: H2O
class: HitranCK
data: amarsw-ck-B1.nc
dependent-species: [vapor.H2O]

- name: CO2
class: HitranCK
data: amarsw-ck-B2.nc
dependent-species: [vapor.dry]

- name: H2O
class: HitranCK
data: amarsw-ck-B3.nc
dependent-species: [vapor.H2O]

bands: [B1, B2, B3]

B1:
units: cm-1
grid-type: cktable
wavenumber-range: [1., 500.]
opacity: [H2O]
rt-solver: Disort
flags: [thermal_emission]
albedo: 0.01

B2:
units: cm-1
grid-type: cktable
wavenumber-range: [500., 1200.]
opacity: [CO2]
rt-solver: Disort
flags: [thermal_emission]
albedo: 0.01

B3:
units: cm-1
grid-type: cktable
wavenumber-range: [1200., 2000.]
opacity: [H2O]
rt-solver: Disort
flags: [thermal_emission]
albedo: 0.01

Disort-flags:
ibcnd: false
usrtau: false
usrang: false
lamber: true
onlyfl: true
spher: false
intensity_correction: true
old_intensity_correction: false
general_source: false
output_uum: false
quiet: true
print-input: false
print-fluxes: false
print-intensity: false
print-transmissivity: false
print-phase-function: true
65 changes: 65 additions & 0 deletions examples/2024-CMetz-amars/amarsw-lbl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
opacity-sources:
- name: H2O
class: Hitran
data: amarsw-lbl-B1.nc
dependent-species: [vapor.H2O]

- name: CO2
class: Hitran
data: amarsw-lbl-B2.nc
dependent-species: [vapor.dry]

- name: H2O
class: Hitran
data: amarsw-lbl-B3.nc
dependent-species: [vapor.H2O]

bands: [B1, B2, B3]

B1:
units: cm-1
grid-type: regular
wavenumber-range: [1., 500.]
resolution: 0.1
opacity: [H2O]
rt-solver: Disort
flags: [thermal_emission]
albedo: 0.01

B2:
units: cm-1
grid-type: regular
wavenumber-range: [500., 1200.]
resolution: 0.1
opacity: [CO2]
rt-solver: Disort
flags: [thermal_emission]
albedo: 0.01

B3:
units: cm-1
grid-type: regular
wavenumber-range: [1200., 2000.]
resolution: 0.1
opacity: [H2O]
rt-solver: Disort
flags: [thermal_emission]
albedo: 0.01

Disort-flags:
ibcnd: false
usrtau: false
usrang: false
lamber: true
onlyfl: true
spher: false
intensity_correction: true
old_intensity_correction: false
general_source: false
output_uum: false
quiet: true
print-input: false
print-fluxes: false
print-intensity: false
print-transmissivity: false
print-phase-function: true
38 changes: 38 additions & 0 deletions examples/2024-CMetz-amars/amarsw-mp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
microphysics:
- H2O-system

H2O-system:
scheme: Kessler94
dependent-species: [vapor.H2O, cloud.H2O(c), cloud.H2O(p)]
parameters:
autoconversion: 1.e-4
accretion: 0.0
evaporation: 3.e-1
sedimentation: -20.

CO2-system:
scheme: Kessler94
dependent-species: [vapor.CO2, cloud.CO2(c), cloud.CO2(p)]
parameters:
autoconversion: 1.e-4
accretion: 0.0
evaporation: 3.e-1
sedimentation: -20.

H2S-system:
scheme: Kessler94
dependent-species: [vapor.H2S, cloud.H2S(c), cloud.H2S(p)]
parameters:
autoconversion: 1.e-4
accretion: 0.0
evaporation: 3.e-1
sedimentation: -20.

SO2-system:
scheme: Kessler94
dependent-species: [vapor.SO2, cloud.SO2(c), cloud.SO2(p)]
parameters:
autoconversion: 1.e-4
accretion: 0.0
evaporation: 3.e-1
sedimentation: -20.
29 changes: 29 additions & 0 deletions examples/2024-CMetz-amars/amarsw-op.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
opacity-sources:
- name: H2O
class: Hitran

- name: CO2
class: Hitran

bands: [B1, B2, B3]

B1:
units: cm-1
grid-type: regular
wavenumber-range: [1., 500.]
resolution: 0.1
opacity: [H2O, CO2]

B2:
units: cm-1
grid-type: regular
wavenumber-range: [500., 1200.]
resolution: 0.1
opacity: [H2O, CO2]

B3:
units: cm-1
grid-type: regular
wavenumber-range: [1200., 2000.]
resolution: 0.1
opacity: [H2O, CO2]
Loading

0 comments on commit 092e2bf

Please sign in to comment.