hscmap

With this module, you can create hscMap windows in Jupyter Lab and control them from Python. Jupyter Lab process remembers status of hscMap windows, so you don’t loose your work on hscMap on reloading or closing the browser window.

Example

Zoom in on M31

import hscmap

w = hscmap.Window(title='My Window')
w.jump_to(10.651, 41.242, 0.5)
See Also:

Plot catalog objects obtained by hscdata.sql

import hscdata.sql

res = hscdata.sql.query('''
SELECT
    object_id
    ,ra
    ,dec
    ,i_cmodel_mag
    ,i_cmodel_magsigma
    ,y_cmodel_mag
    ,y_cmodel_magsigma
FROM
    pdr2_wide.forced
WHERE
    boxSearch(coord,
        151.38831350334513, 151.40458586556656,
        0.06900732437557724, 0.0825390607736913)
    AND isprimary
''', isNullColumn=False)

w = hscmap.Window()
w.jump_to(151.396, 0.076, 0.02)
catalog = w.catalogs.from_query_result(res)
See Also:

Selectable catalog

def selectableCatalog(res):
    indices = []

    def on_click(index):
        if index in indices:
            indices.remove(index)
        else:
            indices.append(index)
        refresh()

    def refresh():
        ra_selected = res.ra[indices]
        dec_selected = res.dec[indices]
        marker.set_coords(ra_selected, dec_selected)

    base = w.catalogs.from_query_result(res, color=[0, 1, 0, 0.25])
    base.on_click = on_click
    marker = w.catalogs.new([], [], name='marker', color=[0, 1, 1, 1])

    def clear():
        marker.remove()
        base.remove()

    refresh()
    return indices, clear

indices, clear = selectableCatalog(res)
# Click some of the objects to select and deselect
print(indices)
See Also:

Loag a FITS image onto an hscMap window

import hscdata.imagecutout as imagecutout

w.jump_to(216.20416023106773, -0.8893594325061295, 0.01)

hdul = imagecutout.getImage(216.20416023106773, -0.8893594325061295,
                            sw='1arcmin', sh='1arcmin', filter='HSC-I')

fits_image = w.fits_images.from_hdu(hdul[1])
See Also:

Save snapshot to file

w.snapshot.save('a.png')
! open a.png
See Also:

Save snapshot to notebook

fut = w.snapshot('a.png')
# wait few seconds
fut.result()
See Also:

Reference

Window

class hscmap.window.Window(*, title=None, mode=None, url=None)[source]

Bases: object

Represents a hscMap window. This can be also accessed with hscmap.Window instead of hscmap.window.Window.

Example

import hscmap

w = hscmap.Window(title="My Window")
Parameters
  • title (str) – Title of the new window

  • mode (str) – Insert mode. one of split-{top, left, right, bottom}, tab-{before, after}

catalogs = None

Catalog manager (CatalogManager) for this window. You can create a catalog through this object.

fits_images = None

Fits image manager (FitsImageManager) for this window. You can add a fits image through this object.

snapshot = None

See Also: hscmap.snapshot.Snapshot

close()[source]

Closes this window

jump_to(ra, dec, fov)[source]

Sets camera to the position.

Parameters
  • ra (float) – RA in dgrees

  • dec (float) – Ddec in decrees

  • fov (float) – Field of view in degrees

Example:

w.jump_to(10, 41, 1)
property title

Window title. Can be set or read.

Catalog

class hscmap.catalog.Catalog(window, ra, dec, columns, *, name, color=None)[source]

Bases: object

Represents a catalog.

Note

You should use hscmap.window.Window.catalogs to create a new Catalog instaed of directly using the constructor.

Parameters
  • window (hscmap.window.Window) – Owner window

  • ra (ndarray) – RA in degrees

  • dec (ndarray) – DEC in degrees

  • columns (dict<str, ndarray> | (str, ndarray)[]) – Additional columns

remove()[source]

Removes this catalog.

property name

Name of this catalog. Can be set and read.

property color

Color of markers. Can be set and read. It’s type should be [float, float, float, float].

set_coords(ra, dec, columns=[])[source]

Updates its objects’ coordinates and columns. Types of arameters are the same as Catalog.

on_click(index)[source]

Callback for clicking objects of this catalog. This method can be overwritten by user. It accepts an index of clicked object.

Example:

res = sql.query('SELECT ...')

catalog = w.catalogs.from_query_result(res)

indices = []
def on_click(index):
    indices.append(index)

catalog.on_click = on_click
class hscmap.catalog.CatalogManager(window)[source]

Bases: object

Manages catalogs that belongs to a hscmap window.

See also

catalogs

new(ra, dec, *, name=None, columns=[], color=None)[source]

Makes new catalog.

Parameters
  • ra (ndarray) – RA in degrees

  • dec (ndarray) – Dec in degrees

  • columns (dict<str, ndarray> | (str, ndarray)[]) – Additional columns

  • name (str) – catalog name

  • color ([float, float, float, float]) – marker color

Returns

Catalog

Example:

n = 100
a = numpy.random.uniform(150, 151, n)
d = numpy.random.uniform(1, 2, n)

w.jump_to(a[0], d[0], 1)
random_catalog = w.catalogs.new(a, d)
from_query_result(res, *, name=None, color=None)[source]

Makes new catalog plot from a resutltant object generated by hscdata.sql.query.

Parameters
  • res (hscdata.sql._QueryResult) – Query result

  • name (str) – Catalog name

  • color ([float, float, float, float]) – Marker color

Returns

Catalog

Example:

import hscdata.sql as sql

res = sql.query("""
SELECT
    object_id
    ,ra
    ,dec
    ,i_cmodel_mag
    ,i_cmodel_magsigma
    ,y_cmodel_mag
    ,y_cmodel_magsigma
FROM
    pdr2_wide.forced
WHERE
    boxSearch(coord,
        151.38831350334513, 151.40458586556656,
        0.06900732437557724, 0.0825390607736913)
    AND isprimary
""", isNullColumn=False)

catalog = w.catalogs.from_query_result(res)
clear()[source]

Clear all catalogs managed by this object.

property members

All catalogs on the window.

Returns

List of Catalog

FitsImage

class hscmap.fitsimage.FitsImage(window, hdu, name)[source]

Bases: object

Represents a FITS image.

Note

Use fits_images to make a new FITS image instead of using the constructor.

remove()[source]

Removes this FITS image.

property name

Name of this FITS image. Can be set and read. Its type must be str

property tone_window

Tone window flag, a boolean value. Can be set and read. If this flag is set to True, the tone window will be shown.

Example:

img = w.fits_images.from_hdu(hdu)
img.tone_window = True
class hscmap.fitsimage.FitsImageManager(window)[source]

Bases: object

Manages FITS images that belongs to a hscmap window.

See also

fits_images

from_hdu(hdu, *, name=None)[source]

Loads FITS image onto a hscMap window.

Parameters
  • hdu (astropy.io.fits.ImageHDU) – Source image HDU

  • name (str) – Name for the new image

Returns

FitsImage

clear()[source]

Clears all FITS images on the window.

property members

All FITS images on the window.

Returns

List of FitsImage

Snapshot

class hscmap.snapshot.Snapshot(window)[source]

Bases: object

See also

snapshot

__call__(*, width=None, height=None)[source]

Makes a request for snapshot. This returns a future object.

Example

fut = w.snapshot()
# wait few seconds
fut.result()
save(filename, *, width=None, height=None)[source]

Saves snapshot of the window to a file.

Parameters

filename (str) – file to save the image.

Returns

asyncio.Future

Example

fut = w.snapshot.save('a.png')
!open a.png