Skip to content

Commit

Permalink
Add class method to load skymap data from a FITS file. This needs to …
Browse files Browse the repository at this point in the history
…be fleshed out.
  • Loading branch information
fjankowsk committed Jan 31, 2024
1 parent 14a8edb commit cd96438
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions skymap/skymap.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,40 @@ def load_from_file(cls, filename):

return loaded

@classmethod
def load_from_fits(cls, filename):
"""
Load Skymap from FITS file.
Parameters
----------
filename: str
The name of the file.
Returns
-------
loaded: ~Skymap
The loaded Skymap object.
Raises
------
RuntimeError
If the file does not exist.
"""

if not os.path.isfile(filename):
raise RuntimeError("The file does not exist: {0}".format(filename))

data = hp.read_map(filename=filename)

# figure out parameters
nside = hp.npix2nside(len(data))

loaded = Skymap(nside=nside, quantity="", unit="")
loaded.__data = data.astype(np.float32)

return loaded

def save_to_file(self, filename):
"""
Save Skymap to file.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_healpy_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_healpy_functionality():
mask = hp.query_disc(
nside=NSIDE,
vec=vec,
radius=np.radians(0.58)
radius=np.radians(0.58),
# radius=np.radians(0.5 * 12 / 60.0)
)

Expand Down

0 comments on commit cd96438

Please sign in to comment.