Skip to content

Commit

Permalink
Merge branch 'master' of github.com:RobertRosca/JAXTAM.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertRosca committed Aug 8, 2018
2 parents 01b001d + c6fb3ad commit 7842103
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 21 deletions.
2 changes: 2 additions & 0 deletions src/JAXTAM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ using Compat
using FITSIO
using Feather
using StatsBase
using Mustache
using DSP
using Plots
gr()
Expand All @@ -32,5 +33,6 @@ include("science/lcurve.jl")
include("science/fspec.jl")
include("science/plots.jl")
include("web/webgen.jl")
include("web/subgen.jl")

end
44 changes: 25 additions & 19 deletions src/science/read_events.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ struct InstrumentData <: JAXTAMData
header::DataFrame
end

function _read_fits_hdu(fits_file, hdu_id)
fits_cols_events = Array{String,1}

try
fits_cols_events = FITSIO.colnames(fits_file[hdu_id])
catch UndefVarError
@warn "FITSIO colnames function not found, try trunning `Pkg.checkout(\"FITSIO\")`"
throw(UndefVarError("colnames not defined"))
function _read_fits_hdu(fits_file, hdu_id; cols="auto")
if cols == "auto"
fits_cols_events = Array{String,1}

try
fits_cols_events = FITSIO.colnames(fits_file[hdu_id])
catch UndefVarError
@warn "FITSIO colnames function not found, try trunning `Pkg.checkout(\"FITSIO\")`"
throw(UndefVarError("colnames not defined"))
end

println(fits_cols_events)
else
fits_cols_events = cols
end

fits_hdu_data = DataFrame()
Expand All @@ -28,25 +34,25 @@ function _read_fits_hdu(fits_file, hdu_id)
if ndims(fits_col_data) == 1
fits_hdu_data[Symbol(col)] = fits_col_data
end
catch
@warn "$col not supported by FITSIO, skipped"
catch error
@warn "$col not supported by FITSIO, skipped - $error"
end
end

return fits_hdu_data
end

function _read_fits_event(fits_path)
print("\n"); @info "Loading $fits_path"
@info "Loading $fits_path"
fits_file = FITS(fits_path)

fits_header = read_header(fits_file[1])
fits_header = read_header(fits_file["EVENTS"])

instrument_name = fits_header["INSTRUME"]
fits_telescope = fits_header["TELESCOP"]
fits_telescope = Symbol(lowercase(fits_telescope))

fits_events_df = _read_fits_hdu(fits_file, "EVENTS")
fits_events_df = _read_fits_hdu(fits_file, "EVENTS"; cols=String["TIME", "PI"])

fits_gtis_df = _read_fits_hdu(fits_file, "GTI")

