コード例 #1
0
ファイル: voevent.py プロジェクト: jdswinbank/fourpiskytools
def create_skeleton_voevent(id, stream, role):
    v = vp.Voevent(stream=id[id_keys.address] + "/" + stream, stream_id=generate_stream_id(), role=role)
    vp.set_who(v, date=datetime.utcnow(), author_ivorn=id[id_keys.address])
    vp.set_author(
        v, shortName=id[id_keys.shortName], contactName=id[id_keys.contactName], contactEmail=id[id_keys.contactEmail]
    )
    return v
コード例 #2
0
 def test_set_author(self):
     vp.set_author(self.v, title='4 Pi Sky Project',
                   shortName='4PiSky',
                   contactName='Tim Staley',
                   contactEmail='*****@*****.**',
                   contactPhone='123456789',
                   contributor='Bob')
     self.assertTrue(vp.valid_as_v2_0(self.v))
     self.assertEqual(self.v.Who.Author.shortName, '4PiSky')
コード例 #3
0
 def test_set_author(self):
     vp.set_author(self.v, title='4 Pi Sky Project',
                   shortName='4PiSky',
                   contactName='Tim Staley',
                   contactEmail='*****@*****.**',
                   contactPhone='123456789',
                   contributor='Bob')
     self.assertTrue(vp.valid_as_v2_0(self.v))
     self.assertEqual(self.v.Who.Author.shortName, '4PiSky')
コード例 #4
0
def test_unicode_voevent_tarball_dump(named_temporary_file):
    ## Now try some unicode characters
    voevent_etrees = fake.heartbeat_packets()
    vp.set_author(voevent_etrees[0], contactName=u"€€€€")
    voevent_rowgen = (models.Voevent.from_etree(v) for v in voevent_etrees)
    fname = named_temporary_file.name
    filestore.write_tarball(voevent_rowgen, fname)
    tarball = tarfile.open(fname)
    assert len(tarball.getmembers()) == len(voevent_etrees)
コード例 #5
0
ファイル: test_filestore.py プロジェクト: timstaley/voeventdb
def test_unicode_voevent_tarball_dump(named_temporary_file):
    ## Now try some unicode characters
    voevent_etrees = fake.heartbeat_packets()
    vp.set_author(voevent_etrees[0], contactName=u"€€€€")
    voevent_rowgen = (models.Voevent.from_etree(v) for v in voevent_etrees)
    fname = named_temporary_file.name
    filestore.write_tarball(voevent_rowgen, fname)
    tarball = tarfile.open(fname)
    assert len(tarball.getmembers()) == len(voevent_etrees)
コード例 #6
0
ファイル: voevent.py プロジェクト: jdswinbank/fourpiskytools
def create_skeleton_voevent(id, stream, role):
    v = vp.Voevent(stream=id[id_keys.address] + '/' + stream,
                   stream_id=generate_stream_id(), role=role)
    vp.set_who(v, date=datetime.utcnow(),
               author_ivorn=id[id_keys.address])
    vp.set_author(v,
                  shortName=id[id_keys.shortName],
                  contactName=id[id_keys.contactName],
                  contactEmail=id[id_keys.contactEmail],
                  )
    return v
コード例 #7
0
ファイル: voevent.py プロジェクト: 4pisky/fourpiskytools
def create_skeleton_voevent(id, stream, role):
    v = vp.Voevent(stream=id[id_keys.address] + '/' + stream,
                   stream_id=generate_stream_id(), role=role)
    now = datetime.utcnow().replace(tzinfo=pytz.UTC)
    vp.set_who(v, date=now,
               author_ivorn=id[id_keys.address])
    vp.set_author(v,
                  shortName=id[id_keys.shortName],
                  contactName=id[id_keys.contactName],
                  contactEmail=id[id_keys.contactEmail],
                  )
    return v
