Skip to content

Commit

Permalink
Merge pull request #28 from astro-transients/add_external_source_name
Browse files Browse the repository at this point in the history
Add an option in the config file to setup manually the source name
  • Loading branch information
mseglar authored Dec 16, 2024
2 parents 55e12aa + 1ba0206 commit 5122602
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 87 deletions.
6 changes: 5 additions & 1 deletion examples/config/FollowupParameters_SWIFT.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ reducedNside = 128
HRnside = 512
mangrove = False
algorithm = 3D
countPrevious = False
countPrevious = False

[general]
downloadMaxRetry = 0
downloadWaitPeriodRetry = 20
6 changes: 4 additions & 2 deletions examples/launcher/Tiling_Observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
parser.add_argument('-o',metavar = 'output path', help='Path to the output folder',default='./output')
parser.add_argument('-cfg',metavar = 'config file', help='Config file for the tiling scheduling',default='../config/FollowupParameters_LST.ini')
parser.add_argument('-galcatName', metavar='galaxy catalog name', default="Gladeplus.h5")
parser.add_argument('-tiles', metavar='tiles already observed', default= None)
parser.add_argument('-tiles', metavar='tiles already observed', default=None)
parser.add_argument('-eventName', metavar='Name of the observed event', default=None)
args = parser.parse_args()
url = args.url
obsTime = datetime.datetime.fromisoformat(args.time)
Expand All @@ -38,6 +39,7 @@
cfgFile = args.cfg
galcatName = args.galcatName
pointingsFile = args.tiles
eventName = args.eventName

if not os.path.exists(outDir):
os.makedirs(outDir)
Expand All @@ -46,7 +48,7 @@
skymap = 'https://gracedb.ligo.org/api/superevents/S190728q/files/GW190728_064510_PublicationSamples_flattened.fits.gz,0'

obspar = ObservationParameters()
obspar.add_parsed_args(skymap, obsTime, datasetDir, galcatName, outDir, pointingsFile)
obspar.add_parsed_args(skymap, obsTime, datasetDir, galcatName, outDir, pointingsFile, eventName)
obspar.from_configfile(cfgFile)

#GetSchedule_confile(url,ObsTime,datasetDir,galcatname,outDir,cfgFile,PointingsFile,type)
Expand Down
18 changes: 9 additions & 9 deletions examples/launcher/Tiling_Observations_GBM.ipynb

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions examples/launcher/Tiling_Observations_Nobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
parser.add_argument('-o',metavar = 'output path', help='Path to the output folder',default='./output')
parser.add_argument('-cfg',metavar = 'config file', help='Config file for the tiling scheduling',default='../config/FollowupParameters.ini')
parser.add_argument('-galcatName', metavar='galaxy catalog name', default="Gladeplus.h5")
parser.add_argument('-tiles', metavar='tiles already observed', default= None)
parser.add_argument('-tiles', metavar='tiles already observed', default=None)
parser.add_argument('-eventName', metavar='Name of the observed event', default=None)

args = parser.parse_args()
skymap = args.skymap
Expand All @@ -37,6 +38,7 @@
cfgFile = args.cfg
galcatName = args.galcatName
pointingsFile = args.tiles
eventName = args.eventName

if not os.path.exists(outDir):
os.makedirs(outDir)
Expand All @@ -56,7 +58,7 @@

for j in range(len(parameters)):
obspar = ObservationParameters()
obspar.add_parsed_args(skymap, obsTime, datasetDir, galcatName, outDir, pointingsFile)
obspar.add_parsed_args(skymap, obsTime, datasetDir, galcatName, outDir, pointingsFile, eventName)
obspar.from_configfile(parameters[j])
obsparameters.append(obspar)

Expand Down
6 changes: 4 additions & 2 deletions examples/launcher/Tiling_Observations_Nobs_Space.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
parser.add_argument('-o',metavar = 'output path', help='Path to the output folder',default='./output')
parser.add_argument('-cfg',metavar = 'config file', help='Config file for the tiling scheduling',default='../config/FollowupParameters.ini')
parser.add_argument('-galcatName', metavar='galaxy catalog name', default="Gladeplus.h5")
parser.add_argument('-tiles', metavar='tiles already observed', default= None)
parser.add_argument('-tiles', metavar='tiles already observed', default=None)
parser.add_argument('-eventName', metavar='Name of the observed event', default=None)
#parser.add_argument('-base', metavar='ground or space', default= "ground")