Expand Down Expand Up @@ -122,7 +128,7 @@ function _save_cl_feather(feather_dir, instrument_name, fits_events_df, fits_gti
Feather.write(joinpath(feather_dir, "$instrument_name\_meta.feather"), fits_meta_df)
end

function read_cl(mission_name::Symbol, obs_row::DataFrames.DataFrame)
function read_cl(mission_name::Symbol, obs_row::DataFrames.DataFrame; overwrite=false)
obsid = obs_row[:obsid][1]
JAXTAM_path = abspath(string(obs_row[:obs_path][1], "/JAXTAM/"))

Expand All @@ -138,7 +144,7 @@ function read_cl(mission_name::Symbol, obs_row::DataFrames.DataFrame)
JAXTAM_e_files = count(contains.(JAXTAM_content, "events"))
JAXTAM_g_files = count(contains.(JAXTAM_content, "gtis"))

if JAXTAM_e_files > 0 && JAXTAM_g_files > 0 && JAXTAM_e_files == JAXTAM_g_files
if JAXTAM_e_files > 0 && JAXTAM_g_files > 0 && JAXTAM_e_files == JAXTAM_g_files && !overwrite
mission_data = Dict{Symbol,InstrumentData}()

#instruments = unique(replace.(JAXTAM_content, r"(_gtis|_events|_meta|_calib|.feather)", ""))
Expand Down Expand Up @@ -177,14 +183,14 @@ function read_cl(mission_name::Symbol, obs_row::DataFrames.DataFrame)
return mission_data
end

function read_cl(mission_name::Symbol, append_df::DataFrames.DataFrame, obsid::String)
function read_cl(mission_name::Symbol, append_df::DataFrames.DataFrame, obsid::String; overwrite=false)
obs_row = master_query(append_df, :obsid, obsid)

return read_cl(mission_name, obs_row)
return read_cl(mission_name, obs_row; overwrite=overwrite)
end

function read_cl(mission_name::Symbol, obsid::String)
function read_cl(mission_name::Symbol, obsid::String; overwrite=false)
append_df = master_a(mission_name)

return read_cl(mission_name, append_df, obsid)
return read_cl(mission_name, append_df, obsid; overwrite=overwrite)
end
98 changes: 98 additions & 0 deletions src/web/subgen.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
function _webgen_format_table(row::DataFrames.DataFrame)
col_num = size(row, 2)

table_th_full = ""
table_td_full = ""

for i = 1:col_num
table_th = """
<th>$(names(row)[i])</th>
"""

table_th_full = string(table_th_full, table_th)

table_td = """
<td>$(row[1, i])</td>
"""

table_td_full = string(table_td_full, table_td)
end

table_html = """
<table id=\"example\" class=\"table table-striped table-bordered\" style=\"width:100%\">
<thead>
<tr>
$table_th_full</tr>
</thead>
<tbody>
<tr>
$table_td_full</tr>
</tbody>
</table>
"""

return table_html
end

_webgen_sub_body_intro = mt"""
<body>
<div class=\"container\">
<h1>Observation {{obsid}} - {{name}}</h1>
<hr>
<h2>Abstract</h2>
<h4>{{title}} - {{subject_category}}</h4>
<p>{{abstract}}</p>
<hr>
<h4>Status</h4>
<table id=\"example\" class=\"table table-striped table-bordered\" style=\"width:100%\">
<thead>
<tr>
<th>public_date</th>
<th>publicity</th>
<th>time</th>
<th>downloaded</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{public_date}}</td>
<td>{{publicity}}</td>
<td>{{time}}</td>
<td>{{downloaded}}</td>
</tr>
</tbody>
</table>
<h4>Source Details</h4>
"""

function _webgen_sub(row::DataFrames.DataFrame)
table_status = _webgen_format_table(row[[:public_date, :publicity, :time, :downloaded]])
table_source = _webgen_format_table(row[[:name, :ra, :dec, :lii, :bii, :obs_type]])
table_obsdet = _webgen_format_table(row[[:time, :end_time, :exposure, :remarks]])
table_misc = _webgen_format_table(row[[:processing_status, :processing_date, :processing_version, :num_processed, :caldb_version, :remarks]])

header = _webgen_head(title="$(row[1, :obsid]) - $(row[1, :name])")

result_html = """
$header
<body>
<div class=\"container\">
<h1>Observation {{obsid}} - {{name}}</h1>
<hr>
<h2>Abstract</h2>
<h4>{{title}} - {{subject_category}}</h4>
<p>{{abstract}}</p>
<hr>
<h4>Status</h4>
$table_status
<h4>Source Details</h4>
$table_source
<h4>Observation Details</h4>
$table_obsdet
<h4>Misc</h4>
$table_misc
</body>
"""

return result_html
end
9 changes: 7 additions & 2 deletions src/web/webgen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ function _webgen_mastertable(mission_name::Symbol)
end

function webgen_mission(mission_name::Symbol)
web_html = string(_webgen_home(mission_name), _webgen_mastertable(mission_name))
web_dir = config(:web)

web_home_dir = joinpath(web_dir, "index.html")
web_home_html = string(_webgen_home(mission_name), _webgen_mastertable(mission_name))

write(web_home_dir, web_home_html)

return web_html
return web_home_dir
end

0 comments on commit 7842103

Please sign in to comment.