Skip to content

Commit

Permalink
Merge pull request #30 from AugustinMortier/0.10.5
Browse files Browse the repository at this point in the history
0.10.5
  • Loading branch information
AugustinMortier authored Oct 25, 2024
2 parents 1d21f8c + 1df07ab commit d4ccb9f
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 47 deletions.
3 changes: 3 additions & 0 deletions aprofiles/cli/config/cfg.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"inversion": {
"method": "forward",
"apriori": {
"var": "lr",
"cfg": "aer_ifs.json"
}
}
Expand All @@ -15,6 +16,7 @@
"inversion": {
"method": "forward",
"apriori": {
"var": "lr",
"cfg": "aer_ifs.json"
}
}
Expand All @@ -23,6 +25,7 @@
"inversion": {
"method": "forward",
"apriori": {
"var": "lr",
"cfg": "aer_ifs.json"
}
}
Expand Down
37 changes: 34 additions & 3 deletions aprofiles/cli/utils/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# @desc A-Profiles - Standard workflow

import aprofiles as apro
from pathlib import Path
import json
import warnings


Expand Down Expand Up @@ -31,15 +33,44 @@ def workflow(path, instruments_types, base_dir, CFG, verbose=False):
# 1. default: forward, 50sr
method = "forward"
apriori = {
"lr": 50
"lr": 50,
"use_cfg": False
}
# 2. if exist, overwrite with CFG["parameters"]
var_apriori = CFG["parameters"][profiles.data.instrument_type]["inversion"]["apriori"]["var"]
if profiles.data.instrument_type in CFG["parameters"]:
if 'cfg' in CFG["parameters"][profiles.data.instrument_type]["inversion"]["apriori"]:
cfg_path = CFG["parameters"][profiles.data.instrument_type]["inversion"]["apriori"]["cfg"]
# open config
f = open(Path(Path(__file__).parent, '..', '..', cfg_path))
aer_ifs = json.load(f)
f.close()
station_id = f'{profiles._data.attrs["wigos_station_id"]}-{profiles._data.attrs["instrument_id"]}'
if station_id in aer_ifs:
apriori = {
var_apriori: aer_ifs[station_id][var_apriori],
"use_cfg": 'True',
"cfg": {
"data": aer_ifs[station_id]["data"],
"use_default": 'False',
"attributes": aer_ifs["attributes"],
"path": cfg_path
}
}
else:
apriori = {
var_apriori: aer_ifs["attributes"]["default"][var_apriori],
"use_cfg": 'True',
"cfg": {
"use_default": 'True',
"attributes": aer_ifs["attributes"],
"path": cfg_path
}
}

if "inversion" in CFG["parameters"][profiles.data.instrument_type]:
if "method" in CFG["parameters"][profiles.data.instrument_type]["inversion"]:
method = CFG["parameters"][profiles.data.instrument_type]["inversion"]["method"]
if "apriori" in CFG["parameters"][profiles.data.instrument_type]["inversion"]:
apriori = CFG["parameters"][profiles.data.instrument_type]["inversion"]["apriori"]

profiles.inversion(zmin=4000., zmax=6000., remove_outliers=True, method=method, apriori=apriori, verbose=verbose)
profiles.write(base_dir)
26 changes: 12 additions & 14 deletions aprofiles/config/aer_ifs.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
{
"0-528-0-06218-A": {
"l0_wavelength": 1064.0,
"data": {
"od550aer": 0.1,
"od550aerbc": 0.1,
"od550aerdust": 0.2
},
"lr": 42
},
"0-20000-0-00203-A": {
"l0_wavelength": 1064.0,
"data": {
"od550aer": 0.1,
"od550aerbc": 0.1,
"od550aerdust": 0.2
},
"apriori": {
"lr": 42
}
"lr": 42
},
"0-20000-0-01492-A": {
"l0_wavelength": 1064.0,
Expand All @@ -17,21 +24,12 @@
"od550aerbc": 0.1,
"od550aerdust": 0.2
},
"apriori": {
"lr": 42
}
"lr": 42
},
"attributes": {
"default": {
"apriori": {
"lr": 48
}
"lr": 48
},
"files": [
"od550.nc",
"od550bc.nc",
"..."
],
"date": "26-09-2024T09:20:00"
}
}
33 changes: 4 additions & 29 deletions aprofiles/retrieval/extinction.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,21 +245,6 @@ def inversion(
rayleigh = apro.rayleigh.RayleighData(
altitude, T0=298, P0=1013, wavelength=wavelength
)

# apriori definition
if 'cfg' in apriori:
cfg_path = apriori['cfg']
# open config
f = open(Path(Path(__file__).parent, '..', cfg_path))
cfg = json.load(f)
f.close()
station_id = f'{profiles._data.attrs["wigos_station_id"]}-{profiles._data.attrs["instrument_id"]}'
if station_id in cfg:
apriori = cfg[station_id]["apriori"]
else:
apriori = cfg["attributes"]["default"]["apriori"]
else:
cfg = None

# aerosol inversion
ext, lr, aod, z_ref = [], [], [], []
Expand Down Expand Up @@ -330,22 +315,12 @@ def inversion(
profiles.data["lidar_ratio"] = ('time', lr)
profiles.data["lidar_ratio"] = profiles.data.lidar_ratio.assign_attrs({
'long_name': f"Lidar Ratio @ {int(wavelength)} nm",
'units': 'sr'
'units': 'sr',
'use_cfg': apriori['use_cfg']
})
if cfg is not None:
profiles.data["lidar_ratio"] = profiles.data.lidar_ratio.assign_attrs({
'use_cfg': 'True',
'cfg_file': cfg_path,
'use_default': str(not station_id in cfg),
'cfg_attributes': str(cfg.get('attributes'))
})
if cfg.get(station_id):
profiles.data["lidar_ratio"] = profiles.data.lidar_ratio.assign_attrs({
f'cfg_{station_id}': str(cfg.get(station_id)),
})
else:
if 'cfg' in apriori:
profiles.data["lidar_ratio"] = profiles.data.lidar_ratio.assign_attrs({
'use_cfg': 'False'
'cfg': str(apriori['cfg'])
})

profiles.data["z_ref"] = ('time', z_ref)
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

:material-history:{ style="text-align: center; font-size: xx-large; display: block" }

## 0.10.5
Oct 25, 2024

- change `aer_ifs.json` structure

## 0.10.4
Oct 19, 2024

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "aprofiles"
version = "0.10.4"
version = "0.10.5"
description = "Analysis of atmospheric profilers measurements"
authors = ["augustinm <augustinm@met.no>"]
license = "GPL-3.0"
Expand Down

0 comments on commit d4ccb9f

Please sign in to comment.