Skip to content
Snippets Groups Projects
Commit d34bdd65 authored by Tobias Hangleiter's avatar Tobias Hangleiter
Browse files

Merge branch 'maint/numpy-2.0' into 'main'

Fix numpy 2.0 reprs

See merge request !43
parents 9e021773 f90e2450
Branches
Tags
2 merge requests!44Fix CI,!43Fix numpy 2.0 reprs
Pipeline #1455044 waiting for manual action
......@@ -18,17 +18,6 @@ before_script:
- python -m pip install --upgrade pip
- python -m pip install hatch
test:
stage: test
script:
- python -m hatch run tests:run
artifacts:
when: always
paths:
- pytest_report.xml
reports:
junit: pytest_report.xml
build:
stage: build
script:
......@@ -37,7 +26,7 @@ build:
paths:
- dist/*.whl
prepare_release_and_deploy2zenodo:
prepare_deploy:
stage: build
image:
name: alpine:latest
......@@ -76,8 +65,21 @@ prepare_release_and_deploy2zenodo:
paths:
- artifacts/*
test:
stage: test
needs: []
script:
- python -m hatch run tests:run
artifacts:
when: always
paths:
- pytest_report.xml
reports:
junit: pytest_report.xml
pages:
stage: deploy
needs: []
script:
- python -m hatch run doc:build
artifacts:
......@@ -91,11 +93,6 @@ pages:
release:
stage: deploy
needs:
- job: "build"
artifacts: true
- job: "prepare_release_and_deploy2zenodo"
artifacts: true
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && '$CI_COMMIT_TAG =~ CALVER_REGEX_DEV'
when: on_success
......@@ -117,10 +114,7 @@ release:
url: '$CI_PROJECT_URL/-/jobs/$CI_JOB_ID/artifacts/file/dist/python_spectrometer-$VERSION-py3-none-any.whl'
deploy2zenodo:
stage: "deploy"
needs:
- job: "prepare_release_and_deploy2zenodo"
artifacts: true
stage: deploy
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && '$CI_COMMIT_TAG =~ $CALVER_REGEX'
when: on_success
......@@ -128,14 +122,11 @@ deploy2zenodo:
when: manual
variables:
DEPLOY2ZENODO_API_URL: https://zenodo.org/api
DEPLOY2ZENODO_DEPOSITION_ID: "create NEW record"
DEPLOY2ZENODO_DEPOSITION_ID: 13785490
DEPLOY2ZENODO_SKIP_PUBLISH: "true"
pypi:
stage: deploy
needs:
- job: "build"
artifacts: true
script:
- pip install -U twine
- twine upload -u "$TWINE_USERNAME" -p "$TWINE_PASSWORD" dist/*
......
......
......@@ -121,7 +121,7 @@ In this short demonstration, we reproduce the example from
Averaging the PSD yields the noise power on the signal.
>>> np.mean(spect[0]['S_processed'][0][256:])
>>> float(np.mean(spect[0]['S_processed'][0][256:]))
0.0009997881856675976
Computing the power spectrum instead yields an estimate for the RMS
......@@ -132,7 +132,7 @@ of the peak. The 'flattop' window seems to give a more accurate result.
>>> spect.reprocess_data(0, window='flattop')
>>> # Need to get from plot since internal data is unchanged
>>> data = spect.ax[0].lines[0].get_ydata()
>>> data.max()
>>> float(data.max())
2.009491183836163
Finally, we can also plot data in dB relative to a given dataset.
......@@ -142,7 +142,7 @@ Finally, we can also plot data in dB relative to a given dataset.
>>> spect.plot_dB_scale = True
>>> spect.set_reference_spectrum(0)
>>> data = spect.ax[0].lines[1].get_ydata()
>>> data.max() # Factor two in amplitude is approx 3 dB
>>> float(data.max()) # Factor two in amplitude is approx 3 dB
3.0284739712568682
See the documentation of :class:`~core.Spectrometer` and its methods
......
......
......@@ -13,7 +13,6 @@ from typing import (Any, Callable, Dict, Generator, Iterator, List,
from unittest import mock
import dill
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import colors
from qutil import io
......@@ -319,9 +318,6 @@ class Spectrometer:
else:
return super().__repr__()
def __del__(self):
plt.close(self.fig)
def __getitem__(self, key: _keyT) -> Dict[str, Any]:
return self._data[self._parse_keys(key)[0]]
......@@ -364,7 +360,7 @@ class Spectrometer:
@savepath.setter
def savepath(self, path):
self._savepath = self._resolve_path(path)
self._savepath = io.to_global_path(path)
def _resolve_path(self, file: _pathT) -> Path:
"""Resolve file to a fully qualified path."""
......@@ -984,7 +980,6 @@ class Spectrometer:
--------
:meth:`recall_from_disk`
"""
# shelve writes three files, .dat, .bak, and .dir. Only need to check for one
if file is None:
file = self._objfile
file = io.check_path_length(
......
......
import os
import pathlib
from tempfile import mkdtemp
import random
import string
import pytest
......@@ -8,9 +9,13 @@ from python_spectrometer import Spectrometer, daq
@pytest.fixture(params=[True, False])
def spectrometer(request) -> Spectrometer:
speck = Spectrometer(daq.QoptColoredNoise(), savepath=mkdtemp(),
def spectrometer(monkeypatch, request) -> Spectrometer:
# patch input to answer overwrite queries with "yes"
monkeypatch.setattr('builtins.input', lambda: 'y')
speck = Spectrometer(daq.QoptColoredNoise(), savepath=pathlib.Path(os.getcwd(), 'data'),
plot_cumulative=True, relative_paths=request.param)
speck.savepath.mkdir(parents=True, exist_ok=True)
cwd = os.getcwd()
os.chdir(speck.savepath)
......@@ -26,12 +31,18 @@ def spectrometer(request) -> Spectrometer:
@pytest.fixture
def serialized(spectrometer: Spectrometer) -> pathlib.Path:
spectrometer.serialize_to_disk('blub')
stem = ''.join(random.choices(string.ascii_letters, k=10))
spectrometer.serialize_to_disk(stem)
yield spectrometer.savepath / 'blub'
yield spectrometer.savepath / stem
for ext in ['.bak', '.dat', '.dir', '_files.txt']:
os.remove(spectrometer.savepath / f'blub{ext}')
exts = ['_files.txt']
if (spectrometer.savepath / stem).is_file():
os.remove(spectrometer.savepath / stem)
else:
exts.extend(['.bak', '.dat', '.dir'])
for ext in exts:
os.remove(spectrometer.savepath / f'{stem}{ext}')
def test_saving(spectrometer: Spectrometer):
......@@ -42,7 +53,13 @@ def test_saving(spectrometer: Spectrometer):
def test_serialization(spectrometer: Spectrometer):
spectrometer.serialize_to_disk('blub')
for ext in ['.bak', '.dat', '.dir', '_files.txt']:
exts = ['_files.txt']
if (spectrometer.savepath / 'blub').is_file():
assert os.path.exists(spectrometer.savepath / 'blub')
else:
exts.extend(['.bak', '.dat', '.dir'])
for ext in exts:
assert os.path.exists(spectrometer.savepath / f'blub{ext}')
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment