astromlp.sdss package

Submodules

astromlp.sdss.datagen module

class astromlp.sdss.datagen.DataGen(ids, x=[], y=[], classes={'gz2c': ['A', 'Ec', 'Ei', 'Er', 'SBa', 'SBaR', 'SBb', 'SBbR', 'SBc', 'SBcR', 'SBd', 'SBdR', 'Sa', 'SaR', 'Sb', 'SbR', 'Sc', 'ScR', 'Sd', 'SdR', 'Seb', 'Sen', 'Ser'], 'subclass': ['AGN', 'BROADLINE', 'STARBURST', 'STARFORMING']}, batch_size=64, helper=None)

Bases: keras.utils.data_utils.Sequence

A data generator to use the SDSS Galaxy Subset dataset with Keras.

ids

list of SDSS object identifiers

Type

str

x

list of input variables (eg. img, spectra)

Type

[str]

y

list of output variables (eg. redshift, subclass)

Type

[str]

batch_size

batch size, defaults to 64

Type

int

on_epoch_end()

Method called at the end of every epoch.

astromlp.sdss.helper module

class astromlp.sdss.helper.Helper(ds: str = '../sdss-gs')

Bases: object

A helper class providing set of helper functions to deal with the SDSS Galaxy Subset dataset, henceforth refereed to as sdss-ds.

ds

location of the sdss-ds dataset, detauls to ‘../sdss-gs’

Type

str

get_obj(id, wise=False)

Retrieve information for a SDSS object.

Parameters

id (int) – a SDSS object identifier

Returns

a Dict containing proprieties available for the object from the sdss-ds

ids_list(has_img=False, has_fits=False, has_spectra=False, has_ssel=False, has_bands=False, has_wise=False, has_gz2c=False)

Build a list of SDSS objects identifiers from the sdss-ds dataset.

Parameters
  • has_img (bool) – include identifier only if RGB image file is available, defaults to False

  • has_fits (bool) – include identifier only if FITS data file is available, defaults to False

  • has_spectra (bool) – include identifier only if spectra data file is available, defaults to False

  • has_ssel (bool) – include identifier only if spectra selected bands data file is available, defaults to False

  • has_bands (bool) – include identifier only if bands data is available, defaults to False

  • has_wise (bool) – include identifier only if WISE data is available, defaults to False

Returns

list of SDSS objects identifiers

load_bands(_ids)

Load list of bands data into a numpy array given list of SDSS object identifiers.

Parameters

ids ([int]) – list of SDSS object identifiers

Returns

a numpy array

load_fits(_ids)

Load list of FITS data into a numpy array given list of SDSS object identifiers.

Parameters

ids ([int]) – list of SDSS object identifiers

Returns

a numpy array

load_img(filename)

Load RGB image into a numpy array from file.

Parameters

filename (str) – RGB image filename

Returns

a numpy array

load_imgs(_ids)

Load list of RGB images into a numpy array given list of SDSS object identifiers.

Parameters

ids ([int]) – list of SDSS object identifiers

Returns

a numpy array

load_spectra(filename)

Load spectra data into a numpy array from file.

Parameters

filename (str) – spectra data filename

Returns

a numpy array

load_spectras(ids)

Load list of spectra data into a numpy array given list of SDSS object identifiers.

Parameters

ids ([int]) – list of SDSS object identifiers

Returns

a numpy array

load_ssel(filename)

Load spectra selected bands data into a numpy array from file.

Parameters

filename (str) – spectra data filename

Returns

a numpy array

load_ssels(ids)

Load list of spectra selected bands data into a numpy array given list of SDSS object identifiers.

Parameters

ids ([int]) – list of SDSS object identifiers

Returns

a numpy array

load_wises(_ids)

Load list of WISE data into a numpy array given list of SDSS object identifiers.

Parameters

ids ([int]) – list of SDSS object identifiers

Returns

a numpy array

random_id()

Return a random SDSS object identifier from the sdss-ds dataset.

Returns

a random SDSS object identifier

save_fits(obj, filename=None, base_dir='./')

Retrieve and save FITS data file for a given SDSS object.

Parameters
  • obj – SDSS object

  • filename (str) – optional filename

Returns

a numpy array

save_img(obj, filename=None)

Retrieve and save RGB image for a given SDSS object.

Parameters
  • obj – SDSS object

  • filename (str) – optional filename

Returns

a numpy array

save_spectra(obj, filename=None)

Retrieve and save spectra data file for a given SDSS object.

Parameters
  • obj – SDSS object

  • filename (str) – optional filename

Returns

a numpy array