args = parser.parse_args()
Expand All @@ -39,6 +40,7 @@
cfgFile = args.cfg
galcatName = args.galcatName
pointingsFile = args.tiles
eventName = args.eventName

if not os.path.exists(outDir):
os.makedirs(outDir)
Expand All @@ -58,7 +60,7 @@

for j in range(len(parameters)):
obspar = ObservationParameters()
obspar.add_parsed_args(skymap, obsTime, datasetDir, galcatName, outDir, pointingsFile, alertType)
obspar.add_parsed_args(skymap, obsTime, datasetDir, galcatName, outDir, pointingsFile, alertType, eventName)
obspar.from_configfile(parameters[j])
obsparameters.append(obspar)
print("obsparameters.base",obsparameters[0].base)
Expand Down
18 changes: 9 additions & 9 deletions examples/launcher/Tiling_Observations_cWB.ipynb

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/tilepy/include/MapManagement/MapReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def __init__(self, obspar):
self.fits_map = fits.open(self.skymap_filename)
self.id_hdu_map = self.getMapHDUId()
self.name_event = self.getSourceName()
if obspar.event_name is not None:
self.name_event = obspar.event_name
self.identifyColumns()

def getMapHDUId(self):
Expand Down
20 changes: 10 additions & 10 deletions src/tilepy/include/ObservationScheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ def GetSchedule(obspar):
print(f"Resulting pointings file is {outfilename}")
if (obspar.doRank):
RankingTimes(obspar.obsTime, skymap, cat, obspar, dirName,
'%s/SuggestedPointings_GalProbOptimisation.txt' % dirName, obspar.name)
'%s/SuggestedPointings_GalProbOptimisation.txt' % dirName, obspar.obs_name)
if (obspar.doPlot):
PointingPlotting(skymap.getMap('prob', obspar.HRnside), obspar, raw_map.name_event, dirName,
'%s/SuggestedPointings_GalProbOptimisation.txt' % dirName, obspar.name, cat)
'%s/SuggestedPointings_GalProbOptimisation.txt' % dirName, obspar.obs_name, cat)
else:
FOLLOWUP = False
print('No observations are scheduled')
Expand Down Expand Up @@ -124,10 +124,10 @@ def GetSchedule(obspar):
print(f"Resulting pointings file is {outfilename}")
if (obspar.doRank):
RankingTimes_2D(obspar.obsTime, skymap.getMap('prob', obspar.HRnside), obspar, dirName,
'%s/SuggestedPointings_2DProbOptimisation.txt' % dirName, obspar.name)
'%s/SuggestedPointings_2DProbOptimisation.txt' % dirName, obspar.obs_name)
if (obspar.doPlot):
PointingPlotting(skymap.getMap('prob', obspar.HRnside), obspar, raw_map.name_event, dirName,
'%s/SuggestedPointings_2DProbOptimisation.txt' % dirName, obspar.name, gal)
'%s/SuggestedPointings_2DProbOptimisation.txt' % dirName, obspar.obs_name, gal)
else:
FOLLOWUP = False
print('No observations are scheduled')
Expand Down Expand Up @@ -192,17 +192,17 @@ def GetUniversalSchedule(obspar):
# for obspar in parameters:
for j in range(len(obspar)):
obspar1 = obspar[j]
SuggestedPointings_1 = SuggestedPointings[SuggestedPointings['ObsName'] == obspar1.name]
SuggestedPointings_1 = SuggestedPointings[SuggestedPointings['ObsName'] == obspar1.obs_name]
print(SuggestedPointings_1)
if (len(SuggestedPointings_1) != 0):
ascii.write(SuggestedPointings_1, '%s/SuggestedPointings_GWOptimisation_%s.txt' %
(dirName, obspar[j].name), overwrite=True, fast_writer=False)
(dirName, obspar[j].obs_name), overwrite=True, fast_writer=False)
RankingTimes_2D(ObservationTime, skymap.getMap('prob', obspar[j].HRnside), obspar[j], dirName,
'%s/SuggestedPointings_GWOptimisation_%s.txt' % (dirName, obspar[j].name),
obspar[j].name)
PointingPlotting(skymap.getMap('prob', obspar[j].HRnside), obspar[j], obspar[j].name, dirName,
'%s/SuggestedPointings_GWOptimisation_%s.txt' % (dirName, obspar[j].obs_name),
obspar[j].obs_name)
PointingPlotting(skymap.getMap('prob', obspar[j].HRnside), obspar[j], obspar[j].obs_name, dirName,
'%s/SuggestedPointings_GWOptimisation_%s.txt' % (
dirName, obspar[j].name), obspar[j].name, cat)
dirName, obspar[j].obs_name), obspar[j].obs_name, cat)
PointingPlotting(skymap.getMap('prob', obspar[j].HRnside), obspar[0], "all", dirName, '%s/SuggestedPointings_GWOptimisation.txt' % dirName, "all",
cat)
else:
Expand Down
2 changes: 1 addition & 1 deletion src/tilepy/include/PointingPlotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def PointingPlottingGWCTA(filename, ID, outDir, SuggestedPointings, obspar):
print('------------------- PLOTTING SCHEDULE --------------------')
print()

