Skip to main content

A python package for retrieving and analysing data from SDSS (Sloan Digital Sky Survey)

Project description

Author: Behrouz Safari
License: MIT

sdss

A python package for retrieving and analysing data from SDSS (Sloan Digital Sky Survey)

Installation

Install the latest version of sdss from PyPI:

pip install sdss

Requirements are numpy, requests, Pillow, matplotlib, pandas and astropy. Versions before 1.0.0 are not dependent on astropy.

Quick start

Let's create a Region:

from sdss import Region

ra = 179.689293428354
dec = -0.454379056007667

reg = Region(ra, dec, fov=0.033)

To see the image:

reg.show()

alt text

To see the image in three gri filter bands (green, red, infrared) separately:

reg.show3b()

alt text

To find nearest objects:

df_obj = reg.nearest_objects()

To find nearest objects with spectrum:

df_sp = reg.nearest_spects()

Photometry example

Let's download a frame, in fits and jpg, retrieve all of its objects.:

from sdss.photometry import frame_filename, obj_frame_url, \
     download_file, unzip, get_df, df_radec2pixel

objid = 1237646587710014999

zip_file = 'data/' + frame_filename(objid) + '.fits.bz2'
fits_file = zip_file[:-4]
jpg_file = fits_file.replace('-r-', '-irg-').replace('fits', 'jpg')

zip_url = obj_frame_url(objid, 'r')
download_file(zip_url, 'data/')
unzip(zip_file)

jpg_url = obj_frame_url(objid, 'irg', jpg=True)
download_file(jpg_url, 'data/')

df = get_df(objid)
df = df_radec2pixel(df=df, fits_file=fits_file)

df.to_csv('data/COMP.csv', index=False)

Now we can plot our target image:

import pandas as pd
import matplotlib.pyplot as plt
from sdss.photometry import frame_filename, obj_from_jpg

objid = 1237646587710014999

jpg_file = 'data/' + frame_filename(objid).replace('-r-', '-irg-') + '.jpg'

df = pd.read_csv('data/COMP.csv')

img = obj_from_jpg(jpg_file=jpg_file, df=df, objid=objid)

fig, ax = plt.subplots()
ax.imshow(img)
plt.show()

Let's find the best apparture:

from sdss.photometry import flux

data = img[:,:,0]
half = data.shape[0]//2
center = (half, half)

ls_r_star = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
ls_background = []
ls_real_flux = []
for r_star in ls_r_star:
    background, real_flux = flux(data, center, r_star)
    ls_background.append(background)
    ls_real_flux.append(real_flux)

fig, ax = plt.subplots()
ax.scatter(ls_r_star, ls_real_flux, c='b')
ax.set_xlabel('R star')
ax.set_ylabel('Sky subtracted flux')
plt.grid()
plt.show()

See more examples at astrodatascience.net

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sdss-1.1.1.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sdss-1.1.1-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file sdss-1.1.1.tar.gz.

File metadata

  • Download URL: sdss-1.1.1.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.7

File hashes

Hashes for sdss-1.1.1.tar.gz
Algorithm Hash digest
SHA256 e40c3bd43c28df692d10e05bbd06a1ef06d55b84e4cb4c11cf0adb61556fa344
MD5 07c85913a665fd89f693f8037637fdd4
BLAKE2b-256 a03d5035a6ef32b94c18be7c25fd4085c1090260fa4268b59954161d4b0263ee

See more details on using hashes here.

File details

Details for the file sdss-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: sdss-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.7

File hashes

Hashes for sdss-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 479ceea56d60febfc73a575640a81cedd71a07b957fab07dd23c4e27661f612d
MD5 f9c9f9da616d119ceb1cfdbf19cbc812
BLAKE2b-256 df31c194d9c3857ccda0b50bf99195577865200e05ca0a984871fc9aaa33d0ee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page