171 lines
6.8 KiB
Plaintext
171 lines
6.8 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "4cffd6c5",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"RA List: [np.float64(24.1741435187182), np.float64(25.759787769012984), np.float64(49.32806570275772), np.float64(55.50613654382996), np.float64(60.97590646798826), np.float64(63.018113741788355), np.float64(143.0416839498853), np.float64(161.69014062163393), np.float64(176.53216723085026), np.float64(183.45178780664702), np.float64(191.28607761407375), np.float64(194.20387680952962), np.float64(204.38304472867193), np.float64(339.2669893687885), np.float64(0.8130105246497964), np.float64(164.03825008738184)]\n",
|
|
"Dec List: [np.float64(15.783869592105441), np.float64(13.645005280982105), np.float64(-41.10817408896737), np.float64(-47.22221653992977), np.float64(-43.34878852480052), np.float64(-32.87392378612486), np.float64(21.501827494459036), np.float64(11.819887017791151), np.float64(47.49512808371984), np.float64(14.900261322222237), np.float64(-0.4622668171007003), np.float64(-8.524938659400307), np.float64(8.885499320910338), np.float64(34.4157929700228), np.float64(16.14532447253357), np.float64(6.1729868291531)]\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import csv\n",
|
|
"from astropy.coordinates import SkyCoord\n",
|
|
"import astropy.units as u\n",
|
|
"\n",
|
|
"# Initialize empty lists for RA and Dec\n",
|
|
"ra_list = []\n",
|
|
"dec_list = []\n",
|
|
"\n",
|
|
"# Define the path to your CSV file\n",
|
|
"csv_file_path = \"GeVgal.csv\"\n",
|
|
"\n",
|
|
"# Open and read the CSV file\n",
|
|
"with open(csv_file_path, 'r') as csvfile:\n",
|
|
" # Use csv.reader to handle the file, skipping the header row\n",
|
|
" csv_reader = csv.reader(csvfile)\n",
|
|
" next(csv_reader) # Skip the header row\n",
|
|
"\n",
|
|
" # Loop through each row in the CSV\n",
|
|
" for row in csv_reader:\n",
|
|
" try:\n",
|
|
" # Extract l and b, which are in the second and third columns (index 1 and 2)\n",
|
|
" l = float(row[1])\n",
|
|
" b = float(row[2])\n",
|
|
"\n",
|
|
" # Create a SkyCoord object with galactic coordinates\n",
|
|
" galactic_coord = SkyCoord(l=l*u.degree, b=b*u.degree, frame='galactic')\n",
|
|
"\n",
|
|
" # Convert to ICRS (equatorial) coordinates\n",
|
|
" icrs_coord = galactic_coord.icrs\n",
|
|
"\n",
|
|
" # Append the RA and Dec values to the lists\n",
|
|
" ra_list.append(icrs_coord.ra.deg)\n",
|
|
" dec_list.append(icrs_coord.dec.deg)\n",
|
|
"\n",
|
|
" except (ValueError, IndexError) as e:\n",
|
|
" # Handle potential errors if a row is malformed\n",
|
|
" print(f\"Skipping a malformed row: {row} - Error: {e}\")\n",
|
|
"\n",
|
|
"# Now, ra_list and dec_list contain the converted coordinates\n",
|
|
"print(\"RA List:\", ra_list)\n",
|
|
"print(\"Dec List:\", dec_list)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "ff1d339a",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Request successful!\n",
|
|
"{\n",
|
|
" \"Status\": 0,\n",
|
|
" \"ErrorMessage\": \"\",\n",
|
|
" \"ClassicUpperLimit\": 36.99647944311798,\n",
|
|
" \"ClassicLowerLimit\": 0.0,\n",
|
|
" \"ClassicOneSideUL\": 33.54440898622437,\n",
|
|
" \"ClassicCountRateUpperLimit\": 0.022452965897451615,\n",
|
|
" \"ClassicCountRateLowerLimit\": 0.0,\n",
|
|
" \"ClassicCountRateOneSideUL\": 0.020357922763323065,\n",
|
|
" \"ClassicFluxUpperLimit\": 7.504496105362505e-13,\n",
|
|
" \"ClassicFluxLowerLimit\": 0.0,\n",
|
|
" \"ClassicFluxOneSideUL\": 6.804265983763352e-13,\n",
|
|
" \"BayesianUpperLimit\": 33.83295926177776,\n",
|
|
" \"BayesianLowerLimit\": 0.10792639479099073,\n",
|
|
" \"BayesianOneSideUL\": 33.727107645421896,\n",
|
|
" \"BayesianCountRateUpperLimit\": 0.020533042385357955,\n",
|
|
" \"BayesianCountRateLowerLimit\": 6.549995291856849e-05,\n",
|
|
" \"BayesianCountRateOneSideUL\": 0.020468801604397097,\n",
|
|
" \"BayesianFluxUpperLimit\": 6.862796537256179e-13,\n",
|
|
" \"BayesianFluxLowerLimit\": 2.189216978388652e-15,\n",
|
|
" \"BayesianFluxOneSideUL\": 6.841325222832595e-13,\n",
|
|
" \"FluxEstimate\": 3.2382519031831067e-13,\n",
|
|
" \"ApertureCounts\": 94,\n",
|
|
" \"ApertureBackgroundCounts\": 78.03571428571428,\n",
|
|
" \"SourceCounts\": 15.964285714285722,\n",
|
|
" \"Exposure\": 2057.325295693534,\n",
|
|
" \"SourceRate\": 0.009688639787230046,\n",
|
|
" \"BackgroundRate\": 0.03793066388142964,\n",
|
|
" \"NormalizedBackgroundRate\": 1.6914547063541448e-05,\n",
|
|
" \"Contamination\": false,\n",
|
|
" \"CountMap\": {\n",
|
|
" \"healpix\": [],\n",
|
|
" \"counts\": [],\n",
|
|
" \"exposure\": [],\n",
|
|
" \"nside\": 4096,\n",
|
|
" \"order\": \"ring\",\n",
|
|
" \"radius_as\": 0.0\n",
|
|
" }\n",
|
|
"}\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import requests\n",
|
|
"import json\n",
|
|
"\n",
|
|
"# Define the URL of your Django API endpoint\n",
|
|
"url = \"http://localhost:8000/api/stacked-upper-limit/\"\n",
|
|
"\n",
|
|
"payload = {\n",
|
|
" \"ra\": ra_list, # List of RA values\n",
|
|
" \"dec\": dec_list, # List of Dec values\n",
|
|
" \"cl\": 0.95, # A numeric confidence level\n",
|
|
" \"survey\": \"1-4\", # A string for the survey parameter\n",
|
|
" \"mr\": 0 # A numeric value for map_radius\n",
|
|
"}\n",
|
|
"\n",
|
|
"try:\n",
|
|
" # Send the PUT request with the JSON payload\n",
|
|
" response = requests.put(url, json=payload)\n",
|
|
"\n",
|
|
" # Check the response status code\n",
|
|
" response.raise_for_status() # This will raise an HTTPError for bad responses (4xx or 5xx)\n",
|
|
"\n",
|
|
" # Print the JSON response from the server\n",
|
|
" print(\"Request successful!\")\n",
|
|
" print(json.dumps(response.json(), indent=4))\n",
|
|
"\n",
|
|
"except requests.exceptions.HTTPError as err:\n",
|
|
" print(f\"HTTP Error: {err}\")\n",
|
|
" print(f\"Response body: {err.response.text}\")\n",
|
|
"except requests.exceptions.RequestException as err:\n",
|
|
" print(f\"An error occurred: {err}\")"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": ".venv-pypy",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.11.11"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|