UseObs = obspar.name
UseObs = obspar.obs_name
FOV = obspar.FOV
# Mask table if necesary
maskClean = (SuggestedPointings['ObsInfo'] == 'True')
Expand Down
52 changes: 24 additions & 28 deletions src/tilepy/include/PointingTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,7 @@
"Get90RegionPixReduced",
"Get90RegionPixGal",
"IsSourceInside",
"ProduceSummaryFileOld",
"FillSummary",
"ProduceSummaryFile",
"ProducePandasSummaryFile",
"ReadSummaryFile",
"ZenithAngleCut_TwoTimes",
"ComputeProbability2D_SelectClusters",
"GetSatelliteName",
"GetSatelliteTime",
"GetSatellitePositions",
Expand Down Expand Up @@ -351,14 +345,16 @@ class ObservationParameters(object):

# Observatory

def __init__(self, name=None, lat=0, lon=0, height=0, sunDown=None, moonDown=None, moonGrey=None, moonPhase=None,
minMoonSourceSeparation=None, maxMoonSourceSeparation=None, maxZenith=None, FOV=None, maxRuns=None,
maxNights=None, duration=None, minDuration=None, useGreytime=None, minSlewing=None, locCut90=None,
minimumProbCutForCatalogue=None, minProbcut=None, distCut=None, doPlot=False, secondRound=None,
zenithWeighting=None, percentageMOC=None, reducedNside=None, HRnside=None, mangrove=None, skymap=None,
obsTime=None, datasetDir=None, galcatName=None, outDir=None, pointingsFile=None, countPrevious=False,
MO=False, algorithm=None, strategy=None, doRank=False, downloadMaxRetry=0, downloadWaitPeriodRetry=20):
self.name = name
def __init__(self, obs_name=None, event_name=None, lat=0, lon=0, height=0, sunDown=None, moonDown=None, moonGrey=None,
moonPhase=None, minMoonSourceSeparation=None, maxMoonSourceSeparation=None, maxZenith=None, FOV=None,
maxRuns=None, maxNights=None, duration=None, minDuration=None, useGreytime=None, minSlewing=None,
locCut90=None, minimumProbCutForCatalogue=None, minProbcut=None, distCut=None, doPlot=False,
secondRound=None, zenithWeighting=None, percentageMOC=None, reducedNside=None, HRnside=None,
mangrove=None, skymap=None, obsTime=None, datasetDir=None, galcatName=None, outDir=None,
pointingsFile=None, countPrevious=False, MO=False, algorithm=None, strategy=None, doRank=False,
downloadMaxRetry=0, downloadWaitPeriodRetry=20):
self.obs_name = obs_name
self.event_name = event_name
self.lat = lat
self.lon = lon
self.height = height
Expand Down Expand Up @@ -418,7 +414,7 @@ def __init__(self, name=None, lat=0, lon=0, height=0, sunDown=None, moonDown=Non
def __str__(self):
txt = ''
txt += '============== Main parsed observation parameters ============== \n'.format()
txt += 'Observatory Name: {}\n'.format(self.name)
txt += 'Observatory Name: {}\n'.format(self.obs_name)
txt += 'Observatory: {}\n'.format(self.lat)
txt += 'Observatory: {}\n'.format(self.lon)
txt += 'Observatory: {}\n'.format(self.height)
Expand All @@ -438,14 +434,15 @@ def __str__(self):
# txt += '----------------------------------------------------------------------\n'.format()
return txt

def add_parsed_args(self, skymap, obsTime, datasetDir, galcatName, outDir, pointingsFile):
def add_parsed_args(self, skymap, obsTime, datasetDir, galcatName, outDir, pointingsFile, eventName=None):
# Parsed args in command line
self.skymap = skymap
self.obsTime = obsTime
self.datasetDir = datasetDir
self.galcatName = galcatName
self.outDir = outDir
self.pointingsFile = pointingsFile
self.event_name = self.event_name if eventName is None else eventName


def from_configfile(self, filepath):
Expand All @@ -455,7 +452,7 @@ def from_configfile(self, filepath):
parser.read(cfg)
parser.sections()
section = 'observatory'
self.name = str(parser.get(section, 'name', fallback=None))
self.obs_name = str(parser.get(section, 'name', fallback=None))
self.lat = float(parser.get(section, 'lat', fallback=0)) * u.deg
self.lon = float(parser.get(section, 'lon', fallback=0)) * u.deg
self.height = float(parser.get(section, 'height', fallback=0)) * u.m
Expand Down Expand Up @@ -511,17 +508,16 @@ def from_configfile(self, filepath):
self.countPrevious = (parser.getboolean(section, 'countPrevious', fallback=None))

section = 'general'
self.downloadMaxRetry = (parser.getboolean(section, 'downloadMaxRetry', fallback=0))
self.downloadMaxRetry = int(parser.getboolean(section, 'downloadMaxRetry', fallback=0))
self.downloadWaitPeriodRetry = float(parser.get(section, 'downloadWaitPeriodRetry', fallback=0))

def from_args(self, name, lat, lon, height, sunDown, moonDown,
moonGrey, moonPhase, minMoonSourceSeparation,
maxMoonSourceSeparation, maxZenith, FOV, maxRuns, maxNights,
duration, minDuration, useGreytime, minSlewing,
minimumProbCutForCatalogue, minProbcut, distCut, doPlot, secondRound,
zenithWeighting, percentageMOC, reducedNside, HRnside,
mangrove):
self.name = name
self.event_name = parser.get(section, 'eventName', fallback=None)

def from_args(self, obsName, eventName, lat, lon, height, sunDown, moonDown, moonGrey, moonPhase,
minMoonSourceSeparation, maxMoonSourceSeparation, maxZenith, FOV, maxRuns, maxNights, duration,
minDuration, useGreytime, minSlewing, minimumProbCutForCatalogue, minProbcut, distCut, doPlot,
secondRound, zenithWeighting, percentageMOC, reducedNside, HRnside, mangrove):
self.obs_name = obsName
self.event_name = eventName
self.lat = lat * u.deg
self.lon = lon * u.deg
self.height = height * u.m
Expand Down Expand Up @@ -1002,7 +998,7 @@ def GetSatelliteName(satellitename, stationsurl):
stations_url = stationsurl
satellites = load.tle_file(stations_url)
#print('Loaded', len(satellites), 'satellites')
by_name = {sat.name: sat for sat in satellites}
by_name = {sat.obs_name: sat for sat in satellites}
satellite_name = by_name.get(satellitename)
return satellite_name

Expand Down
Loading

0 comments on commit 5122602

Please sign in to comment.