Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, time=None, coordinates=None, ra=None, dec=None):
if time is not None:
if not isinstance(time, Time):
time = Time(time, format='gps')
self.time = time
if coordinates:
if ra is not None or dec is not None:
raise ValueError("'ra' and/or 'dec' should not be given if "
"'coordinates' is given, and vice-versa.")
self.coordinates = coordinates
elif ra is not None and dec is not None:
self.coordinates = acoords.ICRSCoordinates(float(ra), float(dec),
obstime=self.time,
unit=(aunits.radian,
aunits.radian))
def _datetime_to_time(dtm):
# astropy.time.Time requires datetime.datetime
if not isinstance(dtm, datetime.datetime):
dtm = datetime.datetime.combine(dtm, datetime.time.min)
return Time(dtm, scale='utc')
f = open(os.path.join(textLocation,"triggers.txt"),"w")
for row in table:
f.write("%.1f %e %e\n"%(row["peak_time"],row["central_freq"],row["snr"]))
f.close()
if params["doPlots"]:
plotLocation = params["path"] + "/" + channel.station_underscore
pylal.pylal_seismon_utils.mkdir(plotLocation)
if params["doEarthquakesAnalysis"]:
pngFile = os.path.join(plotLocation,"omicron-%d-%d.png"%(gpsStart,gpsEnd))
else:
pngFile = os.path.join(plotLocation,"omicron.png")
epoch = gwpy.time.Time(gpsStart, format='gps')
#plot = gwpy.plotter.Plot(auto_refresh=True,figsize=[14,8])
#plot.add_table(table, 'time', 'central_freq', colorcolumn='snr')
plot = gwpy.plotter.TablePlot(table, 'time', 'central_freq', colorcolumn='snr', figsize=[12,6])
plot.add_colorbar(log=False, clim=[6, 20])
plot.xlim = [gpsStart, gpsEnd]
plot.xlabel = 'Time'
plot.ylabel = 'Frequency [Hz]'
plot.axes.set_yscale("log")
plot.colorlabel = r'Signal-to-noise ratio (SNR)'
plot.save(pngFile)
plot.close()
dataOriginalASD = gwpy.spectrum.Spectrum(dataOriginalASD, f0=np.min(freq), df=(freq[1]-freq[0]))
dataResidualASD = np.array(dataResidualASD.data)
dataResidualASD = dataResidualASD[indexes]
dataResidualASD = gwpy.spectrum.Spectrum(dataResidualASD, f0=np.min(freq), df=(freq[1]-freq[0]))
dataFFASD = np.array(dataFFASD.data)
dataFFASD = dataFFASD[indexes]
dataFFASD = gwpy.spectrum.Spectrum(dataFFASD, f0=np.min(freq), df=(freq[1]-freq[0]))
originalASD.append(dataOriginalASD)
residualASD.append(dataResidualASD)
FFASD.append(dataFFASD)
dt = gpss[1] - gpss[0]
epoch = gwpy.time.Time(gpss[0], format='gps')
originalSpecgram = gwpy.spectrogram.Spectrogram.from_spectra(*originalASD, dt=dt,epoch=epoch)
residualSpecgram = gwpy.spectrogram.Spectrogram.from_spectra(*residualASD, dt=dt,epoch=epoch)
FFSpecgram = gwpy.spectrogram.Spectrogram.from_spectra(*FFASD, dt=dt,epoch=epoch)
freq = np.array(originalSpecgram.frequencies)
bins,originalSpecvar = pylal.pylal_seismon_utils.spectral_histogram(originalSpecgram)
original_spectral_variation_50per = pylal.pylal_seismon_utils.spectral_percentiles(originalSpecvar,bins,50)
bins,residualSpecvar = pylal.pylal_seismon_utils.spectral_histogram(residualSpecgram)
residual_spectral_variation_50per = pylal.pylal_seismon_utils.spectral_percentiles(residualSpecvar,bins,50)
bins,FFSpecvar = pylal.pylal_seismon_utils.spectral_histogram(FFSpecgram)
FF_spectral_variation_50per = pylal.pylal_seismon_utils.spectral_percentiles(FFSpecvar,bins,50)
if params["doPlots"]:
plotDirectory = params["path"] + "/Wiener/" + target_channel.station_underscore
pylal.pylal_seismon_utils.mkdir(plotDirectory)
def epoch(self):
"""Starting GPS time epoch for these `Bits`.
This attribute is recorded as a `~astropy.time.Time` object in the
GPS format, allowing native conversion into other formats.
See :mod:`~astropy.time` for details on the `Time` object.
"""
try:
return Time(self._epoch, format='gps')
except AttributeError:
return None
def auto_gps_label(self):
"""Automatically set the x-axis label based on the current GPS scale
"""
scale = self.xaxis._scale
epoch = scale.get_epoch()
if int(epoch) == epoch:
epoch = int(epoch)
if epoch is None:
self.set_xlabel('GPS Time')
else:
unit = scale.get_unit_name()
utc = re.sub(r'\.0+', '',
Time(epoch, format='gps', scale='utc').iso)
self.set_xlabel('Time [%s] from %s UTC (%s)'
% (unit, utc, repr(epoch)))
def fetch(self, start, end, channels):
if isinstance(channels, basestring) or isinstance(channels, Channel):
channels = [channels]
channels = map(str, channels)
gpsstart = int(floor(isinstance(start, Time) and start.gps or start))
gpsend = int(ceil(isinstance(end, Time) and end.gps or end))
out = self._connection.fetch(gpsstart, gpsend, channels)
series = []
for i,data in enumerate(out):
epoch = Time(data.gps_seconds, data.gps_nanoseconds, format='gps')
channel = Channel.query(data.channel.name)
series.append(TimeSeries(data.data, channel=channel, epoch=epoch))
if len(series) == 1:
return series[0]
else:
return series
if newSpectra == []:
newSpectra = specgram.data[:,j]
else:
newSpectra = np.vstack([newSpectra,specgram.data[:,j]])
newSpectra = np.array(newSpectra)
if len(newSpectra.shape) > 1:
newSpectra = np.mean(newSpectra, axis = 0)
sig, bgcolor = pylal.pylal_seismon_utils.html_bgcolor(np.mean(newSpectraNow),newSpectra)
f.write("%e %e %e %e %s\n"%(ff_ave[i],ff_ave[i+1],np.mean(newSpectraNow),sig,bgcolor))
key = "%s-%s"%(ff_ave[i],ff_ave[i+1])
dt = tts[-1] - tts[-2]
epoch = gwpy.time.Time(tts[0], format='gps')
timeseries = gwpy.timeseries.TimeSeries(newSpectra, epoch=epoch, sample_rate=1.0/dt)
sigDict[key] = {}
#timeseries.data = np.log10(timeseries.data)
sigDict[key]["data"] = timeseries
f.close()
if params["doPlots"]:
plotDirectory = params["path"] + "/" + channel.station_underscore
pylal.pylal_seismon_utils.mkdir(plotDirectory)
fl, low, fh, high = pylal.pylal_seismon_NLNM.NLNM(2)
def __init__(self, time=None, coordinates=None, ra=None, dec=None):
if time is not None:
if not isinstance(time, Time):
time = Time(time, format='gps')
self.time = time
if coordinates:
if ra is not None or dec is not None:
raise ValueError("'ra' and/or 'dec' should not be given if "
"'coordinates' is given, and vice-versa.")
self.coordinates = coordinates
elif ra is not None and dec is not None:
self.coordinates = acoords.ICRSCoordinates(float(ra), float(dec),
obstime=self.time,
unit=(aunits.radian,
aunits.radian))
def set_epoch(self, epoch):
if epoch is None:
self._epoch = None
return
elif not isinstance(epoch, Time):
if hasattr(epoch, "seconds"):
epoch = [epoch.seconds, epoch.nanoseconds*1e-9]
elif hasattr(epoch, "gpsSeconds"):
epoch = [epoch.gpsSeconds, epoch.gpsNanoSeconds*1e-9]
else:
epoch = modf(epoch)[::-1]
epoch = Time(*epoch, format='gps', precision=6)
self._epoch = epoch.copy(format='gps')