rowCount();$i++){ $row = $resultCoordinates->fetch(); $targetName = $row['targetName']; // $resultCoordinates $ra = $row['ra']; // $resultCoordinates $declination = $row['declination']; // $resultCoordinates $coordinates[$targetName][0] = $ra; $coordinates[$targetName][1] = $declination; } //See how many exceptions there are per script $queryScript = "SELECT COUNT(`time`) AS `number`, `script` "; $queryScript .= "FROM `exceptions` "; $queryScript .= "WHERE `time`>='$date' AND `status` LIKE '$status' GROUP BY `script` ORDER BY FIELD(`script`,'monitoring_pipeline.py', 'monitoring_xrtgrblc.py')"; $resultScript = db_query($queryScript,$dbh); if($resultScript->rowCount()>0){ for($i=0;$i<$resultScript->rowCount();$i++){ $row = $resultScript->fetch(); $this->exceptions->script[$i]->name = $row["script"]; // $resultScript $this->exceptions->script[$i]->number = $row["number"]; // $resultScript $query = "SELECT `exceptions`.`ID`, DATE_FORMAT(`exceptions`.`time`,'%m-%d-%Y %H:%i:%s') AS `time`, `exceptions`.`targetName`, `exceptions`.`observationID`, `exceptions`.`description`, `exceptions`.`status`, `exceptions`.`comments`, "; $query .= "`observations`.`targetID`, `observations`.`segment`, "; $query .= "`observations`.`pipeline_wt`, `observations`.`wttime`, `observations`.`wtsnapshots`, `observations`.`wtevents`, "; $query .= "`observations`.`pipeline_pc`, `observations`.`pctime`, `observations`.`pcsnapshots`, `observations`.`pcevents`, "; $query .= "`observations`.`pipeline`, `observations`.`xrtgrblc`, `observations`.`plot`, "; $query .= "TIMESTAMPDIFF(SECOND,`exceptions`.`time`,NOW()) AS `timeSinceProcessed` "; $query .= "FROM `exceptions`, `observations` "; $query .= "WHERE `script` LIKE '".$this->exceptions->script[$i]->name."' AND `time`>='$date' AND `exceptions`.`status` LIKE '$status' AND "; $query .= "`exceptions`.`observationID` LIKE `observations`.`observationID` AND `exceptions`.`targetName` LIKE `observations`.`targetName` ORDER BY `ID`"; $result = db_query($query,$dbh); //Grab individual exceptions to report back for($j=0;$j<$result->rowCount();$j++){ $row = $result->fetch(); $this->exceptions->script[$i]->exception[$j]->ID = $row["ID"]; // $result $this->exceptions->script[$i]->exception[$j]->time = $row["time"]; // $result $this->exceptions->script[$i]->exception[$j]->targetName = $row["targetName"]; // $result $this->exceptions->script[$i]->exception[$j]->observationID = $row["observationID"]; // $result $this->exceptions->script[$i]->exception[$j]->description = $row["description"]; // $result $this->exceptions->script[$i]->exception[$j]->targetID = $row["targetID"]; // $result $this->exceptions->script[$i]->exception[$j]->segment = $row["segment"]; // $result $this->exceptions->script[$i]->exception[$j]->status = $row["status"]; // $result $this->exceptions->script[$i]->exception[$j]->comments = $row["comments"]; // $result $this->exceptions->script[$i]->exception[$j]->pipeline = $row["pipeline"]; // $result $this->exceptions->script[$i]->exception[$j]->xrtgrblc = $row["xrtgrblc"]; // $result $this->exceptions->script[$i]->exception[$j]->plot = $row["plot"]; // $result $this->exceptions->script[$i]->exception[$j]->timeSinceProcessed = $row["timeSinceProcessed"]; // $result $afst = new AFST(); $afst -> SimpleStatistics($this->exceptions->script[$i]->exception[$j]->targetID,$this->exceptions->script[$i]->exception[$j]->segment); $this->exceptions->script[$i]->exception[$j]->observationEnd = $afst->observation->end; $this->exceptions->script[$i]->exception[$j]->timeSince = $afst->observation->timeSince; $this->exceptions->script[$i]->exception[$j]->RA = $afst->observation->ra; $this->exceptions->script[$i]->exception[$j]->declination = $afst->observation->declination; $sourceCoordinates = $coordinates[$this->exceptions->script[$i]->exception[$j]->targetName]; if($afst->observation->ra!=''){ $observationCoordinates = array($afst->observation->ra,$afst->observation->declination); $this->exceptions->script[$i]->exception[$j]->separation = Separation($sourceCoordinates,$observationCoordinates); } else $this->exceptions->script[$i]->exception[$j]->separation="Not observed"; //There is not as much information if the observation doesn't get through the pipeline. Try the AFST instead. if($this->exceptions->script[$i]->name=='monitoring_pipeline.py'){ $this->exceptions->script[$i]->exception[$j]->pipeline_wt = $row["pipeline_wt"]; // $result $this->exceptions->script[$i]->exception[$j]->wtTime = 0; $this->exceptions->script[$i]->exception[$j]->wtSnapshots = 0; $this->exceptions->script[$i]->exception[$j]->wtEvents = 0; $this->exceptions->script[$i]->exception[$j]->pipeline_pc = $row["pipeline_pc"]; // $result $this->exceptions->script[$i]->exception[$j]->pcTime = 0; $this->exceptions->script[$i]->exception[$j]->pcSnapshots = 0; $this->exceptions->script[$i]->exception[$j]->pcEvents = 0; if($afst->observation->xrt==6){ $this->exceptions->script[$i]->exception[$j]->wtTime = $afst->observation->duration; $this->exceptions->script[$i]->exception[$j]->wtSnapshots = $afst->observation->snapshots; $this->exceptions->script[$i]->exception[$j]->mode = 'WT'; } elseif($afst->observation->xrt==7) { $this->exceptions->script[$i]->exception[$j]->pcTime = $afst->observation->duration; $this->exceptions->script[$i]->exception[$j]->pcSnapshots = $afst->observation->snapshots; $this->exceptions->script[$i]->exception[$j]->mode = 'PC'; } else { $this->exceptions->script[$i]->exception[$j]->wtTime = $afst->observation->duration; $this->exceptions->script[$i]->exception[$j]->wtSnapshots = $afst->observation->snapshots; $this->exceptions->script[$i]->exception[$j]->pcTime = $afst->observation->duration; $this->exceptions->script[$i]->exception[$j]->pcSnapshots = $afst->observation->snapshots; if($afst->observation->xrt==0) $this->exceptions->script[$i]->exception[$j]->mode = 'Auto'; else $this->exceptions->script[$i]->exception[$j]->mode = 'Unknown'; } } else { $this->exceptions->script[$i]->exception[$j]->pipeline_wt = $row["pipeline_wt"]; // $result $this->exceptions->script[$i]->exception[$j]->wtTime = $row["wttime"]; // $result $this->exceptions->script[$i]->exception[$j]->wtSnapshots = $row["wtsnapshots"]; // $result $this->exceptions->script[$i]->exception[$j]->wtEvents = $row["wtevents"]; // $result $this->exceptions->script[$i]->exception[$j]->pipeline_pc = $row["pipeline_pc"]; // $result $this->exceptions->script[$i]->exception[$j]->pcTime = $row["pctime"]; // $result $this->exceptions->script[$i]->exception[$j]->pcSnapshots = $row["pcsnapshots"]; // $result $this->exceptions->script[$i]->exception[$j]->pcEvents = $row["pcevents"]; // $result if($this->exceptions->script[$i]->exception[$j]->pcSnapshots>0 && $this->exceptions->script[$i]->exception[$j]->wtSnapshots>0) $this->exceptions->script[$i]->exception[$j]->mode='Auto'; else if($this->exceptions->script[$i]->exception[$j]->wtSnapshots>0) $this->exceptions->script[$i]->exception[$j]->mode='WT'; else if($this->exceptions->script[$i]->exception[$j]->pcSnapshots>0) $this->exceptions->script[$i]->exception[$j]->mode='PC'; else $this->exceptions->script[$i]->exception[$j]->mode='Unknown'; } } } } else unset($this->exceptions); } function UserViaEmail($email){ $dbh = unidentified_db_connect(); $query = "SELECT `fname`, `lname`, `email`, `pw`, `status`, `key`, `logIn` FROM `users` WHERE `email` LIKE '$email'"; $result = db_query($query,$dbh); if($result->rowCount()>0){ $row = $result->fetch(); $this->user->fName = $row['fname']; // $result $this->user->lName = $row['lname']; // $result $this->user->email = $row['email']; // $result $this->user->pw = $row['pw']; // $result $this->user->status = $row['status']; // $result $this->user->key = $row['key']; // $result $this->user->logIn = $row['logIn']; // $result /* $querySources = "SELECT `source`.`targetName`, `source`.`folder`, `source`.`RA`, `source`.`declination`, "; $querySources .= "`source`.`privacy`, `source`.`plot` FROM `user_defined_sources` "; $querySources .= "JOIN `source` ON (`user_defined_sources`.`targetName` = `source`.`targetName`) WHERE `email` LIKE '".$this->user->email."'"; $resultSources = db_query($querySources,$dbh); if($resultSources->rowCount()>0){ for($i=0;$i<$resultSources->rowCount();$i++){ $this->user->sources[$i]->targetName = $row['targetName']; // $resultSources // $this->user->sources[$i]->folder = $row['folder']; // $resultSources // $this->user->sources[$i]->RA = $row['RA']; // $resultSources // $this->user->sources[$i]->declination = $row['declination']; // $resultSources // $this->user->sources[$i]->type = $row['type']; // $resultSources // $this->user->sources[$i]->plot = $row['plot']; // $resultSources } } */ } else unset($this->user); } function UserViaKey($key){ $dbh = unidentified_db_connect(); $query = "SELECT `fname`, `lname`, `email`, `pw`, `email`, `status`, `key`, `logIn` FROM `users` WHERE `key` LIKE '$key'"; $result = db_query($query,$dbh); if($result->rowCount()>0){ $row = $result->fetch(); $this->user->fName = $row['fname']; // $result $this->user->lName = $row['lname']; // $result $this->user->email = $row['email']; // $result $this->user->pw = $row['pw']; // $result $this->user->status = $row['status']; // $result $this->user->key = $row['key']; // $result $this->user->logIn = $row['logIn']; // $result } else unset($this->user); } function GetUsers(){ $dbh = unidentified_db_connect(); $query = "SELECT COUNT(`email`) AS `number`, `status` FROM `users` GROUP BY `status` ORDER BY FIELD(`status`, 'new', 'admin', 'user')"; $resultStatus = db_query($query,$dbh); if($resultStatus->rowCount()>0){ for($i=0;$i<$resultStatus->rowCount();$i++){ $srow = $resultStatus->fetch(); $this->users->status[$i]->status = $srow['status']; // $resultStatus $this->users->status[$i]->number = $srow['number']; // $resultStatus $query = "SELECT `fname`, `lname`, `email` FROM `users` WHERE `status` LIKE '".$this->users->status[$i]->status."'"; $result = db_query($query,$dbh); for($j=0;$j<$result->rowCount();$j++){ $row = $result->fetch(); $this->users->status[$i]->user[$j]->fName = $row['fname']; // $result $this->users->status[$i]->user[$j]->lName = $row['lname']; // $result $this->users->status[$i]->user[$j]->email = $row['email']; // $result } } } else $this->users = 0; } function UpdateUserStatus($email,$status){ $dbh = unidentified_db_connect(); if($email!='stroh@astroh.org'){ if($status=='decline') $command = "DELETE FROM `users` WHERE `email` LIKE '$email'"; else $command = "UPDATE `users` SET `status` = '$status' WHERE `email` LIKE '$email'"; db_query($command,$dbh); } } function AddUserKey($email,$key){ $dbh = unidentified_db_connect(); $command = "UPDATE `users` SET `key` = '$key', `logIn` = NOW() WHERE `email` LIKE '$email'"; db_query($command,$dbh); } function ChangePassword($email,$hash){ $dbh = unidentified_db_connect(); $command = "UPDATE `users` SET `pw`='$hash' WHERE `email` LIKE '$email'"; db_query($command,$dbh); } function UpdateException($id,$status,$comments,$targetName,$observationID){ $dbh = unidentified_db_connect(); if($status=='reprocess'){ $command = "DELETE FROM `observations` WHERE `targetName` LIKE '$targetName' AND `observationID` LIKE '$observationID'"; db_query($command,$dbh); $command = "UPDATE `exceptions` SET `status`='closed', `comments`='$comments' WHERE `ID`='$id'"; db_query($command,$dbh); //Update SDC in case their was a problem with the download $dbh = sdc_db_connect(); $command = "UPDATE `observations` SET `downloaded`='no' WHERE `observationID` LIKE '$observationID'"; db_query($command,$dbh); } else { $command = "UPDATE `exceptions` SET `status`='$status', `comments`='$comments' WHERE `ID`='$id'"; db_query($command,$dbh); if($status=='override'){ $query = "SELECT `targetName`, `targetID` AS `exceptions` FROM `override_list` WHERE `exception`=$id"; $result = db_query($query,$dbh); if($result->rowCount()<1){ $commandOverride = "INSERT INTO `override_list` (`targetName`, `targetID`, `segment`, `exception`, `comment`) VALUES "; $targetID = ltrim(substr($observationID,0,8),0); if(substr($observationID,8,11)=='000') $segment = 0; else $segment = ltrim(substr($observationID,8,11),0); $commandOverride .= "('$targetName',$targetID,$segment,$id,'$comments')"; db_query($commandOverride,$dbh); } } } } function AddUserSource($targetName,$email=False){ if($email==False) $email = $_SESSION['user']->email; $dbh = unidentified_db_connect(); $query = "SELECT `email`, `targetName` FROM `user_defined_sources` WHERE `email` LIKE '$email' AND `targetName` LIKE '$targetName'"; $result = db_query($query,$dbh); //If it doesn't already exist, add it to the database if($result->rowCount()==0){ $command = "INSERT INTO `user_defined_sources` (`email`, `targetName`) VALUES ('$email', '$targetName')"; db_query($command,$dbh); return ''; } else return "This target was already associated with this user account."; } function AddNewSource($targetName,$ra,$dec,$type,$email=False){ $dbh = unidentified_db_connect(); $query = "SELECT `targetName` FROM `source` WHERE `targetName` LIKE '$targetName'"; $result = db_query($query,$dbh); //If it doesn't already exist, add it to the database if($result->rowCount()==0){ $command = "INSERT INTO `source` (`targetName`, `RA`, `declination`, `privacy`) VALUES ('$targetName', '$ra', '$dec', '$type')"; $myResult = db_query($command,$dbh); if($myResult){ if($email==False){ $firstName = $_SESSION['user']->fName; $lastName = $_SESSION['user']->lName; $email = $_SESSION['user']->email; $status = $_SESSION['user']->status; } else { $queryUser = "SELECT `fname`, `lname`, `email`, `pw`, `status`, `key`, `logIn` FROM `users` WHERE `email` LIKE '$email'"; $resultUser = db_query($queryUser,$dbh); $row = $resultUser->fetch(); if($resultUser->rowCount()>0){ $firstName = $row['fname']; // $resultUser $lastName = $row['lname']; // $resultUser $email = $row['email']; // $resultUser $status = $row['status']; // $resultUser } } switch($type){ case 'main': $myType = 'Main List'; break; case 'public': $myType = 'Extended Public List'; break; case 'private': $myType = $lastName."'s Private List"; break; } $email_msg = "A new target has been added to the monitoring database.\n\n"; $email_msg .= "Target Name: $targetName\n"; $email_msg .= "R.A.: $ra\n"; $email_msg .= "Dec : $dec\n"; $email_msg .= "Added To: $myType\n"; $email_msg .= "Added By: ".$_SESSION['user']->fName." ".$_SESSION['user']->lName."\n"; $email_msg .= "Email: $email\n\n"; $email_msg .= "Data should begin processing during the next time the automated scripts run.\n\n\n"; $email_msg .= "M.C. Stroh (automated)\n\n\n\n"; ///////////////////////////////// //Send to master list //create new smtp object $smtp = new SMTP; $smtp->do_debug = 1; # sets the amount of debug information we get //connect to the smtp server if(!$smtp->connect("email.science.psu.edu")) { echo "Error: " . $smtp->error["error"] . "\n"; } //say hello so we all know who we are $smtp->Hello(); //start the mail transaction with with the return path address $smtp->Mail(""); $smtp->Recipient($GLOBALS['masterEmail']); //send the message including headers (headers must be followed by an empty newline) $smtp->Data("Subject: New monitoring target added\n". "From: monitoring@swift.psu.edu\n". "To: ".$GLOBALS['masterEmail']."\n". "\n". $email_msg ."\n"); //the mail either has been sent or failed either way we are done $smtp->quit(); ///////////////////////////////// //Send to PI //create new smtp object $smtp = new SMTP; $smtp->do_debug = 1; # sets the amount of debug information we get //connect to the smtp server if(!$smtp->connect("email.science.psu.edu")) { echo "Error: " . $smtp->error["error"] . "\n"; } //say hello so we all know who we are $smtp->Hello(); //start the mail transaction with with the return path address $smtp->Mail(""); $smtp->Recipient($email); //send the message including headers (headers must be followed by an empty newline) $smtp->Data("Subject: New monitoring user request\n". "From: monitoring@swift.psu.edu\n". "To: $email\n". "\n". $email_msg ."\n"); //the mail either has been sent or failed either way we are done $smtp->quit(); } return ''; } else return "This target was already in the source catalog. You should see the data available to you now."; } function Statistics(){ $dbh = unidentified_db_connect(); $processQuery = "SELECT DATE_FORMAT(`start`,'%H:%i:%S %m/%d/%Y') AS `start`, `start` AS `start1`, "; $processQuery .= "DATE_FORMAT(`sdc`,'%H:%i:%S %m/%d/%Y') AS `sdc`, `duration` ";//DATE_FORMAT(`datedownload`,'%H:%i:%S %m/%d/%Y') AS `download`, "; //$processQuery .= "DATE_FORMAT(`datepipeline`,'%H:%i:%S %m/%d/%Y') AS `pipeline`, DATE_FORMAT(`xrtgrblc`,'%H:%i:%S %m/%d/%Y') AS `xrtgrblc`, "; //$processQuery .= "DATE_FORMAT(`plot`,'%H:%i:%S %m/%d/%Y') AS `plot`, DATE_FORMAT(`extract`,'%H:%i:%S %m/%d/%Y') AS `extract`, `duration` "; $processQuery .= "FROM `process_log` ORDER BY `start1` DESC LIMIT 1"; $procResult = db_query($processQuery,$dbh); if($procResult->rowCount()>0){ $row = $procResult->fetch(); $this->job->start = $row['start']; // $procResult $this->job->sdc = $row['sdc']; // $procResult //$this->job->download = $row['download']; // $procResult //$this->job->pipeline = $row['pipeline']; // $procResult //$this->job->xrtgrblc = $row['xrtgrblc']; // $procResult //$this->job->plot = $row['plot']; // $procResult //$this->job->extract = $row['extract']; // $procResult $this->job->duration = $row['duration']; // $procResult } /* $updateTargetIDQuery = "SELECT DATE_FORMAT(`update_targetID`,'%H:%i:%S %m/%d/%Y') AS `update_targetID` FROM `process_log` WHERE `update_targetID` IS NOT NULL ORDER BY `start` DESC LIMIT 1"; $updateTargetIDResult = db_query($updateTargetIDQuery,$dbh); if($updateTargetIDResult->rowCount()>0){ $this->job->update_targetID = $row['update_targetID']; // $updateTargetIDResult } $processQuery = "SELECT DATE_FORMAT(`plot`,'%H:%i:%S %m/%d/%Y') AS `plot` "; $processQuery .= "FROM `process_log` WHERE `plot` IS NOT NULL ORDER BY `start` DESC LIMIT 1"; $procResult = db_query($processQuery,$dbh); if($procResult->rowCount()>0){ $this->job->lastCompleted = $row['plot']; // $procResult } //First we want to screen out which observations have been added to the override list so that we don't non-processed items for them as errors $preQuery = "SELECT `targetID`, `segment` FROM `override_list` ORDER BY `targetID`, `segment`"; $preResult = db_query($preQuery,$dbh); $observationIDs = ''; if($preResult->rowCount()>0){ for($i=0;$i<$preResult->rowCount();$i++){ $targetID = $row['targetID']; // $preResult $segment = $row['segment']; // $preResult $observationID = str_repeat('0',8-strlen($targetID)).$targetID.str_repeat('0',3-strlen($segment)).$segment; //Add to list if($observationIDs!='') $observationIDs .=', '; $observationIDs .= "'$observationID'"; } } */ $query = "SELECT (SELECT COUNT(`targetName`) FROM `source`) AS 'number_sources', "; $query .= "(SELECT COUNT(`targetName`) FROM `source` WHERE `privacy`='public' AND `targetName` REGEXP '1FGL') AS 'number_sources_1fgl', "; $query .= "(SELECT COUNT(`targetName`) FROM `source` WHERE `privacy`='public' AND `targetName` REGEXP '2FGL') AS 'number_sources_2fgl', "; $query .= "(SELECT COUNT(`targetName`) FROM `source` WHERE `privacy` IN ('private', 'debug')) AS 'number_sources_private', "; $query .= "(SELECT COUNT(`targetName`) FROM `observations`) AS 'number_observations', "; $query .= "(SELECT COUNT(DISTINCT(`targetID`)) FROM `targetID`) AS 'number_targetIDs', "; $query .= "(SELECT COUNT(`targetName`) FROM `observations` WHERE `pipeline`=0) AS 'number_observations_pipeline_no', "; //AND `observationID` NOT IN ($observationIDs) $query .= "(SELECT COUNT(`targetName`) FROM `observations` WHERE `pipeline`>1) AS 'number_observations_pipeline_error', "; $query .= "(SELECT COUNT(`targetName`) FROM `observations` WHERE `pipeline`=1) AS 'number_observations_pipeline_yes', "; /* $query .= "(SELECT COUNT(`targetName`) FROM `observations` WHERE `pipeline`='yes' AND `xrtgrblc_commands`='no' AND (`observations`.`wtevents`>0 OR `observations`.`pcevents`>0) AND `observationID` NOT IN ($observationIDs)) AS 'number_observations_xrtgrblc_waiting', "; $query .= "(SELECT COUNT(`targetName`) FROM `observations` WHERE `pipeline`='yes' AND `xrtgrblc_commands`='yes' AND `xrtgrblc`='no') AS 'number_observations_xrtgrblc_no', "; $query .= "(SELECT COUNT(`targetName`) FROM `observations` WHERE `pipeline`='yes' AND `xrtgrblc_commands`='yes' AND `xrtgrblc`='error') AS 'number_observations_xrtgrblc_error', "; $query .= "(SELECT COUNT(`targetName`) FROM `observations` WHERE `pipeline`='yes' AND `xrtgrblc_commands`='yes' AND `xrtgrblc`='yes') AS 'number_observations_xrtgrblc_yes', "; $query .= "(SELECT COUNT(`ID`) FROM `xrtgrblc_commands` WHERE `processed`='no') AS 'number_jobs_no', "; $query .= "(SELECT COUNT(`ID`) FROM `xrtgrblc_commands` WHERE `processed`='error') AS 'number_jobs_error', "; $query .= "(SELECT COUNT(`ID`) FROM `xrtgrblc_commands` WHERE `processed`='yes') AS 'number_jobs_yes', "; */ $query .= "(SELECT COUNT(`targetName`) FROM `source` WHERE `plot`='no') AS 'number_sources_plot_no', "; $query .= "(SELECT COUNT(`targetName`) FROM `source` WHERE `plot`='yes') AS 'number_sources_plot_yes', "; /* $query .= "(SELECT COUNT(`observationID`) FROM `observations` WHERE `plot`='no' AND `xrtgrblc_commands`='yes' AND `xrtgrblc`='yes') AS 'number_observations_plot_no', "; $query .= "(SELECT COUNT(`observationID`) FROM `observations` WHERE `plot`='yes' AND `xrtgrblc_commands`='yes' AND `xrtgrblc`='yes') AS 'number_observations_plot_yes', "; $query .= "(SELECT COUNT(`observationID`) FROM `observations` WHERE `extract`='no' AND `xrtgrblc_commands`='yes' AND `xrtgrblc`='yes' AND `detection`='yes') AS 'number_observations_extract_no', "; $query .= "(SELECT COUNT(`observationID`) FROM `observations` WHERE `extract`='yes' AND `xrtgrblc_commands`='yes' AND `xrtgrblc`='yes') AS 'number_observations_extract_yes', "; $query .= "(SELECT COUNT(`observationID`) FROM `observations` WHERE `extract`='error' AND `xrtgrblc_commands`='yes' AND `xrtgrblc`='yes') AS 'number_observations_extract_error', "; $query .= "(SELECT COUNT(`observationID`) FROM `observations` WHERE `spec`='no' AND `extract`='yes') AS 'number_observations_spec_no', "; $query .= "(SELECT COUNT(`observationID`) FROM `observations` WHERE `spec`='yes' AND `extract`='yes') AS 'number_observations_spec_yes', "; $query .= "(SELECT COUNT(`observationID`) FROM `observations` WHERE `spec`='error' AND `extract`='yes') AS 'number_observations_spec_error', "; */ $query .= "(SELECT SUM(`pctime`) FROM `observations`) AS 'total_time_pc', "; $query .= "(SELECT SUM(`pcsnapshots`) FROM `observations`) AS 'total_snapshots_pc', "; $query .= "(SELECT SUM(`pcevents`) FROM `observations`) AS 'total_events_pc', "; $query .= "(SELECT COUNT(`ID`) FROM `exceptions` WHERE `status`='open') AS 'number_open_exceptions', "; $query .= "(SELECT COUNT(`ID`) FROM `exceptions` WHERE `status`='closed') AS 'number_closed_exceptions', "; $query .= "(SELECT COUNT(`ID`) FROM `exceptions` WHERE `status`='bug') AS 'number_bug_exceptions', "; $query .= "(SELECT COUNT(`observationID`) FROM `observations` WHERE `datepipeline`<='2013-03-29 10:30:00' AND `pipeline`=1) AS 'number_left_for_reprocessing' "; //echo "SELECT COUNT(`targetName`) FROM `observations` WHERE `pipeline`='yes' AND `xrtgrblc_commands`='no' AND `observationID` NOT IN ($observationIDs)) AS 'number_observations_xrtgrblc_no' "; $result = db_query($query,$dbh); if($result->rowCount()>0){ $row = $result->fetch(); $this->statistics->sources->number = $row['number_sources']; // $result $this->statistics->sources->fgl1->number = $row['number_sources_1fgl']; // $result $this->statistics->sources->fgl2->number = $row['number_sources_2fgl']; // $result $this->statistics->sources->private->number = $row['number_sources_private']; // $result $this->statistics->targetIDs->number = $row['number_targetIDs']; // $result $this->statistics->observations->number = $row['number_observations']; // $result $this->statistics->observations->pipeline->no->number = $row['number_observations_pipeline_no']; // $result $this->statistics->observations->pipeline->error->number = $row['number_observations_pipeline_error']; // $result $this->statistics->observations->pipeline->yes->number = $row['number_observations_pipeline_yes']; // $result //Reprocessing $this->statistics->observations->reprocessing->number = $row['number_left_for_reprocessing']; // $result /* $this->statistics->observations->xrtgrblc->waiting->number = $row['number_observations_xrtgrblc_waiting']; // $result $this->statistics->observations->xrtgrblc->no->number = $row['number_observations_xrtgrblc_no']; // $result $this->statistics->observations->xrtgrblc->error->number = $row['number_observations_xrtgrblc_error']; // $result $this->statistics->observations->xrtgrblc->yes->number = $row['number_observations_xrtgrblc_yes']; // $result $this->statistics->observations->extract->no = $row['number_observations_extract_no']; // $result $this->statistics->observations->extract->yes = $row['number_observations_extract_yes']; // $result $this->statistics->observations->extract->error = $row['number_observations_extract_error']; // $result $this->statistics->observations->spec->no = $row['number_observations_spec_no']; // $result $this->statistics->observations->spec->yes = $row['number_observations_spec_yes']; // $result $this->statistics->observations->spec->error = $row['number_observations_spec_error']; // $result $this->statistics->jobs->no->number = $row['number_jobs_no']; // $result $this->statistics->jobs->yes->number = $row['number_jobs_yes']; // $result $this->statistics->jobs->error->number = $row['number_jobs_error']; // $result $this->statistics->plot->observations->no->number = $row['number_observations_plot_no']; // $result $this->statistics->plot->observations->yes->number = $row['number_observations_plot_yes']; // $result */ $this->statistics->plot->sources->no->number = $row['number_sources_plot_no']; // $result $this->statistics->plot->sources->yes->number = $row['number_sources_plot_yes']; // $result /* $this->statistics->observations->wt->time = $row['total_time_wt']; // $result $this->statistics->observations->wt->snapshots = $row['total_snapshots_wt']; // $result $this->statistics->observations->wt->events = $row['total_events_wt']; // $result */ $this->statistics->observations->pc->time = $row['total_time_pc']; // $result $this->statistics->observations->pc->snapshots = $row['total_snapshots_pc']; // $result $this->statistics->observations->pc->events = $row['total_events_pc']; // $result //Exceptions $this->statistics->exceptions->open = $row['number_open_exceptions']; // $result $this->statistics->exceptions->closed = $row['number_closed_exceptions']; // $result $this->statistics->exceptions->bug = $row['number_bug_exceptions']; // $result } } function LightCurve($targetName,$type='standard'){ $dbh = unidentified_db_connect(); $query = "SELECT `light_curve_bins`.`xrtgrblc_ID`, `light_curve_bins`.`mode`, "; $query .= "`light_curve_bins`.`time`, `light_curve_bins`.`xax_e`, `light_curve_bins`.`timeDel`, `light_curve_bins`.`fracExp`, "; $query .= "`light_curve_bins`.`rateNet`, `light_curve_bins`.`errorNet`, "; $query .= "`light_curve_bins`.`rateCor`, `light_curve_bins`.`errorCor`, "; $query .= "`light_curve_bins`.`rateRaw`, `light_curve_bins`.`errorRaw`, "; $query .= "`light_curve_bins`.`rateBkg`, `light_curve_bins`.`errorBkg`, "; $query .= "`light_curve_bins`.`rateFlux`, `light_curve_bins`.`errorFlux` FROM `xrtgrblc_commands` "; $query .= "JOIN `light_curve_bins` ON (`xrtgrblc_commands`.`ID` LIKE `light_curve_bins`.`xrtgrblc_ID`) "; $query .= "WHERE `xrtgrblc_commands`.`processed` LIKE 'yes' AND "; $query .= "`xrtgrblc_commands`.`targetName` LIKE '$targetName' AND "; $query .= "`xrtgrblc_commands`.`privacy` LIKE '$type' "; $query .= "ORDER BY `light_curve_bins`.`time`"; $result = db_query($query,$dbh); //echo $result->rowCount(); $metToUnixEpoch = date("U", mktime(0, 0, 0, 1, 1, 2001)); $mjdUnixEpoch = 40587.; if($result->rowCount()>0){ for($i=0;$i<$result->rowCount();$i++){ $row = $result->fetch(); $this->lightcurve[$i] = new stdClass(); $this->lightcurve[$i]->ID = $row['xrtgrblc_ID']; // $result $this->lightcurve[$i]->mode = $row['mode']; // $result $this->lightcurve[$i]->time->MET = $row['time']; // $result $this->lightcurve[$i]->time->MJD = ($row['time']+$metToUnixEpoch)/86400.+$mjdUnixEpoch; $this->lightcurve[$i]->xax_e->seconds = $row['xax_e']; // $result $this->lightcurve[$i]->xax_e->days = $row['xax_e']/86400.; $this->lightcurve[$i]->timeDel->seconds = $row['timeDel']; // $result $this->lightcurve[$i]->timeDel->days = $row['timeDel']/86400.; $this->lightcurve[$i]->fracExp = $row['fracExp']; // $result $this->lightcurve[$i]->rateNet = $row['rateNet']; // $result $this->lightcurve[$i]->errorNet = $row['errorNet']; // $result $this->lightcurve[$i]->rateCor = $row['rateCor']; // $result $this->lightcurve[$i]->errorCor = $row['errorCor']; // $result $this->lightcurve[$i]->rateRaw = $row['rateRaw']; // $result $this->lightcurve[$i]->errorRaw = $row['errorRaw']; // $result $this->lightcurve[$i]->rateBkg = $row['rateBkg']; // $result $this->lightcurve[$i]->errorBkg = $row['errorBkg']; // $result $this->lightcurve[$i]->rateFlux = $row['rateFlux']; // $result $this->lightcurve[$i]->errorFlux = $row['errorFlux']; // $result } } else $this->lightcurve=0; } function SDCLastModified(){ $dbh = sdc_db_connect(); $query = "SELECT DATE_FORMAT(MAX(`modified`),'%H:%i:%S %m/%d/%Y') AS `modified`, "; $query .= "IF(DATE_ADD(NOW(), INTERVAL 1 DAY)rowCount()>0){ $row = $result->fetch(); $this->sdc->lastUpdated = $row['modified']; // $result switch($result->fetch()['old']){ case '0': $this->sdc->old = False; $this->sdc->color='#0c0'; break; case '1': $this->sdc->old = True; $this->sdc->color='#c00'; break; } } } function SourcesInfo($type='1FGL',$sorted='default'){ $dbh = unidentified_db_connect(); //Grab source information from the database $query = "SELECT `source`.`targetName`, `source`.`ra`, `source`.`declination`, `source`.`expTime`, `source`.`folder`, `source`.`privacy`, "; if($type!='field') $query .= "MAX(DATE_FORMAT(`observations`.`datepipeline`,'%m-%d-%Y')) AS `datepipeline`, "; $query .= "(SELECT COUNT(`detections`.`targetName`) FROM `detections` WHERE `detections`.`detectionType` LIKE 'Detection' AND `detections`.`targetName`=`source`.`targetName` AND `detections`.`inside95` LIKE 'Yes') AS `inside95`, "; $query .= "(SELECT COUNT(`detections`.`targetName`) FROM `detections` WHERE `detections`.`detectionType` LIKE 'Detection' AND `detections`.`targetName`=`source`.`targetName`) AS `detections` "; $query .= "FROM `source`"; if($type!='field') $query .= ", `observations` WHERE `source`.`targetName` = `observations`.`targetName` AND `observations`.`pipeline`=1 AND "; else $query .= " WHERE "; $query .= "`source`.`plot`='Y' AND "; //$query .= " `source`.`expTime`>0 AND `source`.`plot`='Y' AND "; if(in_array($type,array('1FGL','2FGL','3FGL', '4FGL'))) $query .= "`source`.`privacy` LIKE 'public' AND `source`.`targetName` REGEXP '$type' "; // if(in_array($type,array('3FGL'))) $query .= "`source`.`privacy` LIKE 'public' AND `source`.`targetName` REGEXP '$type' "; else if($type=='private') $query .= "`source`.`privacy` LIKE 'debug' "; else if($type=='field') $query .= "`source`.`privacy` IN ('field5','field10','field15','field20') "; $query .= "GROUP BY `source`.`targetName` "; $order = "ORDER BY "; if($sorted=='lastUpdated' && $type!='field') $order .= "MAX(`observations`.`datepipeline`) DESC, "; $order .= "`ra` ASC"; $query .= $order; if($type=='field') $query .= ", `expTime` ASC"; $result = db_query($query,$dbh) or die('Not found'); if($result->rowCount()>0){ for($i=0; $i<$result->rowCount(); $i++){ $row = $result->fetch(); $this->source[$i] = new stdClass(); $this->source[$i]->targetName = $row['targetName']; // $result $this->source[$i]->ra = number_format($row['ra'],4); // $result $this->source[$i]->dec = number_format($row['declination'],4); // $result $this->source[$i]->exposureTime = number_format(0.001*$row['expTime'], 1, '.', ''); // $result $this->source[$i]->detections = $row['detections']; // $result $this->source[$i]->type = $row['privacy']; // $result $this->source[$i]->folder = $row['folder']; // $result $this->source[$i]->fullFolder = "private_new/".$this->sources[$i]->folder; $this->source[$i]->inside95 = $row['inside95']; // $result if($type!='field') $this->source[$i]->lastUpdated = $row['datepipeline']; // $result } } else unset($this->source); } function SourcesInfoPaper($type='main'){ //Offset since server thinks we're in UTC $timeOffset = -1*date('Z'); $dbh = unidentified_db_connect(); //Grab source information from the database $query = "SELECT `source`.`targetName`, `source`.`folder`, `source`.`RA`, `source`.`declination`, `source`.`privacy`, `source`.`fractionalVariabilitySingleBin`, `source`.`fractionalVariabilityStandard`, "; $query .= "`source`.`errorFractionalVariabilitySingleBin`, `source`.`errorFractionalVariabilityStandard`, "; $query .= "`source`.`meanSingleBin`, `source`.`errorMeanSingleBin`, `source`.`minimumSingleBin`, `source`.`errorMinimumSingleBin`, `source`.`maximumSingleBin`, `source`.`errorMaximumSingleBin`, "; $query .= "ROUND(SUM(`light_curve_bins`.`timeDel`*`light_curve_bins`.`fracExp`)/1000.) AS `exposureTime`, "; $query .= "FROM_UNIXTIME((MAX(`light_curve_bins`.`time`-`light_curve_bins`.`xax_e`)+UNIX_TIMESTAMP('2001-01-01'))+".$timeOffset.",'%M %D, %Y') AS `lastObserved`, "; $query .= "`source`.`countsToFluxConversionFactor`, `source`.`errorCountsToFluxConversionFactor` "; $query .= "FROM "; $query .= "`light_curve_bins` LEFT OUTER JOIN `xrtgrblc_commands` ON "; $query .= "(`xrtgrblc_commands`.`ID`=`light_curve_bins`.`xrtgrblc_ID`) JOIN `source` "; $query .= "ON (`source`.`targetName`=`xrtgrblc_commands`.`targetName`) "; if($type!='main' && $type!='public' && $type!='private') $query .= "JOIN `user_defined_sources` ON (`user_defined_sources`.`targetName` LIKE `source`.`targetName`) "; $query .= "WHERE `xrtgrblc_commands`.`privacy` LIKE 'single bin' AND `light_curve_bins`.`rateCor`>0 AND (`light_curve_bins`.`rateCor`>`light_curve_bins`.`errorCor` OR `light_curve_bins`.`errorCor` IS NULL) AND `light_curve_bins`.`mode_switching` LIKE 'no' AND "; $query .= "(`source`.`new` LIKE 'no' OR `source`.`plot` LIKE 'yes') AND "; if($type!='main' && $type!='public' && $type!='private') $query .= "`user_defined_sources`.`email` LIKE '$type' "; else $query .= "`source`.`privacy` LIKE '$type' "; //Filter out observations after August 31st, 2012 $query .= "AND `light_curve_bins`.`time`<368150403 "; $query .= "GROUP BY `source`.`targetName` "; $query .= "ORDER BY `source`.`RA`"; $result = db_query($query,$dbh); if($result->rowCount()>0){ for($i=0;$i<$result->rowCount();$i++){ $row = $result->fetch(); $this->source[$i]->targetName = $row['targetName']; // $result $this->source[$i]->folder = $row['folder']; // $result $this->source[$i]->lastObserved = $row['lastObserved']; // $result $this->source[$i]->exposureTime = $row['exposureTime']; // $result $this->source[$i]->type = $row['type']; // $result $this->source[$i]->fracVar->singleBin = $row['fractionalVariabilitySingleBin']; // $result $this->source[$i]->fracVar->errorSingleBin = $row['errorFractionalVariabilitySingleBin']; // $result $this->source[$i]->fracVar->standard = $row['fractionalVariabilityStandard']; // $result $this->source[$i]->fracVar->errorStandard = $row['errorFractionalVariabilityStandard']; // $result $this->source[$i]->countsToFluxConversionFactor = $row['countsToFluxConversionFactor']; // $result $this->source[$i]->errorCountsToFluxConversionFactor = $row['errorCountsToFluxConversionFactor']; // $result $this->source[$i]->RA = $row['RA']; // $result if(is_numeric($this->source[$i]->countsToFluxConversionFactor)){ $fitQuery = "SELECT `start`, `stop`, `rateCor`, `errorCor`, `convFactor`, `errorConvFactor`, "; $fitQuery .= "`mode`, `counts`, `bins`, `degrees_of_freedom`, `statistic_type`, `statistic_value`, "; $fitQuery .= "`unabsorbed_flux`, `positive_error_unabsorbed_flux`, `negative_error_unabsorbed_flux` "; $fitQuery .= "FROM `sources_spectral_fits` WHERE `targetName` LIKE '".$this->source[$i]->targetName."' ORDER BY `mode` DESC, `start` ASC"; $fitResult = db_query($fitQuery,$dbh); if($fitResult->rowCount()>0){ for($j=0;$j<$fitResult->rowCount();$j++){ $frow = $fitResult->fetch(); $this->source[$i]->fit[$j]->start = $frow['start']; // $fitResult $this->source[$i]->fit[$j]->stop = $frow['stop']; // $fitResult $this->source[$i]->fit[$j]->mode = $frow['mode']; // $fitResult $this->source[$i]->fit[$j]->statistic_value = $frow['statistic_value']; // $fitResult $this->source[$i]->fit[$j]->dof = $frow['degrees_of_freedom']; // $fitResult $this->source[$i]->fit[$j]->unabsorbed_flux = $frow['unabsorbed_flux']; // $fitResult $this->source[$i]->fit[$j]->positive_error_unabsorbed_flux = $frow['positive_error_unabsorbed_flux']; // $fitResult $this->source[$i]->fit[$j]->negative_error_unabsorbed_flux = $frow['negative_error_unabsorbed_flux']; // $fitResult } } $this->source[$i]->nFits = $fitResult->rowCount(); } $testRA = $this->source[$i]->RA*24/360.; $RA[0] = floor($testRA); $testRA1 = $testRA - $RA[0]; $RA[1] = floor(60.*($testRA1)); $testRA2 = $testRA1 - $RA[1]/60.; $RA[2] = round(3600.*($testRA2)); $sexagesimalRA = ''; for($j=0;$j<3;$j++){ if($RA[$j]==0) $RA[$j] = '00'; if(strlen($RA[$j])<2) $sexagesimalRA .= "0"; $sexagesimalRA .= $RA[$j]; if($j!=2) $sexagesimalRA .= " "; } $this->source[$i]->sexRA = $sexagesimalRA; $this->source[$i]->declination = $row['declination']; // $result $testDec = abs($this->source[$i]->declination); $declination[0] = floor($testDec); $testDec1 = $testDec - $declination[0]; $declination[1] = floor(60.*($testDec1)); $testDec2 = $testDec1 - $declination[1]/60.; $declination[2] = round(3600.*($testDec2)); if($this->source[$i]->declination<0) $sexagesimalDec = '-'; else $sexagesimalDec = '+'; for($j=0;$j<3;$j++){ if(strlen($declination[$j])<2) $sexagesimalDec .= "0"; $sexagesimalDec .= $declination[$j]; if($j!=2) $sexagesimalDec .= " "; } $this->source[$i]->sexDeclination = $sexagesimalDec; $this->source[$i]->meanRate = $row['meanSingleBin']; // $result $this->source[$i]->errorMeanRate = $row['errorMeanSingleBin']; // $result $this->source[$i]->minimumRate = $row['minimumSingleBin']; // $result $this->source[$i]->errorMinimumRate = $row['errorMinimumSingleBin']; // $result $this->source[$i]->maximumRate = $row['maximumSingleBin']; // $result $this->source[$i]->errorMaximumRate = $row['errorMaximumSingleBin']; // $result } } else unset($this->source); } public function Detections($targetName,$type){ //Type is usually 'Detection' or 'Background' but may also be 'Unknown' for debugging purposes //Connect to the database and get the folder where the information resides $dbh = unidentified_db_connect(); $query = "SELECT `raCentroid`, `decCentroid`, `snr`, `expTime`, `rateSosta`, `errorSosta`, `snrSosta`, `poissonSosta`, `posErrCentroid`, `ctsBgInnerBox` "; $query .= "FROM `detections` "; $query .= "WHERE `detectionType` LIKE '$type' AND "; //$query .= "REPLACE(REPLACE(`targetName`,' ',''),'+',' ') LIKE '$targetName' "; $query .= "`targetName` LIKE '$targetName' "; $query .= "ORDER BY `snrSosta` DESC"; $result = db_query($query,$dbh) or die('Not found'); // echo $query; if($result->rowCount()>0){ for($i=0;$i<$result->rowCount();$i++){ $row = $result->fetch(); $detections[$i] = new stdClass(); $detections[$i]->ra = $row['raCentroid']; // $result $detections[$i]->dec = $row['decCentroid']; // $result $detections[$i]->snr = $row['snr']; // $result $detections[$i]->expTime = $row['expTime']; // $result $detections[$i]->rate = $row['rateSosta']; // $result $detections[$i]->errorRate = $row['errorSosta']; // $result //Trim values based on significant digits $detections[$i]->rateDisplay = SignificantDigits($detections[$i]->rate, $detections[$i]->errorRate); if($detections[$i]->rate>0){ $detections[$i]->snrSosta = number_format($row['snrSosta'],3); // $result } else { $detections[$i]->snrSosta = 'N/A'; } $detections[$i]->poisson = $row['poissonSosta']; // $result $detections[$i]->posError = $row['posErrCentroid']; // $result $detections[$i]->ctsBgInnerBox = $row['ctsBgInnerBox']; // $result $coordinates = DecToSex($detections[$i]->ra, $detections[$i]->dec); $detections[$i]->raSexigesimal = $coordinates[0]; $detections[$i]->decSexigesimal = $coordinates[1]; } } else $detections = 0; return $detections; } public function KnownSources($targetName,$catalog='other'){ if($catalog=='xray'){ //$catalogNull = "No X-ray or Gamma Ray sources found."; //$tableTitle = "Known X-Ray and Gamma Ray Sources"; $catalogString = "(`catalog`.`catalog` LIKE 'xray' OR `catalog`.`catalog` LIKE 'mggammacat')"; //$catalogColumn = "Observatory/Database Table"; } else { //$catalogNull = "No radio, optical or UV sources found."; //$tableTitle = "Known Radio, Optical and UV Sources"; $catalogString = "`catalog`.`catalog` NOT LIKE 'xray' AND `catalog`.`catalog` NOT LIKE 'mggammacat'"; //$catalogColumn = "Database Table"; } $dbh = unidentified_db_connect(); $sql = "SELECT `catalog`.`name`, `catalog`.`ra`, `catalog`.`declination`, `catalog`.`offset`, `catalog`.`observatory`, `catalog`.`plot` FROM `catalog` "; $sql .= "JOIN `source` ON (`source`.`targetName` = `catalog`.`targetName`) "; //$sql .= "WHERE REPLACE(REPLACE(`source`.`targetName`,' ',''),'+',' ') LIKE '$targetName' AND "; $sql .= "WHERE `source`.`targetName` LIKE '$targetName' AND "; $sql .= "`catalog`.`ra`<=`source`.`raMax` AND `catalog`.`ra`>=`source`.`raMin` AND `catalog`.`declination`<=`source`.`decMax` AND `catalog`.`declination`>=`source`.`decMin` AND $catalogString ORDER BY `offset` ASC, `plot` ASC"; $result = db_query($sql,$dbh) or die('Not found'); if($result->rowCount()>0){ for($i=0;$i<$result->rowCount();$i++){ $row = $result->fetch(); $knownSources[$i] = new stdClass(); $knownSources[$i]->targetName = $row['name']; // $result $knownSources[$i]->ra = $row['ra']; // $result $knownSources[$i]->dec = $row['declination']; // $result $knownSources[$i]->offset = number_format($row['offset'],2); // $result $knownSources[$i]->observatory = $row['observatory']; // $result $knownSources[$i]->plot = $row['plot']; // $result $coordinates = DecToSex($knownSources[$i]->ra, $knownSources[$i]->dec); $knownSources[$i]->raSexigesimal = $coordinates[0]; $knownSources[$i]->decSexigesimal = $coordinates[1]; } } else $knownSources = 0; return $knownSources; } function SourcePlots($targetName){ //Grab list of sources already in the database -- do this to protect against SQL injection self::GetAllSourceNames(); //See if user input is in the list if(in_array($targetName,$this->allTargetNames->htmlTargetNames)){ $targetName = $this->allTargetNames->targetNames[array_search($targetName, $this->allTargetNames->htmlTargetNames)]; //Connect to the database and get the folder where the information resides $dbh = unidentified_db_connect(); $query = "SELECT `targetName`, `privacy`, `folder` FROM `source` "; //$query .= "WHERE REPLACE(REPLACE(`targetName`,' ',''),'+',' ') LIKE '".$targetName."'"; $query .= "WHERE `targetName` LIKE '$targetName'"; $result = db_query($query,$dbh); //Make sure a valid source was given if($result->rowCount()>0){ $row = $result->fetch(); $this->source = new stdClass(); $this->source->targetName = $row['targetName']; // $result $this->source->folder = $row['folder']; // $result $this->source->type = $row['privacy']; // $result $this->source->detections = self::Detections($targetName,'Detection'); if($this->source->detections==0){ $this->source->detectionsOutput = "

No detected excesses found.
"; unset($this->source->detection); } else { $detectionsOutput = "

Detected Excesses (SNR(Sosta) > 3.0)

\n"; $detectionsOutput .= " \n"; $detectionsOutput .= " \n"; $detectionsOutput .= " \n"; $detectionsOutput .= " \n"; $detectionsOutput .= " \n"; $detectionsOutput .= " \n"; $detectionsOutput .= " \n"; //$detectionsOutput .= " \n"; $detectionsOutput .= " \n"; $detectionsOutput .= " \n"; $detectionsOutput .= " \n"; $detectionsOutput .= " \n"; $counter = 0; foreach($this->source->detections as &$detections){ $counter++; if(fmod($counter,2)==0) $rowColor = "#ccc"; else $rowColor = "#ddd"; $detectionsOutput .= " \n"; $detectionsOutput .= " \n"; $detectionsOutput .= " \n"; $detectionsOutput .= " \n"; $detectionsOutput .= " \n"; $detectionsOutput .= " \n"; //" ".$detections->rate." //$detectionsOutput .= " \n"; //$detections->errorRateSi." ". $detectionsOutput .= " \n"; $detectionsOutput .= " \n"; $detectionsOutput .= " \n"; $detectionsOutput .= " \n"; } $detectionsOutput .= "
#R.A. (J2000)Dec. (J2000)Pos. Error (")Rate (cts/s)Rate ErrorCountsSNR (Detect)SNR (Sosta)
".$counter."".$detections->raSexigesimal."".$detections->decSexigesimal."".$detections->posError."".$detections->rateDisplay."".$detections->errorRate."".$detections->ctsBgInnerBox."".number_format($detections->snr,3)."".$detections->snrSosta."
\n"; $this->source->detectionsOutput = $detectionsOutput; } $this->source->rejectedExcesses = self::Detections($targetName,'Background'); if($this->source->rejectedExcesses==0){ $this->source->rejectedExcessesOutput = "

No rejected excesses found.
"; unset($this->source->rejectedExcesses); } else { $rejectionsOutput = "

Rejected Excesses (Due to Overlaps or SNR(Sosta) < 3.0)

\n"; $rejectionsOutput .= " \n"; $rejectionsOutput .= " \n"; $rejectionsOutput .= " \n"; $rejectionsOutput .= " \n"; $rejectionsOutput .= " \n"; $rejectionsOutput .= " \n"; $rejectionsOutput .= " \n"; //$rejectionsOutput .= " \n"; $rejectionsOutput .= " \n"; $rejectionsOutput .= " \n"; $rejectionsOutput .= " \n"; $rejectionsOutput .= " \n"; $counter = 0; foreach($this->source->rejectedExcesses as &$detections){ $counter++; if(fmod($counter,2)==0) $rowColor = "#ccc"; else $rowColor = "#ddd"; $rejectionsOutput .= " \n"; $rejectionsOutput .= " \n"; $rejectionsOutput .= " \n"; $rejectionsOutput .= " \n"; $rejectionsOutput .= " \n"; $rejectionsOutput .= " \n"; //$rejectionsOutput .= " \n"; $rejectionsOutput .= " \n"; $rejectionsOutput .= " \n"; $rejectionsOutput .= " \n"; $rejectionsOutput .= " \n"; } $rejectionsOutput .= "
#R.A. (J2000)Dec. (J2000)Pos. Error (")Rate (cts/s)Rate ErrorCountsSNR (Detect)SNR (Sosta)
".$counter."".$detections->raSexigesimal."".$detections->decSexigesimal."".$detections->posError."".$detections->rateDisplay."".$detections->errorRateSi."".$detections->ctsBgInnerBox."".number_format($detections->snr,3)."".$detections->snrSosta."
\n"; $this->source->rejectionsOutput = $rejectionsOutput; } //Known X-Ray and Gamma Ray Catalogs $this->source->knownSources = new stdClass(); $this->source->knownSources->xray = self::KnownSources($targetName,'xray'); if($this->source->knownSources->xray==0){ $this->source->knownSources->xrayOutput = "

No known X-ray or gamma ray sources found.
"; } else { $xrayOutput = "

Known X-Ray and Gamma Ray Sources

\n"; $xrayOutput .= " \n"; $xrayOutput .= " \n"; $xrayOutput .= " \n"; $xrayOutput .= " \n"; $xrayOutput .= " \n"; $xrayOutput .= " \n"; $xrayOutput .= " \n"; $xrayOutput .= " \n"; $xrayOutput .= " \n"; $counter = 0; $rowCounter = 0; foreach($this->source->knownSources->xray as &$knownSources){ if($knownSources->plot=='Y'){ $counter++; $displayCounter = $counter; } else $displayCounter = ''; $rowCounter++; if(fmod($rowCounter,2)==0) $rowColor = "#ccc"; else $rowColor = "#ddd"; $xrayOutput .= " \n"; $xrayOutput .= " \n"; $xrayOutput .= " \n"; $xrayOutput .= " \n"; $xrayOutput .= " \n"; $xrayOutput .= " \n"; $xrayOutput .= " \n"; $xrayOutput .= " \n"; } $xrayOutput .= "
#Source NameR.A. (J2000)Dec. (J2000)Offset (')Observatory/Database Table
".$displayCounter."".$knownSources->targetName."".$knownSources->raSexigesimal."".$knownSources->decSexigesimal."".$knownSources->offset."".$knownSources->observatory."
\n"; $this->source->knownSources->xrayOutput = $xrayOutput; } //Other Catalogs $this->source->knownSources->other = self::KnownSources($targetName); if($this->source->knownSources->other==0){ $this->source->knownSources->otherOutput = "

No known radio, optical or UV sources found.
"; } else { $otherOutput = "

Known Radio, Optical and UV Sources

\n"; $otherOutput .= " \n"; $otherOutput .= " \n"; $otherOutput .= " \n"; $otherOutput .= " \n"; $otherOutput .= " \n"; $otherOutput .= " \n"; $otherOutput .= " \n"; $otherOutput .= " \n"; $otherOutput .= " \n"; $counter = 0; $rowCounter = 0; foreach($this->source->knownSources->other as &$knownSources){ $rowCounter++; if($knownSources->plot=='Y'){ $counter++; $displayCounter = $counter; } else $displayCounter = ''; if(fmod($rowCounter,2)==0) $rowColor = "#ccc"; else $rowColor = "#ddd"; $otherOutput .= " \n"; $otherOutput .= " \n"; $otherOutput .= " \n"; $otherOutput .= " \n"; $otherOutput .= " \n"; $otherOutput .= " \n"; $otherOutput .= " \n"; $otherOutput .= " \n"; } $otherOutput .= "
#Source NameR.A. (J2000)Dec. (J2000)Offset (')Database Table
".$displayCounter."".$knownSources->targetName."".$knownSources->raSexigesimal."".$knownSources->decSexigesimal."".$knownSources->offset."".$knownSources->observatory."
\n"; $this->source->knownSources->otherOutput = $otherOutput; } } else unset($this->source); } else unset($this->source); } function GetExternalLinks($targetName){ //Connect to the database and get the list of links associated with that source $dbh = unidentified_db_connect(); $query = "SELECT `site`, `link` FROM `external_links` WHERE `targetName` LIKE '$targetName'"; $result = db_query($query,$dbh); if($result->rowCount()>0){ for($i=0;$i<$result->rowCount();$i++){ $row = $result->fetch(); $this->externalLinks[$i]->site = preg_replace('/Fermi/','Fermi',preg_replace('/Swift/','Swift',$row['site'])); // $result $this->externalLinks[$i]->link = $row['link']; // $result } } else unset($this->externalLinks); } function GetSourceSpectralFit($targetName){ //Connect to the database and get the spectral fit parameters $dbh = unidentified_db_connect(); //Grab spectral fit parameters for individual modes $query = "SELECT `start`, `stop`, `rateCor`, `errorCor`, `convFactor`, `errorConvFactor`, `mode`, "; $query .= "`counts`, `bins`, `degrees_of_freedom`, `statistic_type`, `statistic_value`, "; $query .= "`nH`, `positive_error_nH`, `negative_error_nH`, "; $query .= "`photon_index`, `positive_error_photon_index`, `negative_error_photon_index`, "; $query .= "`unabsorbed_flux`, `positive_error_unabsorbed_flux`, `negative_error_unabsorbed_flux`"; $query .= "FROM `sources_spectral_fits` WHERE `targetName` LIKE '$targetName' ORDER BY `mode` ASC, `start` ASC"; $result = db_query($query,$dbh); if($result->rowCount()>0){ for($i=0;$i<$result->rowCount();$i++){ $row = $result->fetch(); $mode = $row['mode']; // $result $start = $row['start']; // $result $stop = $row['stop']; // $result $this->spectralFit[$i]->mode = $mode; $this->spectralFit[$i]->start = $start; $this->spectralFit[$i]->stop = $stop; $this->spectralFit[$i]->image = "spec_".strtolower($mode)."_".preg_replace('/\-/','',$start)."_".preg_replace('/\-/','',$stop).".gif"; $this->spectralFit[$i]->counts = $row['counts']; // $result $this->spectralFit[$i]->bins = $row['bins']; // $result $this->spectralFit[$i]->degrees_of_freedom = $row['degrees_of_freedom']; // $result $this->spectralFit[$i]->statistic_type = $row['statistic_type']; // $result $this->spectralFit[$i]->statistic_value = rtrim($row['statistic_value'],'0'); // $result $this->spectralFit[$i]->nH = $row['nH']; // $result $this->spectralFit[$i]->positive_error_nH = $row['positive_error_nH']; // $result $this->spectralFit[$i]->negative_error_nH = $row['negative_error_nH']; // $result $this->spectralFit[$i]->photon_index = $row['photon_index']; // $result $this->spectralFit[$i]->positive_error_photon_index = $row['positive_error_photon_index']; // $result $this->spectralFit[$i]->negative_error_photon_index = $row['negative_error_photon_index']; // $result $this->spectralFit[$i]->unabsorbed_flux = $row['unabsorbed_flux']; // $result $this->spectralFit[$i]->positive_error_unabsorbed_flux = $row['positive_error_unabsorbed_flux']; // $result $this->spectralFit[$i]->negative_error_unabsorbed_flux = $row['negative_error_unabsorbed_flux']; // $result } } else unset($this->spectralFit); } function SourcesSpectralTable(){ $dbh = unidentified_db_connect(); $query = "SELECT `source`.`targetName` FROM `source` WHERE `source`.`privacy` LIKE 'main' ORDER BY `source`.`RA` ASC"; $result = db_query($query,$dbh); if($result->rowCount()>0){ for($i=0;$i<$result->rowCount();$i++){ $row = $result->fetch(); $targetName = $row['targetName']; // $result $queryS = "SELECT "; $queryS .= "`sources_spectral_fits`.`statistic_value`, `sources_spectral_fits`.`degrees_of_freedom`, "; $queryS .= "`sources_spectral_fits`.`nH`, `sources_spectral_fits`.`positive_error_nH`, `sources_spectral_fits`.`negative_error_nH`, "; $queryS .= "`sources_spectral_fits`.`photon_index`, `sources_spectral_fits`.`positive_error_photon_index`, `sources_spectral_fits`.`negative_error_photon_index`, "; $queryS .= "`sources_spectral_fits`.`normalization`, `sources_spectral_fits`.`positive_error_normalization`, `sources_spectral_fits`.`negative_error_normalization` "; $queryS .= "FROM `sources_spectral_fits` WHERE `sources_spectral_fits`.`targetName` LIKE '$targetName' ORDER BY `sources_spectral_fits`.`start`"; $resultS = db_query($queryS,$dbh); $nHAv = 0; $nHAvPos = 0; $nHAvNeg = 0; $photonIndexAv = 0; $photonIndexAvPos = 0; $photonIndexAvNeg = 0; $normalizationAv = 0; $normalizationAvPos = 0; $normalizationAvNeg = 0; $chiSqTot = 0; for($j=0;$j<$resultS->rowCount();$j++){ $statisticValue = $row['statistic_value']; // $resultS $statisticDegreesOfFreedom = $row['degrees_of_freedom']; // $resultS $statisticNh = $row['nH']; // $resultS $statisticNhPos = $row['positive_error_nH']; // $resultS $statisticNhNeg = $row['negative_error_nH']; // $resultS $nHAv += $statisticNh; $nHAvPos += $statisticNh+$statisticNhPos; $nHAvNeg += $statisticNh-$statisticNhNeg; $statisticPhotonIndex = $row['photon_index']; // $resultS $statisticPhotonIndexPos = $row['positive_error_photon_index']; // $resultS $statisticPhotonIndexNeg = $row['negative_error_photon_index']; // $resultS $photonIndexAv += $statisticPhotonIndex; $photonIndexAvPos += $statisticPhotonIndex+$statisticPhotonIndexPos; $photonIndexAvNeg += $statisticPhotonIndex-$statisticPhotonIndexNeg; $statisticNormalization = $row['normalization']; // $resultS $statisticNormalizationPos = $row['positive_error_normalization']; // $resultS $statisticNormalizationNeg = $row['negative_error_normalization']; // $resultS $normalizationAv += $statisticNormalization; $normalizationAvPos += $statisticNormalization+$statisticNormalizationPos; $normalizationAvNeg += $statisticNormalization-$statisticNormalizationNeg; $chiSqTot += $statisticValue/$statisticDegreesOfFreedom; } $n = $resultS->rowCount(); $nHAv = $nHAv/$n; $nHAvPos = $nHAvPos/$n; $nHAvNeg = $nHAvNeg/$n; $photonIndexAv = $photonIndexAv/$n; $photonIndexAvPos = $photonIndexAvPos/$n; $photonIndexAvNeg = $photonIndexAvNeg/$n; $normalizationAv = $normalizationAv/$n; $normalizationAvPos = $normalizationAvPos/$n; $normalizationAvNeg = $normalizationAvNeg/$n; $chiSq = $chiSqTot/$n; //We want to calculate the SDOM $runningTotal = 0; if($resultS->rowCount()>1){ for($j=0;$j<$resultS->rowCount();$j++){ $statisticValue = $row['statistic_value']; // $resultS $runningTotal += pow($statisticValue - $chiSq,2); } $chiSqError = sqrt(1./($resultS->rowCount()-1)*$runningTotal)/sqrt($resultS->rowCount()); } else $chiSqError = -1; $this->source[$i]->targetName = $targetName; $this->source[$i]->nH = $nHAv; $this->source[$i]->nHPosError = $nHAvPos-$nHAv; $this->source[$i]->nHNegError = $nHAv-$nHAvNeg; $this->source[$i]->photonIndex = $photonIndexAv; $this->source[$i]->photonIndexPosError = $photonIndexAvPos-$photonIndexAv; $this->source[$i]->photonIndexNegError = $photonIndexAv-$photonIndexAvNeg; $this->source[$i]->normalization = $normalizationAv; $this->source[$i]->normalizationPosError = $normalizationAvPos-$normalizationAv; $this->source[$i]->normalizationNegError = $normalizationAv-$normalizationAvNeg; $this->source[$i]->chiSq = $chiSq; $this->source[$i]->chiSqError = $chiSqError; } } } function UpcomingObservations($username,$targetName=False,$initialDate=False,$finalDate=False, $maxObservations=False){ //We're going to create a list of dates and times when observations are tentatively scheduled for our program //Play with inputs first if($initialDate===False) $initialDate = "NOW()"; if($finalDate===False) $finalDate = "'3001-01-01'"; //Find ToOs that we want to keep private from the public $dbh = unidentified_db_connect(); $queryPrivateToO = "SELECT `ID` FROM `private_ToOs` ORDER BY `ID` ASC"; $resultPrivateToO = db_query($queryPrivateToO,$dbh); $privateToOs = '0'; //Need something or else the $queryToo has issues if($resultPrivateToO->rowCount()){ for($i=0;$i<$resultPrivateToO->rowCount();$i++){ $row = $resultPrivateToO->fetch(); if($privateToOs!='') $privateToOs .= ","; $privateToOs .= $row['ID']; // $resultPrivateToO } } //See what targetIDs are associated with a source if($targetName!==False){ $targetName = preg_replace('/ /','',$targetName); //Trim so we can accept more entries //Need two potential replace statements based on whether we receive targetName through $_GET or database $queryTargetIDs = "SELECT `targetID` FROM `targetID` WHERE REPLACE(`targetName`,' ','') LIKE '$targetName' OR REPLACE(REPLACE(`targetName`,'+',''),' ','') LIKE '$targetName'"; $resultTargetIDs = db_query($queryTargetIDs,$dbh); $targetIDs = '-1'; //Need something or else the $queryToo has issues if($resultTargetIDs->rowCount()){ for($i=0;$i<$resultTargetIDs->rowCount();$i++){ if($targetIDs!='') $targetIDs .= ","; $targetIDs .= $row['targetID']; // $resultTargetIDs } } } //Connect to the ToO database $dbToo = db_connect(); //Query a list of current ToOs $queryToo = "SELECT `TOO_ID`, DATE_FORMAT(`DATE`,'%m/%d/%Y') AS `DATE`, `TIME`, `SOURCE_NAME`, `DONE`, DATE_FORMAT(`DATE_END`,'%m/%d/%Y') AS `DATE_END` FROM `TOO` WHERE `DECISION` REGEXP 'Approved' AND `USERNAME` = '$username' AND `DONE`=0 AND `TOO_ID` NOT IN ($privateToOs) ORDER BY `TOO_ID` DESC"; $resultToo = db_query($queryToo,$dbToo); //Continue if ToOs exist if($resultToo->rowCount()>0){ //Create list of ToO IDs we can search for in the calendar $tooIDString = ''; for($i=0;$i<$resultToo->rowCount();$i++){ if($tooIDString!='') $tooIDString .= ','; $tooIDString .= $row['TOO_ID']; // $resultToo } //Now search for the targets in the calendar based on our ToOs $dbCalendar = sot_db_connect(); //Query list of future observations $queryCalendar = "SELECT `start`, `stop`, `target_ID`, `target_name`, `duration` "; $queryCalendar .= "FROM `calendar` "; $queryCalendar .= "WHERE `privacy` LIKE 'TOO' AND `typeID` IN ($tooIDString) "; $queryCalendar .= "AND `start`>=$initialDate and `stop`<=$finalDate "; if($targetName!==False) $queryCalendar .= "AND `target_ID` IN ($targetIDs) "; $queryCalendar .= "ORDER BY `start` ASC, `target_name` ASC"; //If we are using maxObservations, limit to the most recent maxObservations entries if($maxObservations!==False && is_numeric($maxObservations)) $queryCalendar .= " LIMIT $maxObservations"; //echo $queryCalendar; $resultCalendar = db_query($queryCalendar,$dbCalendar); //Continue if calendar entries exist if($resultCalendar->rowCount()>0){ for($i=0;$i<$resultCalendar->rowCount();$i++){ $this->observations[$i]->start = $row['start']; // $resultCalendar $this->observations[$i]->stop = $row['stop']; // $resultCalendar $this->observations[$i]->targetID = $row['target_ID']; // $resultCalendar $this->observations[$i]->targetName = $row['target_name']; // $resultCalendar $this->observations[$i]->duration = $row['duration']; // $resultCalendar } } else unset($observations); } else unset($observations); } function GetAllSourceNames(){ $this->allTargetNames = new stdClass(); //Connect to the database and get the name of all sources $dbh = unidentified_db_connect(); $query = "SELECT REPLACE(REPLACE(`targetName`,' ',''),'+',' ') AS `htmlTargetName`, `targetName` FROM `source` ORDER BY `targetName` ASC"; $result = db_query($query,$dbh); if($result->rowCount()>0){ for($i=0;$i<$result->rowCount();$i++){ $row = $result->fetch(); $this->allTargetNames->targetNames[$i] = $row['targetName']; // $result $this->allTargetNames->htmlTargetNames[$i] = $row['htmlTargetName']; // $result } } else unset($this->allTargetNames); } } function RandomString($length=10){ $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $string = ''; for ($p = 0; $p < $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters))]; } return $string; } function check_email_address($email) { // First, we check that there's one @ symbol, // and that the lengths are right. if (!preg_match("/^[^@]{1,64}@[^@]{1,255}$/", $email)) { // Email invalid because wrong number of characters // in one section or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!preg_match("/^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%& ↪'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$/", $local_array[$i])) { return false; } } // Check if domain is IP. If not, // it should be valid domain name if (!preg_match("/^\[?[0-9\.]+\]?$/", $email_array[1])) { $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!preg_match("/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])| ↪([A-Za-z0-9]+))$/", $domain_array[$i])) { return false; } } } return true; } function do_html_header($title){ // print an HTML header $titleHTML = preg_replace('/Swift/','Swift',preg_replace('/Fermi/','Fermi',$title)); echo<< $title

$titleHTML


END; /* */ } function do_html_footer(){ // print an HTML footer echo<<

Penn State University Goddard Space Flight Center Swift

END; } function do_html_warning_main(){ // print an HTML header echo<<
These results are part of the Swift program to follow-up Fermi unassociated sources in an attempt to find X-ray counterparts to the unidentified gamma-ray sources. As new observations are performed, these pages will be updated in nearly real time. Please use these results as a guide and proceed with caution when using them in a publication since they are the result of an automated analysis.

When using these data and results in publications, please reference M.C. Stroh & A.D. Falcone 2013, ApJS, 207, 28; arXiv: 1305.4949 for a description of many of the analysis techniques used to reduce these data (note: a more detailed paper describing the complete data set and analysis is forthcoming). Please contact Abe Falcone and Michael Stroh at unassociated@swift.psu.edu if you have any questions about the program or the analysis, or to simply to let us know that you've made use of these data.


END; } function do_html_warning_data(){ // $changeLogLocation = '/unassociated/changelog.php'; // ChangeLog Last Updated: 2013-02-01 // print an HTML header echo<<
Caution: For completeness, sources are listed if the "detection" exceeds 3 sigma. The significances and images are shown so you can make more stringent significance cuts, if desired.

END; } function LastUpdated(){ /* $dbh = unidentified_db_connect(); $queryTime = "SELECT `sdc` FROM `process_log` WHERE `duration` IS NOT NULL ORDER BY `start` DESC LIMIT 1"; $resTime = db_query($queryTime,$dbh) or die('Not found'); $sdcTime = $row['sdc']; // $resTime list($sdcDate,$sdcTime) = preg_split('/ /',$sdcTime); $tz = date("T"); echo<<
Last Updated: $sdcDate $sdcTime $tz

END; */ } function Login($newUserSubmitted = False){ if($newUserSubmitted) echo "

User request submitted. An email has been sent to an administrator who will handle your request.

\n"; //if($userError) echo "

Provided user information is incorrect.

\n"; echo<<
Login

END; } function NewUserForm($submitError = '',$fName='',$lName='',$email='',$fNameError=False,$lNameError=False,$emailError=False,$pass1Error=False,$pass2Error=False,$passMatchError=False){ if($submitError) echo "

There was an error handling your request, please try again.
\n"; if($fNameError) echo "

Fill-out 'First Name.'
\n"; if($lNameError) echo "

Fill-out 'Last Name.'
\n"; if($emailError) echo "

Email address was not valid or user already exists.
\n"; if($pass1Error || $pass2Error) echo "

Password must be at least 8 digits long.
\n"; if($passMatchError) echo "

Passwords did not match.
\n"; echo<<
New User Request




END; } function MyCrypt($pass){ return md5($pass); } function AddNewUser($fName,$lName,$email,$hash){ $dbh = unidentified_db_connect(); $command = "INSERT INTO `users` (`fname`, `lname`, `email`, `pw`) VALUES ('$fName','$lName','$email','$hash')"; echo $command; return db_query($command,$dbh); } function CheckLogIn(){ if (!isset ($_COOKIE[ini_get('session.name')])) { session_start(); } if(!isset($_SESSION['user']) && isset($_COOKIE["UnassociatedLogin"])){ $unassociated = new Unassociated(); $unassociated->UserViaKey($_COOKIE["UnassociatedLogin"]); if($unassociated->user && isset($unassociated->user->status) && $unassociated->user->status!='new'){ $logInTime = strptime($unassociated->user->logIn,'%Y-%m-%d %H:%M:%S'); if(mktime($logInTime['tm_hour'],$logInTime['tm_min'],$logInTime['tm_sec'],$logInTime['tm_mon']+1,$logInTime['tm_mday'],$logInTime['tm_year']+1900)+14*86400.>strtotime('now')){ $unassociated->UserViaEmail($unassociated->user->email); $_SESSION['user'] = $unassociated->user; } else { setcookie('UnassociatedLogin', "",time()-3600); session_unset(); session_destroy(); header( "Location: https://www.swift.psu.edu/unassociated/admin.php" ); } } } } function GetUserHeader(){ if(isset($_SESSION['user']) && $_SESSION['user']->status!='new'){ //Center div echo "\t\t
\n"; //Sub div for source lists echo "\t\t\t
"; echo "Sources"; echo "
\n"; echo "\t\t\t
"; echo "Last Updated Sources"; echo "
\n"; if($_SESSION['user']->status=='admin'){ //Sub div for adding sources //echo "\t\t\t
"; //echo "Add Sources"; //echo "
\n"; //Sub div for statistics echo "\t\t\t
"; echo "Status"; echo "
\n"; //Sub div for exceptions echo "\t\t\t
"; echo "Exceptions"; echo "
\n"; //Sub div for user list echo "\t\t\t
"; echo "Users"; echo "
\n"; //Sub div for tables list // echo "\t\t\t
"; // echo "Tables"; // echo "
\n"; } //Sub div for logout echo "\t\t\t
"; echo "Account Info"; echo "
\n"; //Sub div for logout echo "\t\t\t\n"; echo "\t\t
"; } } //Display target list function DisplayTargetList($type='1FGL',$administrator=False, $sorted='default'){ $unassociated = new Unassociated(); if($sorted=='lastUpdated') $unassociated -> SourcesInfo($type,$sorted); else $unassociated -> SourcesInfo($type); if(isset($unassociated->source)){ $arrow_image = "Expand"; echo<< END; $maxCols = 6; if($sorted=='lastUpdated') $maxCols = 7; //List all of the FGL catalogs to date. $allCatalogs=array('1FGL','2FGL','3FGL', '4FGL'); if(in_array($type,$allCatalogs)){ switch($type){ case '1FGL': $not = array('2FGL','3FGL','4FGL'); break; case '2FGL': $not = array('1FGL','3FGL','4FGL'); break; case '3FGL': $not = array('1FGL','2FGL','4FGL'); break; case '4FGL': $not = array('1FGL','2FGL','3FGL'); break; } echo "\n"; } else if($type=='field'){ echo "\n"; } else if($type=='private'){ echo "\n"; } else { echo "\n"; } echo<< END; if($sorted=='lastUpdated'){ echo<<
Last
Updated
END; } echo<< END; #Counter for deciding the color. Can't use $i below because we may need to skip over the source $sourceCounter = 0; #Loop over each source to add to the list for($i=0;$isource);$i++){ if(fmod($sourceCounter,2)==0) $rowColor = "#ccc"; else $rowColor = "#ddd"; if(in_array($unassociated->source[$i]->type,array('private', 'debug', 'field5', 'field10', 'field15', 'field20'))){ $plotDir = "/unassociated/private_new/"; //Mysource.php is only accessible to log in members. $link = "mySource.php?source=".preg_replace('/ /','',$unassociated->source[$i]->targetName); $plotRel = "./private_new/"; } else { $plotDir = "/unassociated/data_new/"; if($administrator) $link = "mySource.php?source=".preg_replace('/ /','',$unassociated->source[$i]->targetName); else $link = "source.php?source=".preg_replace('/ /','',$unassociated->source[$i]->targetName); $plotRel = "./data_new/"; } $plot = $plotDir.$unassociated->source[$i]->folder."/field.gif"; #Skip over source if it isn't plotted if(file_exists($plotRel.$unassociated->source[$i]->folder."/field.gif")){ $sourceCounter++; echo "\t\t\t
\n"; echo "\t\t\t\t\n";//$arrow_image echo "\t\t\t\t\n"; echo "\t\t\t\t\n"; echo "\t\t\t\t\n"; echo "\t\t\t\t\n"; echo "\t\t\t\t\n"; if($sorted=='lastUpdated') echo "\t\t\t\t\n"; echo "\n"; /* echo "\t\t\t\n"; echo "\t\t\t\t\n"; echo "\t\t\t\n"; */ } } echo "\t\t

$type Fields

"; //Create links to the remaining FGL catalogs listed in $allCatalogs. $c=0; $viewLink=''; while($cView ".$not[$c]." fields
"; $c=$c+1; //$viewLink ="View 2FGL fields
"; } //Display the links. echo $viewLink; echo "

All Test Fields

All Private Fields

Private Fields


Target

RA (J2000)

Dec (J2000)
Exposure
Time (ks)
# of Excesses
in XRT FoV
\n"; echo "\t\t\t\t\t\n"; echo "\t\t\t\t
".$unassociated->source[$i]->ra."
".$unassociated->source[$i]->dec."
".$unassociated->source[$i]->exposureTime."
".$unassociated->source[$i]->detections."
".$unassociated->source[$i]->lastUpdated."
\n"; $size = getimagesize($plot); $w = floor(0.75*$size[0]); $h = floor(0.75*$size[1]); echo "\t\t\t\t\tFull Swift light curve for ".$unassociated->source[$i]->targetName.""; echo "\t\t\t\t
\n\t\n"; } } function DisplayTargetInfo($targetName,$private=False){ $unassociated = new Unassociated(); $unassociated -> SourcePlots($targetName); $mainDirectory = "/unassociated/"; if(isset($unassociated->source)){ $targetName = $unassociated->source->targetName; $folder = $unassociated->source->folder; $type = $unassociated->source->type; if($type=='public') $folder = "data_new/$folder"; else $folder = "private_new/$folder"; $webDirectory = $mainDirectory.$folder; echo<<

$targetName

Field

Detected Excesses

Swift-XRT image of the field for $targetName Swift-XRT detections in the field for $targetName
END; echo $unassociated->source->detectionsOutput; echo<<
END; if(isset($unassociated->source->rejectionsOutput)) echo $unassociated->source->rejectionsOutput; echo<<

X-Ray and Gamma Ray Catalogs

More Catalogs

Swift-XRT image with known X-ray and gamma ray sources for $targetName Swift-XRT image with known radio, optical and UV sources for $targetName
END; echo $unassociated->source->knownSources->xrayOutput; echo<<
END; echo $unassociated->source->knownSources->otherOutput; echo<<
END; } } function DisplayAllObservationInfo($target,$private=False,$spec=False){ $unassociated = new Unassociated(); $unassociated -> SourcePlots($target); $webDir = "/unassociated/"; if(isset($unassociated->plot) && (($unassociated->plot->type=='main' || $unassociated->plot->type=='public') || ($unassociated->plot->type!='main' && $unassociated->plot->type!='public' && $private==True))){ $targetName = $unassociated->plot->targetName; $type = $unassociated->plot->type; $folder = $unassociated->plot->folder; if($type=='main' || $type=='public') $folder = "data_new/$folder/"; else $folder = "private_new/$folder/"; //Overall data //padding-bottom:50px; echo "\t\t
\n"; echo "\t\t\t

$targetName

\n"; echo "\t\t
\n"; if(isset($unassociated->plot->observation)){ // echo "\t\t
\n"; $lastObs = True; $additionalObs = False; foreach($unassociated->plot->observation as &$obs){ $observationID = $obs->observationID; $observed = $obs->observed; //Plots $lcPlotObsStandardBin = $folder.$observationID."/lightcurve.png"; $hrPlotObsStandardBin = $folder.$observationID."/hardness.png"; //Data files $lcData1 = $folder.$observationID."/lightcurve.txt"; $lcData2 = $folder.$observationID."/lightcurve2.txt"; $hrData1 = $folder.$observationID."/hardness.txt"; if(!isset($size) && file_exists($lcPlotObsStandardBin)) $size = getimagesize($lcPlotObsStandardBin); if(isset($size)){ $w = floor(0.5*$size[0]); $h = floor(0.5*$size[1]); if(!$additionalObs) { echo "\t\t
\n\t\t\t\n"; echo "\t\t\t\t\n"; echo "\t\t\t\t\t\n"; echo "\t\t\t\t\n"; $additionalObs=True; } if(file_exists($lcPlotObsStandardBin)){ echo "\t\t\t\t\n"; echo "\t\t\t\t\t\n"; echo "\t\t\t\t\t\n"; echo "\t\t\t\t\t\n"; echo "\t\t\t\t\n"; } } } //Close table and div if needed if($additionalObs) echo "\t\t\t
\n"; echo "\t\t\t\t\t\t

All Individual Observations

\n"; echo "\t\t\t\t\t\t$observed\n"; echo "\t\t\t\t\t\tSwift light curve for Observation ID $observationID
\n"; echo "\t\t\t\t\t\tLight Curve (txt)
\n"; echo "\t\t\t\t\t\tDetailed Light Curve (txt)
\n"; if(file_exists($hrPlotObsStandardBin)) { echo "\t\t\t\t\t\tSwift hardness ratio for Observation ID $observationID
\n"; echo "\t\t\t\t\t\tHardness Ratio (txt)\n"; } else echo "\t\t\t\t\t\t "; echo "
\n\t\t
"; } } } function Radec2vec($ra,$dec){ $ra = deg2rad($ra); $dec = deg2rad($dec); $v1 = cos($dec)*cos($ra); $v2 = cos($dec)*sin($ra); $v3 = sin($dec); return array($v1,$v2,$v3); } function DotProduct($v1,$v2){ $dotProduct = $v1[0]*$v2[0] + $v1[1]*$v2[1] + $v1[2]*$v2[2]; return $dotProduct; } function Separation($c1,$c2){ //Accepts the RA, dec of two vectors and returns the separation between them //RA and dec must be in degrees //Output is in arcminutes //Convert both to vectors $v1 = Radec2vec($c1[0], $c1[1]); $v2 = Radec2vec($c2[0], $c2[1]); return rad2deg(acos(DotProduct($v1,$v2)))*60.; } function SignificantDigits($value,$error,$offset = 0){ if($value<0) return 'N/A'; $errorBase = floor(log10($error)); $meanBase = floor(log10($value)); if((number_format($error,-1*$errorBase)/pow(10,$errorBase))<2) $errorBase--; $error = number_format($error/pow(10,$meanBase),$meanBase-$errorBase); $value = number_format($value/pow(10,$meanBase),$meanBase-$errorBase); // return array($value,$error); if($meanBase==0){ $output = "\$ $value ± $error \$"; } else $output = "($value ± $error) x 10".($meanBase+$offset).""; return $output; /* if(!is_array($error)) $error = array($error); $errorBase = floor(log10($error)); $meanBase = floor(log10($value)); if((number_format(min($error),-1*$errorBase)/pow(10,$errorBase))<2) $errorBase--; if(count($error)<2){ $error = number_format($error[0]/pow(10,$meanBase),$meanBase-$errorBase); $errorString = " \pm $error "; } else { $error[0] = number_format($error[0]/pow(10,$meanBase),$meanBase-$errorBase); $error[1] = number_format($error[1]/pow(10,$meanBase),$meanBase-$errorBase); $errorString = "^{+".$error[0]."}_{-".$error[1]."} "; } $value = number_format($value/pow(10,$meanBase),$meanBase-$errorBase); if($meanBase==0){ $output = "\$ $value$errorString\$"; } else $output = "\$ ($value$errorString) \\times 10^{".($meanBase+$offset)."} \$"; return $output; */ } function FutureObservations($username,$targetName=False,$initialDate=False,$finalDate=False,$maxObservations=False){ $unassociated = new Unassociated(); $unassociated -> UpcomingObservations('stroh',$targetName,$initialDate,$finalDate,$maxObservations); if(isset($unassociated->observations)){ echo<< END; if($targetName!==False && $maxObservations!==False){ $nObservations = count($unassociated->observations); echo<< END; } echo<< END; for($i=0;$iobservations);$i++){ $start = $unassociated->observations[$i]->start; $stop = $unassociated->observations[$i]->stop; $targetName = $unassociated->observations[$i]->targetName; $duration = number_format($unassociated->observations[$i]->duration/1000.,1); if(fmod($i,2) == 0) echo " "; else echo " "; echo<<
$start
END; } if($targetName!==False && $maxObservations!==False){ $link = "/unassociated/futureObservations.php?targetName=".preg_replace('/\s/','',$targetName).""; echo<< END; } else if($targetName!==False){ $link = "/unassociated/futureObservations.php"; echo<< END; } echo "
Next $nObservations observations
Window Start
Window Stop
Target Name
Exposure
Time (ks)
$stop
$targetName
$duration
"; echo "
"; } else { echo<<
No observations are currently scheduled for this source through our programs.
END; } } function sanitizeText($text){ /* if(get_magic_quotes_gpc()) $text = stripcslashes($text);*/ /* $text = str_replace("<", "<", $text); $text = str_replace(">", ">", $text); $text = str_replace("\"", """, $text); $text = str_replace("'", "'", $text); */ //$text = $text; return $text; } //Convert Decimal to Sexigesimal function DecToSex($ra,$dec){ //R.A. $raSex1 = floor($ra/15.); $raSex2 = floor(60*($ra-$raSex1*15.)/15.); $raSex3 = number_format(60*(60*($ra-$raSex1*15)/15-$raSex2),2); if($raSex1<10) $raSex1 = "0".$raSex1; if($raSex2<10) $raSex2 = "0".$raSex2; if($raSex3<10) $raSex3 = "0".$raSex3; $raSex = $raSex1." ".$raSex2." ".$raSex3; //Declination if($dec>=0) $decSexSign = "+"; else $decSexSign = "-"; $decSex1 = floor(abs($dec)); $decSex2 = floor(60*(abs($dec)-$decSex1)); $decSex3 = number_format(((abs($dec)-$decSex1)*60-$decSex2)*60,2); if($decSex1<10) $decSex1 = "0".$decSex1; if($decSex2<10) $decSex2 = "0".$decSex2; if($decSex3<10) $decSex3 = "0".$decSex3; $decSex = $decSexSign.$decSex1." ".$decSex2." ".$decSex3; return array($raSex,$decSex); } function Redirect(){ header( "HTTP/1.1 301 Moved Permanently" ); header( "Status: 301 Moved Permanently" ); header( "Location: https://www.swift.psu.edu/unassociated/" ); }