save_ssel(obj, filename=None, spectra_filename=None)

Retrieve and save spectra selected bands data file for a given SDSS object.

Parameters
  • obj – SDSS object

  • filename (str) – optional filename

Returns

a numpy array

y_list(ids, target)

Build a list of target data to use in the data generator for a continuous variable.

Parameters
  • ids ([int]) – list of SDSS object identifiers

  • target (str) – target variable

Returns

a numpy array

y_list_class(ids, target, classes)

Build a list of target data to use in the data generator for a class variable.

Parameters
  • ids ([int]) – list of SDSS object identifiers

  • target (str) – target variable

  • classes – classes object

Returns

a numpy array, class set

astromlp.sdss.predictor module

class astromlp.sdss.predictor.Predictor(model, model_store='./astromlp-models/model_store', x=None, y=None, helper=None, tmp_dir='/tmp/mysdss')

Bases: object

A predictor class for predicting data using astromlp-models.

model

the astromlp-model identifier (eg, i2r, f2s)

Type

str

model_store

location of the model store, defaults to ‘./astromlp-models/model_store’

Type

str

predict(objid, extra=True, return_input=True)

Perform a prediction on a model for a SDSS object identifier.

Parameters

objid (id) – SDSS object identifier

Returns

an object where the key output contains the resulting prediction

astromlp.sdss.shared module

astromlp.sdss.skyserver module

class astromlp.sdss.skyserver.SkyServer(base_url='http://skyserver.sdss.org/dr16/SkyServerWS')

Bases: object

Helper class to perform operations using the SkyServer Web Service.

base_url

SkyServer API base URL

Type

str

get_obj(objid, wise=True)

Retrieve information for a SDSS object.

Parameters
  • objid (int) – a SDSS object identifier

  • wise (bool) – include WISE data, defaults to False

Returns

a Dict containing proprieties available for the object from the sdss-ds

save_jpeg(objid, filename, ra=None, dec=None, scale=0.2, width=150, height=150)

Save RGB image in JPEG format for a given SDSS object identifier.

Parameters
  • objid (int) – a SDSS object identifier

  • filename (str) – RG image filename

  • scale (float) – scale to use, defaults to 0.2

  • width (int) – image width, defaults to 150

  • height (int) – image height, defaults to 150

  • wise (bool) – include WISE data, defaults to False

Returns

RGB image filename

astromlp.sdss.utils module

astromlp.sdss.utils.build_datagens(ids, x=None, y=None, batch_size=32, helper=None)

Build a data generator for a training, validation and test sets.

Parameters
  • ids ([int]) – a list of SDSS object identifiers

  • x ([str]) – list of input variables (eg. img, spectra)

  • y ([str]) – list of output variables (eg. redshift, subclass)

  • batch_size (int) – batch size, defaults to 32

Returns

a tuple of data generators

astromlp.sdss.utils.history_fit_plots(name, history, base_dir='./model_plots', smoothing=False)

Create plots given a tensorflow history object.

Parameters
  • name – model name

  • history – tensorflow history object or history dictionary

astromlp.sdss.utils.history_load(name, base_dir='./model_history')

Load saved model history.

Parameters
  • name (str) – model name

  • base_dir (str) – files base directory (optional, defaults to ‘./model_history’)

Returns

history dict from file

astromlp.sdss.utils.history_save(name, history, base_dir='./model_history')

Save model history given a tensorflow history object.

Parameters
  • name (str) – model name

  • history (dict) – tensorflow history object

  • base_dir (str) – files base directory (optional, defaults to ‘./model_history’)

astromlp.sdss.utils.my_callbacks(name=None, path=None, check_point=False, monitor='val_loss', mode='min', lr_scheduler=False, schedule='time_based_decay', tensor_board=True)

Return a list of Keras callbacks.

Parameters
  • name (str) – model name

  • path (str) – model path, for saving the model

  • check_point (bool) – include the ModelCheckpoint Keras default callback

  • lr_scheduler (bool) – include the LearningRateScheduler Keras default callback

  • schedule (str) – the learning rate schedule, ‘time_based_decay’ or ‘step_decay’

  • tensor_board (bool) – include the TensorBoard Keras default callback

astromlp.sdss.utils.train_test_split(ids)

Split list of ids into a training and test sets.

Parameters

ids ([int]) – a list of SDSS object identifiers

Returns

a tuple of lists

astromlp.sdss.utils.train_val_test_split(ids)

Split list of ids into a training, validation and test sets.

Parameters

ids ([int]) – a list of SDSS object identifiers

Returns

a tuple of lists

Module contents