コード例 #8
0
ファイル: FRBCat.py プロジェクト: sipior/frbcatdb
 def set_author(self):
     '''
     Add author section to voevent object.
     '''
     # set a plactholder if none of the contact details are in the database
     # for some of the original entries
     if not any([self.event['title'], self.event['short_name'],
                 self.event['contact_name'], self.event['contact_email'],
                 self.event['contact_phone']]):
         self.event['contact_name'] = 'frbcatdb_extracted'
     # set author section
     vp.set_author(self.v,
                   title=self.event['title'],
                   shortName=self.event['short_name'],
                   logoURL=self.event['logo_url'],
                   contactName=self.event['contact_name'],
                   contactEmail=self.event['contact_email'],
                   contactPhone=self.event['contact_phone'])
コード例 #9
0
ファイル: voevent.py プロジェクト: timstaley/pysovo
def create_skeleton_4pisky_voevent(substream, stream_id,
                                   role=vp.definitions.roles.test,
                                   date=None):
    author_ivorn = ivorn_base+'/robots'
    if date is None:
        date = datetime.datetime.utcnow()

    v = vp.Voevent(stream=ivorn_base+ '/' + substream,
               stream_id=stream_id, role=role)

    vp.set_who(v, date=date,
               author_ivorn=author_ivorn)
    vp.set_author(v,
                  shortName="4PiSkyBot",
                  contactName="Tim Staley",
                  contactEmail="*****@*****.**"
                  )
    return v
コード例 #10
0
import datetime
import os

import pytz
import voeventparse as vp

# Set the basic packet ID and Author details

v = vp.Voevent(stream='astronomy.physics.science.org/super_exciting_events',
               stream_id=123, role=vp.definitions.roles.test)

vp.set_who(v, date=datetime.datetime.utcnow(),
           author_ivorn="voevent.4pisky.org")

vp.set_author(v, title="4PiSky Testing Node",
              shortName="Tim"
              )

# Now create some Parameters for entry in the 'What' section.

# Strictly speaking, parameter values should be strings,
# with a manually specified dataType; one of
# `string` (default), `int` , or `float`.
# e.g.
int_flux = vp.Param(name='int_flux',
                    value="2.0e-3",
                    unit='Janskys',
                    ucd='em.radio.100-200MHz',
                    dataType='float',
                    ac=False)
