#!/usr/bin/env python # coding: utf-8 # In[1]: import csv from astropy.coordinates import SkyCoord import astropy.units as u # Initialize empty lists for RA and Dec ra_list = [] dec_list = [] # Define the path to your CSV file csv_file_path = "GeVgal.csv" # Open and read the CSV file with open(csv_file_path, 'r') as csvfile: # Use csv.reader to handle the file, skipping the header row csv_reader = csv.reader(csvfile) next(csv_reader) # Skip the header row # Loop through each row in the CSV for row in csv_reader: try: # Extract l and b, which are in the second and third columns (index 1 and 2) l = float(row[1]) b = float(row[2]) # Create a SkyCoord object with galactic coordinates galactic_coord = SkyCoord(l=l*u.degree, b=b*u.degree, frame='galactic') # Convert to ICRS (equatorial) coordinates icrs_coord = galactic_coord.icrs # Append the RA and Dec values to the lists ra_list.append(icrs_coord.ra.deg) dec_list.append(icrs_coord.dec.deg) except (ValueError, IndexError) as e: # Handle potential errors if a row is malformed print(f"Skipping a malformed row: {row} - Error: {e}") # Now, ra_list and dec_list contain the converted coordinates print("RA List:", ra_list) print("Dec List:", dec_list) # In[ ]: import requests import json # Define the URL of your Django API endpoint url = "http://localhost:8000/api/stacked-upper-limit/" payload = { "ra": ra_list, # List of RA values "dec": dec_list, # List of Dec values "cl": 0.95, # A numeric confidence level "survey": "1-4", # A string for the survey parameter "mr": 0 # A numeric value for map_radius } try: # Send the PUT request with the JSON payload response = requests.put(url, json=payload) # Check the response status code response.raise_for_status() # This will raise an HTTPError for bad responses (4xx or 5xx) # Print the JSON response from the server print("Request successful!") print(json.dumps(response.json(), indent=4)) except requests.exceptions.HTTPError as err: print(f"HTTP Error: {err}") print(f"Response body: {err.response.text}") except requests.exceptions.RequestException as err: print(f"An error occurred: {err}")