From 60b7ce3d3df2cd1a56ec8078d6df500b9c76539d Mon Sep 17 00:00:00 2001 From: stephane Date: Tue, 30 May 2023 12:56:39 +0200 Subject: [PATCH 1/3] minor changes --- scripts/build.jl | 5 ++++- src/GaiaClustering.jl | 2 +- src/data.jl | 2 +- src/isochrones.jl | 16 ++++++++++++++-- src/stellarcluster.jl | 3 ++- src/utils.jl | 2 +- 6 files changed, 23 insertions(+), 7 deletions(-) diff --git a/scripts/build.jl b/scripts/build.jl index aad48cb..896978a 100644 --- a/scripts/build.jl +++ b/scripts/build.jl @@ -85,7 +85,10 @@ function reprocess(meta) if haskey(row, :mclm) mextra.mcl= Int(floor(row.mclm)) else mextra.mcl= Int(floor(row.mcl)) end if haskey(row, :mneim) mextra.mnei= Int(floor(row.mneim)) else mextra.mnei= Int(floor(row.mnei)) end - debug_red(mextra) + #smextra.wvel= 8.0 + debug_red("Weights : $(mextra.w3d) $(mextra.wvel) $(mextra.whrd) ") + + extra(mextra, optim) push!(dfp, [mextra.votname]) CSV.write(progressfile, dfp, delim=";") diff --git a/src/GaiaClustering.jl b/src/GaiaClustering.jl index b517c39..e94bcea 100644 --- a/src/GaiaClustering.jl +++ b/src/GaiaClustering.jl @@ -24,7 +24,7 @@ using PyCall , PyPlot using VoronoiCells import GeometryBasics as gb -VERSION= "1.7.7" +VERSION= "1.7.8-dev" ## include all the types include("types.jl") diff --git a/src/data.jl b/src/data.jl index a2c25a9..bb49cd0 100644 --- a/src/data.jl +++ b/src/data.jl @@ -548,7 +548,7 @@ function get_data(m::GaiaClustering.meta) if m.zpt=="yes" zoff= true - println("## Will apply Zero Point offset correction on parallax...") + println("## Applying Zero Point offset correction on parallax...") else zoff= false end diff --git a/src/isochrones.jl b/src/isochrones.jl index 5c2a0ae..3254f7e 100644 --- a/src/isochrones.jl +++ b/src/isochrones.jl @@ -224,14 +224,27 @@ function update_nan_oc(df) ## absolute magnitude df.G = df.gbar0 .+ 5 .- 5log10.(df.distance) + debug_red(df) + return(df) end ########################################## ### get solar mass from isochrone ### function get_star_mass(df, iso) + global n println("### add star mass...") - n= length(iso.Gaia_G_EDR3) + + n= 0 + try + # debug_red(iso) + global n= length(iso.Gaia_G_EDR3) + debug_red("n: $n") + catch e + println("### Warning, no valid Gaia_G_EDR3 field in solution...") + return(0) + end + diso= zeros(2,n) diso[1,:] = iso.Gaia_BPmRP_EDR3 diso[2,:] = iso.Gaia_G_EDR3 @@ -280,7 +293,6 @@ function perform_isochrone_fitting(df, isomodeldir) df= update_nan_oc(df) - # debug_red(first(iso)) df= get_star_mass(df, iso) feh_gaia= median(df.mh) diff --git a/src/stellarcluster.jl b/src/stellarcluster.jl index 7f40fcc..8789132 100644 --- a/src/stellarcluster.jl +++ b/src/stellarcluster.jl @@ -783,7 +783,8 @@ function cycle_extraction_optim(df::GaiaClustering.Df, dfcart::GaiaClustering.Df println("## label $labelmax written as an oc solution...") ### isochrone fitting... - minptsiso= 10 # minimum pts to fit.. + minptsiso= 10 # minimum pts to fit. + if m.iso == "yes" && count(!isnan, oc.ag) > minptsiso println("## Performing isochrone fitting on the solution...") debug_red(count(!isnan, oc.ag)) diff --git a/src/utils.jl b/src/utils.jl index 4eef90b..d8f7eb1 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -76,7 +76,7 @@ end function debug_red(msg) ## - # println(red("##_debug_###### $msg")) + println(red("##_debug_###### $msg")) end ### check if two directories exist, if not issue a warning and extinction From 236c8d9f3d6238ffeaf985a479a0029c2cabe28d Mon Sep 17 00:00:00 2001 From: stephane Date: Fri, 2 Jun 2023 11:14:02 +0200 Subject: [PATCH 2/3] more checks on data --- src/isochrones.jl | 25 ++++++++++++++++++++++--- src/utils.jl | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/isochrones.jl b/src/isochrones.jl index 3254f7e..0a75037 100644 --- a/src/isochrones.jl +++ b/src/isochrones.jl @@ -130,6 +130,8 @@ function dist_cmd2iso(df, iso, wgt) diso[1,:] = iso.Gaia_BPmRP_EDR3 diso[2,:] = iso.Gaia_G_EDR3 + # debug_red("dist_cmd ...........") + kdtree = KDTree(diso; leafsize = 10) npts= length(df.G) @@ -138,9 +140,12 @@ function dist_cmd2iso(df, iso, wgt) pts[2,:] = df.G idxs, dists = knn(kdtree, pts, 1, true) + dists = dists .* wgt total= sum(dists) + # debug_red("dists total ... $total") + return(total) end ################################################################################ @@ -224,7 +229,6 @@ function update_nan_oc(df) ## absolute magnitude df.G = df.gbar0 .+ 5 .- 5log10.(df.distance) - debug_red(df) return(df) end @@ -241,7 +245,7 @@ function get_star_mass(df, iso) global n= length(iso.Gaia_G_EDR3) debug_red("n: $n") catch e - println("### Warning, no valid Gaia_G_EDR3 field in solution...") + println("### Warning : no valid Gaia_G_EDR3 field in solution...") return(0) end @@ -272,6 +276,8 @@ function perform_isochrone_fitting(df, isomodeldir) df= update_mag(df,false) oc= filter(:G => G -> !any(f -> f(G), (ismissing, isnothing, isnan)), df) + noc= nrow(oc) + debug_red("...length $noc") ## reading isochrone model if isomodeldir == "" @@ -295,7 +301,20 @@ function perform_isochrone_fitting(df, isomodeldir) df= get_star_mass(df, iso) - feh_gaia= median(df.mh) + if typeof(df) == Int64 ## no solution... + println("### Warning: no solution...") + feh_gaia= -99 + else + feh_gaia= median(df.mh) + end + return(df , age, feh, feh_gaia, iso) +end +## counting valid row in a df... +function counting_valid(df) + dft= filter(:mh => mh -> !any(f -> f(mh), (ismissing, isnothing, isnan)), df) + + nvalid= length(dft.mh) + return(nvalid) end \ No newline at end of file diff --git a/src/utils.jl b/src/utils.jl index d8f7eb1..4eef90b 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -76,7 +76,7 @@ end function debug_red(msg) ## - println(red("##_debug_###### $msg")) + # println(red("##_debug_###### $msg")) end ### check if two directories exist, if not issue a warning and extinction From 3db03db33601ee37f332f4083c472195b0225bee Mon Sep 17 00:00:00 2001 From: stephane Date: Fri, 2 Jun 2023 11:14:19 +0200 Subject: [PATCH 3/3] more checks --- src/GaiaClustering.jl | 2 +- src/stellarcluster.jl | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/GaiaClustering.jl b/src/GaiaClustering.jl index e94bcea..82debd8 100644 --- a/src/GaiaClustering.jl +++ b/src/GaiaClustering.jl @@ -24,7 +24,7 @@ using PyCall , PyPlot using VoronoiCells import GeometryBasics as gb -VERSION= "1.7.8-dev" +VERSION= "1.7.8" ## include all the types include("types.jl") diff --git a/src/stellarcluster.jl b/src/stellarcluster.jl index 8789132..f412d49 100644 --- a/src/stellarcluster.jl +++ b/src/stellarcluster.jl @@ -784,8 +784,10 @@ function cycle_extraction_optim(df::GaiaClustering.Df, dfcart::GaiaClustering.Df ### isochrone fitting... minptsiso= 10 # minimum pts to fit. + nvalid= counting_valid(oc) + debug_red("nvalid : $nvalid") - if m.iso == "yes" && count(!isnan, oc.ag) > minptsiso + if m.iso == "yes" && count(!isnan, oc.ag) > minptsiso && nvalid > minptsiso println("## Performing isochrone fitting on the solution...") debug_red(count(!isnan, oc.ag)) oc, age, feh, feh_gaia, iso= perform_isochrone_fitting(oc, m.isomodel)