int_flux.Description = 'Integrated Flux'
コード例 #11
0
def init_voevent(conf_vo, what_com):
    """
    Create common structure for all VO events

    :param conf_vo: dictionary with common info, needed for header
    :param what_com: dictionary with common info for all type of events
    :return: vo event object
    """

    # initiate VO event object through voeventparse
    voevent = vp.Voevent(stream=conf_vo["stream"],
                         stream_id=conf_vo["streamid"],
                         role=conf_vo["role"])

    # include who part, required by VO protocol
    vp.set_who(voevent, date=datetime.datetime.utcnow(), author_ivorn=conf_vo["authorivorn"])

    # info of the origin, required by VO protocol
    vp.set_author(voevent, contactName=conf_vo["contactName"])
    vp.set_author(voevent, shortName=conf_vo["Experiment"])
    vp.set_author(voevent, contactPhone=conf_vo["contactPhone"])
    vp.set_author(voevent, contactEmail=conf_vo["contactEmail"])

    # fill infos from the original event, add them to What section
    # first type of the alert (GW, neutrinos, ...)
    alertype = vp.Param(name="Event_type",
                        value=what_com["event_type"], ucd="meta.id", dataType="string")
    alertype.Description = "Type of the alert"
    voevent.What.append(alertype)
    
    # include event name provided by the external observatory or GRANDMA
    eventid = vp.Param(name="Event_ID",
                      value=what_com["name_id"], ucd="meta.id", dataType="string")
    eventid.Description = "Name event, given by external observatory"
    voevent.What.append(eventid)


    # include trigger number provided by the external observatory
    trigid = vp.Param(name="Trigger_ID",
                      value=what_com["trigger_id"], ucd="meta.id", dataType="string")
    trigid.Description = "Trigger ID, given by external observatory"
    voevent.What.append(trigid)
    

    # Provide the status of the alert, given by external observatory
    alertstatus = vp.Param(name="Event_status",
                           value=what_com["event_status"],
                           ucd="meta.version", dataType="string")
    alertstatus.Description = "Event status (preliminary, initial, update, retraction)"
    voevent.What.append(alertstatus)

    # Serial number of the revision
    alertstatus_iter = vp.Param(name="Pkt_ser_num",
                                value=str(what_com["pkt_ser_num"]), ucd="meta.number",
                                dataType="int")
    alertstatus_iter.Description = \
        "Packet serial number since beginning, increase by 1 for every revision received"
    voevent.What.append(alertstatus_iter)

    if what_com["event_status"] not in ["Retraction", "retraction"]:
        # Instrument(s) involved in the alert
        triginstru = vp.Param(name="Instruments",
                              value=what_com["inst"], ucd="meta.code", dataType="string")
        triginstru.Description = "Instruments which originated of the alert"
        voevent.What.append(triginstru)
   	
   	
   	# include longshort provided by the external observatory
    eventid = vp.Param(name="LongShort",
                      value=str(what_com["longshort"]), ucd="meta.id", dataType="string")
    eventid.Description = "Long-short classification, given by external observatory"
    voevent.What.append(eventid)

   	# include hardness ratio classification provided by the external observatory
    hratio = vp.Param(name="Hratio",
                      value=str(what_com["hratio"]), ucd="meta.number", dataType="float")
    hratio.Description = "Hardness ratio classification, given by external observatory"
    voevent.What.append(hratio)

   	# include sun_distance classification provided by the external observatory
    sun_distance = vp.Param(name="Sun_distance",
                      value=str(what_com["sun_distance"]), ucd="meta.number", dataType="float")
    sun_distance.Description = "Sun distance from space, given by external observatory"
    voevent.What.append(sun_distance)

   	# include moon_distance classification provided by the external observatory
    moon_distance = vp.Param(name="Moon_distance",
                      value=str(what_com["moon_distance"]), ucd="meta.number", dataType="float")
    moon_distance.Description = "Moon distance from space, given by external observatory"
    voevent.What.append(moon_distance)    

   	# include moon_illumination classification provided by the external observatory
    moon_illum = vp.Param(name="Moon_illum",
                      value=str(what_com["moon_illum"]), ucd="meta.number", dataType="float")
    moon_illum.Description = "Moon illumination from space, given by external observatory"
    voevent.What.append(moon_illum)        
    
    
    return voevent
コード例 #12
0
# We'll start by creating the skeleton of our VOEvent packet. We set the role to test so that nobody is tempted to start acting on the contents of this demo event. We also set the timestamp in the ``Who`` block to the time the event was generated (not when the observation was made), as per the
# [specification](http://wiki.ivoa.net/twiki/bin/view/IVOA/VOEventTwoPointZero):

# In[ ]:

v = vp.Voevent(stream='hotwired.org/gaia_demo',
               stream_id=1,
               role=vp.definitions.roles.test)

# In[ ]:

#Set Who.Date timestamp to date of packet-generation:
vp.set_who(v,
           date=datetime.datetime.utcnow(),
           author_ivorn="foo.hotwired.hotwireduniverse.org/bar")
vp.set_author(v, title="Hotwired VOEvent Hands-on", contactName="Joe Bloggs")
v.Description = "This is not an official Gaia data product."

# At any time, you can use ``vp.dumps`` (dump-string) to take a look at the VOEvent you've composed so far:

# In[ ]:

# print(vp.dumps(v, pretty_print=True))

# However, that's pretty dense! Use ``vp.prettystr`` to view a single element, which is a bit easier on the eyes:

# In[ ]:

print(vp.prettystr(v.Who))

