-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
124 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
module Cosmic | ||
|
||
include("basic_cos.jl") | ||
include("thermo.jl") | ||
include("astroquery.jl") | ||
|
||
export a, redshift, cosmology, Mpc_to_km, sec_to_year, H, my_f, my_g, | ||
hubble_distance, χ, hubble_time, T, age, look_back_time, scale_fact, | ||
da_dt, ageGyr,scalefact_part | ||
da_dt, ageGyr,scalefact_part, fetch_gaia_data, filter_missing_values | ||
|
||
end# module end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using HTTP | ||
using DataFrames | ||
using CSV | ||
|
||
function fetch_gaia_data(query::String) | ||
url = "https://gea.esac.esa.int/tap-server/tap/sync" | ||
params = Dict( | ||
"REQUEST" => "doQuery", | ||
"LANG" => "ADQL", | ||
"FORMAT" => "csv", | ||
"QUERY" => query | ||
) | ||
encoded_params = join(["$k=$(HTTP.escapeuri(v))" for (k, v) in params], "&") | ||
response = HTTP.post(url, ["Content-Type" => "application/x-www-form-urlencoded"], encoded_params) | ||
if response.status == 200 | ||
data = CSV.read(IOBuffer(response.body), DataFrame) | ||
return data | ||
else | ||
error("Error: ", response.status, "\n", String(response.body)) | ||
end | ||
end | ||
|
||
function filter_missing_values(df::DataFrame) | ||
clean_data = dropmissing(df) | ||
return clean_data | ||
end | ||
|
||
query = """ | ||
SELECT TOP 10 | ||
source_id, | ||
ra, | ||
dec, | ||
parallax, | ||
phot_g_mean_mag | ||
FROM gaiadr3.gaia_source | ||
WHERE ra BETWEEN 0 AND 10 | ||
AND dec BETWEEN -10 AND 10 | ||
""" | ||
|
||
query1 = """ | ||
SELECT | ||
source_id, | ||
ra, | ||
dec, | ||
parallax, | ||
phot_g_mean_mag | ||
FROM gaiadr3.gaia_source | ||
WHERE ra BETWEEN 0 AND 10 | ||
AND dec BETWEEN -10 AND 10 | ||
""" | ||
|
||
function filter_missing_values(df::DataFrame) | ||
# Filter rows containing missing values | ||
clean_data = dropmissing(df) | ||
return clean_data | ||
end | ||
|
||
|
||
data = fetch_gaia_data(query1) | ||
dat_fil = filter_missing_values(data) | ||
println(dat_fil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,51 @@ | ||
using Cosmic | ||
using Test | ||
using Plots | ||
|
||
@testset "Cosmic.jl" begin | ||
@test my_f(2,1) == 11 | ||
@test my_g(2) == 4 | ||
@test redshift(2.9e-4) ≈ 3447.27586 | ||
@test cosmology().h ≈ 0.6774 | ||
@test scalefact_part(cosmology(),100) ≈ 148.9412838881 | ||
@test ageGyr(cosmology(),0) ≈ 13.80743453918 | ||
end | ||
end | ||
|
||
|
||
|
||
query = """ | ||
SELECT source_id, | ||
phot_g_mean_mag, | ||
bp_rp, | ||
phot_g_mean_flux, | ||
parallax | ||
FROM gaiadr3.gaia_source | ||
WHERE bp_rp IS NOT NULL AND phot_g_mean_mag IS NOT NULL AND parallax > 50 | ||
ORDER BY phot_g_mean_mag ASC | ||
""" | ||
|
||
gaia_data = fetch_gaia_data(query) | ||
data = filter_missing_values(gaia_data) | ||
|
||
parallax = gaia_data[:, "parallax"] | ||
distance = 1000.0 ./ parallax # distance in parsecs | ||
abs_mag = gaia_data[:, "phot_g_mean_mag"] .+ 5 .* log10.(parallax / 100.0) | ||
|
||
luminosity = 10 .^ ((4.83 .- abs_mag) ./ 2.5) | ||
|
||
bp_rp = gaia_data[:, "bp_rp"] | ||
|
||
normalized_bp_rp = (bp_rp .- minimum(bp_rp)) ./ (maximum(bp_rp) .- minimum(bp_rp)) | ||
|
||
cmap = cgrad(:plasma) | ||
|
||
scatter(bp_rp, log10.(luminosity), | ||
marker_z=normalized_bp_rp, | ||
color=cmap, | ||
xlabel="BP-RP", | ||
ylabel="Log(Luminosity/Lsun)", | ||
title="HR Diagram", | ||
legend=false, | ||
reverse=true) | ||
|
||
ylims!((minimum(log10.(luminosity)) - 0.5, maximum(log10.(luminosity)) + 0.5)) | ||
|
||
plot!() |