Skip to content

Commit

Permalink
Merge pull request #433 from GreenBankObservatory/issue_336
Browse files Browse the repository at this point in the history
Issue 336
  • Loading branch information
astrofle authored Dec 2, 2024
2 parents 8e13069 + a3fad4d commit 2275284
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 44 deletions.
14 changes: 14 additions & 0 deletions docs/source/_static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ are more visible */
background-color: #C6B9D2;
}

/*
* */
.widget-subarea {
background-color: var(--pst-color-surface) !important;
border-radius: 0.25rem !important;
/*border: 1px solid var(--mystnb-stdout-border-color) !important;*/
/*background: var(--mystnb-stdout-bg-color) !important;*/
}

div.output.text_html {
background-color: var(--pst-color-background) !important;
background: var(--pst-color-background) !important;
}

.black {
color: black;
}
Expand Down
7 changes: 7 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"numpydoc",
"sphinx_inline_tabs",
"sphinx_design",
"sphinx_copybutton",
]

numpydoc_show_class_members = True
Expand Down Expand Up @@ -263,6 +264,8 @@

# Cache notebooks to only re-run when cells change
nb_execution_mode = "cache"
# Use this mode if working on the documentation with sphinx-autobuild.
# nb_execution_mode = "auto"

# Where to store the notebook cache
nb_execution_cache_path = "jupyter_cache"
Expand All @@ -273,3 +276,7 @@
"dollarmath",
]
myst_dmath_double_inline = True