# ##Adding ``What`` content##
コード例 #13
0
def NewVOEvent(dm, dm_err, width, snr, flux, ra, dec, semiMaj, semiMin, ymw16, name, importance, utc, gl, gb): 

    z = dm/1200.0  #May change
    errDeg = semiMaj/60.0

    # Parse UTC
    utc_YY = int(utc[:4])
    utc_MM = int(utc[5:7])
    utc_DD = int(utc[8:10])
    utc_hh = int(utc[11:13])
    utc_mm = int(utc[14:16])
    utc_ss = float(utc[17:])
    t = Time('T'.join([utc[:10], utc[11:]]), scale='utc', format='isot')
    mjd = t.mjd
    
    now = Time.now()
    mjd_now = now.mjd
   
    ivorn = ''.join([name, str(utc_hh), str(utc_mm), '/', str(mjd_now)]) 

    v = vp.Voevent(stream='nl.astron.apertif/alert', stream_id=ivorn, role=vp.definitions.roles.test)
 #   v = vp.Voevent(stream='nl.astron.apertif/alert', stream_id=ivorn, role=vp.definitions.roles.observation)
    # Author origin information
    vp.set_who(v, date=datetime.datetime.utcnow(), author_ivorn="nl.astron")
    # Author contact information
    vp.set_author(v, title="ASTRON ALERT FRB Detector", contactName="Leon Oostrum", contactEmail="*****@*****.**", shortName="ALERT")
    # Parameter definitions

    #Apertif-specific observing configuration %%TODO: update parameters as necessary for new obs config
    beam_sMa = vp.Param(name="beam_semi-major_axis", unit="MM", ucd="instr.beam;pos.errorEllipse;phys.angSize.smajAxis", ac=True, value=semiMaj)
    beam_sma = vp.Param(name="beam_semi-minor_axis", unit="MM", ucd="instr.beam;pos.errorEllipse;phys.angSize.sminAxis", ac=True, value=semiMin)
    beam_rot = vp.Param(name="beam_rotation_angle", value=0.0, unit="Degrees", ucd="instr.beam;pos.errorEllipse;instr.offset", ac=True)
    tsamp = vp.Param(name="sampling_time", value=0.0496, unit="ms", ucd="time.resolution", ac=True)
    bw = vp.Param(name="bandwidth", value=300.0, unit="MHz", ucd="instr.bandwidth", ac=True)
    nchan = vp.Param(name="nchan", value="1536", dataType="int", ucd="meta.number;em.freq;em.bin", unit="None")
    cf = vp.Param(name="centre_frequency", value=1400.0, unit="MHz", ucd="em.freq;instr", ac=True)
    npol = vp.Param(name="npol", value="2", dataType="int", unit="None")
    bits = vp.Param(name="bits_per_sample", value="8", dataType="int", unit="None")
    gain = vp.Param(name="gain", value=1.0, unit="K/Jy", ac=True)
    tsys = vp.Param(name="tsys", value=75.0, unit="K", ucd="phot.antennaTemp", ac=True)
    backend = vp.Param(name="backend", value="ARTS")
#    beam = vp.Param(name="beam", value= )

    v.What.append(vp.Group(params=[beam_sMa, beam_sma, beam_rot, tsamp, bw, nchan, cf, npol, bits, gain, tsys, backend], name="observatory parameters"))

    #Event parameters
    DM = vp.Param(name="dm", ucd="phys.dispMeasure", unit="pc/cm^3", ac=True, value=dm )
#    DM_err = vp.Param(name="dm_err", ucd="stat.error;phys.dispMeasure", unit="pc/cm^3", ac=True, value=dm_err)
    Width = vp.Param(name="width", ucd="time.duration;src.var.pulse", unit="ms", ac=True, value=width)
    SNR = vp.Param(name="snr", ucd="stat.snr", unit="None", ac=True, value=snr)
    Flux = vp.Param(name="flux", ucd="phot.flux", unit="Jy", ac=True, value=flux)
    Flux.Description = "Calculated from radiometer equation. Not calibrated."
    Gl = vp.Param(name="gl", ucd="pos.galactic.lon", unit="Degrees", ac=True, value=gl)
    Gb = vp.Param(name="gb", ucd="pos.galactic.lat", unit="Degrees", ac=True, value=gb)

    v.What.append(vp.Group(params=[DM, Width, SNR, Flux, Gl, Gb], name="event parameters"))
