Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
{
"name": "decode",
"image":"python:3.11",
"features": {
"ghcr.io/devcontainers-contrib/features/poetry:2": {
"version": "1.8.3"
}
},
"containerEnv": {
"POETRY_VIRTUALENVS_CREATE": "false"
},
"image": "ghcr.io/astral-sh/uv:python3.12-bookworm",
"runArgs": [
"--name=decode"
],
"postCreateCommand": "poetry install",
"containerEnv": {
"UV_PROJECT_ENVIRONMENT": "/usr/local"
},
"postCreateCommand": "uv sync --frozen",
"customizations": {
"vscode": {
"extensions": [
"github.vscode-pull-request-github",
"mhutchie.git-graph",
"ms-python.black-formatter",
"ms-python.python",
"streetsidesoftware.code-spell-checker",
Expand All @@ -26,12 +19,11 @@
"settings": {
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"python.analysis.autoImportCompletions": true,
"python.languageServer": "Pylance",
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true,
"editor.insertSpaces": true,
"editor.tabSize": 4,
"python.languageServer": "Pylance"
"editor.formatOnSave": true
}
}
}
Expand Down
15 changes: 6 additions & 9 deletions .github/workflows/gh-pages.yaml → .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: GitHub Pages
name: Docs

on:
release:
Expand All @@ -9,19 +9,16 @@ jobs:
job:
name: GitHub Pages
runs-on: ubuntu-latest
container: ghcr.io/astral-sh/uv:python3.12-bookworm
env:
POETRY_VIRTUALENVS_CREATE: false
UV_PROJECT_ENVIRONMENT: /usr/local
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- uses: abatilo/actions-poetry@v3
with:
poetry-version: "1.8.3"
- run: poetry install
submodules: true
- run: uv sync --frozen
- run: docs/build
- uses: peaceiris/actions-gh-pages@v3
- uses: peaceiris/actions-gh-pages@v4
with:
force_orphan: true
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
13 changes: 6 additions & 7 deletions .github/workflows/pypi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ jobs:
job:
name: PyPI
runs-on: ubuntu-latest
container: ghcr.io/astral-sh/uv:python3.12-bookworm
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
UV_PROJECT_ENVIRONMENT: /usr/local
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- uses: abatilo/actions-poetry@v3
with:
poetry-version: "1.8.3"
- run: poetry publish --build
submodules: true
- run: uv build && uv publish
26 changes: 12 additions & 14 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,32 @@ on:
push:
branches:
- main
- deshima2.0
pull_request:
branches:
- main
- deshima2.0

jobs:
job:
name: Test (Python ${{ matrix.python }})
name: Test (${{ matrix.env }})
runs-on: ubuntu-latest
container: ghcr.io/astral-sh/uv:${{ matrix.env }}
env:
POETRY_VIRTUALENVS_CREATE: false
PYTHON_DIRS: decode docs tests
UV_PROJECT_ENVIRONMENT: /usr/local
strategy:
fail-fast: false
matrix:
python: ["3.9", "3.10", "3.11", "3.12"]
env:
- python3.9-bookworm
- python3.10-bookworm
- python3.11-bookworm
- python3.12-bookworm
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- uses: abatilo/actions-poetry@v3
with:
poetry-version: "1.8.3"
- run: poetry install
- run: black --check decode docs tests
- run: pyright decode docs tests
- run: uv sync --frozen
- run: black --check ${PYTHON_DIRS}
- run: pyright ${PYTHON_DIRS}
- run: pytest -v tests
- run: docs/build
102 changes: 101 additions & 1 deletion decode/convert.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
__all__ = ["coord_units", "frame", "units"]
__all__ = ["coord_units", "frame", "to_brightness", "to_dfof", "units"]


# standard library
from logging import getLogger
from typing import Optional, Sequence, TypeVar, Union


Expand All @@ -11,6 +12,10 @@
from astropy.units import Equivalency, Quantity, Unit


# constants
LOGGER = getLogger(__name__)


# type hints
T = TypeVar("T")
Multiple = Union[Sequence[T], T]
Expand Down Expand Up @@ -84,6 +89,101 @@ def frame(da: xr.DataArray, new_frame: str, /) -> xr.DataArray:
return da.assign_coords(frame=new_frame)


def to_brightness(
dems: xr.DataArray,
/,
*,
T_amb: float = 273.0,
T_room: float = 293.0,
) -> xr.DataArray:
"""Convert DEMS on the df/f scale to the brightness temperature scale.

Args:
dems: Input DEMS DataArray on the df/f scale.
T_amb: Default ambient temperature value to be used
when all ``dems.temperature`` values are NaN.
T_room: Default room temperature value to be used
when all ``dems.aste_cabin_temperature`` values are NaN.

Returns:
DEMS DataArray on the brightness temperature scale.

"""
if dems.long_name == "Brightness" or dems.units == "K":
LOGGER.warning("DEMS may already be on the brightness temperature scale.")

if all(np.isnan(T_room_ := dems.aste_cabin_temperature)):
T_room_ = T_room

if all(np.isnan(T_amb_ := dems.temperature)):
T_amb_ = T_amb

fwd = dems.d2_resp_fwd.data
p0 = dems.d2_resp_p0.data
T0 = dems.d2_resp_t0.data

return (
dems.copy(
deep=True,
data=(
(dems.data + p0 * (T_room_ + T0) ** 0.5) ** 2 / (p0**2 * fwd)
- (T0 + (1 - fwd) * T_amb_) / fwd
),
)
.astype(dems.dtype)
.assign_attrs(long_name="Brightness", units="K")
)


def to_dfof(
dems: xr.DataArray,
/,
*,
T_amb: float = 273.0,
T_room: float = 293.0,
) -> xr.DataArray:
"""Convert DEMS on the brightness temperature scale to the df/f scale.

Args:
dems: Input DEMS DataArray on the brightness temperature scale.
T_amb: Default ambient temperature value to be used
when all ``dems.temperature`` values are NaN.
T_room: Default room temperature value to be used
when all ``dems.aste_cabin_temperature`` values are NaN.

Returns:
DEMS DataArray on the df/f scale.

"""
if dems.long_name == "df/f" or dems.units == "dimensionless":
LOGGER.warning("DEMS may already be on the df/f scale.")

if all(np.isnan(T_room_ := dems.aste_cabin_temperature)):
T_room_ = T_room

if all(np.isnan(T_amb_ := dems.temperature)):
T_amb_ = T_amb

fwd = dems.d2_resp_fwd.data
p0 = dems.d2_resp_p0.data
T0 = dems.d2_resp_t0.data

return (
dems.copy(
deep=True,
data=(
p0
* (
(fwd * dems.data + (1 - fwd) * T_amb_ + T0) ** 0.5
- (T_room_ + T0) ** 0.5
)
),
)
.astype(dems.dtype)
.assign_attrs(long_name="df/f", units="dimensionless")
)


def units(
da: xr.DataArray,
new_units: UnitLike,
Expand Down
Loading