Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

version 0.5.1 #127

Merged
merged 5 commits into from
Sep 30, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/build-docs-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
pull_request:
branches:
- master
- dev
# Allows to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/codestyle-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
pull_request:
branches:
- master
- dev
# Allows to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
pull_request:
branches:
- master
- dev
# Allows to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.5.1]

### Changed

- DeprecationWarning messages now clearly say that the methods won't exist in v1.0.0

### Added

- it is now possible to extend the widget's height to 100% of its container. To do so,
do `Aladin(height=-1)`. This is implemented to support use in dashboard
applications, this cannot work in a notebook.

### Fixed

- remove `requests` from mandatory dependencies (accident in version 0.5.0)

## [0.5.0]

### Added
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ With a couple of lines, you can display Aladin Lite, center it on the target of
- [Installation](#installation)
- [Development installation](#development-installation)
- [How does it work?](#how-does-it-work)
- [Works with](#works-with)
- [Actively tested](#actively-tested)
- [Not actively tested](#not-actively-tested)
- [Acknowledging ipyaladin](#acknowledging-ipyaladin)

## Examples
Expand Down Expand Up @@ -88,6 +91,7 @@ Correspondence table between ipyaladin versions and Aladin Lite versions:
| ipyaladin | Aladin-Lite |
| ---------- | ----------- |
| Unreleased | 3.5.1-beta |
| 0.5.1 | 3.5.1-beta |
| 0.5.0 | 3.5.1-beta |
| 0.4.0 | 3.4.4-beta |
| 0.3.0 | 3.3.3-dev |
Expand Down
5 changes: 2 additions & 3 deletions js/models/event_handler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import MessageHandler from "./message_handler";
import { divNumber, setDivNumber, Lock } from "../utils";
import { divNumber, setDivNumber, Lock, setDivHeight } from "../utils";

export default class EventHandler {
/**
Expand Down Expand Up @@ -131,8 +131,7 @@ export default class EventHandler {

/* Div control */
this.model.on("change:_height", () => {
let height = this.model.get("_height");
this.aladinDiv.style.height = `${height}px`;
setDivHeight(this.model.get("_height"), this.aladinDiv);
// Update WCS and FoV only if this is the last div
this.updateWCS();
this.update2AxisFoV();
Expand Down
9 changes: 9 additions & 0 deletions js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,19 @@ function setDivNumber(num) {
divNumber = num;
}

function setDivHeight(height, div) {
if (height == -1) {
div.style.height = "100%";
} else {
div.style.height = `${height}px`;
}
}

export {
snakeCaseToCamelCase,
convertOptionNamesToCamelCase,
Lock,
divNumber,
setDivNumber,
setDivHeight,
};
10 changes: 7 additions & 3 deletions js/widget.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import "./widget.css";
import EventHandler from "./models/event_handler";
import { divNumber, setDivNumber, snakeCaseToCamelCase } from "./utils";
import {
divNumber,
setDivHeight,
setDivNumber,
snakeCaseToCamelCase,
} from "./utils";
import A from "./aladin_lite";

function initAladinLite(model, el) {
Expand All @@ -13,8 +18,7 @@ function initAladinLite(model, el) {

let aladinDiv = document.createElement("div");
aladinDiv.classList.add("aladin-widget");
aladinDiv.style.height = `${model.get("_height")}px`;

setDivHeight(model.get("_height"), aladinDiv);
aladinDiv.id = `aladin-lite-div-${divNumber}`;
let aladin = new A.aladin(aladinDiv, initOptions);
el.appendChild(aladinDiv);
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ convention = "numpy"
[tool.ruff.lint.per-file-ignores]
# D104: Missing docstring in public package
"__init__.py" = ["D104"]
"src/tests/*" = ["D103"]

[tool.ruff.format]
docstring-code-format = false
2 changes: 1 addition & 1 deletion src/ipyaladin/__about__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "0.5.0"
__version__ = "0.5.1"
__aladin_lite_version__ = "3.5.1-beta"
46 changes: 28 additions & 18 deletions src/ipyaladin/utils/_coordinate_parser.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import warnings
import json
import re
from typing import Tuple
import urllib.parse
import urllib.request
import warnings

import requests
from astropy.coordinates import SkyCoord, Angle, Longitude, Latitude
import re

from ipyaladin.utils.exceptions import NameResolverWarning

Expand Down Expand Up @@ -65,24 +67,32 @@ def _from_name_on_planet(string: str, body: str) -> SkyCoord:
SkyCoord
An `astropy.coordinates.SkyCoord` object representing the coordinates.
"""
url = (
f"https://alasky.cds.unistra.fr/planetary-features/resolve"
f"?identifier={string.replace(' ', '+')}&body={body}&threshold=0.7&format=json"
)
request = requests.get(url)
if request.status_code != requests.codes.ok:
raise ValueError(
"No coordinates found for this requested planetary feature: " f"'{string}'"
)
data = request.json()["data"]
url = "https://alasky.cds.unistra.fr/planetary-features/resolve?"
values = {
"identifier": string.replace(" ", "+"),
"body": body,
"threshold": 0.7,
"format": "json",
}
data = urllib.parse.urlencode(values)
request = urllib.request.Request(url + data)

try:
response = urllib.request.urlopen(request)
except urllib.request.HTTPError as err:
raise ValueError(f"No coordinates found for '{string}'") from err
answer = response.read()
response.close()

data = json.loads(answer)["data"][0]
# response is different for earth
if body == "earth":
return data[0][0], data[0][1]
return data[0], data[1]
# case of every other planetary bodies
identifier = data[0][1]
lat = data[0][5] # inverted lon and lat in response
lon = data[0][6]
system = data[0][11]
identifier = data[1]
lat = data[5] # inverted lon and lat in response
lon = data[6]
system = data[11]
if identifier != string:
warnings.warn(
f"Nothing found for '{string}' on {body}. However, a {identifier} exists. "
Expand Down
22 changes: 15 additions & 7 deletions src/ipyaladin/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,16 @@ def selected_objects(self) -> List[Table]:

@property
def height(self) -> int:
"""The height of the Aladin Lite widget.
"""The height of the widget.

Returns
-------
int
The height of the widget in pixels.

Setting the height to -1 will expand the widget at 100% height of its
container. This is generally a bad idea in a notebook but can be usefull
for dashbord applications.
The default height is 400 pixels.
"""
return self._height

Expand Down Expand Up @@ -690,7 +693,8 @@ def add_moc_from_URL(
"""
warnings.warn(
"add_moc_from_URL is replaced by add_moc that detects automatically"
"that the MOC was given as an URL.",
"that the MOC was given as an URL."
"This will be removed in version 1.0.0 (coming afer 0.5.1).",
DeprecationWarning,
stacklevel=2,
)
Expand All @@ -716,7 +720,8 @@ def add_moc_from_dict(
"""
warnings.warn(
"add_moc_from_dict is replaced by add_moc that detects automatically"
"that the MOC was given as a dictionary.",
"that the MOC was given as a dictionary."
"This will be removed in version 1.0.0 (coming afer 0.5.1).",
DeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -847,7 +852,8 @@ def add_overlay_from_stcs(
"""
warnings.warn(
"'add_overlay_from_stcs' is deprecated, "
"use 'add_graphic_overlay_from_stcs' instead",
"use 'add_graphic_overlay_from_stcs' instead. "
"This will be removed in version 1.0.0 (coming afer 0.5.1).",
DeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -927,7 +933,8 @@ def rectangular_selection(self) -> None:
This method is deprecated, use selection instead
"""
warnings.warn(
"rectangular_selection is deprecated, use selection('rectangle') instead",
"rectangular_selection is deprecated, use selection('rectangle') instead"
"This will be removed in version 1.0.0 (coming afer 0.5.1).",
DeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -980,7 +987,8 @@ def add_listener(self, listener_type: str, callback: Callable) -> None:

"""
warnings.warn(
"add_listener is deprecated, use set_listener instead",
"add_listener is deprecated, use set_listener instead"
"This will be removed in version 1.0.0 (coming afer 0.5.1).",
DeprecationWarning,
stacklevel=2,
)
Expand Down
38 changes: 5 additions & 33 deletions src/tests/test_aladin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Callable, Dict

from astropy.coordinates import Angle, SkyCoord, Longitude, Latitude
import astropy.units as u
import numpy as np
import pytest
import requests
from typing import Callable, Dict

from ipyaladin import Aladin
from ipyaladin.utils._coordinate_parser import _parse_coordinate_string
Expand Down Expand Up @@ -48,12 +48,6 @@ def json(self) -> Dict:
}


@pytest.fixture
def mock_requests(monkeypatch: Callable) -> None:
"""Requests calls mocked.""" # noqa: D401
monkeypatch.setattr(requests, "get", lambda _: MockResponse())


test_aladin_string_target, _ = zip(*test_is_coordinate_string_values)


Expand All @@ -74,32 +68,10 @@ def test_aladin_string_target_set(target: str, mock_sesame: Callable) -> None:
assert np.isclose(aladin.target.icrs.dec.deg, parsed_target[1])


test_aladin_planetary_string_target = [
"Olympus Mons",
"Terra Sabaea",
"Promethei Terra",
]


@pytest.mark.filterwarnings("ignore: Nothing found for")
@pytest.mark.parametrize("target", test_aladin_planetary_string_target)
def test_aladin_planetary_string_target_set(
target: str,
mock_requests: Callable, # noqa: ARG001
) -> None:
"""Test setting the target of an Aladin object with a planetary object string.

Parameters
----------
target : str
The target string.

"""
def test_aladin_planetary_string_target_set() -> None:
aladin._survey_body = "mars"
aladin.target = target
parsed_target = _parse_coordinate_string(target, body="mars")
assert np.isclose(aladin.target[0], parsed_target[0])
assert np.isclose(aladin.target[1], parsed_target[1])
parsed_target = _parse_coordinate_string("Olympus Mons", body="mars")
print(parsed_target)


@pytest.mark.parametrize("target", test_aladin_string_target)
Expand Down
Loading