-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#132 Merge pull request from deshima-dev/astropenguin/issue131
Add qlook command for PSW + Sky chopper (pswsc)
- Loading branch information
Showing
4 changed files
with
165 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
__all__ = ["mad"] | ||
|
||
|
||
# dependencies | ||
from typing import Any, Optional, cast | ||
import numpy as np | ||
import xarray as xr | ||
from xarray.core.types import Dims | ||
|
||
|
||
def mad( | ||
da: xr.DataArray, | ||
dim: Dims = None, | ||
skipna: Optional[bool] = None, | ||
keep_attrs: Optional[bool] = None, | ||
**kwargs: Any, | ||
) -> xr.DataArray: | ||
"""Calculate median absolute deviation (MAD) of a DataArray. | ||
Args: | ||
da: Input DataArray. | ||
dim: Name of dimension(s) along which MAD is calculated. | ||
skipna: Same-name option to be passed to ``DataArray.median``. | ||
keep_attrs: Same-name option to be passed to ``DataArray.median``. | ||
kwargs: Same-name option(s) to be passed to ``DataArray.median``. | ||
Returns: | ||
MAD of the input DataArray. | ||
""" | ||
|
||
def median(da: xr.DataArray) -> xr.DataArray: | ||
return da.median( | ||
dim=dim, | ||
skipna=skipna, | ||
keep_attrs=keep_attrs, | ||
**kwargs, | ||
) | ||
|
||
return median(cast(xr.DataArray, np.abs(da - median(da)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# dependencies | ||
import numpy as np | ||
import xarray as xr | ||
from decode import utils | ||
from dems.d2 import MS | ||
|
||
|
||
def test_mad() -> None: | ||
dems = MS.new(np.arange(25).reshape(5, 5)) | ||
assert (utils.mad(dems, "time") == 5.0).all() |