def _get_soucelist_from_gsm(self, measurement_set,
                    sourcelist, monet_db_host, monet_db_port, monet_db_name,
                    monet_db_user, monet_db_password, assoc_theta=None):
        """
        Create a bbs sky model. Based on the measurement (set) suplied
        The skymap is created at the sourcelist
        """
        # Create monetdb connection
        conn = self._create_monet_db_connection(monet_db_host, monet_db_name,
                 monet_db_user, monet_db_password, monet_db_port)
        self.logger.debug("Connected to monet db at: {0}:{1}  {2}".format(
                monet_db_host, monet_db_port, monet_db_name))

        # get position of the target in the sky
        (ra_c, decl_c) = self._get_ra_and_decl_from_ms(measurement_set)
        self.logger.debug("ra and dec from measurement set: {0}, {1}".format(
                    ra_c, decl_c))

        # Get the Fov: sources in this fov should be included in the skumodel
        fov_radius = self._field_of_view(measurement_set)
        self.logger.debug(
            "Using the folowing calculated field of view: {0}".format(
                fov_radius))

        # !!magic constant!! This value is calculated based on        
        # communications with Bart Sheers
        if assoc_theta == None:
            assoc_theta = 90.0 / 3600
        try:
            # Transform the ra and decl to rad
            ra_c = float(ra_c) * (180 / math.pi)
            if ra_c < 0:  #gsm utils break when using negative ra_c ergo add 360
                ra_c += 360.0
            decl_c = float(decl_c) * (180 / math.pi)
            self.logger.debug("external call to gsm module:")
            self.logger.debug("gsm.expected_fluxes_in_fov(conn, {0} , {1}, {2}, {3}, {4}, {5})".format(
                ra_c, decl_c, float(fov_radius), float(assoc_theta), sourcelist, "storespectraplots=False"))

            gsm.expected_fluxes_in_fov(conn, ra_c ,
                        decl_c, float(fov_radius),
                        float(assoc_theta), sourcelist,
                        storespectraplots=False)
            self.logger.debug(gsm.__file__)

        except Exception, exception:
            self.logger.error("expected_fluxes_in_fov raise exception: " +
                              str(exception))
            return 1
    def _get_soucelist_from_gsm(self, measurement_set,
                    sourcelist, monet_db_host, monet_db_port, monet_db_name,
                    monet_db_user, monet_db_password, assoc_theta=None):
        """
        Create a bbs sky model. Based on the measurement (set) suplied
        The skymap is created at the sourcelist
        """
        # Create monetdb connection
        conn = self._create_monet_db_connection(monet_db_host, monet_db_name,
                 monet_db_user, monet_db_password, monet_db_port)
        self.logger.debug("Connected to monet db at: {0}:{1}  {2}".format(
                monet_db_host, monet_db_port, monet_db_name))

        # get position of the target in the sky
        (ra_c, decl_c) = self._get_ra_and_decl_from_ms(measurement_set)
        self.logger.debug("ra and dec from measurement set: {0}, {1}".format(
                    ra_c, decl_c))

        # Get the Fov: sources in this fov should be included in the skumodel
        fov_radius = self._field_of_view(measurement_set)
        self.logger.debug(
            "Using the folowing calculated field of view: {0}".format(
                fov_radius))

        # !!magic constant!! This value is calculated based on        
        # communications with Bart Sheers
        if assoc_theta == None:
            assoc_theta = 90.0 / 3600
        try:
            # Transform the ra and decl to rad
            ra_c = float(ra_c) * (180 / math.pi)
            if ra_c < 0:  #gsm utils break when using negative ra_c ergo add 360
                ra_c += 360.0
            decl_c = float(decl_c) * (180 / math.pi)
            self.logger.debug("external call to gsm module:")
            self.logger.debug("gsm.expected_fluxes_in_fov(conn, {0} , {1}, {2}, {3}, {4}, {5})".format(
                ra_c, decl_c, float(fov_radius), float(assoc_theta), sourcelist, "storespectraplots=False"))

            gsm.expected_fluxes_in_fov(conn, ra_c ,
                        decl_c, float(fov_radius),
                        float(assoc_theta), sourcelist,
                        storespectraplots=False)
            self.logger.debug(gsm.__file__)

        except Exception, exception:
            self.logger.error("expected_fluxes_in_fov raise exception: " +
                              str(exception))
            return 1
