Skip to content

Commit

Permalink
Merge pull request #117 from cds-astro/make-write-call-save
Browse files Browse the repository at this point in the history
- add the `n_cells` method to each MOC type
- adds a new file to test abstract moc and remove duplicated `save` tests
- the `mocpy.stmoc.STMOC.from_spatial_coverages` now also accepts non iterable objects (prevents from having to wrap a single moc in a list each time it's used)
- fixed a warning in the notebooks because of `max_norder` argument that was introduced in a former version
- makes the `write` function `call` save internally [#114 ]
- save now accepts `fits_keywords` to be added to the header (was needed to keep all of `write` functionalities)
  • Loading branch information
ManonMarchand authored Nov 17, 2023
2 parents 091b210 + 2255310 commit 364618d
Show file tree
Hide file tree
Showing 20 changed files with 669 additions and 485 deletions.
9 changes: 3 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
default_language_version:
# force all unspecified python hooks to run python3.10
python: python3.10
repos:
# General hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: detect-private-key
description: "Check accidental private keys in code"
Expand All @@ -16,12 +13,12 @@ repos:
description: "Remove trailing whitespaces"
# Run Black on files
- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.11.0
hooks:
- id: black
# Fast linter to replace flake8
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.263'
rev: 'v0.1.5'
hooks:
- id: ruff
fail_fast: true
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

* currently supported versions of python now range from 3.8 to 3.12. There is a catch for python 3.8: the corresponding astropy version is pinned to astropy<5.3
* the deprecated `write` method now calls `save` internally

### Fixed

* all methods of `MOC` with signatures like `function(self, lon, lat, **kwargs)` now accept both lists of coordinates and single coordinates
* `mocpy.stmoc.STMOC.from_spatial_coverages` also accepts single moc objects (had to be a list before)
* `AbstractMOC` derives from metaclass `ABCMeta`

### Added

* `save` now accepts `fits_keywords` that are added to the fits header before writing the file
* `n_cells` gives the number of cells corresponding to a given order

## [0.13.0]

Expand Down
26 changes: 15 additions & 11 deletions notebooks/00-MOCpy_introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,17 @@
}
],
"source": [
"import mocpy\n",
"from mocpy import WCS\n",
"\n",
"import matplotlib.pyplot as plt\n",
"\n",
"from regions import CircleSkyRegion\n",
"import astropy.units as u\n",
"import matplotlib.pyplot as plt\n",
"import mocpy\n",
"from astropy.coordinates import Angle, SkyCoord\n",
"from astroquery.cds import cds\n",
"from astroquery.vizier import Vizier\n",
"from astroquery.simbad import Simbad\n",
"\n",
"from astroquery.vizier import Vizier\n",
"from ipyaladin import Aladin\n",
"from ipywidgets import Layout, Box, widgets\n",
"from ipywidgets import Box, Layout, widgets\n",
"from mocpy import WCS\n",
"from regions import CircleSkyRegion\n",
"\n",
"mocpy.__version__"
]
Expand Down Expand Up @@ -387,8 +384,15 @@
"viz.ROW_LIMIT = -1\n",
"# Photometric standard stars (tables II and IV of paper)\n",
"tables = viz.get_catalogs(\"II/50\")\n",
"\n",
"print(tables)\n",
"tables"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"table = tables[0]\n",
"table"
]
Expand Down
21 changes: 10 additions & 11 deletions notebooks/STMOC from time ranges.ipynb

Large diffs are not rendered by default.

59 changes: 36 additions & 23 deletions notebooks/filtering_astropy_table.ipynb

Large diffs are not rendered by default.

18 changes: 8 additions & 10 deletions notebooks/from_fits_and_intersection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"outputs": [],
"source": [
"import astropy.units as u\n",
"from astropy.coordinates import SkyCoord, Angle\n",
"import matplotlib.pyplot as plt\n",
"from mocpy import WCS, MOC"
"from astropy.coordinates import Angle, SkyCoord\n",
"from mocpy import MOC, WCS"
]
},
{
Expand Down Expand Up @@ -208,20 +208,18 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"MOC can also be serialized in JSON:\n",
"```python\n",
"m_intersect.write(format='json')\n",
"```"
"# MOC can also be serialized in JSON:\n",
"\n",
"m_intersect.to_string(format='json')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Or write it directly to a FITS/JSON file:\n",
"```python\n",
"m_intersect.write(path=<filename>, write_to_file=True, format='json'/'fits')\n",
"```"
"# Or write it directly to a FITS/JSON file:\n",
"\n",
"m_intersect.save(path=\"/tmp/moc\", write_to_file=True, format='json')\n"
]
}
],
Expand Down
22 changes: 9 additions & 13 deletions notebooks/query_vizier_table.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"metadata": {},
"outputs": [],
"source": [
"from mocpy import MOC\n",
"import astropy.units as u"
"import astropy.units as u\n",
"from mocpy import MOC"
]
},
{
Expand All @@ -28,15 +28,7 @@
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING: Keyword 'TTYPE1' found more than once in a same HDU! We use the first occurrence.\n"
]
}
],
"outputs": [],
"source": [
"moc = MOC.from_vizier_table(\"VIII/84/7c\", nside=64)"
]
Expand Down Expand Up @@ -108,7 +100,7 @@
"source": [
"# table = moc.query_simbad(10000)\n",
"table = moc.query_vizier_table(\"I/239/hip_main\", max_rows=100000)\n",
"print(table)"
"table"
]
},
{
Expand All @@ -135,7 +127,11 @@
}
],
"source": [
"moc_table = MOC.from_lonlat(table[\"_RAJ2000\"].T * u.deg, table[\"_DEJ2000\"].T * u.deg, 7)\n",
"moc_table = MOC.from_lonlat(\n",
" table[\"_RAJ2000\"].T * u.deg,\n",
" table[\"_DEJ2000\"].T * u.deg,\n",
" max_norder=7,\n",
")\n",
"moc_table.display_preview()"
]
}
Expand Down
10 changes: 7 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dev = [
"astropy_healpix",
"pre-commit >= 2.20",
"pytest > 6.0",
"pytest-mock",
"pytest-cov",
"requests"
]
Expand All @@ -49,7 +50,8 @@ notebooks = [
"astroquery",
"ipyaladin",
"maser-data",
"regions"
"regions",
"nbmake" # to test the notebooks
]

[project.urls]
Expand Down Expand Up @@ -92,16 +94,18 @@ ruff = ["--ignore=B018,FBT003"]

[tool.ruff]
fix = true
show-fixes = true
force-exclude = true
exclude = ["docs/conf.py"]
format = "grouped"
extend-include = ["*.ipynb"]
output-format = "grouped"
show-source = true
ignore-init-module-imports = true
target-version = "py37"
extend-select = ["SIM", "FBT", "D", "UP", "N", "S", "B", "A",
"C4", "ICN", "RET", "ARG", "PD", "PGH",
"RUF", "YTT", "BLE", "COM", "DTZ", "EXE",
"ISC", "ICN001", "PIE", "PTH"
"ISC", "ICN001", "PIE", "PTH", "W", "I", "T20"
]
extend-ignore = ["E501", "D203", "D213", "D100", "N816", "D105", "N806", "N803", "FBT002", "N802"]
# E501: line length (done by black in our case)
Expand Down
Loading

0 comments on commit 364618d

Please sign in to comment.