Skip to content
This repository was archived by the owner on Mar 24, 2026. It is now read-only.
/ SOCRATES Public archive

Commit 6045abf

Browse files
committed
Fix typo in readme. Fix upper-case conversion in phys.chem_safe()
1 parent 94eeddf commit 6045abf

File tree

4 files changed

+91
-92
lines changed

4 files changed

+91
-92
lines changed

make/Mk_cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Generated automatically
22
# System: Linux atmlxint6.atm.ox.ac.uk 5.4.0-193-generic #213-Ubuntu SMP Fri Aug 2 19:14:16 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
3-
# Date: Wed 30 Oct 20:07:01 GMT 2024
3+
# Date: Thu 31 Oct 13:48:05 GMT 2024
44

55
FORTCOMP = /usr/bin/gfortran -Ofast -march=native -fPIC -c
66
LINK = /usr/bin/gfortran -Ofast -march=native -fPIC

spectraltools/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ This subdirectory is not part of the original SOCRATES repository. It is distrib
55
### Overview
66

77
Computing k-coefficients from a line-list is very expensive because there can be a large number of transitions for a single molecule. To speed this up, it is useful to split the process into two steps:
8-
1. Calculating cross-sections from a line-list (at line resolution).
9-
2. Calculating k-coefficients from the cross-sections (at a lower resolution).
10-
8+
1. Calculating cross-sections from a line-list (at line resolution).
9+
2. Calculating k-coefficients from the cross-sections (at a lower resolution).
10+
1111
Step 1 is by far the slowest, so it is helpful to use pre-computed opacities. These tools aim to generalise the creation of SpectralFiles from pre-computed opacity tables by converting them into a common netCDF format. These netCDF files can then be read by SOCRATES when generating SpectralFiles with the required properties.
1212