Example #3
0
    def _get_soucelist_from_gsm(self,
                                measurement_set,
                                sourcelist,
                                monet_db_host,
                                monet_db_port,
                                monet_db_name,
                                monet_db_user,
                                monet_db_password,
                                assoc_theta=None):
        """
        Create a bbs sky model. Based on the measurement (set) suplied
        The skymap is created at the sourcelist
        """
        # Create monetdb connection
        conn = self._create_monet_db_connection(monet_db_host, monet_db_name,
                                                monet_db_user,
                                                monet_db_password,
                                                monet_db_port)
        self.logger.debug("Connected to monet db at: {0}:{1}  {2}".format(
            monet_db_host, monet_db_port, monet_db_name))

        # get position of the target in the sky
        (ra_c, decl_c) = self._get_ra_and_decl_from_ms(measurement_set)
        self.logger.debug("ra and dec from measurement set: {0}, {1}".format(
            ra_c, decl_c))

        # Get the Fov: sources in this fov should be included in the skumodel
        fov_radius = self._field_of_view(measurement_set)
        self.logger.debug(
            "Using the folowing calculated field of view: {0}".format(
                fov_radius))

        # !!magic constant!! This value is calculated based on
        # communications with Bart Sheers
        if assoc_theta == None:
            assoc_theta = 90.0 / 3600
        try:
            # Transform the ra and decl to rad
            ra_c = float(ra_c) * (180 / math.pi)
            if ra_c < 0:  #gsm utils break when using negative ra_c ergo add 360
                ra_c += 360.0
            decl_c = float(decl_c) * (180 / math.pi)
            self.logger.debug("external call to gsm module:")
            self.logger.debug(
                "gsm.expected_fluxes_in_fov(conn, {0} , {1}, {2}, {3}, {4}, {5})"
                .format(ra_c, decl_c, float(fov_radius), float(assoc_theta),
                        sourcelist, "storespectraplots=False"))

            gsm.expected_fluxes_in_fov(conn,
                                       ra_c,
                                       decl_c,
                                       float(fov_radius),
                                       float(assoc_theta),
                                       sourcelist,
                                       storespectraplots=False)
            self.logger.debug(gsm.__file__)

        except Exception as exception:
            self.logger.error("expected_fluxes_in_fov raise exception: " +
                              str(exception))
            return 1

        # validate the retrieve sourcelist
        fp = open(sourcelist)
        sourcelist_corrected = self._validate_and_correct_sourcelist(fp.read())
        fp.close()

        if sourcelist_corrected != None:
            self.logger.debug("Found duplicates in the sourcelist!")
            self.logger.debug("Creating a new sourcelist")
            #if a corrected sourcelist is created.
            # move original sourcelist
            shutil.move(sourcelist, sourcelist + "_with_duplicates")
            # write correcte sourcelist at that location
            fp = open(
                sourcelist,
                "w",
            )
            fp.write(sourcelist_corrected)
            self.logger.debug("Moved sourcelist and create a new sourcelist")
            fp.close()
        else:
            self.logger.debug("Sourcelist did not contain duplicates")
        return 0
Example #4
0
def gsmMain(name, argv):

    import sys

    import math

    import monetdb
    import monetdb.sql as db
    import lofar.gsm.gsmutils as gsm
    #import gsmutils as gsm

    if len(argv) < 4 or (argv[0] == '-p' and len(argv) < 6):
        print('')
        print('Insufficient arguments given; run as:')
        print('')
        print(
            '   %s [-p patchname] outfile RA DEC radius [vlssFluxCutoff [assocTheta]]'
            % name)
        print('to select using a cone')
        print('')
        print(
            '   -p patchname    if given, all sources belong to this single patch'
        )
        print('   outfile         path-name of the output file')
        print('                   It will be overwritten if already existing')
        print(
            '   RA              cone center Right Ascension (J2000, degrees)')
        print(
            '   DEC             cone center Declination     (J2000, degrees)')
        print('   radius          cone radius                 (degrees)')
        print('   vlssFluxCutoff  minimum flux (Jy) of VLSS sources to use')
        print('                   default = 4')
        print('   assocTheta      uncertainty in matching     (degrees)')
        print('                   default = 0.00278  (10 arcsec)')
        print('')
        return False

    # Get the arguments.
    patch = ''
    st = 0
    if argv[0] == '-p':
        patch = argv[1]
        st = 2
    outfile = argv[st]
    try:
        ra = float(argv[st + 1])
        dec = float(argv[st + 2])
    except ValueError:
        # Try to parse ra-dec as in the output of msoverview, e.g. 08:13:36.0000 +48.13.03.0000
        ralst = argv[st + 1].split(':')
        ra = math.copysign(
            abs(float(ralst[0])) + float(ralst[1]) / 60. +
            float(ralst[2]) / 3600., float(ralst[0]))
        declst = argv[st + 2].split('.')
        dec = math.copysign(
            abs(float(declst[0])) + float(declst[1]) / 60. +
            float('.'.join(declst[2:])) / 3600., float(declst[0]))
    radius = float(argv[st + 3])
    cutoff = 4.
    theta = 0.00278
    if len(argv) > st + 4:
        cutoff = float(argv[st + 4])
    if len(argv) > st + 5:
        theta = float(argv[st + 5])

    db_host = "gsmdb.control.lofar"
    #db_host = "napels"
    db_dbase = "gsm"
    db_user = "******"
    db_passwd = "msss"
    #db_passwd = "gsm"
    db_port = 51000
    db_autocommit = True

    try:
        conn = db.connect(hostname=db_host,
                          database=db_dbase,
                          username=db_user,
                          password=db_passwd,
                          port=db_port,
                          autocommit=db_autocommit)
        gsm.expected_fluxes_in_fov(conn,
                                   ra,
                                   dec,
                                   radius,
                                   theta,
                                   outfile,
                                   patchname=patch,
                                   storespectraplots=False,
                                   deruiter_radius=3.717,
                                   vlss_flux_cutoff=cutoff)
    except db.Error as e:
        raise