# -- sphinx-copybutton config -------------------------------------
copybutton_exclude = ".linenos, .gp"
2 changes: 1 addition & 1 deletion notebooks/examples/dataIO.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.0"
"version": "3.10.0"
}
},
"nbformat": 4,
Expand Down
36 changes: 33 additions & 3 deletions notebooks/examples/flagging.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@
{
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x7a1f64721dd0>"
"<matplotlib.image.AxesImage at 0x7f146739bdc0>"
]
},
"execution_count": 8,
Expand Down Expand Up @@ -459,10 +459,40 @@
"ps.plot(xaxis_unit=\"chan\")"
]
},
{
"cell_type": "markdown",
"id": "2debf76f-0a0d-4062-b23d-00c02d4ada5c",
"metadata": {},
"source": [
"## Removing Flags\n",
"\n",
"To remove flags from the `GBTFITSLoad` object use the `clear_flags` method."
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "6a96b98e-8bd9-4959-a190-800ad10d6c4d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" ID TAG OBJECT BANDWID DATE-OBS DURATION EXPOSURE TSYS TDIM7 TUNIT7 CTYPE1 CRVAL1 CRPIX1 CDELT1 CTYPE2 ... PLNUM FDNUM INT INTNUM NSAVE HDU BINTABLE ROW PROC OBSTYPE SUBOBSMODE FITSINDEX CHAN UTC # SELECTED\n",
"--- --- ------ ------- -------- -------- -------- ---- ----- ------ ------ ------ ------ ------ ------ ... ----- ----- --- ------ ----- --- -------- --- ---- ------- ---------- --------- ---- --- ----------\n"
]
}
],
"source": [
"sdfits.clear_flags()\n",
"sdfits.flags.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b00993ae-a385-4293-9182-f34bd18432b3",
"id": "4bb26ea3-602a-4e72-96df-87235c29105c",
"metadata": {},
"outputs": [],
"source": []
Expand All @@ -484,7 +514,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
"version": "3.10.0"
}
},
"nbformat": 4,
Expand Down
3 changes: 1 addition & 2 deletions notebooks/examples/frequencyswitch.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"metadata": {},
"source": [
"# Frequency-switched Data Reduction\n",
"-----------------------------------\n",
"\n",
"This notebook shows how to use `dysh` to calibrate a frequency switched observations. The idea is similar to an OnOff observation, except the telescope does not move to an Off in position on the sky, but moves its intermediate frequency in frequency space. Here we call the On and Off the Sig and Ref, but both will have the signal, just shifted in the band. Since the telescope is always tracking the target, combining the Sig and a shifted (folded) Ref, a $\\sqrt{2}$ improvement in signal-to-noise can be achieved.\n",
"\n",
Expand Down Expand Up @@ -724,7 +723,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.0"
"version": "3.10.0"
},
"toc": {
"base_numbering": 0
Expand Down
3 changes: 1 addition & 2 deletions notebooks/examples/nodding.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"metadata": {},
"source": [
"# Nodding Data Reduction\n",
"------------------------\n",
"\n",
"This notebook shows the reduction path of a nodding observation in a multi-beam receiver.\n",
"\n",
Expand Down Expand Up @@ -558,7 +557,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.10.0"
}
},
"nbformat": 4,
Expand Down
3 changes: 1 addition & 2 deletions notebooks/examples/positionswitch.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"metadata": {},
"source": [
"# Position-Switched Data Reduction\n",
"----------------------------------\n",
"\n",
"This notebook shows how to use `dysh` to calibrate an OnOff observation.\n",
"It retrieves and calibrates position-switch scans using `GBTFITSLoad.getps()`, which returns a `ScanBlock` object. OffOn observations can be reduced the same way."
Expand Down Expand Up @@ -929,7 +928,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.0"
"version": "3.10.0"
},
"toc": {
"base_numbering": 0
Expand Down
3 changes: 1 addition & 2 deletions notebooks/examples/smoothing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"metadata": {},
"source": [
"# Smoothing\n",
"-----------\n",
"\n",
"This notebook shows how to use `dysh` to smooth a spectrum. For the example below we will use data from the Position-Switch example. The following dysh commands are the simplest to get and smooth a spectrum (leaving out all the function arguments):\n",
"\n",
Expand Down Expand Up @@ -793,7 +792,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.0"
"version": "3.10.0"
},
"toc": {
"base_numbering": 0
Expand Down
4 changes: 2 additions & 2 deletions notebooks/examples/subbeamnod.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"metadata": {},
"source": [
"# SubBeamNod Data Reduction\n",
"---------------------------\n",
"\n",
"This notebook shows how to use `dysh` to calibrate an SubBeamNod observation via two different methods. It retrieves and calibrates SubBeamNod scans using `GBTFITSLoad.subbeamnod()` which returns a `ScanBlock` object. "
]
},
Expand Down Expand Up @@ -493,7 +493,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.0"
"version": "3.10.0"
}
},
"nbformat": 4,
Expand Down
3 changes: 1 addition & 2 deletions notebooks/examples/velocity_frames.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"metadata": {},
"source": [
"# Spectral Axes, Velocity Frames and Conventions in `dysh`\n",
"----------------------------------\n",
"\n",
"This notebook shows how to change spectral axes to represent different rest frames and Doppler conventions."
]
Expand Down Expand Up @@ -877,7 +876,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.0"
"version": "3.10.0"
},
"toc": {
"base_numbering": 0
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ dev = [
"sphinx-inline-tabs",
"sphinx-book-theme",
"sphinx-design",
"sphinx-copybutton",
"sphinxcontrib-mermaid",
"nbformat",
"nbclient",
Expand Down
6 changes: 3 additions & 3 deletions src/dysh/fits/gbtfitsload.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ def getps(
Returns
-------
scanblock : `~spectra.scan.ScanBlock`
ScanBlock containing the individual `~spectra.scan.PSScan`s
ScanBlock containing one or more `~spectra.scan.PSScan`.

"""

Expand Down Expand Up @@ -1260,7 +1260,7 @@ def getnod(
Returns
-------
scanblock : `~spectra.scan.ScanBlock`
ScanBlock containing the individual `~spectra.scan.NodScan`s
ScanBlock containing one or more `~spectra.scan.NodScan`.

"""

Expand Down Expand Up @@ -1493,7 +1493,7 @@ def getfs(
Returns
-------
scanblock : `~spectra.scan.ScanBlock`
ScanBlock containing the individual `~spectra.scan.FSScan`s
ScanBlock containing one or more`~spectra.scan.FSScan`.

"""
debug = kwargs.pop("debug", False)
Expand Down
17 changes: 9 additions & 8 deletions src/dysh/fits/sdfitsload.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,17 @@ def rawspectrum(self, i, bintable=0, setmask=False):

Parameters
----------
i : int
The row index to retrieve.
bintable : int or None
The index of the `bintable` attribute. If None, the underlying bintable is computed from i
setmask : bool
If True, set the data mask according to the current flags in the `_flagmask` attribute.
i : int
The row index to retrieve.
bintable : int or None
The index of the `bintable` attribute. If None, the underlying bintable is computed from i
setmask : bool
If True, set the data mask according to the current flags in the `_flagmask` attribute.

Returns
-------
rawspectrum : ~numpy.ma.MaskedArray
The i-th row of DATA column of the input bintable, masked according to `setmask`
rawspectrum : ~numpy.ma.MaskedArray
The i-th row of DATA column of the input bintable, masked according to `setmask`

"""
if bintable is None:
Expand Down
2 changes: 1 addition & 1 deletion src/dysh/spectra/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ def data_ishift(y, ishift, axis=-1, remove_wrap=True, fill_value=np.nan):

def data_fshift(y, fshift, method="fft", pad=False, window=True):
"""
Shift `y` by `fshift` channels, where |`fshift`|<1.
Shift `y` by `fshift` channels, where `abs(fshift)<1`.

Parameters
----------
Expand Down
26 changes: 14 additions & 12 deletions src/dysh/spectra/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,22 +341,24 @@ def stats(self, roll=0, qac=False):

Parameters
----------
roll : int
Return statistics on a 'rolled' array differenced with the
original array. If there is no correllaton between channels,
a roll=1 would return an RMS sqrt(2) larger than that of the
input array. Another advantage of rolled statistics it will
remove most slow variations, thus RMS/sqrt(2) might be a better
indication of the underlying RMS.
Default: 0
qac : bool
If set, the returned simple string contains mean,rms,datamin,datamax
for easier visual regression. Based on some legacy code.
Default: False
roll : int
Return statistics on a 'rolled' array differenced with the
original array. If there is no correllaton between channels,
a roll=1 would return an RMS sqrt(2) larger than that of the
input array. Another advantage of rolled statistics it will
remove most slow variations, thus RMS/sqrt(2) might be a better
indication of the underlying RMS.
Default: 0
qac : bool
If set, the returned simple string contains mean,rms,datamin,datamax
for easier visual regression. Based on some legacy code.
Default: False

Returns
-------
stats : dict
Dictionary consisting of (mean,median,rms,datamin,datamax)

"""

if roll == 0:
Expand Down
11 changes: 7 additions & 4 deletions src/dysh/util/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from rich.progress import Progress
from tenacity import retry, stop_after_attempt

from dysh.log import init_logging, logger


@retry(stop=stop_after_attempt(3))
def from_url(url, path=Path(".")):
Expand All @@ -30,7 +32,6 @@ def from_url(url, path=Path(".")):
if type(path) is str:
path = Path(path)

print(f"Starting download...")
try:
# Make the HTTPX client
client = httpx.Client(follow_redirects=True)
Expand All @@ -49,11 +50,12 @@ def from_url(url, path=Path(".")):

# Skip downloading if file already exists
if savepath.exists():
print(f"{filename} already downloaded at {path}")
logger.info(f"{filename} already downloaded at {path}")
return savepath

else:
# Download the file
logger.info("Starting download...")
resp.raise_for_status()

# Download to a temporary path first
Expand All @@ -62,7 +64,7 @@ def from_url(url, path=Path(".")):

# Write chunks to file with progress bar
with open(tmp_path, "wb") as out_file:
with Progress() as progress:
with Progress(refresh_per_second=5) as progress:
task_length = int(resp.headers.get("content-length", 0))
task = progress.add_task("[red]Downloading...", total=task_length)
for chunk in resp.iter_raw():
Expand All @@ -77,7 +79,7 @@ def from_url(url, path=Path(".")):

# Rename the temp file to the desired name
tmp_path.rename(savepath)
print(f"Saved {filename} to {savepath}")
logger.info(f"Saved {filename} to {savepath}")

return Path(savepath)

Expand All @@ -104,4 +106,5 @@ def main():


if __name__ == "__main__":
init_logging(2)
main()

0 comments on commit 2275284

Please sign in to comment.