Skip to content

Commit

Permalink
Update documentation to new interface
Browse files Browse the repository at this point in the history
  • Loading branch information
MetinSa committed Jun 28, 2024
1 parent d61e697 commit 363b9e5
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 42 deletions.
4 changes: 2 additions & 2 deletions docs/examples/astropy_healpix_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import zodipy

model = zodipy.Model(30 * u.micron, n_proc=multiprocessing.cpu_count())
model = zodipy.Model(30 * u.micron)

healpix = ahp.HEALPix(nside=256, frame="galactic")
pixels = np.arange(healpix.npix)
Expand All @@ -18,7 +18,7 @@
# Note that we manually set the obstime attribute
skycoord.obstime = Time("2022-01-14")

emission = model.evaluate(skycoord)
emission = model.evaluate(skycoord, nprocesses=multiprocessing.cpu_count())

hp.mollview(
emission,
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/component_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"Earth-trailing Feature",
]

model = zodipy.Model(24 * u.micron, n_proc=multiprocessing.cpu_count())
model = zodipy.Model(24 * u.micron)

nside = 32
pixels = np.arange(hp.nside2npix(nside))
Expand All @@ -32,7 +32,7 @@
obstime=Time("2022-01-14"),
)

emission = model.evaluate(skycoord, return_comps=True)
emission = model.evaluate(skycoord, return_comps=True, nprocesses=multiprocessing.cpu_count())

fig = plt.figure(figsize=(8, 7))
for idx, comp_emission in enumerate(emission):
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/healpy_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

import zodipy

model = zodipy.Model(30 * u.micron, n_proc=multiprocessing.cpu_count())
model = zodipy.Model(30 * u.micron)

nside = 256
pixels = np.arange(hp.nside2npix(nside))
lon, lat = hp.pix2ang(nside, pixels, lonlat=True)

skycoord = SkyCoord(lon, lat, unit=u.deg, frame="galactic", obstime=Time("2022-01-14"))

emission = model.evaluate(skycoord)
emission = model.evaluate(skycoord, nprocesses=multiprocessing.cpu_count())

