Skip to content

Commit

Permalink
Format code with Yapf & custom options
Browse files Browse the repository at this point in the history
  • Loading branch information
KastanDay committed Aug 29, 2023
1 parent 5fb81f7 commit 703210f
Showing 1 changed file with 39 additions and 35 deletions.
74 changes: 39 additions & 35 deletions eklavya/image_testing.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from function_calling_sloan import *
import requests


# Function to query galaxies within 1 arcminute of a given point
def query_galaxies(ra, dec):
# Base URL for the SDSS API's SkyServer SQL Search service
base_url = "http://skyserver.sdss.org/dr16/SkyServerWS/SearchTools/SqlSearch"
# Base URL for the SDSS API's SkyServer SQL Search service
base_url = "http://skyserver.sdss.org/dr16/SkyServerWS/SearchTools/SqlSearch"

# SQL query to retrieve galaxies within 1 arcminute of the specified point
query = f"""
# SQL query to retrieve galaxies within 1 arcminute of the specified point
query = f"""
SELECT TOP 100
p.objid, p.ra, p.dec
FROM PhotoObjAll p
Expand All @@ -17,21 +18,22 @@ def query_galaxies(ra, dec):
AND p.type = 3 -- Select only galaxies (type=3)
"""

# Construct the API request URL
url = f"{base_url}?cmd={query}"
# Construct the API request URL
url = f"{base_url}?cmd={query}"

# Make the HTTP GET request to the SDSS API
response = requests.get(url)
# Make the HTTP GET request to the SDSS API
response = requests.get(url)

# Check if the request was successful (status code 200)
if response.status_code == 200:
# Parse the response JSON to obtain the galaxy coordinates
data = response.json()
galaxies = [(i + 1, float(entry['ra']), float(entry['dec'])) for i, entry in enumerate(data)]
return galaxies
else:
print(f"Error: Unable to fetch galaxy data. Status code: {response.status_code}")
return []

# Check if the request was successful (status code 200)
if response.status_code == 200:
# Parse the response JSON to obtain the galaxy coordinates
data = response.json()
galaxies = [(i+1, float(entry['ra']), float(entry['dec'])) for i, entry in enumerate(data)]
return galaxies
else:
print(f"Error: Unable to fetch galaxy data. Status code: {response.status_code}")
return []

# Given point (RA, Dec) in degrees
ra_point = 184.9511
Expand All @@ -40,26 +42,28 @@ def query_galaxies(ra, dec):
# Query galaxies within 1 arcminute of the given point
galaxies_within_1arcmin = query_galaxies(ra_point, dec_point)


# Function to get the image cutouts for the galaxies
def get_galaxy_images(galaxies, image_size=256):
# Base URL for the SDSS API's Image Cutout service
base_url = "http://skyserver.sdss.org/dr16/SkyServerWS/ImgCutout/getjpeg"

for i, (ra, dec) in enumerate(galaxies):
# Construct the API request URL for each galaxy
url = f"{base_url}?ra={ra}&dec={dec}&scale=0.2&width={image_size}&height={image_size}"

# Make the HTTP GET request to the SDSS API
response = requests.get(url)

# Check if the request was successful (status code 200)
if response.status_code == 200:
# Save the image as a file
with open(f"galaxy_{i+1}.jpg", "wb") as f:
f.write(response.content)
print(f"Image for galaxy {i+1} saved as galaxy_{i+1}.jpg")
else:
print(f"Error: Unable to fetch the image for galaxy {i+1}. Status code: {response.status_code}")
# Base URL for the SDSS API's Image Cutout service
base_url = "http://skyserver.sdss.org/dr16/SkyServerWS/ImgCutout/getjpeg"

for i, (ra, dec) in enumerate(galaxies):
# Construct the API request URL for each galaxy
url = f"{base_url}?ra={ra}&dec={dec}&scale=0.2&width={image_size}&height={image_size}"

# Make the HTTP GET request to the SDSS API
response = requests.get(url)

# Check if the request was successful (status code 200)
if response.status_code == 200:
# Save the image as a file
with open(f"galaxy_{i+1}.jpg", "wb") as f:
f.write(response.content)
print(f"Image for galaxy {i+1} saved as galaxy_{i+1}.jpg")
else:
print(f"Error: Unable to fetch the image for galaxy {i+1}. Status code: {response.status_code}")


# Get images for the galaxies within 1 arcminute
get_galaxy_images(galaxies_within_1arcmin)

0 comments on commit 703210f

Please sign in to comment.