Example #5
0
def gsmMain(name, argv):

    import sys

    import monetdb
    import monetdb.sql as db
    import lofar.gsm.gsmutils as gsm
    #import gsmutils as gsm

    if len(argv) < 4 or (argv[0] == '-p' and len(argv) < 6):
        print ''
        print 'Insufficient arguments given; run as:'
        print ''
        print '   %s [-p patchname] outfile RA DEC radius [vlssFluxCutoff [assocTheta]]' % name
        print 'to select using a cone'
        print ''
        print '   -p patchname    if given, all sources belong to this single patch'
        print '   outfile         path-name of the output file'
        print '                   It will be overwritten if already existing'
        print '   RA              cone center Right Ascension (J2000, degrees)'
        print '   DEC             cone center Declination     (J2000, degrees)'
        print '   radius          cone radius                 (degrees)'
        print '   vlssFluxCutoff  minimum flux (Jy) of VLSS sources to use'
        print '                   default = 4'
        print '   assocTheta      uncertainty in matching     (degrees)'
        print '                   default = 0.00278  (10 arcsec)'
        print ''
        return False

    # Get the arguments.
    patch = ''
    st = 0
    if argv[0] == '-p':
        patch = argv[1]
        st = 2
    outfile = argv[st]
    ra = float(argv[st + 1])
    dec = float(argv[st + 2])
    radius = float(argv[st + 3])
    cutoff = 4.
    theta = 0.00278
    if len(argv) > st + 4:
        cutoff = float(argv[st + 4])
    if len(argv) > st + 5:
        theta = float(argv[st + 5])

    db_host = "ldb002"
    #db_host = "napels"
    db_dbase = "gsm"
    db_user = "******"
    db_passwd = "msss"
    #db_passwd = "gsm"
    db_port = 51000
    db_autocommit = True

    try:
        conn = db.connect(hostname=db_host,
                          database=db_dbase,
                          username=db_user,
                          password=db_passwd,
                          port=db_port,
                          autocommit=db_autocommit)
        gsm.expected_fluxes_in_fov(conn,
                                   ra,
                                   dec,
                                   radius,
                                   theta,
                                   outfile,
                                   patchname=patch,
                                   storespectraplots=False,
                                   deruiter_radius=3.717,
                                   vlss_flux_cutoff=cutoff)
    except db.Error, e:
        raise