hp.mollview(
emission,
Expand Down
78 changes: 42 additions & 36 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,39 +31,14 @@ import zodipy

model = zodipy.Model(25 * u.micron, name="planck18")
```

### Multiprocessing
ZodiPy will distribute the input coordinates to cores if the keyword argument `n_proc` is `>= 1` using Python's `multiprocessing` module.

=== "Specifying number of processes"
```py hl_lines="4"
import astropy.units as u
import zodipy

model = zodipy.Model(25 * u.micron, n_proc=4)
```
=== "Custom pool object"

```py hl_lines="1 6 7"
import multiprocessing

import astropy.units as u
import zodipy

pool = multiprocessing.Pool(4)
model = zodipy.Model(25 * u.micron, pool=pool)
```

!!! tip
For all available optional keyword arguments in `zodipy.Model` see [the API reference](reference.md#zodipy.zodipy.Model).

## Simulating zodiacal light
To make zodiacal light simulations ZodiPy needs to know three things: 1) Sky coordinates for which to simulate zodiacal light; 2) The position of the observer to know where the vertex of the rays is positioned; and 3) the time of observation, used to query the position of Earth.

### The SkyCoord object
The sky coordinates are provided through Astropy's powerful `astropy.coordinates.SkyCoord` object, which can represent the observed coordinates in several formats. Users unfamiliar with the `SkyCoord` object should visit the [official Astropy documentation](https://docs.astropy.org/en/stable/coordinates/index.html) before using ZodiPy to learn the basics.
The sky coordinates for which to simulate zodiacal light is given to ZodiPy using Astropy's `astropy.coordinates.SkyCoord` object. Users unfamiliar with the `SkyCoord` object should visit the [official Astropy documentation](https://docs.astropy.org/en/stable/coordinates/index.html) before using ZodiPy to learn the basics.

When using the `SkyCoord` in ZodiPy, the user **must** set the `obstime` and `frame` attributes. For a single observation in galactic coordinates, the `SkyCoord` object may look something like

For a single observation in galactic coordinates, the `SkyCoord` object may look something like
```py hl_lines="2 5 6 7 8 9 10"
import astropy.units as u
from astropy.coordinates import SkyCoord
Expand All @@ -76,22 +51,26 @@ skycoord = SkyCoord(
frame="galactic"
)
```
The `astropy.time.Time` object can represent time in many formats, including Julian and modified Julian dates (see the [documentation](https://docs.astropy.org/en/stable/time/) on times with Astropy).
The `obstime` keyword is mandetory, and is given by an `astropy.time.Time` object, which can represent time in many formats, including Julian and modified Julian dates (see the [documentation](https://docs.astropy.org/en/stable/time/) on times with Astropy).

The sky coordinates should represent observer-centric coordinates. The observer-position is therefore required to compute the line-of-sight integrals, but this is provided not in the `SkyCoord` object, but rather in the `evaluate` method which we will see soon.

The user should use the following coordinate frames when transforming between Ecliptic, Galatic, and Celestial coordinates in string representation:
Common coordinate frames are the Ecliptic, Galactic, and Celestial frames ("E", "G", "C" in `healpy`), which can be specified through string representations:

- "barycentricmeanecliptic"
- "galactic"
- "icrs"
- `"barycentricmeanecliptic"` (Ecliptic)
- `"galactic"` (Galactic)
- `"icrs"` (Celestial)

or using the frame objects imported from `astropy.coordinataes`:
or using the frame objects imported from `astropy.coordinates`:

- `BarycentricMeanEcliptic`
- `Galactic`
- `ICRS`

!!! info "Notes on coordinate frames"
The user input is assumed to be observer-centric, meaning that we do not care about the origin of the frame passed in. This is instead supplied through the `obspos` keyword in the `evaluate` method. The above built-in Astropy frames share an origin and can therefore trivially be converted internally in ZodiPy.
While the above listed built-in Astropy frames do *not* represent observer-centric coordinate frames,
we still use these to specify the frame rotation, which is required internally as the model is evaluated in
ecliptic coordinates.

In the following, we show three sets of observations in all three coordinate frames
```py hl_lines="2 9 15 21"
Expand Down Expand Up @@ -176,6 +155,33 @@ This argument accepts both a string representing a body recognized by `astropy.c
!!! tip
If the coordinates in the `SkyCoord` object contain a large number of re-observations, as is the case for many satellite observations, setting the `contains_duplicates` keyword in the `evaluate` method to `True` will speed up the evaluations.


### Multiprocessing
ZodiPy will distribute the input coordinates to cores if the keyword argument `nprocesses` in the `evaluate` method is `nprocesses >= 1` using Python's `multiprocessing` module.
```py hl_lines="1 17"
import multiprocessing

import astropy.units as u
from astropy.coordinates import SkyCoord
from astropy.time import Time
import zodipy

model = zodipy.Model(25 * u.micron)

skycoord = SkyCoord(
40 * u.deg,
60 * u.deg,
obstime=Time("2020-01-01"),
frame="galactic"
)

emission = model.evaluate(skycoord, nprocesses=multiprocessing.cpu_count())
```

!!! tip
For all available optional keyword arguments in `zodipy.Model` see [the API reference](reference.md#zodipy.zodipy.Model).


## Examples

### Emission along an Ecliptic scan
Expand All @@ -189,7 +195,7 @@ In the following, we simulate a scan across the Ecliptic plane


### HEALPIx maps
We can use [healpy](https://healpy.readthedocs.io/en/latest/) or [Astropy-healpix](https://astropy-healpix.readthedocs.io/en/latest/) package to create a `SkyCoord` object directly from a HEALPIx pixelization
We can use [healpy](https://healpy.readthedocs.io/en/latest/) or [Astropy-healpix](https://astropy-healpix.readthedocs.io/en/latest/) to create a `SkyCoord` object directly from a HEALPIx pixelization

=== "healpy"

Expand Down

0 comments on commit 363b9e5

Please sign in to comment.