#    v.What.append(vp.Group(params=[DM, DM_err, Width, SNR, Flux, Gl, Gb], name="event parameters"))

    #Advanced parameters (note, change script if using a differeing MW model)
    mw_dm = vp.Param(name="MW_dm_limit", unit="pc/cm^3", ac=True, value=ymw16)
    mw_model = vp.Param(name="galactic_electron_model", value="YMW16")
    redshift_inferred = vp.Param(name="redshift_inferred", ucd="src.redshift", unit="None", value=z)
    redshift_inferred.Description = "Redshift estimated using z = DM/1200.0 (Ioka 2003)"

    v.What.append(vp.Group(params=[mw_dm, mw_model, redshift_inferred], name="advanced parameters"))


    #WhereWhen

    vp.add_where_when(v, coords=vp.Position2D(ra=ra, dec=dec, err=errDeg, units='deg', system=vp.definitions.sky_coord_system.utc_fk5_geo),
        obs_time=datetime.datetime(utc_YY,utc_MM,utc_DD,utc_hh,utc_mm,int(utc_ss), tzinfo=pytz.UTC), observatory_location="WSRT")

    #Why
    
    vp.add_why(v, importance=imp)
    v.Why.Name = name

    if vp.valid_as_v2_0(v):
        with open('%s.xml' % utc, 'wb') as f:
            voxml = vp.dumps(v)
            xmlstr = minidom.parseString(voxml).toprettyxml(indent="   ")
            f.write(xmlstr)
            print(vp.prettystr(v.Who))
            print(vp.prettystr(v.What))
            print(vp.prettystr(v.WhereWhen))
            print(vp.prettystr(v.Why))
    else:
        print "Unable to write file %s.xml" % name
コード例 #14
0
import os

import pytz
import voeventparse as vp

# Set the basic packet ID and Author details

v = vp.Voevent(stream='astronomy.physics.science.org/super_exciting_events',
               stream_id=123,
               role=vp.definitions.roles.test)

vp.set_who(v,
           date=datetime.datetime.utcnow(),
           author_ivorn="voevent.4pisky.org")

vp.set_author(v, title="4PiSky Testing Node", shortName="Tim")

# Now create some Parameters for entry in the 'What' section.

# Strictly speaking, parameter values should be strings,
# with a manually specified dataType; one of
# `string` (default), `int` , or `float`.
# e.g.
int_flux = vp.Param(name='int_flux',
                    value="2.0e-3",
                    unit='Janskys',
                    ucd='em.radio.100-200MHz',
                    dataType='float',
                    ac=False)
int_flux.Description = 'Integrated Flux'
コード例 #15
0
# 
# We'll start by creating the skeleton of our VOEvent packet. We set the role to test so that nobody is tempted to start acting on the contents of this demo event. We also set the timestamp in the ``Who`` block to the time the event was generated (not when the observation was made), as per the 
# [specification](http://wiki.ivoa.net/twiki/bin/view/IVOA/VOEventTwoPointZero):

# In[ ]:

v = vp.Voevent(stream='hotwired.org/gaia_demo', stream_id=1,
                       role=vp.definitions.roles.test)


# In[ ]:

#Set Who.Date timestamp to date of packet-generation:
vp.set_who(v, date=datetime.datetime.utcnow(), 
        author_ivorn="foo.hotwired.hotwireduniverse.org/bar")
vp.set_author(v, title="Hotwired VOEvent Hands-on",
                      contactName="Joe Bloggs")
v.Description = "This is not an official Gaia data product."


# At any time, you can use ``vp.dumps`` (dump-string) to take a look at the VOEvent you've composed so far:

# In[ ]:

# print(vp.dumps(v, pretty_print=True))


# However, that's pretty dense! Use ``vp.prettystr`` to view a single element, which is a bit easier on the eyes:

# In[ ]:

print(vp.prettystr(v.Who))
コード例 #16
0
    def _NewVOEvent(self, dm, dm_err, width, snr, flux, ra, dec, semiMaj, semiMin,
                    ymw16, name, importance, utc, gl, gb, gain,
                    dt=TSAMP.to(u.ms).value, delta_nu_MHz=(BANDWIDTH / NCHAN).to(u.MHz).value,
                    nu_GHz=1.37, posang=0, test=None):
        """
        Create a VOEvent

        :param float dm: Dispersion measure (pc cm**-3)
        :param float dm_err: Error on DM (pc cm**-3)
        :param float width: Pulse width (ms)
        :param float snr: Signal-to-noise ratio
        :param float flux: flux density (mJy)
        :param float ra: Right ascension (deg)
        :param float dec: Declination (deg)
        :param float semiMaj: Localisation region semi-major axis (arcmin)
        :param float semiMin: Localisation region semi-minor axis (arcmin)
        :param float ymw16: YMW16 DM (pc cm**-3)
        :param str name: Source name
        :param float importance: Trigger importance (0-1)
        :param str utc: UTC arrival time in ISOT format
        :param float gl: Galactic longitude (deg)
        :param float gb: Galactic latitude (deg)
        :param float gain: Telescope gain (K Jy**-1)
        :param float dt: Telescope time resolution (ms)
        :param float delta_nu_MHz: Telescope frequency channel width (MHz)
        :param float nu_GHz: Telescope centre frequency (GHz)
        :param float posang: Localisation region position angle (deg)
        :param bool test: Whether to send a test event or observation event
        """

        z = dm / 1000.0  # May change
        errDeg = semiMaj / 60.0

        # Parse UTC
        utc_YY = int(utc[:4])
        utc_MM = int(utc[5:7])
        utc_DD = int(utc[8:10])
        utc_hh = int(utc[11:13])
        utc_mm = int(utc[14:16])
        utc_ss = float(utc[17:])
        t = Time(utc, scale='utc', format='isot')
        # IERS server is down, avoid using it
        t.delta_ut1_utc = 0
        mjd = t.mjd

        ivorn = ''.join([name, str(utc_hh), str(utc_mm), '/', str(mjd)])

        # use default value for test flag if not set
        if test is None:
            test = self.test

        # Set role to either test or real observation
        if test:
            self.logger.info("Event type is test")
            v = vp.Voevent(stream='nl.astron.apertif/alert', stream_id=ivorn,
                           role=vp.definitions.roles.test)
        else:
            self.logger.info("Event type is observation")
            v = vp.Voevent(stream='nl.astron.apertif/alert', stream_id=ivorn,
                           role=vp.definitions.roles.observation)
        # Author origin information
        vp.set_who(v, date=datetime.datetime.utcnow(), author_ivorn="nl.astron")
        # Author contact information
        vp.set_author(v, title="ARTS FRB alert system", contactName="Leon Oostrum",
                      contactEmail="*****@*****.**", shortName="ALERT")
        # Parameter definitions

        # Apertif-specific observing configuration
        beam_sMa = vp.Param(name="beam_semi-major_axis", unit="MM",
                            ucd="instr.beam;pos.errorEllipse;phys.angSize.smajAxis", ac=True, value=semiMaj)
        beam_sma = vp.Param(name="beam_semi-minor_axis", unit="MM",
                            ucd="instr.beam;pos.errorEllipse;phys.angSize.sminAxis", ac=True, value=semiMin)
        beam_rot = vp.Param(name="beam_rotation_angle", value=str(posang), unit="Degrees",
                            ucd="instr.beam;pos.errorEllipse;instr.offset", ac=True)
        tsamp = vp.Param(name="sampling_time", value=str(dt), unit="ms", ucd="time.resolution", ac=True)
        bw = vp.Param(name="bandwidth", value=str(delta_nu_MHz), unit="MHz", ucd="instr.bandwidth", ac=True)
        nchan = vp.Param(name="nchan", value=str(NCHAN), dataType="int",
                         ucd="meta.number;em.freq;em.bin", unit="None")
        cf = vp.Param(name="centre_frequency", value=str(1000 * nu_GHz), unit="MHz", ucd="em.freq;instr", ac=True)
        npol = vp.Param(name="npol", value="2", dataType="int", unit="None")
        bits = vp.Param(name="bits_per_sample", value="8", dataType="int", unit="None")
        gain = vp.Param(name="gain", value=str(gain), unit="K/Jy", ac=True)
        tsys = vp.Param(name="tsys", value=str(TSYS.to(u.Kelvin).value), unit="K", ucd="phot.antennaTemp", ac=True)
        backend = vp.Param(name="backend", value="ARTS")
        # beam = vp.Param(name="beam", value= )

        v.What.append(vp.Group(params=[beam_sMa, beam_sma, beam_rot, tsamp,
                                       bw, nchan, cf, npol, bits, gain, tsys, backend],
                               name="observatory parameters"))

        # Event parameters
        DM = vp.Param(name="dm", ucd="phys.dispMeasure", unit="pc/cm^3", ac=True, value=str(dm))
        DM_err = vp.Param(name="dm_err", ucd="stat.error;phys.dispMeasure", unit="pc/cm^3", ac=True, value=str(dm_err))
        Width = vp.Param(name="width", ucd="time.duration;src.var.pulse", unit="ms", ac=True, value=str(width))
        SNR = vp.Param(name="snr", ucd="stat.snr", unit="None", ac=True, value=str(snr))
        Flux = vp.Param(name="flux", ucd="phot.flux", unit="Jy", ac=True, value=str(flux))
        Flux.Description = "Calculated from radiometer equation. Not calibrated."
        Gl = vp.Param(name="gl", ucd="pos.galactic.lon", unit="Degrees", ac=True, value=str(gl))
        Gb = vp.Param(name="gb", ucd="pos.galactic.lat", unit="Degrees", ac=True, value=str(gb))

        # v.What.append(vp.Group(params=[DM, Width, SNR, Flux, Gl, Gb], name="event parameters"))
        v.What.append(vp.Group(params=[DM, DM_err, Width, SNR, Flux, Gl, Gb], name="event parameters"))

        # Advanced parameters (note, change script if using a differeing MW model)
        mw_dm = vp.Param(name="MW_dm_limit", unit="pc/cm^3", ac=True, value=str(ymw16))
        mw_model = vp.Param(name="galactic_electron_model", value="YMW16")
        redshift_inferred = vp.Param(name="redshift_inferred", ucd="src.redshift", unit="None", value=str(z))
        redshift_inferred.Description = "Redshift estimated using z = DM/1000.0"

        v.What.append(vp.Group(params=[mw_dm, mw_model, redshift_inferred], name="advanced parameters"))

        # WhereWhen
        vp.add_where_when(v, coords=vp.Position2D(ra=ra, dec=dec, err=errDeg, units='deg',
                                                  system=vp.definitions.sky_coord_system.utc_fk5_geo),
                          obs_time=datetime.datetime(utc_YY, utc_MM, utc_DD, utc_hh, utc_mm, int(utc_ss),
                                                     tzinfo=pytz.UTC),
                          observatory_location="WSRT")

        # Why
        vp.add_why(v, importance=importance)
        v.Why.Name = name

        if vp.valid_as_v2_0(v):
            with open('{}.xml'.format(utc), 'wb') as f:
                voxml = vp.dumps(v)
                xmlstr = minidom.parseString(voxml).toprettyxml(indent="   ")
                f.write(xmlstr.encode())
                self.logger.info(vp.prettystr(v.Who))
                self.logger.info(vp.prettystr(v.What))
                self.logger.info(vp.prettystr(v.WhereWhen))
                self.logger.info(vp.prettystr(v.Why))
        else:
            self.logger.error("Unable to write file {}.xml".format(name))