Example #6
0
def gsmMain(name, argv):

    import sys

    import monetdb
    import monetdb.sql as db
    import lofar.gsm.gsmutils as gsm

    # import gsmutils as gsm

    if len(argv) < 4 or (argv[0] == "-p" and len(argv) < 6):
        print ""
        print "Insufficient arguments given; run as:"
        print ""
        print "   %s [-p patchname] outfile RA DEC radius [vlssFluxCutoff [assocTheta]]" % name
        print "to select using a cone"
        print ""
        print "   -p patchname    if given, all sources belong to this single patch"
        print "   outfile         path-name of the output file"
        print "                   It will be overwritten if already existing"
        print "   RA              cone center Right Ascension (J2000, degrees)"
        print "   DEC             cone center Declination     (J2000, degrees)"
        print "   radius          cone radius                 (degrees)"
        print "   vlssFluxCutoff  minimum flux (Jy) of VLSS sources to use"
        print "                   default = 4"
        print "   assocTheta      uncertainty in matching     (degrees)"
        print "                   default = 0.00278  (10 arcsec)"
        print ""
        return False

    # Get the arguments.
    patch = ""
    st = 0
    if argv[0] == "-p":
        patch = argv[1]
        st = 2
    outfile = argv[st]
    ra = float(argv[st + 1])
    dec = float(argv[st + 2])
    radius = float(argv[st + 3])
    cutoff = 4.0
    theta = 0.00278
    if len(argv) > st + 4:
        cutoff = float(argv[st + 4])
    if len(argv) > st + 5:
        theta = float(argv[st + 5])

    db_host = "ldb002"
    # db_host = "napels"
    db_dbase = "gsm"
    db_user = "******"
    db_passwd = "msss"
    # db_passwd = "gsm"
    db_port = 51000
    db_autocommit = True

    try:
        conn = db.connect(
            hostname=db_host,
            database=db_dbase,
            username=db_user,
            password=db_passwd,
            port=db_port,
            autocommit=db_autocommit,
        )
        gsm.expected_fluxes_in_fov(
            conn,
            ra,
            dec,
            radius,
            theta,
            outfile,
            patchname=patch,
            storespectraplots=False,
            deruiter_radius=3.717,
            vlss_flux_cutoff=cutoff,
        )
    except db.Error, e:
        raise
Example #7
0
File: gsm.py Project: jjdmol/LOFAR
def gsmMain (name, argv):

    import sys
 
    import math

    import monetdb
    import monetdb.sql as db
    import lofar.gsm.gsmutils as gsm 
    #import gsmutils as gsm 

    if len(argv) < 4  or  (argv[0] == '-p'  and  len(argv) < 6):
        print ''
        print 'Insufficient arguments given; run as:'
        print ''
        print '   %s [-p patchname] outfile RA DEC radius [vlssFluxCutoff [assocTheta]]' % name
        print 'to select using a cone'
        print ''
        print '   -p patchname    if given, all sources belong to this single patch'
        print '   outfile         path-name of the output file'
        print '                   It will be overwritten if already existing'
        print '   RA              cone center Right Ascension (J2000, degrees)'
        print '   DEC             cone center Declination     (J2000, degrees)'
        print '   radius          cone radius                 (degrees)'
        print '   vlssFluxCutoff  minimum flux (Jy) of VLSS sources to use'
        print '                   default = 4'
        print '   assocTheta      uncertainty in matching     (degrees)'
        print '                   default = 0.00278  (10 arcsec)'
        print ''
        return False

    # Get the arguments.
    patch   = ''
    st = 0
    if argv[0] == '-p':
        patch = argv[1]
        st = 2
    outfile = argv[st]
    try:
      ra      = float(argv[st+1])
      dec     = float(argv[st+2])
    except ValueError:
      # Try to parse ra-dec as in the output of msoverview, e.g. 08:13:36.0000 +48.13.03.0000
      ralst = argv[st+1].split(':')
      ra = math.copysign(abs(float(ralst[0]))+float(ralst[1])/60.+float(ralst[2])/3600.,float(ralst[0]))
      declst = argv[st+2].split('.')
      dec = math.copysign(abs(float(declst[0]))+float(declst[1])/60.+float('.'.join(declst[2:]))/3600.,float(declst[0]))
    radius  = float(argv[st+3])
    cutoff  = 4.
    theta   = 0.00278
    if len(argv) > st+4:
        cutoff = float(argv[st+4])
    if len(argv) > st+5:
        theta = float(argv[st+5])

    db_host = "ldb002.offline.lofar"
    #db_host = "napels"
    db_dbase = "gsm"
    db_user = "******"
    db_passwd = "msss"
    #db_passwd = "gsm"
    db_port = 51000
    db_autocommit = True

    try:
        conn = db.connect(hostname=db_host, database=db_dbase, username=db_user,
                          password=db_passwd, port=db_port, autocommit=db_autocommit)
        gsm.expected_fluxes_in_fov (conn, ra, dec, radius, theta, outfile,
                                    patchname=patch,
                                    storespectraplots=False,
                                    deruiter_radius=3.717,
                                    vlss_flux_cutoff=cutoff)
    except db.Error, e:
        raise