1313
**You will need to download the source cross-sections yourself**. For a given database (`db`) and absorber (`ab`), the files should be placed in the directory `data/db/ab/`. All output files will be written to `output/`, which **you will also need to create yourself** or create a symbolic link called `output` which points to another extant location. The tools are primarily targeted at parsing cross-sections from DACE, with other databases partially supported for comparison purposes. It is recommended that you download cross-sections using the `Tinterpolate_dace.py` tool, and then generate spectral files using `Tmake_spectralfile.py`.
@@ -16,10 +16,10 @@ These tools all operate by storing the spectral absorption cross-section (versus
1616

1717
### Content
1818

19-
| Tool | Description |
19+
| Tool | Description |
2020
|--------------------------|---------------|
2121
| `Tmake_spectralfile.py` | Generate a spectral file for the specified absorbers and wavenumber/pressure/temperature range |
22-
| `Tconvert_dace.py` | Convert DACE binary files into the netCDF format for the specified absorber |
22+
| `Tconvert_dace.py` | Convert DACE binary files into the netCDF format for the specified absorber |
2323
| `Tdownload_cia.py` | Download CIA databases from the HITRAN website into `data/cia/` |
2424
| `Tplot_absorption.py` | Plot absorption cross-section versus wavenumber |
2525
| `Tcalc_checksum.py` | Calculate the BLAKE2b checksum of a file in order to verify its integrity |
@@ -32,15 +32,15 @@ These tools all operate by storing the spectral absorption cross-section (versus
3232
* SOCRATES
3333
- Must have been compiled
3434
- Executables have been added to your `PATH` variable using `. ./set_rad_env`
35-
* Python (version >= 3.11) and the following libraries
35+
* Python (version >= 3.11) and the following libraries
3636
- numpy
3737
- netcdf4
3838
- glob
3939
- shutil
4040
- requests
4141
- hashlib
4242
- matplotlib
43-
- dace_query
43+
- dace-query
4444
- h5py
4545

4646
### Online sources

spectraltools/Tmake_spectralfile.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#!/usr/bin/env python3
1+
#!/usr/bin/env python3
22
# Python wizard for interactive file conversion
33

4-
# Import local files
4+
# Import local files
55
import src.utils as utils
66
import src.spectral as spectral
77
import src.dace as dace
@@ -38,7 +38,7 @@ def main():
3838

3939

4040

41-
41+
4242
# ------------ EXECUTION -------------
4343
# Check volatile names
4444
for i in range(len(vols)):
@@ -53,7 +53,7 @@ def main():
5353
formula_path = os.path.join(utils.dirs[source], v.strip()+"/")
5454
if not os.path.exists(formula_path):
5555
raise Exception("Could not find folder '%s'" % formula_path)
56-
56+
5757

5858
# ===========
5959
# Remove content of output folder under this alias (optionally including netCDFs)
@@ -71,7 +71,7 @@ def main():
7171
print("Parameters")
7272
print(" source: %s"%source)
7373
print(" alias: %s"%alias)
74-
print(" vols: %s"%utils.get_arr_as_str(vols))
74+
print(" vols: %s"%utils.get_arr_as_str(vols))
7575
print(" nvols: %d"%len(vols))
7676
print(" nband: %d"%nband)
7777
print(" numin, numax, dnu : %.1f, %g, %.2f cm-1"%(numin, numax, dnu))
@@ -104,7 +104,7 @@ def main():
104104
dat_numax = max(dat_numax, vol_numax)
105105
print(" numin, numax = %.1f, %.1f cm-1"%(vol_numin, vol_numax))
106106

107-
# get tmin, tmax
107+
# get tmin, tmax
108108
_,at,_ = dace.list_all_ptf(formula_path)
109109
dat_tmin = min(dat_tmin, np.amin(at))
110110
dat_tmax = max(dat_tmax, np.amax(at))
@@ -133,7 +133,7 @@ def main():
133133

134134

135135
# ===========
136-
# Determine bands
136+
# Determine bands
137137
band_edges = spectral.best_bands(nu_arr, method, nband)
138138

139139

@@ -154,7 +154,7 @@ def main():
154154
nc_paths[v] = ncp
155155
if os.path.exists(ncp) and preNC:
156156
print("WARNING: Using pre-existing netCDF file for %s lbl absorption. Any configuration mismatch here will lead to issues."%v)
157-
continue
157+
continue
158158

159159
# Get numin, numax for this volatile
160160
formula_path = os.path.join(utils.dirs[source], v+"/")
@@ -167,7 +167,7 @@ def main():
167167
# This is for performance reasons, but is also critical for ensuring that the volatiles all use the same p,t points
168168
files = []
169169
print("Using pt->f map from %s for %s"%(vols[-1],v))
170-
for f in arr_f:
170+
for f in arr_f:
171171
# Try simply substituting volatile name and wavenumber range
172172
ftry = list(str(f).replace(vols[-1], v))
173173
ftry[-26:-21] = str_numin[:]
@@ -176,16 +176,16 @@ def main():
176176

177177
if os.path.exists(ftry):
178178
files.append(ftry)
179-
continue
179+
continue
180180

181-
# Try also substituting "out"<->"itp"
181+
# Try also substituting "out"<->"itp"
182182
if "Itp" in ftry:
183183
ftry = ftry.replace("Itp", "Out")
184184
else:
185185
ftry = ftry.replace("Out", "Itp")
186186
if os.path.exists(ftry):
187187
files.append(ftry)
188-
continue
188+
continue
189189

190190
raise Exception("Could not find bin file for '%s' corresponding to '%s'"%(v,f))
191191

@@ -203,14 +203,14 @@ def main():
203203

204204

205205
# ===========
206-
# Calculate k-coefficients from netCDF
206+
# Calculate k-coefficients from netCDF
207207
for i,f1 in enumerate(vols):
208208
spectral.calc_kcoeff_lbl(alias, f1, nc_paths[f1])
209-
for f2 in vols[i:]:
209+
for f2 in vols[i:]:
210210
spectral.calc_kcoeff_cia(alias, f1, f2, dnu_last)
211211

212212

213-
# ===========
213+
# ===========
214214
# Calculate water droplet properties
215215
if drops and ("H2O" in vols):
216216
spectral.calc_waterdroplets(alias)
@@ -221,8 +221,8 @@ def main():
221221
spectral.assemble(alias, vols)
222222

223223
# ------------------------------------
224-
return
225-
224+
return
225+
226226

227227
if __name__ == "__main__":
228228
utils.checkenv()

spectraltools/src/phys.py

Lines changed: 66 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Physical constants
1+
# Physical constants
22

33
# Universal gas constant [J K-1 mol-1]
4-
R_gas = 8.31446261815324
4+
R_gas = 8.31446261815324
55

66
# Stefan-boltzmann constant [W m−2 K−4]
7-
sigma = 5.670367e-8
7+
sigma = 5.670367e-8
88

99
# Avogadro's constant [mol-1]
1010
N_av = 6.02214076e+23
@@ -30,9 +30,9 @@ def iso_to_formula(iso:str):
3030
for c in str(a): # for each char
3131
if amu: # skip AMU
3232
if c.isdigit():
33-
continue
33+
continue
3434
else:
35-
amu=False
35+
amu=False
3636
f += c
3737
return f
3838

@@ -115,77 +115,76 @@ def iso_to_formula(iso:str):
115115
"Magnesium oxide" :"MgO",
116116
}
117117

118-
# Get chemical's safe name
118+
# Get chemical's safe name
119119
def chemsafe(name:str):
120-
up = name.upper()
121120

122121
# name provided
123-
if up in chem_dict.keys():
124-
return chem_dict[up]
125-
122+
if name in chem_dict.keys():
123+
return chem_dict[name]
124+
126125
# form provided
127-
if up in chem_dict.values():
128-
return up
129-
126+
if name in chem_dict.values():
127+
return name
128+
130129
# nope
131130
return None
132131

133132
# Formulae's MMW in g/mol (taken from src/radiance_core/gas_list_pcf.f90 -- see references therein)
134133
form_mmw = {
135-
"H2O": 18.0153,
136-
"CO2": 44.0100,
137-
"O3": 47.9982,
138-
"N2O": 44.0128,
139-
"CO": 28.0106,
140-
"CH4": 16.0430,
141-
"O2": 31.9988,
142-
"NO": 30.0061,
143-
"SO2": 64.0628,
144-
"NO2": 46.0055,
145-
"NH3": 17.0306,
146-
"HNO3": 63.0129,
147-
"N2": 28.0134,
148-
"CFC11": 137.3686,
149-
"CFC12": 120.9140,
150-
"CFC113": 187.3765,
151-
"HCFC22": 86.46892,
152-
"HFC125": 120.02227,
153-
"HFC134a": 102.03184,
154-
"CFC114": 170.921,
155-
"TiO ": 63.866,
156-
"VO": 66.9409,
157-
"H2": 2.01588,
158-
"He": 4.002602,
159-
"OCS": 60.075,
160-
"Na": 22.98976928,
161-
"K": 39.0983,
162-
"FeH": 56.853,
163-
"CrH": 53.004,
164-
"Li": 6.941,
165-
"Rb": 85.4678,
166-
"Cs": 132.9054519,
167-
"PH3": 33.99758,
168-
"C2H2": 26.0373,
169-
"HCN": 27.0253,
170-
"H2S": 34.081,
171-
"Ar": 39.948,
172-
"O": 15.9994,
173-
"N": 14.00674,
174-
"NO3": 63.0128,
175-
"N2O5": 108.0104,
176-
"HONO": 47.0134,
177-
"HO2NO2": 79.0122,
178-
"H2O2": 34.0147,
179-
"C2H6": 30.0690,
180-
"CH3 ": 15.0345,
181-
"H2CO ": 30.0260,
182-
"HO2": 33.0067,
183-
"HDO": 19.0214,
184-
"HCl": 36.461,
185-
"HF": 20.00689,
186-
"cis-OSSO": 96.129,
187-
"trans-OSSO": 96.129,
188-
"OSO-S": 96.129,
134+
"H2O": 18.0153,
135+
"CO2": 44.0100,
136+
"O3": 47.9982,
137+
"N2O": 44.0128,
138+
"CO": 28.0106,
139+
"CH4": 16.0430,
140+
"O2": 31.9988,
141+
"NO": 30.0061,
142+
"SO2": 64.0628,
143+
"NO2": 46.0055,
144+
"NH3": 17.0306,
145+
"HNO3": 63.0129,
146+
"N2": 28.0134,
147+
"CFC11": 137.3686,
148+
"CFC12": 120.9140,
149+
"CFC113": 187.3765,
150+
"HCFC22": 86.46892,
151+
"HFC125": 120.02227,
152+
"HFC134a": 102.03184,
153+
"CFC114": 170.921,
154+
"TiO ": 63.866,
155+
"VO": 66.9409,
156+
"H2": 2.01588,
157+
"He": 4.002602,
158+
"OCS": 60.075,
159+
"Na": 22.98976928,
160+
"K": 39.0983,
161+
"FeH": 56.853,
162+
"CrH": 53.004,
163+
"Li": 6.941,
164+
"Rb": 85.4678,
165+
"Cs": 132.9054519,
166+
"PH3": 33.99758,
167+
"C2H2": 26.0373,
168+
"HCN": 27.0253,
169+
"H2S": 34.081,
170+
"Ar": 39.948,
171+
"O": 15.9994,
172+
"N": 14.00674,
173+
"NO3": 63.0128,
174+
"N2O5": 108.0104,
175+
"HONO": 47.0134,
176+
"HO2NO2": 79.0122,
177+
"H2O2": 34.0147,
178+
"C2H6": 30.0690,
179+
"CH3 ": 15.0345,
180+
"H2CO ": 30.0260,
181+
"HO2": 33.0067,
182+
"HDO": 19.0214,
183+
"HCl": 36.461,
184+
"HF": 20.00689,
185+
"cis-OSSO": 96.129,
186+
"trans-OSSO": 96.129,
187+
"OSO-S": 96.129,
189188

190189
}
191190

0 commit comments

Comments
 (0)