コード例 #17
0
ファイル: voevent.py プロジェクト: dsa110/dsa110-event
def create_voevent(jsonfile=None, deployment=False, **kwargs):
    """ template syntax for voeventparse creation of voevent
    """

    required = [
        'internalname', 'mjds', 'dm', 'width', 'snr', 'ra', 'dec', 'radecerr'
    ]
    preferred = ['fluence', 'p_flux', 'importance', 'dmerr']

    # set values
    dd = kwargs.copy()
    if jsonfile is not None:  # as made by caltechdata.set_metadata
        for k, v in trigger.items():
            if k in required + preferred:
                dd[k] = v

    assert all([
        k in dd for k in required
    ]), f'Input keys {list(dd.keys())} not complete (requires {required})'

    # TODO: set this correctly
    dt = time.Time(dd['mjds'], format='mjd').to_datetime(timezone=pytz.utc)

    # create voevent instance
    role = vp.definitions.roles.observation if deployment else vp.definitions.roles.test
    v = vp.Voevent(
        stream='',  # TODO: check
        stream_id=1,
        role=role)

    vp.set_who(v,
               date=datetime.datetime.utcnow(),
               author_ivorn="voevent.dsa-110.caltech.org")  # TODO: check

    vp.set_author(v,
                  title="DSA-110 Testing Node",
                  contactName="Casey Law",
                  contactEmail="*****@*****.**")

    params = []
    dm = vp.Param(name="dm",
                  value=str(dd['dm']),
                  unit="pc/cm^3",
                  ucd="phys.dispMeasure;em.radio.750-1500MHz",
                  dataType='float',
                  ac=True)
    dm.Description = 'Dispersion Measure'
    params.append(dm)

    width = vp.Param(name="width",
                     value=str(dd['width']),
                     unit="ms",
                     ucd="time.duration;src.var.pulse",
                     dataType='float',
                     ac=True)
    width.Description = 'Temporal width of burst'
    params.append(width)

    snr = vp.Param(name="snr",
                   value=str(dd['snr']),
                   ucd="stat.snr",
                   dataType='float',
                   ac=True)
    snr.Description = 'Signal to noise ratio'
    params.append(snr)

    if 'fluence' in dd:
        fluence = vp.Param(
            name='fluence',
            value=str(dd['fluence']),
            unit='Jansky ms',
            ucd='em.radio.750-1500MHz',  # TODO: check
            dataType='float',
            ac=False)
        fluence.Description = 'Fluence'
        params.append(fluence)

    if 'p_flux' in dd:
        p_flux = vp.Param(name='peak_flux',
                          value=str(dd['p_flux']),
                          unit='Janskys',
                          ucd='em.radio.750-1500MHz',
                          dataType='float',
                          ac=True)
        p_flux.Description = 'Peak Flux'
        params.append(p_flux)

    if 'dmerr' in dd:
        dmerr = vp.Param(name="dm_error",
                         value=str(dd['dmerr']),
                         unit="pc/cm^3",
                         ucd="phys.dispMeasure;em.radio.750-1500MHz",
                         dataType='float',
                         ac=True)
        dmerr.Description = 'Dispersion Measure error'
        params.append(dmerr)

    v.What.append(vp.Group(params=params, name='event parameters'))

    vp.add_where_when(v,
                      coords=vp.Position2D(
                          ra=str(dd['ra']),
                          dec=str(dd['dec']),
                          err=str(dd['radecerr']),
                          units='deg',
                          system=vp.definitions.sky_coord_system.utc_fk5_geo),
                      obs_time=dt,
                      observatory_location='OVRO')

    print("\n***Here is your WhereWhen:***\n")
    print(vp.prettystr(v.WhereWhen))

    print("\n***And your What:***\n")
    print(vp.prettystr(v.What))

    vp.add_how(v,
               descriptions='Discovered with DSA-110',
               references=vp.Reference('http://deepsynoptic.org'))

    if 'importance' in dd:
        vp.add_why(v, importance=str(dd['importance']))
    else:
        vp.add_why(v)
    v.Why.Name = str(dd['internalname'])

    vp.assert_valid_as_v2_0(v)

    return v