Instruction:
Explain what the following Python 3 code does
def get_active_address(name, arec):
    addrs = arec.get(name)
    if addrs:
        return Message("/oper/ns", "info", addrs)
    else:
        return Message("/oper/ns", "info", "")

Response: Get the addresses of the active modules for a given publisher name.


Instruction:
Write a Python 3 script for
running the listener and answer to requests.

Response:
def run(self, *args):
        """Run the listener and answer to requests.
        """
        del args

        arec = AddressReceiver(max_age=self._max_age,
                               multicast_enabled=self._multicast_enabled)
        arec.start()
        port = PORT

        try:
            with nslock:
                self.listener = get_context().socket(REP)
                self.listener.bind("tcp://*:" + str(port))
                logger.debug('Listening on port %s', str(port))
                poller = Poller()
                poller.register(self.listener, POLLIN)
            while self.loop:
                with nslock:
                    socks = dict(poller.poll(1000))
                    if socks:
                        if socks.get(self.listener) == POLLIN:
                            msg = self.listener.recv_string()
                    else:
                        continue
                    logger.debug("Replying to request: " + str(msg))
                    msg = Message.decode(msg)
                    self.listener.send_unicode(six.text_type(get_active_address(
                        msg.data["service"], arec)))
        except KeyboardInterrupt:
            # Needed to stop the nameserver.
            pass
        finally:
            arec.stop()
            self.stop()


Instruction:
Here you have a function in Python 3, explain what it does
def stop(self):
        self.listener.setsockopt(LINGER, 1)
        self.loop = False
        with nslock:
            self.listener.close()

Response: Stop the name server.


Instruction:
How would you explain what the following Python 3 function does
def check_requirements(requirements, ignore=None):
	ignore = (ignore or [])
	not_satisfied = []
	working_set = pkg_resources.working_set
	installed_packages = dict((p.project_name, p) for p in working_set)  # pylint: disable=E1133

	if isinstance(requirements, str):
		with open(requirements, 'r') as file_h:
			requirements = file_h.readlines()
	elif hasattr(requirements, 'readlines'):
		requirements = requirements.readlines()
	elif not isinstance(requirements, (list, tuple)):
		raise TypeError('invalid type for argument requirements')

	for req_line in requirements:
		req_line = req_line.strip()
		parts = re.match(r'^([\w\-]+)(([<>=]=)(\d+(\.\d+)*))?$', req_line)
		if not parts:
			raise ValueError("requirement '{0}' is in an invalid format".format(req_line))
		req_pkg = parts.group(1)
		if req_pkg in ignore:
			continue
		if req_pkg not in installed_packages:
			try:
				find_result = working_set.find(pkg_resources.Requirement.parse(req_line))
			except pkg_resources.ResolutionError:
				find_result = False
			if not find_result:
				not_satisfied.append(req_pkg)
			continue
		if not parts.group(2):
			continue
		req_version = distutils.version.StrictVersion(parts.group(4))
		installed_pkg = installed_packages[req_pkg]
		installed_version = re.match(r'^((\d+\.)*\d+)', installed_pkg.version)
		if not installed_version:
			not_satisfied.append(req_pkg)
			continue
		installed_version = distutils.version.StrictVersion(installed_version.group(0))
		if parts.group(3) == '==' and installed_version != req_version:
			not_satisfied.append(req_pkg)
		elif parts.group(3) == '>=' and installed_version < req_version:
			not_satisfied.append(req_pkg)
		elif parts.group(3) == '<=' and installed_version > req_version:
			not_satisfied.append(req_pkg)
	return not_satisfied

Response: Parse the requirements file for package information to determine if all requirements are met.


Instruction:
Can you implement a function in Python 3 that
gives a list of 4 - element tuples transforms it into a numpy array

Response:
def segments_to_numpy(segments):
    """given a list of 4-element tuples, transforms it into a numpy array"""
    segments = numpy.array(segments, dtype=SEGMENT_DATATYPE, ndmin=2)  # each segment in a row
    segments = segments if SEGMENTS_DIRECTION == 0 else numpy.transpose(segments)
    return segments


Instruction:
Create a Python 3 function to
give a rectangle and an image returns it s corresponding subimage

Response:
def region_from_segment(image, segment):
    """given a segment (rectangle) and an image, returns it's corresponding subimage"""
    x, y, w, h = segment
    return image[y:y + h, x:x + w]


Instruction:
Here you have a function in Python 3, explain what it does
def ingest(self):
        self.log.debug('starting the ``get`` method')

        # A YAML DICTIONARY OF sherlock-catalogues TABLE NAME AND THE SELECT
        # QUERY TO LIFT THE DATA FROM THE MARSHALL
        yamlFilePath = '/'.join(string.split(__file__, '/')
                                [:-1]) + "/resources/pessto_marshall_table_selects.yaml"
        stream = file(yamlFilePath, 'r')
        marshallQueries = yaml.load(stream)
        stream.close()
        self.primaryIdColumnName = "primaryId"
        self.raColName = "raDeg"
        self.declColName = "decDeg"

        # CREATE THE MARSHALL IMPORT CATALOGUE TABLES (IF THEY DO NOT EXIST)
        directory_script_runner(
            log=self.log,
            pathToScriptDirectory='/'.join(string.split(__file__,
                                                        '/')[:-1]) + "/resources",
            databaseName=self.settings["database settings"][
                "static catalogues"]["db"],
            loginPath=self.settings["database settings"][
                "static catalogues"]["loginPath"],
            successRule="delete",
            failureRule="failed"
        )

        for k, v in marshallQueries["pessto queries"].iteritems():
            self.dbTableName = k
            self.databaseInsertbatchSize = 500
            dictList = self._create_dictionary_of_marshall(
                marshallQuery=v["query"],
                marshallTable=v["marshallTable"]
            )

            tableName = self.dbTableName
            self.add_data_to_database_table(
                dictList=dictList
            )

        self.log.debug('completed the ``get`` method')
        return None

Response: Ingest the ePESSTO Marshall transient stream into the sherlock - catalogues database


Instruction:
Can you generate a brief explanation for the following Python 3 code
def _create_dictionary_of_marshall(
            self,
            marshallQuery,
            marshallTable):
        """create a list of dictionaries containing all the rows in the marshall stream

        **Key Arguments:**
            - ``marshallQuery`` -- the query used to lift the required data from the marshall database.
            - ``marshallTable`` -- the name of the marshall table we are lifting the data from.

        **Return:**
            - ``dictList`` - a list of dictionaries containing all the rows in the marshall stream
        """
        self.log.debug(
            'starting the ``_create_dictionary_of_marshall`` method')

        dictList = []
        tableName = self.dbTableName

        rows = readquery(
            log=self.log,
            sqlQuery=marshallQuery,
            dbConn=self.pmDbConn,
            quiet=False
        )

        totalCount = len(rows)
        count = 0

        for row in rows:
            if "dateCreated" in row:
                del row["dateCreated"]
            count += 1
            if count > 1:
                # Cursor up one line and clear line
                sys.stdout.write("\x1b[1A\x1b[2K")
            print "%(count)s / %(totalCount)s `%(tableName)s` data added to memory" % locals()
            dictList.append(dict(row))

        self.log.debug(
            'completed the ``_create_dictionary_of_marshall`` method')
        return dictList

Response: create a list of dictionaries containing all the rows in the marshall stream


Instruction:
Can you create a Python 3 function that
imports the ned_d catalogue into the catalogues database and creates the HTMIDs for that table.

Response:
def ingest(self):
        """Import the ned_d catalogue into the catalogues database

        The method first generates a list of python dictionaries from the ned_d datafile, imports this list of dictionaries into a database table and then generates the HTMIDs for that table.

        **Usage:**

            See class docstring for usage

        .. todo ::

            - update docstring text
            - check sublime snippet exists
            - clip any useful text to docs mindmap
            - regenerate the docs and check redendering of this docstring
        """
        self.log.debug('starting the ``get`` method')

        dictList = self._create_dictionary_of_ned_d()
        self.primaryIdColumnName = "primaryId"
        self.raColName = "raDeg"
        self.declColName = "decDeg"

        tableName = self.dbTableName
        createStatement = u"""
            CREATE TABLE `%(tableName)s` (
              `primaryId` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'An internal counter',
              `Method` varchar(150) DEFAULT NULL,
              `dateCreated` datetime DEFAULT CURRENT_TIMESTAMP,
              `dateLastModified` datetime DEFAULT CURRENT_TIMESTAMP,
              `updated` varchar(45) DEFAULT '0',
              `dist_derived_from_sn` varchar(150) DEFAULT NULL,
              `dist_in_ned_flag` varchar(10) DEFAULT NULL,
              `dist_index_id` mediumint(9) DEFAULT NULL,
              `dist_mod` double DEFAULT NULL,
              `dist_mod_err` double DEFAULT NULL,
              `dist_mpc` double DEFAULT NULL,
              `galaxy_index_id` mediumint(9) DEFAULT NULL,
              `hubble_const` double DEFAULT NULL,
              `lmc_mod` double DEFAULT NULL,
              `notes` varchar(500) DEFAULT NULL,
              `primary_ned_id` varchar(150) DEFAULT NULL,
              `redshift` double DEFAULT NULL,
              `ref` varchar(150) DEFAULT NULL,
              `ref_date` int(11) DEFAULT NULL,
              `master_row` tinyint(4) DEFAULT '0',
              `major_diameter_arcmin` double DEFAULT NULL,
              `ned_notes` varchar(700) DEFAULT NULL,
              `object_type` varchar(100) DEFAULT NULL,
              `redshift_err` double DEFAULT NULL,
              `redshift_quality` varchar(100) DEFAULT NULL,
              `magnitude_filter` varchar(10) DEFAULT NULL,
              `minor_diameter_arcmin` double DEFAULT NULL,
              `morphology` varchar(50) DEFAULT NULL,
              `hierarchy` varchar(50) DEFAULT NULL,
              `galaxy_morphology` varchar(50) DEFAULT NULL,
              `radio_morphology` varchar(50) DEFAULT NULL,
              `activity_type` varchar(50) DEFAULT NULL,
              `in_ned` tinyint(4) DEFAULT NULL,
              `raDeg` double DEFAULT NULL,
              `decDeg` double DEFAULT NULL,
              `eb_v` double DEFAULT NULL,
              `sdss_coverage` TINYINT DEFAULT NULL,
              PRIMARY KEY (`primaryId`),
              UNIQUE KEY `galaxy_index_id_dist_index_id` (`galaxy_index_id`,`dist_index_id`)
            ) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=latin1;
        DROP VIEW IF EXISTS `view_%(tableName)s_master_recorders`;
            CREATE
                VIEW `view_%(tableName)s_master_recorders` AS
                    (SELECT
                        `%(tableName)s`.`primary_ned_id` AS `primary_ned_id`,
                        `%(tableName)s`.`object_type` AS `object_type`,
                        `%(tableName)s`.`raDeg` AS `raDeg`,
                        `%(tableName)s`.`decDeg` AS `decDeg`,
                        `%(tableName)s`.`dist_mpc` AS `dist_mpc`,
                        `%(tableName)s`.`dist_mod` AS `dist_mod`,
                        `%(tableName)s`.`dist_mod_err` AS `dist_mod_err`,
                        `%(tableName)s`.`Method` AS `dist_measurement_method`,
                        `%(tableName)s`.`redshift` AS `redshift`,
                        `%(tableName)s`.`redshift_err` AS `redshift_err`,
                        `%(tableName)s`.`redshift_quality` AS `redshift_quality`,
                        `%(tableName)s`.`major_diameter_arcmin` AS `major_diameter_arcmin`,
                        `%(tableName)s`.`minor_diameter_arcmin` AS `minor_diameter_arcmin`,
                        `%(tableName)s`.`magnitude_filter` AS `magnitude_filter`,
                        `%(tableName)s`.`eb_v` AS `gal_eb_v`,
                        `%(tableName)s`.`hierarchy` AS `hierarchy`,
                        `%(tableName)s`.`morphology` AS `morphology`,
                        `%(tableName)s`.`radio_morphology` AS `radio_morphology`,
                        `%(tableName)s`.`activity_type` AS `activity_type`,
                        `%(tableName)s`.`ned_notes` AS `ned_notes`,
                        `%(tableName)s`.`in_ned` AS `in_ned`,
                        `%(tableName)s`.`primaryId` AS `primaryId`
                    FROM
                        `%(tableName)s`
                    WHERE
                        (`%(tableName)s`.`master_row` = 1));
        """ % locals()

        self.add_data_to_database_table(
            dictList=dictList,
            createStatement=createStatement
        )

        self._clean_up_columns()
        self._get_metadata_for_galaxies()
        self._update_sdss_coverage()

        self.log.debug('completed the ``get`` method')
        return None


Instruction:
Write a Python 3 function that can
create a list of dictionaries containing all the rows in the ned_d catalogue

Response:
def _create_dictionary_of_ned_d(
            self):
        """create a list of dictionaries containing all the rows in the ned_d catalogue

        **Return:**
            - ``dictList`` - a list of dictionaries containing all the rows in the ned_d catalogue

        .. todo ::

            - update key arguments values and definitions with defaults
            - update return values and definitions
            - update usage examples and text
            - update docstring text
            - check sublime snippet exists
            - clip any useful text to docs mindmap
            - regenerate the docs and check redendering of this docstring
        """
        self.log.debug(
            'starting the ``_create_dictionary_of_ned_d`` method')

        count = 0
        with open(self.pathToDataFile, 'rb') as csvFile:
            csvReader = csv.reader(
                csvFile, dialect='excel', delimiter=',', quotechar='"')
            totalRows = sum(1 for row in csvReader)
        csvFile.close()
        totalCount = totalRows

        with open(self.pathToDataFile, 'rb') as csvFile:
            csvReader = csv.reader(
                csvFile, dialect='excel', delimiter=',', quotechar='"')
            theseKeys = []
            dictList = []
            for row in csvReader:
                if len(theseKeys) == 0:
                    totalRows -= 1
                if "Exclusion Code" in row and "Hubble const." in row:
                    for i in row:
                        if i == "redshift (z)":
                            theseKeys.append("redshift")
                        elif i == "Hubble const.":
                            theseKeys.append("hubble_const")
                        elif i == "G":
                            theseKeys.append("galaxy_index_id")
                        elif i == "err":
                            theseKeys.append("dist_mod_err")
                        elif i == "D (Mpc)":
                            theseKeys.append("dist_mpc")
                        elif i == "Date (Yr. - 1980)":
                            theseKeys.append("ref_date")
                        elif i == "REFCODE":
                            theseKeys.append("ref")
                        elif i == "Exclusion Code":
                            theseKeys.append("dist_in_ned_flag")
                        elif i == "Adopted LMC modulus":
                            theseKeys.append("lmc_mod")
                        elif i == "m-M":
                            theseKeys.append("dist_mod")
                        elif i == "Notes":
                            theseKeys.append("notes")
                        elif i == "SN ID":
                            theseKeys.append("dist_derived_from_sn")
                        elif i == "method":
                            theseKeys.append("dist_method")
                        elif i == "Galaxy ID":
                            theseKeys.append("primary_ned_id")
                        elif i == "D":
                            theseKeys.append("dist_index_id")
                        else:
                            theseKeys.append(i)
                    continue

                if len(theseKeys):
                    count += 1
                    if count > 1:
                        # Cursor up one line and clear line
                        sys.stdout.write("\x1b[1A\x1b[2K")
                    if count > totalCount:
                        count = totalCount
                    percent = (float(count) / float(totalCount)) * 100.
                    print "%(count)s / %(totalCount)s (%(percent)1.1f%%) rows added to memory" % locals()
                    rowDict = {}
                    for t, r in zip(theseKeys, row):
                        rowDict[t] = r
                        if t == "ref_date":
                            try:
                                rowDict[t] = int(r) + 1980
                            except:
                                rowDict[t] = None

                    if rowDict["dist_index_id"] != "999999":
                        dictList.append(rowDict)

        csvFile.close()

        self.log.debug(
            'completed the ``_create_dictionary_of_ned_d`` method')
        return dictList


Instruction:
Implement a Python 3 function for
cleaning up the columns of the NED table

Response:
def _clean_up_columns(
            self):
        """clean up columns of the NED table

        .. todo ::

            - update key arguments values and definitions with defaults
            - update return values and definitions
            - update usage examples and text
            - update docstring text
            - check sublime snippet exists
            - clip any useful text to docs mindmap
            - regenerate the docs and check redendering of this docstring
        """
        self.log.debug('starting the ``_clean_up_columns`` method')

        tableName = self.dbTableName

        print "cleaning up %(tableName)s columns" % locals()

        sqlQuery = u"""
                set sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION";
            """ % locals()
        writequery(
            log=self.log,
            sqlQuery=sqlQuery,
            dbConn=self.cataloguesDbConn,
        )

        sqlQuery = u"""
                update %(tableName)s set dist_mod_err = null where dist_mod_err = 0;
                update %(tableName)s set dist_in_ned_flag = null where dist_in_ned_flag = "";
                update %(tableName)s set notes = null where notes = "";
                update %(tableName)s set redshift = null where redshift = 0;
                update %(tableName)s set dist_derived_from_sn = null where dist_derived_from_sn = "";
                update %(tableName)s set hubble_const = null where hubble_const = 0;
                update %(tableName)s set lmc_mod = null where lmc_mod = 0;
                update %(tableName)s set master_row = 0;
                update %(tableName)s set master_row = 1 where primaryId in (select * from (select distinct primaryId from %(tableName)s group by galaxy_index_id) as alias);
            """ % locals()
        writequery(
            log=self.log,
            sqlQuery=sqlQuery,
            dbConn=self.cataloguesDbConn,
        )

        self.log.debug('completed the ``_clean_up_columns`` method')
        return None


Instruction:
Implement a Python 3 function for
getting metadata for a set of galaxies

Response:
def _get_metadata_for_galaxies(
            self):
        """get metadata for galaxies

        .. todo ::

            - update key arguments values and definitions with defaults
            - update return values and definitions
            - update usage examples and text
            - update docstring text
            - check sublime snippet exists
            - clip any useful text to docs mindmap
            - regenerate the docs and check redendering of this docstring
        """
        self.log.debug('starting the ``_get_metadata_for_galaxies`` method')

        total, batches = self._count_galaxies_requiring_metadata()
        print "%(total)s galaxies require metadata. Need to send %(batches)s batch requests to NED." % locals()

        totalBatches = self.batches
        thisCount = 0

        # FOR EACH BATCH, GET THE GALAXY IDs, QUERY NED AND UPDATE THE DATABASE
        while self.total:
            thisCount += 1
            self._get_3000_galaxies_needing_metadata()
            dictList = self._query_ned_and_add_results_to_database(thisCount)

            self.add_data_to_database_table(
                dictList=dictList,
                createStatement=False
            )

            self._count_galaxies_requiring_metadata()

        self.log.debug('completed the ``_get_metadata_for_galaxies`` method')
        return None


Instruction:
Implement a function in Python 3 to
get 3000 galaxies needing metadata

Response:
def _get_3000_galaxies_needing_metadata(
            self):
        """ get 3000 galaxies needing metadata

        **Return:**
            - ``len(self.theseIds)`` -- the number of NED IDs returned

        .. todo ::

            - update key arguments values and definitions with defaults
            - update return values and definitions
            - update usage examples and text
            - update docstring text
            - check sublime snippet exists
            - clip any useful text to docs mindmap
            - regenerate the docs and check redendering of this docstring
        """
        self.log.debug(
            'starting the ``_get_3000_galaxies_needing_metadata`` method')

        tableName = self.dbTableName

        # SELECT THE DATA FROM NED TABLE
        self.theseIds = {}
        sqlQuery = u"""
            select primaryId, primary_ned_id from %(tableName)s where master_row = 1 and in_ned is null limit 3000;
        """ % locals()
        rows = readquery(
            log=self.log,
            sqlQuery=sqlQuery,
            dbConn=self.cataloguesDbConn,
            quiet=False
        )
        for row in rows:
            self.theseIds[row["primary_ned_id"]] = row["primaryId"]

        self.log.debug(
            'completed the ``_get_3000_galaxies_needing_metadata`` method')

        return len(self.theseIds)


Instruction:
Given the following Python 3 function, write the documentation
def _query_ned_and_add_results_to_database(
            self,
            batchCount):
        """ query ned and add results to database

        **Key Arguments:**
            - ``batchCount`` - the index number of the batch sent to NED

        .. todo ::

            - update key arguments values and definitions with defaults
            - update return values and definitions
            - update usage examples and text
            - update docstring text
            - check sublime snippet exists
            - clip any useful text to docs mindmap
            - regenerate the docs and check redendering of this docstring
        """
        self.log.debug(
            'starting the ``_query_ned_and_add_results_to_database`` method')

        tableName = self.dbTableName
        # ASTROCALC UNIT CONVERTER OBJECT
        converter = unit_conversion(
            log=self.log
        )

        # QUERY NED WITH BATCH
        totalCount = len(self.theseIds)
        print "requesting metadata from NED for %(totalCount)s galaxies (batch %(batchCount)s)" % locals()
        search = namesearch(
            log=self.log,
            names=self.theseIds.keys(),
            quiet=True
        )
        results = search.get()
        print "results returned from ned -- starting to add to database" % locals()

        # CLEAN THE RETURNED DATA AND UPDATE DATABASE
        totalCount = len(results)
        count = 0
        sqlQuery = ""
        dictList = []

        colList = ["redshift_quality", "redshift", "hierarchy", "object_type", "major_diameter_arcmin", "morphology", "magnitude_filter",
                   "ned_notes", "eb_v", "raDeg", "radio_morphology", "activity_type", "minor_diameter_arcmin", "decDeg", "redshift_err", "in_ned"]

        if not len(results):
            for k, v in self.theseIds.iteritems():
                dictList.append({
                    "in_ned": 0,
                    "primaryID": v
                })
        for thisDict in results:

            thisDict["tableName"] = tableName
            count += 1
            for k, v in thisDict.iteritems():
                if not v or len(v) == 0:
                    thisDict[k] = "null"
                if k in ["major_diameter_arcmin", "minor_diameter_arcmin"] and (":" in v or "?" in v or "<" in v):
                    thisDict[k] = v.replace(":", "").replace(
                        "?", "").replace("<", "")
                if isinstance(v, str) and '"' in v:
                    thisDict[k] = v.replace('"', '\\"')
            if "Input name not" not in thisDict["input_note"] and "Same object as" not in thisDict["input_note"]:
                if thisDict["ra"] != "null" and thisDict["dec"] != "null":
                    thisDict["raDeg"] = converter.ra_sexegesimal_to_decimal(
                        ra=thisDict["ra"]
                    )
                    thisDict["decDeg"] = converter.dec_sexegesimal_to_decimal(
                        dec=thisDict["dec"]
                    )
                else:
                    thisDict["raDeg"] = None
                    thisDict["decDeg"] = None
                thisDict["in_ned"] = 1
                thisDict["eb_v"] = thisDict["eb-v"]

                row = {}
                row["primary_ned_id"] = thisDict["input_name"]

                try:
                    row["primaryID"] = self.theseIds[thisDict["input_name"]]
                    for c in colList:
                        if thisDict[c] == "null":
                            row[c] = None
                        else:
                            row[c] = thisDict[c]
                    dictList.append(row)
                except:
                    g = thisDict["input_name"]
                    self.log.error(
                        "Cannot find database table %(tableName)s primaryID for '%(g)s'\n\n" % locals())
                    dictList.append({
                        "in_ned": 0,
                        "primary_ned_id": thisDict["input_name"]
                    })

            else:
                dictList.append({
                    "primary_ned_id": thisDict["input_name"],
                    "in_ned": 0,
                    "primaryID": self.theseIds[thisDict["input_name"]]
                })

        self.log.debug(
            'completed the ``_query_ned_and_add_results_to_database`` method')
        return dictList

Response: query ned and add results to database


Instruction:
Implement a function in Python 3 to
update SDSS coverage for the current key - item

Response:
def _update_sdss_coverage(
            self):
        """ update sdss coverage

        .. todo ::

            - update key arguments values and definitions with defaults
            - update return values and definitions
            - update usage examples and text
            - update docstring text
            - check sublime snippet exists
            - clip any useful text to docs mindmap
            - regenerate the docs and check redendering of this docstring
        """
        self.log.debug('starting the ``_update_sdss_coverage`` method')

        tableName = self.dbTableName

        # SELECT THE LOCATIONS NEEDING TO BE CHECKED
        sqlQuery = u"""
            select primary_ned_id, primaryID, raDeg, decDeg, sdss_coverage from %(tableName)s where sdss_coverage is null and master_row = 1 and in_ned = 1 order by dist_mpc;
        """ % locals()
        rows = readquery(
            log=self.log,
            sqlQuery=sqlQuery,
            dbConn=self.cataloguesDbConn,
            quiet=False
        )

        totalCount = len(rows)
        count = 0
        for row in rows:
            count += 1
            if count > 1:
                # Cursor up three lines and clear
                sys.stdout.write("\x1b[1A\x1b[2K")
                sys.stdout.write("\x1b[1A\x1b[2K")
                sys.stdout.write("\x1b[1A\x1b[2K")

            if count > totalCount:
                count = totalCount
            percent = (float(count) / float(totalCount)) * 100.

            primaryID = row["primaryID"]
            raDeg = float(row["raDeg"])
            decDeg = float(row["decDeg"])
            primary_ned_id = row["primary_ned_id"]

            # SDSS CAN ONLY ACCEPT 60 QUERIES/MIN
            time.sleep(1.1)
            print "%(count)s / %(totalCount)s (%(percent)1.1f%%) NED galaxies checked for SDSS coverage" % locals()
            print "NED NAME: ", primary_ned_id

            # covered = True | False | 999 (i.e. not sure)
            sdss_coverage = check_coverage(
                log=self.log,
                ra=raDeg,
                dec=decDeg
            ).get()

            if sdss_coverage == 999:
                sdss_coverage_flag = "null"
            elif sdss_coverage == True:
                sdss_coverage_flag = 1
            elif sdss_coverage == False:
                sdss_coverage_flag = 0
            else:
                self.log.error('cound not get sdss coverage' % locals())
                sys.exit(0)

            # UPDATE THE DATABASE FLAG
            sqlQuery = u"""
                update %(tableName)s set sdss_coverage = %(sdss_coverage_flag)s where primaryID = %(primaryID)s
            """ % locals()
            writequery(
                log=self.log,
                sqlQuery=sqlQuery,
                dbConn=self.cataloguesDbConn,
            )

        self.log.debug('completed the ``_update_sdss_coverage`` method')
        return None


Instruction:
Make a summary of the following Python 3 code
def run(self, command, **kwargs):
        return RemoteTask(self.hostname, command,
                          identity_file=self._identity_file, **kwargs)

Response: Run a command on the remote host.


Instruction:
Here you have a function in Python 3, explain what it does
def send_file(self, file_name, remote_destination=None, **kwargs):
        if not remote_destination:
            remote_destination = file_name

        return SubprocessTask(
            self._rsync_cmd() +
            ['-ut', file_name, '%s:%s' % (self.hostname, remote_destination)],
            **kwargs)

Response: Sends a file to a remote host with rsync.


Instruction:
Can you tell what is the following Python 3 function doing
def get_file(self, file_name, local_destination=None, **kwargs):
        if not local_destination:
            local_destination = file_name

        return SubprocessTask(
            self._rsync_cmd() +
            ['-ut', '%s:%s' % (self.hostname, file_name), local_destination],
            **kwargs)

Response: Get a file from a remote host with rsync.


Instruction:
Make a summary of the following Python 3 code
def make_config(self, data: dict):
        self.validate_config(data)
        config_data = self.prepare_config(data)
        return config_data

Response: Make a MIP config.


Instruction:
Given the following Python 3 function, write the documentation
def validate_config(data: dict) -> dict:
        errors = ConfigSchema().validate(data)
        if errors:
            for field, messages in errors.items():
                if isinstance(messages, dict):
                    for level, sample_errors in messages.items():
                        sample_id = data['samples'][level]['sample_id']
                        for sub_field, sub_messages in sample_errors.items():
                            LOG.error(f"{sample_id} -> {sub_field}: {', '.join(sub_messages)}")
                else:
                    LOG.error(f"{field}: {', '.join(messages)}")
            raise ConfigError('invalid config input', errors=errors)

Response: Convert to MIP config format.


Instruction:
Write a Python 3 function for
preparing the config data.

Response:
def prepare_config(data: dict) -> dict:
        """Prepare the config data."""
        data_copy = deepcopy(data)
        # handle single sample cases with 'unknown' phenotype
        if len(data_copy['samples']) == 1:
            if data_copy['samples'][0]['phenotype'] == 'unknown':
                LOG.info("setting 'unknown' phenotype to 'unaffected'")
                data_copy['samples'][0]['phenotype'] = 'unaffected'
        # set the mother/father to '0' if they are not set for a sample
        for sample_data in data_copy['samples']:
            sample_data['mother'] = sample_data.get('mother') or '0'
            sample_data['father'] = sample_data.get('father') or '0'
            if sample_data['analysis_type'] == 'wgs' and sample_data.get('capture_kit') is None:
                sample_data['capture_kit'] = DEFAULT_CAPTURE_KIT
        return data_copy


Instruction:
Can you generate the documentation for the following Python 3 function
def save_config(self, data: dict) -> Path:
        out_dir = Path(self.families_dir) / data['family']
        out_dir.mkdir(parents=True, exist_ok=True)
        out_path = out_dir / 'pedigree.yaml'
        dump = ruamel.yaml.round_trip_dump(data, indent=4, block_seq_indent=2)
        out_path.write_text(dump)
        return out_path

Response: Save a config to the expected location.


Instruction:
Can you generate the documentation for the following Python 3 function
def _broadcast(src_processor, src_atr_name, dest_processors, dest_atr_name, transform_function):
    value = getattr(src_processor, src_atr_name)
    value = transform_function(value)
    for d in dest_processors:
        setattr(d, dest_atr_name, value)

Response: This function is used exclusively by create_broadcast.


Instruction:
Write a Python 3 script to
create a function intended to be called as a Processor posthook that copies some of the processor s attributes to other processors

Response:
def create_broadcast(src_atr_name, dest_processors, dest_atr_name=None, transform_function=lambda x: x):
    """
    This method creates a function, intended to be called as a
    Processor posthook, that copies some of the processor's attributes
    to other processors
    """
    from functools import partial
    if dest_atr_name == None:
        dest_atr_name = src_atr_name
    if not hasattr(dest_processors, "__iter__"):  # a single processor was given instead
        dest_processors = [dest_processors]
    return partial(_broadcast, src_atr_name=src_atr_name, dest_processors=dest_processors, dest_atr_name=dest_atr_name,
                   transform_function=transform_function)


Instruction:
Make a summary of the following Python 3 code
def get_parameters(self):
        parameter_names = self.PARAMETERS.keys()
        # TODO: Unresolved reference for processor
        parameter_values = [getattr(processor, n) for n in parameter_names]
        return dict(zip(parameter_names, parameter_values))

Response: returns a dictionary with the processor s stored parameters


Instruction:
Can you tell what is the following Python 3 function doing
def set_parameters(self, **args):
        for k, v in self.PARAMETERS.items():
            new_value = args.get(k)
            if new_value != None:
                if not _same_type(new_value, v):
                    raise Exception(
                        "On processor {0}, argument {1} takes something like {2}, but {3} was given".format(self, k, v,
                                                                                new_value))
                setattr(self, k, new_value)
        not_used = set(args.keys()).difference(set(self.PARAMETERS.keys()))
        not_given = set(self.PARAMETERS.keys()).difference(set(args.keys()))
        return not_used, not_given

Response: sets the processor stored parameters


Instruction:
How would you explain what the following Python 3 function does
def get_parameters(self):
        d = {}
        for p in self.processors:
            parameter_names = list(p.PARAMETERS.keys())
            parameter_values = [getattr(p, n) for n in parameter_names]
            d.update(dict(zip(parameter_names, parameter_values)))
        return d

Response: gets from all wrapped processors


Instruction:
Write a Python 3 script for
setting to all wrapped processors

Response:
def set_parameters(self, **args):
        """sets to all wrapped processors"""
        not_used = set()
        not_given = set()
        for p in self.processors:
            nu, ng = p.set_parameters(**args)
            not_used = not_used.union(nu)
            not_given = not_given.union(ng)
        return not_used, not_given


Instruction:
Explain what the following Python 3 code does
def render(self, filename):
        self.elapsed_time = -time()
        dpi = 100
        fig = figure(figsize=(16, 9), dpi=dpi)
        with self.writer.saving(fig, filename, dpi):
            for frame_id in xrange(self.frames + 1):
                self.renderFrame(frame_id)
                self.writer.grab_frame()
        self.elapsed_time += time()

Response: Render the content of the current page.


Instruction:
Write a Python 3 script to
print in standard output report about animation rendering.

Response:
def report(self):
        """Prints in standard output report about animation rendering. Namely, it prints seconds spent, number of
        frames and step size that is used in functional animation.
        """
        message = 'Elapsed in {0} seconds with {1} frames and {2} step.'
        print(message.format(self.elapsed_time, self.frames, self.step))


Instruction:
Implement a function in Python 3 to
add a new address to the subscribing list for topics.

Response:
def add(self, address, topics=None):
        """Add *address* to the subscribing list for *topics*.

        It topics is None we will subscibe to already specified topics.
        """
        with self._lock:
            if address in self.addresses:
                return False

            topics = self._magickfy_topics(topics) or self._topics
            LOGGER.info("Subscriber adding address %s with topics %s",
                        str(address), str(topics))
            subscriber = get_context().socket(SUB)
            for t__ in topics:
                subscriber.setsockopt_string(SUBSCRIBE, six.text_type(t__))
            subscriber.connect(address)
            self.sub_addr[subscriber] = address
            self.addr_sub[address] = subscriber
            if self.poller:
                self.poller.register(subscriber, POLLIN)
            return True


Instruction:
Make a summary of the following Python 3 code
def remove(self, address):
        with self._lock:
            try:
                subscriber = self.addr_sub[address]
            except KeyError:
                return False
            LOGGER.info("Subscriber removing address %s", str(address))
            if self.poller:
                self.poller.unregister(subscriber)
            del self.addr_sub[address]
            del self.sub_addr[subscriber]
            subscriber.close()
            return True

Response: Remove a topic from the subscribing list for topics*.


Instruction:
Implement a Python 3 function for
updating with a set of addresses.

Response:
def update(self, addresses):
        """Updating with a set of addresses.
        """
        if isinstance(addresses, six.string_types):
            addresses = [addresses, ]
        s0_, s1_ = set(self.addresses), set(addresses)
        sr_, sa_ = s0_.difference(s1_), s1_.difference(s0_)
        for a__ in sr_:
            self.remove(a__)
        for a__ in sa_:
            self.add(a__)
        return bool(sr_ or sa_)


Instruction:
Can you tell what is the following Python 3 function doing
def add_hook_sub(self, address, topics, callback):
        LOGGER.info("Subscriber adding SUB hook %s for topics %s",
                    str(address), str(topics))
        socket = get_context().socket(SUB)
        for t__ in self._magickfy_topics(topics):
            socket.setsockopt_string(SUBSCRIBE, six.text_type(t__))
        socket.connect(address)
        self._add_hook(socket, callback)

Response: Add a SUB socket to receive the specified topics.


Instruction:
Make a summary of the following Python 3 code
def add_hook_pull(self, address, callback):
        LOGGER.info("Subscriber adding PULL hook %s", str(address))
        socket = get_context().socket(PULL)
        socket.connect(address)
        self._add_hook(socket, callback)

Response: Add a PULL socket to be used to pull the current version of the current process.


Instruction:
Given the following Python 3 function, write the documentation
def _add_hook(self, socket, callback):
        self._hooks.append(socket)
        self._hooks_cb[socket] = callback
        if self.poller:
            self.poller.register(socket, POLLIN)

Response: Generic hook. The passed socket has to be "receive only".


Instruction:
Can you generate the documentation for the following Python 3 function
def recv(self, timeout=None):
        if timeout:
            timeout *= 1000.

        for sub in list(self.subscribers) + self._hooks:
            self.poller.register(sub, POLLIN)
        self._loop = True
        try:
            while self._loop:
                sleep(0)
                try:
                    socks = dict(self.poller.poll(timeout=timeout))
                    if socks:
                        for sub in self.subscribers:
                            if sub in socks and socks[sub] == POLLIN:
                                m__ = Message.decode(sub.recv_string(NOBLOCK))
                                if not self._filter or self._filter(m__):
                                    if self._translate:
                                        url = urlsplit(self.sub_addr[sub])
                                        host = url[1].split(":")[0]
                                        m__.sender = (m__.sender.split("@")[0]
                                                      + "@" + host)
                                    yield m__

                        for sub in self._hooks:
                            if sub in socks and socks[sub] == POLLIN:
                                m__ = Message.decode(sub.recv_string(NOBLOCK))
                                self._hooks_cb[sub](m__)
                    else:
                        # timeout
                        yield None
                except ZMQError as err:
                    LOGGER.exception("Receive failed: %s", str(err))
        finally:
            for sub in list(self.subscribers) + self._hooks:
                self.poller.unregister(sub)

Response: Receive a message from all the subscribers.


Instruction:
Can you create a Python 3 function that
closes the subscriber and close the local subscribers.

Response:
def close(self):
        """Close the subscriber: stop it and close the local subscribers.
        """
        self.stop()
        for sub in list(self.subscribers) + self._hooks:
            try:
                sub.setsockopt(LINGER, 1)
                sub.close()
            except ZMQError:
                pass


Instruction:
Write a Python 3 script for
adding the magick to the topics if missing.

Response:
def _magickfy_topics(topics):
        """Add the magick to the topics if missing.
        """
        # If topic does not start with messages._MAGICK (pytroll:/), it will be
        # prepended.
        if topics is None:
            return None
        if isinstance(topics, six.string_types):
            topics = [topics, ]
        ts_ = []
        for t__ in topics:
            if not t__.startswith(_MAGICK):
                if t__ and t__[0] == '/':
                    t__ = _MAGICK + t__
                else:
                    t__ = _MAGICK + '/' + t__
            ts_.append(t__)
        return ts_


Instruction:
Explain what the following Python 3 code does
def handle_msg(self, msg):
        addr_ = msg.data["URI"]
        status = msg.data.get('status', True)
        if status:
            service = msg.data.get('service')
            for service in self.services:
                if not service or service in service:
                    LOGGER.debug("Adding address %s %s", str(addr_),
                                 str(service))
                    self.subscriber.add(addr_)
                    break
        else:
            LOGGER.debug("Removing address %s", str(addr_))
            self.subscriber.remove(addr_)

Response: handle the message *msg*.


Instruction:
Write a Python 3 script to
classify the transients in the database

Response:
def classify(self):
        """
        *classify the transients selected from the transient selection query in the settings file or passed in via the CL or other code*

        **Return:**
            - ``crossmatches`` -- list of dictionaries of crossmatched associated sources
            - ``classifications`` -- the classifications assigned to the transients post-crossmatches (dictionary of rank ordered list of classifications)

        See class docstring for usage.

        .. todo ::

            - update key arguments values and definitions with defaults
            - update return values and definitions
            - update usage examples and text
            - update docstring text
            - check sublime snippet exists
            - clip any useful text to docs mindmap
            - regenerate the docs and check redendering of this docstring
        """

        global theseBatches
        global crossmatchArray

        self.log.debug('starting the ``classify`` method')

        remaining = 1

        # THE COLUMN MAPS - WHICH COLUMNS IN THE CATALOGUE TABLES = RA, DEC,
        # REDSHIFT, MAG ETC
        colMaps = get_crossmatch_catalogues_column_map(
            log=self.log,
            dbConn=self.cataloguesDbConn
        )

        self._create_tables_if_not_exist()

        import time
        start_time = time.time()

        # COUNT SEARCHES
        sa = self.settings["search algorithm"]
        searchCount = 0
        brightnessFilters = ["bright", "faint", "general"]
        for search_name, searchPara in sa.iteritems():
            for bf in brightnessFilters:
                if bf in searchPara:
                    searchCount += 1

        cpuCount = psutil.cpu_count()
        if searchCount > cpuCount:
            searchCount = cpuCount

        largeBatchSize = 5000
        miniBatchSize = 100
        self.largeBatchSize = largeBatchSize

        # print "mini batch size ", str(miniBatchSize)

        while remaining:

            # IF A TRANSIENT HAS NOT BEEN PASSED IN VIA THE COMMAND-LINE, THEN
            # QUERY THE TRANSIENT DATABASE
            if not self.ra and not self.dec:

                # COUNT REMAINING TRANSIENTS
                from fundamentals.mysql import readquery
                sqlQuery = self.settings["database settings"][
                    "transients"]["transient count"]
                thisInt = randint(0, 100)
                if "where" in sqlQuery:
                    sqlQuery = sqlQuery.replace(
                        "where", "where %(thisInt)s=%(thisInt)s and " % locals())

                if remaining == 1 or remaining < largeBatchSize:
                    rows = readquery(
                        log=self.log,
                        sqlQuery=sqlQuery,
                        dbConn=self.transientsDbConn,
                    )
                    remaining = rows[0]["count(*)"]
                else:
                    remaining = remaining - largeBatchSize

                print "%(remaining)s transient sources requiring a classification remain" % locals()

                # START THE TIME TO TRACK CLASSIFICATION SPPED
                start_time = time.time()

                # A LIST OF DICTIONARIES OF TRANSIENT METADATA
                transientsMetadataList = self._get_transient_metadata_from_database_list()

                count = len(transientsMetadataList)
                print "  now classifying the next %(count)s transient sources" % locals()

                # EXAMPLE OF TRANSIENT METADATA
                # { 'name': 'PS17gx',
                # 'alt_id': 'PS17gx',
                # 'object_classification': 'SN',
                # 'dec': '+43:25:44.1',
                # 'id': 1,
                # 'ra': '08:57:57.19'}
            # TRANSIENT PASSED VIA COMMAND-LINE
            else:
                if not self.name:
                    name = "transient"
                else:
                    name = self.name
                transient = {
                    'name': name,
                    'object_classification': None,
                    'dec': self.dec,
                    'id': name,
                    'ra': self.ra
                }
                transientsMetadataList = [transient]
                remaining = 0

            if self.oneRun:
                remaining = 0

            if len(transientsMetadataList) == 0:
                if self.daemonMode == False:
                    remaining = 0
                    print "No transients need classified"
                    return None, None
                else:
                    print "No remaining transients need classified, will try again in 5 mins"
                    time.sleep("10")

            # FROM THE LOCATIONS OF THE TRANSIENTS, CHECK IF OUR LOCAL NED DATABASE
            # NEEDS UPDATED
            if self.updateNed:

                self._update_ned_stream(
                    transientsMetadataList=transientsMetadataList
                )

            # SOME TESTING SHOWED THAT 25 IS GOOD
            total = len(transientsMetadataList)
            batches = int((float(total) / float(miniBatchSize)) + 1.)

            if batches == 0:
                batches = 1

            start = 0
            end = 0
            theseBatches = []
            for i in range(batches):
                end = end + miniBatchSize
                start = i * miniBatchSize
                thisBatch = transientsMetadataList[start:end]
                theseBatches.append(thisBatch)

            print "BATCH SIZE = %(total)s" % locals()
            print "MINI BATCH SIZE = %(batches)s x %(miniBatchSize)s" % locals()

            # DEFINE AN INPUT ARRAY
            # cores = psutil.cpu_count()
            # if cores > 8:
            #     cores = 8

            start_time2 = time.time()

            print "START CROSSMATCH"

            crossmatchArray = fmultiprocess(log=self.log, function=self._crossmatch_transients_against_catalogues,
                                            inputArray=range(len(theseBatches)), poolSize=None, colMaps=colMaps)

            print "FINISH CROSSMATCH/START RANKING: %d" % (time.time() - start_time2,)
            start_time2 = time.time()

            classifications = {}
            crossmatches = []

            for sublist in crossmatchArray:
                sublist = sorted(
                    sublist, key=itemgetter('transient_object_id'))

                # REORGANISE INTO INDIVIDUAL TRANSIENTS FOR RANKING AND
                # TOP-LEVEL CLASSIFICATION EXTRACTION

                batch = []
                if len(sublist) != 0:
                    transientId = sublist[0]['transient_object_id']
                    for s in sublist:
                        if s['transient_object_id'] != transientId:
                            # RANK TRANSIENT CROSSMATCH BATCH
                            cl, cr = self._rank_classifications(
                                batch, colMaps)
                            crossmatches.extend(cr)
                            classifications = dict(
                                classifications.items() + cl.items())

                            transientId = s['transient_object_id']
                            batch = [s]
                        else:
                            batch.append(s)

                    # RANK FINAL BATCH
                    cl, cr = self._rank_classifications(
                        batch, colMaps)
                    classifications = dict(
                        classifications.items() + cl.items())
                    crossmatches.extend(cr)

            for t in transientsMetadataList:
                if t["id"] not in classifications:
                    classifications[t["id"]] = ["ORPHAN"]

            if self.cl:
                self._print_results_to_stdout(
                    classifications=classifications,
                    crossmatches=crossmatches
                )

            # UPDATE THE TRANSIENT DATABASE IF UPDATE REQUESTED (ADD DATA TO
            # tcs_crossmatch_table AND A CLASSIFICATION TO THE ORIGINAL TRANSIENT
            # TABLE)
            print "FINISH RANKING/START UPDATING TRANSIENT DB: %d" % (time.time() - start_time2,)
            start_time2 = time.time()
            if self.update and not self.ra:
                self._update_transient_database(
                    crossmatches=crossmatches,
                    classifications=classifications,
                    transientsMetadataList=transientsMetadataList,
                    colMaps=colMaps
                )

            print "FINISH UPDATING TRANSIENT DB/START ANNOTATING TRANSIENT DB: %d" % (time.time() - start_time2,)
            start_time2 = time.time()

            if self.ra:
                return classifications, crossmatches

            if self.updatePeakMags and self.settings["database settings"]["transients"]["transient peak magnitude query"]:
                self.update_peak_magnitudes()
            self.update_classification_annotations_and_summaries(
                self.updatePeakMags)

            print "FINISH ANNOTATING TRANSIENT DB: %d" % (time.time() - start_time2,)
            start_time2 = time.time()

            classificationRate = count / (time.time() - start_time)
            print "Sherlock is classify at a rate of %(classificationRate)2.1f transients/sec" % locals()

        self.log.debug('completed the ``classify`` method')
        return None, None


Instruction:
Given the following Python 3 function, write the documentation
def _get_transient_metadata_from_database_list(
            self):
        """use the transient query in the settings file to generate a list of transients to corssmatch and classify

         **Return:**
            - ``transientsMetadataList``

        .. todo ::

            - update key arguments values and definitions with defaults
            - update return values and definitions
            - update usage examples and text
            - update docstring text
            - check sublime snippet exists
            - clip any useful text to docs mindmap
            - regenerate the docs and check redendering of this docstring
        """
        self.log.debug(
            'starting the ``_get_transient_metadata_from_database_list`` method')

        sqlQuery = self.settings["database settings"][
            "transients"]["transient query"] + " limit " + str(self.largeBatchSize)

        thisInt = randint(0, 100)
        if "where" in sqlQuery:
            sqlQuery = sqlQuery.replace(
                "where", "where %(thisInt)s=%(thisInt)s and " % locals())

        transientsMetadataList = readquery(
            log=self.log,
            sqlQuery=sqlQuery,
            dbConn=self.transientsDbConn,
            quiet=False
        )

        self.log.debug(
            'completed the ``_get_transient_metadata_from_database_list`` method')
        return transientsMetadataList

Response: use the transient query to generate a list of transients to corssmatch and classify


Instruction:
Implement a Python 3 function for
updating the NED stream for the given transient metadata

Response:
def _update_ned_stream(
        self,
        transientsMetadataList
    ):
        """ update the NED stream within the catalogues database at the locations of the transients

        **Key Arguments:**
            - ``transientsMetadataList`` -- the list of transient metadata lifted from the database.

        .. todo ::

            - update key arguments values and definitions with defaults
            - update return values and definitions
            - update usage examples and text
            - update docstring text
            - check sublime snippet exists
            - clip any useful text to docs mindmap
            - regenerate the docs and check redendering of this docstring
        """
        self.log.debug('starting the ``_update_ned_stream`` method')

        coordinateList = []
        for i in transientsMetadataList:
            # thisList = str(i["ra"]) + " " + str(i["dec"])
            thisList = (i["ra"], i["dec"])
            coordinateList.append(thisList)

        coordinateList = self._remove_previous_ned_queries(
            coordinateList=coordinateList
        )

        # MINIMISE COORDINATES IN LIST TO REDUCE NUMBER OF REQUIRE NED QUERIES
        coordinateList = self._consolidate_coordinateList(
            coordinateList=coordinateList
        )

        stream = ned(
            log=self.log,
            settings=self.settings,
            coordinateList=coordinateList,
            radiusArcsec=self.settings["ned stream search radius arcec"]
        )
        stream.ingest()

        sqlQuery = """SET session sql_mode = "";""" % locals(
        )
        writequery(
            log=self.log,
            sqlQuery=sqlQuery,
            dbConn=self.cataloguesDbConn
        )

        sqlQuery = """update tcs_cat_ned_stream set magnitude = CAST(`magnitude_filter` AS DECIMAL(5,2)) where magnitude is null;""" % locals(
        )
        writequery(
            log=self.log,
            sqlQuery=sqlQuery,
            dbConn=self.cataloguesDbConn
        )

        self.log.debug('completed the ``_update_ned_stream`` method')
        return None


Instruction:
Make a summary of the following Python 3 code
def _remove_previous_ned_queries(
            self,
            coordinateList):
        """iterate through the transient locations to see if we have recent local NED coverage of that area already

        **Key Arguments:**
            - ``coordinateList`` -- set of coordinate to check for previous queries

        **Return:**
            - ``updatedCoordinateList`` -- coordinate list with previous queries removed

        .. todo ::

            - update key arguments values and definitions with defaults
            - update return values and definitions
            - update usage examples and text
            - update docstring text
            - check sublime snippet exists
            - clip any useful text to docs mindmap
            - regenerate the docs and check redendering of this docstring
        """
        self.log.debug('starting the ``_remove_previous_ned_queries`` method')

        # 1 DEGREE QUERY RADIUS
        radius = 60. * 60.
        updatedCoordinateList = []
        keepers = []

        # CALCULATE THE OLDEST RESULTS LIMIT
        now = datetime.now()
        td = timedelta(
            days=self.settings["ned stream refresh rate in days"])
        refreshLimit = now - td
        refreshLimit = refreshLimit.strftime("%Y-%m-%d %H:%M:%S")

        raList = []
        raList[:] = [c[0] for c in coordinateList]
        decList = []
        decList[:] = [c[1] for c in coordinateList]

        # MATCH COORDINATES AGAINST PREVIOUS NED SEARCHES
        cs = conesearch(
            log=self.log,
            dbConn=self.cataloguesDbConn,
            tableName="tcs_helper_ned_query_history",
            columns="*",
            ra=raList,
            dec=decList,
            radiusArcsec=radius,
            separations=True,
            distinct=True,
            sqlWhere="dateQueried > '%(refreshLimit)s'" % locals(),
            closest=False
        )
        matchIndies, matches = cs.search()

        # DETERMINE WHICH COORDINATES REQUIRE A NED QUERY
        curatedMatchIndices = []
        curatedMatches = []
        for i, m in zip(matchIndies, matches.list):
            match = False
            row = m
            row["separationArcsec"] = row["cmSepArcsec"]
            raStream = row["raDeg"]
            decStream = row["decDeg"]
            radiusStream = row["arcsecRadius"]
            dateStream = row["dateQueried"]
            angularSeparation = row["separationArcsec"]

            if angularSeparation + self.settings["first pass ned search radius arcec"] < radiusStream:
                curatedMatchIndices.append(i)
                curatedMatches.append(m)

        # NON MATCHES
        for i, v in enumerate(coordinateList):
            if i not in curatedMatchIndices:
                updatedCoordinateList.append(v)

        self.log.debug('completed the ``_remove_previous_ned_queries`` method')
        return updatedCoordinateList

Response: remove previous NED queries for the given transient locations


Instruction:
Create a Python 3 function to
run the transients through the crossmatch algorithm in the settings file and return the list of dictionaries of the associated sources that are crossmatched from the database

Response:
def _crossmatch_transients_against_catalogues(
            self,
            transientsMetadataListIndex,
            colMaps):
        """run the transients through the crossmatch algorithm in the settings file

         **Key Arguments:**
            - ``transientsMetadataListIndex`` -- the list of transient metadata lifted from the database.
            - ``colMaps`` -- dictionary of dictionaries with the name of the database-view (e.g. `tcs_view_agn_milliquas_v4_5`) as the key and the column-name dictary map as value (`{view_name: {columnMap}}`).

        **Return:**
            - ``crossmatches`` -- a list of dictionaries of the associated sources crossmatched from the catalogues database

        .. todo ::

            - update key arguments values and definitions with defaults
            - update return values and definitions
            - update usage examples and text
            - update docstring text
            - check sublime snippet exists
            - clip any useful text to docs mindmap
            - regenerate the docs and check redendering of this docstring
        """

        global theseBatches

        self.log.debug(
            'starting the ``_crossmatch_transients_against_catalogues`` method')

        # SETUP ALL DATABASE CONNECTIONS

        transientsMetadataList = theseBatches[transientsMetadataListIndex]

        dbConn = database(
            log=self.log,
            dbSettings=self.settings["database settings"]["static catalogues"]
        ).connect()

        self.allClassifications = []

        cm = transient_catalogue_crossmatch(
            log=self.log,
            dbConn=dbConn,
            transients=transientsMetadataList,
            settings=self.settings,
            colMaps=colMaps
        )
        crossmatches = cm.match()

        self.log.debug(
            'completed the ``_crossmatch_transients_against_catalogues`` method')

        return crossmatches


Instruction:
Here you have a function in Python 3, explain what it does
def _update_transient_database(
            self,
            crossmatches,
            classifications,
            transientsMetadataList,
            colMaps):
        """ update transient database with classifications and crossmatch results

        **Key Arguments:**
            - ``crossmatches`` -- the crossmatches and associations resulting from the catlaogue crossmatches
            - ``classifications`` -- the classifications assigned to the transients post-crossmatches (dictionary of rank ordered list of classifications)
            - ``transientsMetadataList`` -- the list of transient metadata lifted from the database.
            - ``colMaps`` -- maps of the important column names for each table/view in the crossmatch-catalogues database

        .. todo ::

            - update key arguments values and definitions with defaults
            - update return values and definitions
            - update usage examples and text
            - update docstring text
            - check sublime snippet exists
            - clip any useful text to docs mindmap
            - regenerate the docs and check redendering of this docstring
        """

        self.log.debug('starting the ``_update_transient_database`` method')

        import time
        start_time = time.time()
        print "UPDATING TRANSIENTS DATABASE WITH RESULTS"
        print "DELETING OLD RESULTS"

        now = datetime.now()
        now = now.strftime("%Y-%m-%d_%H-%M-%S-%f")

        transientTable = self.settings["database settings"][
            "transients"]["transient table"]
        transientTableClassCol = self.settings["database settings"][
            "transients"]["transient classification column"]
        transientTableIdCol = self.settings["database settings"][
            "transients"]["transient primary id column"]

        # COMBINE ALL CROSSMATCHES INTO A LIST OF DICTIONARIES TO DUMP INTO
        # DATABASE TABLE
        transientIDs = [str(c)
                        for c in classifications.keys()]
        transientIDs = ",".join(transientIDs)

        # REMOVE PREVIOUS MATCHES
        sqlQuery = """delete from sherlock_crossmatches where transient_object_id in (%(transientIDs)s);""" % locals(
        )
        writequery(
            log=self.log,
            sqlQuery=sqlQuery,
            dbConn=self.transientsDbConn,
        )
        sqlQuery = """delete from sherlock_classifications where transient_object_id in (%(transientIDs)s);""" % locals(
        )
        writequery(
            log=self.log,
            sqlQuery=sqlQuery,
            dbConn=self.transientsDbConn,
        )

        print "FINISHED DELETING OLD RESULTS/ADDING TO CROSSMATCHES: %d" % (time.time() - start_time,)
        start_time = time.time()

        if len(crossmatches):
            insert_list_of_dictionaries_into_database_tables(
                dbConn=self.transientsDbConn,
                log=self.log,
                dictList=crossmatches,
                dbTableName="sherlock_crossmatches",
                dateModified=True,
                batchSize=10000,
                replace=True,
                dbSettings=self.settings["database settings"][
                    "transients"]
            )

        print "FINISHED ADDING TO CROSSMATCHES/UPDATING CLASSIFICATIONS IN TRANSIENT TABLE: %d" % (time.time() - start_time,)
        start_time = time.time()

        sqlQuery = ""
        inserts = []
        for k, v in classifications.iteritems():
            thisInsert = {
                "transient_object_id": k,
                "classification": v[0]
            }
            inserts.append(thisInsert)

        print "FINISHED UPDATING CLASSIFICATIONS IN TRANSIENT TABLE/UPDATING sherlock_classifications TABLE: %d" % (time.time() - start_time,)
        start_time = time.time()

        insert_list_of_dictionaries_into_database_tables(
            dbConn=self.transientsDbConn,
            log=self.log,
            dictList=inserts,
            dbTableName="sherlock_classifications",
            dateModified=True,
            batchSize=10000,
            replace=True,
            dbSettings=self.settings["database settings"][
                "transients"]
        )

        print "FINISHED UPDATING sherlock_classifications TABLE: %d" % (time.time() - start_time,)
        start_time = time.time()

        self.log.debug('completed the ``_update_transient_database`` method')
        return None

Response: update the transient database with the given crossmatches classifications transientsMetadataList and colMaps


Instruction:
Given the following Python 3 function, write the documentation
def _rank_classifications(
            self,
            crossmatchArray,
            colMaps):
        """*rank the classifications returned from the catalogue crossmatcher, annotate the results with a classification rank-number (most likely = 1) and a rank-score (weight of classification)*

        **Key Arguments:**
            - ``crossmatchArrayIndex`` -- the index of list of unranked crossmatch classifications
            - ``colMaps`` -- dictionary of dictionaries with the name of the database-view (e.g. `tcs_view_agn_milliquas_v4_5`) as the key and the column-name dictary map as value (`{view_name: {columnMap}}`).

        **Return:**
            - ``classifications`` -- the classifications assigned to the transients post-crossmatches
            - ``crossmatches`` -- the crossmatches annotated with rankings and rank-scores

        .. todo ::

            - update key arguments values and definitions with defaults
            - update return values and definitions
            - update usage examples and text
            - update docstring text
            - check sublime snippet exists
            - clip any useful text to docs mindmap
            - regenerate the docs and check redendering of this docstring
        """
        self.log.debug('starting the ``_rank_classifications`` method')

        crossmatches = crossmatchArray

        # GROUP CROSSMATCHES INTO DISTINCT SOURCES (DUPLICATE ENTRIES OF THE
        # SAME ASTROPHYSICAL SOURCE ACROSS MULTIPLE CATALOGUES)
        ra, dec = zip(*[(r["raDeg"], r["decDeg"]) for r in crossmatches])

        from HMpTy.htm import sets
        xmatcher = sets(
            log=self.log,
            ra=ra,
            dec=dec,
            radius=3 / (60. * 60.),  # in degrees
            sourceList=crossmatches
        )
        groupedMatches = xmatcher.match

        associatationTypeOrder = ["AGN", "CV", "NT", "SN", "VS", "BS"]

        # ADD DISTINCT-SOURCE KEY
        dupKey = 0
        distinctMatches = []
        for x in groupedMatches:
            dupKey += 1
            mergedMatch = copy.deepcopy(x[0])
            mergedMatch["merged_rank"] = int(dupKey)

            # ADD OTHER ESSENTIAL KEYS
            for e in ['z', 'photoZ', 'photoZErr']:
                if e not in mergedMatch:
                    mergedMatch[e] = None

            bestDirectDistance = {
                "direct_distance": mergedMatch["direct_distance"],
                "direct_distance_modulus": mergedMatch["direct_distance_modulus"],
                "direct_distance_scale": mergedMatch["direct_distance"],
                "qual": colMaps[mergedMatch["catalogue_view_name"]]["object_type_accuracy"]
            }
            bestSpecz = {
                "z": mergedMatch["z"],
                "distance": mergedMatch["distance"],
                "distance_modulus": mergedMatch["distance_modulus"],
                "scale": mergedMatch["scale"],
                "qual": colMaps[mergedMatch["catalogue_view_name"]]["object_type_accuracy"]
            }
            bestPhotoz = {
                "photoZ": mergedMatch["photoZ"],
                "photoZErr": mergedMatch["photoZErr"],
                "distance": mergedMatch["distance"],
                "distance_modulus": mergedMatch["distance_modulus"],
                "scale": mergedMatch["scale"],
                "qual": colMaps[mergedMatch["catalogue_view_name"]]["object_type_accuracy"]
            }

            for i, m in enumerate(x):
                m["merged_rank"] = int(dupKey)
                if i > 0:
                    # MERGE ALL BEST MAGNITUDE MEASUREMENTS
                    for f in self.filterPreference:
                        if f in m and m[f] and (f not in mergedMatch or (f + "Err" in mergedMatch and (f + "Err" not in m or (mergedMatch[f + "Err"] > m[f + "Err"])))):
                            mergedMatch[f] = m[f]
                            try:
                                mergedMatch[f + "Err"] = m[f + "Err"]
                            except:
                                pass
                    mergedMatch["original_search_radius_arcsec"] = "multiple"
                    mergedMatch["catalogue_object_subtype"] = "multiple"
                    mergedMatch["catalogue_view_name"] = "multiple"

                    # MERGE SEARCH NAMES
                    snippet = m["search_name"].split(" ")[0].upper()

                    if "/" not in mergedMatch["search_name"] and snippet not in mergedMatch["search_name"].upper():
                        mergedMatch["search_name"] = mergedMatch["search_name"].split(
                            " ")[0].upper() + "/" + m["search_name"].split(" ")[0].upper()
                    elif snippet not in mergedMatch["search_name"].upper():
                        mergedMatch[
                            "search_name"] += "/" + m["search_name"].split(" ")[0].upper()
                    elif "/" not in mergedMatch["search_name"]:
                        mergedMatch["search_name"] = mergedMatch["search_name"].split(
                            " ")[0].upper()

                    mergedMatch["catalogue_table_name"] = mergedMatch[
                        "search_name"]

                    # MERGE CATALOGUE SOURCE NAMES
                    mergedMatch["catalogue_object_id"] = str(
                        mergedMatch["catalogue_object_id"])
                    m["catalogue_object_id"] = str(m["catalogue_object_id"])
                    if m["catalogue_object_id"].replace(" ", "").lower() not in mergedMatch["catalogue_object_id"].replace(" ", "").lower():
                        mergedMatch["catalogue_object_id"] += "/" + \
                            m["catalogue_object_id"]

                    # DETERMINE BEST CLASSIFICATION
                    if mergedMatch["classificationReliability"] == 3 and m["classificationReliability"] < 3:
                        mergedMatch["association_type"] = m["association_type"]
                        mergedMatch["classificationReliability"] = m[
                            "classificationReliability"]

                    if m["classificationReliability"] != 3 and m["association_type"] in associatationTypeOrder and (mergedMatch["association_type"] not in associatationTypeOrder or associatationTypeOrder.index(m["association_type"]) < associatationTypeOrder.index(mergedMatch["association_type"])):
                        mergedMatch["association_type"] = m["association_type"]
                        mergedMatch["classificationReliability"] = m[
                            "classificationReliability"]

                    # FIND BEST DISTANCES
                    if "direct_distance" in m and m["direct_distance"] and colMaps[m["catalogue_view_name"]]["object_type_accuracy"] > bestDirectDistance["qual"]:
                        bestDirectDistance = {
                            "direct_distance": m["direct_distance"],
                            "direct_distance_modulus": m["direct_distance_modulus"],
                            "direct_distance_scale": m["direct_distance_scale"],
                            "catalogue_object_type": m["catalogue_object_type"],
                            "qual": colMaps[m["catalogue_view_name"]]["object_type_accuracy"]
                        }
                    # FIND BEST SPEC-Z
                    if "z" in m and m["z"] and colMaps[m["catalogue_view_name"]]["object_type_accuracy"] > bestSpecz["qual"]:
                        bestSpecz = {
                            "z": m["z"],
                            "distance": m["distance"],
                            "distance_modulus": m["distance_modulus"],
                            "scale": m["scale"],
                            "catalogue_object_type": m["catalogue_object_type"],
                            "qual": colMaps[m["catalogue_view_name"]]["object_type_accuracy"]
                        }
                    # FIND BEST PHOT-Z
                    if "photoZ" in m and m["photoZ"] and colMaps[m["catalogue_view_name"]]["object_type_accuracy"] > bestPhotoz["qual"]:
                        bestPhotoz = {
                            "photoZ": m["photoZ"],
                            "photoZErr": m["photoZErr"],
                            "distance": m["distance"],
                            "distance_modulus": m["distance_modulus"],
                            "scale": m["scale"],
                            "catalogue_object_type": m["catalogue_object_type"],
                            "qual": colMaps[m["catalogue_view_name"]]["object_type_accuracy"]
                        }
                    # CLOSEST ANGULAR SEP & COORDINATES
                    if m["separationArcsec"] < mergedMatch["separationArcsec"]:
                        mergedMatch["separationArcsec"] = m["separationArcsec"]
                        mergedMatch["raDeg"] = m["raDeg"]
                        mergedMatch["decDeg"] = m["decDeg"]

            # MERGE THE BEST RESULTS
            for l in [bestPhotoz, bestSpecz, bestDirectDistance]:
                for k, v in l.iteritems():
                    if k != "qual":
                        mergedMatch[k] = v

            mergedMatch["catalogue_object_id"] = str(mergedMatch[
                "catalogue_object_id"]).replace(" ", "")

            # RECALULATE PHYSICAL DISTANCE SEPARATION
            if mergedMatch["direct_distance_scale"]:
                mergedMatch["physical_separation_kpc"] = mergedMatch[
                    "direct_distance_scale"] * mergedMatch["separationArcsec"]
            elif mergedMatch["scale"]:
                mergedMatch["physical_separation_kpc"] = mergedMatch[
                    "scale"] * mergedMatch["separationArcsec"]

            if "/" in mergedMatch["search_name"]:
                mergedMatch["search_name"] = "multiple"

            distinctMatches.append(mergedMatch)

        crossmatches = []
        for xm, gm in zip(distinctMatches, groupedMatches):

            # SPEC-Z GALAXIES
            if (xm["physical_separation_kpc"] is not None and xm["physical_separation_kpc"] != "null" and xm["physical_separation_kpc"] < 20. and xm["association_type"] == "SN" and (("z" in xm and xm["z"] is not None) or "photoZ" not in xm or xm["photoZ"] is None or xm["photoZ"] < 0.)):
                rankScore = xm["classificationReliability"] * 1000 + 2. - \
                    xm["physical_separation_kpc"] / 10
            # PHOTO-Z GALAXIES
            elif (xm["physical_separation_kpc"] is not None and xm["physical_separation_kpc"] != "null" and xm["physical_separation_kpc"] < 20. and xm["association_type"] == "SN"):
                rankScore = xm["classificationReliability"] * 1000 + 2.2 - \
                    xm["physical_separation_kpc"] / 10
            # NOT SPEC-Z, NON PHOTO-Z GALAXIES
            elif (xm["association_type"] == "SN"):
                rankScore = xm["classificationReliability"] * 1000 + 5.
            # VS
            elif (xm["association_type"] == "VS"):
                rankScore = xm["classificationReliability"] * \
                    1000 + xm["separationArcsec"] + 2.
            # BS
            elif (xm["association_type"] == "BS"):
                rankScore = xm["classificationReliability"] * \
                    1000 + xm["separationArcsec"]
            else:
                rankScore = xm["classificationReliability"] * \
                    1000 + xm["separationArcsec"] + 10.
            xm["rankScore"] = rankScore
            crossmatches.append(xm)
            if len(gm) > 1:
                for g in gm:
                    g["rankScore"] = rankScore

        crossmatches = sorted(
            crossmatches, key=itemgetter('rankScore'), reverse=False)
        crossmatches = sorted(
            crossmatches, key=itemgetter('transient_object_id'))

        transient_object_id = None
        uniqueIndexCheck = []
        classifications = {}
        crossmatchesKeep = []
        rank = 0
        transClass = []
        for xm in crossmatches:
            rank += 1
            if rank == 1:
                transClass.append(xm["association_type"])
                classifications[xm["transient_object_id"]] = transClass
            xm["rank"] = rank
            crossmatchesKeep.append(xm)
        crossmatches = crossmatchesKeep

        crossmatchesKeep = []
        for xm in crossmatches:
            group = groupedMatches[xm["merged_rank"] - 1]
            xm["merged_rank"] = None
            crossmatchesKeep.append(xm)

            if len(group) > 1:
                groupKeep = []
                uniqueIndexCheck = []
                for g in group:
                    g["merged_rank"] = xm["rank"]
                    g["rankScore"] = xm["rankScore"]
                    index = "%(catalogue_table_name)s%(catalogue_object_id)s" % g
                    # IF WE HAVE HIT A NEW SOURCE
                    if index not in uniqueIndexCheck:
                        uniqueIndexCheck.append(index)
                        crossmatchesKeep.append(g)

        crossmatches = crossmatchesKeep

        self.log.debug('completed the ``_rank_classifications`` method')

        return classifications, crossmatches

Response: rank the classifications returned from the catalogue crossmatcher


Instruction:
Given the following Python 3 function, write the documentation
def _print_results_to_stdout(
            self,
            classifications,
            crossmatches):
        """*print the classification and crossmatch results for a single transient object to stdout*

        **Key Arguments:**
            - ``crossmatches`` -- the unranked crossmatch classifications
            - ``classifications`` -- the classifications assigned to the transients post-crossmatches (dictionary of rank ordered list of classifications)

        .. todo ::

            - update key arguments values and definitions with defaults
            - update return values and definitions
            - update usage examples and text
            - update docstring text
            - check sublime snippet exists
            - clip any useful text to docs mindmap
            - regenerate the docs and check redendering of this docstring
        """
        self.log.debug('starting the ``_print_results_to_stdout`` method')

        if self.verbose == 0:
            return

        if self.name in classifications:
            headline = self.name + "'s Predicted Classification: " + \
                classifications[self.name][0]
        else:
            headline = self.name + "'s Predicted Classification: ORPHAN"
        print headline
        print
        print "Suggested Associations:"

        # REPORT ONLY THE MOST PREFERED MAGNITUDE VALUE
        basic = ["association_type", "rank", "rankScore", "catalogue_table_name", "catalogue_object_id", "catalogue_object_type", "catalogue_object_subtype",
                 "raDeg", "decDeg", "separationArcsec", "physical_separation_kpc", "direct_distance", "distance", "z", "photoZ", "photoZErr", "Mag", "MagFilter", "MagErr", "classificationReliability", "merged_rank"]
        verbose = ["search_name", "catalogue_view_name", "original_search_radius_arcsec", "direct_distance_modulus", "distance_modulus", "direct_distance_scale", "major_axis_arcsec", "scale", "U", "UErr",
                   "B", "BErr", "V", "VErr", "R", "RErr", "I", "IErr", "J", "JErr", "H", "HErr", "K", "KErr", "_u", "_uErr", "_g", "_gErr", "_r", "_rErr", "_i", "_iErr", "_z", "_zErr", "_y", "G", "GErr", "_yErr", "unkMag"]
        dontFormat = ["decDeg", "raDeg", "rank",
                      "catalogue_object_id", "catalogue_object_subtype", "merged_rank"]

        if self.verbose == 2:
            basic = basic + verbose

        for c in crossmatches:
            for f in self.filterPreference:
                if f in c and c[f]:
                    c["Mag"] = c[f]
                    c["MagFilter"] = f.replace("_", "").replace("Mag", "")
                    if f + "Err" in c:
                        c["MagErr"] = c[f + "Err"]
                    else:
                        c["MagErr"] = None
                    break

        allKeys = []
        for c in crossmatches:
            for k, v in c.iteritems():
                if k not in allKeys:
                    allKeys.append(k)

        for c in crossmatches:
            for k in allKeys:
                if k not in c:
                    c[k] = None

        printCrossmatches = []
        for c in crossmatches:
            ordDict = collections.OrderedDict(sorted({}.items()))
            for k in basic:
                if k in c:
                    if k == "catalogue_table_name":
                        c[k] = c[k].replace("tcs_cat_", "").replace("_", " ")
                    if k == "classificationReliability":
                        if c[k] == 1:
                            c["classification reliability"] = "synonym"
                        elif c[k] == 2:
                            c["classification reliability"] = "association"
                        elif c[k] == 3:
                            c["classification reliability"] = "annotation"
                        k = "classification reliability"
                    if k == "catalogue_object_subtype" and "sdss" in c["catalogue_table_name"]:
                        if c[k] == 6:
                            c[k] = "galaxy"
                        elif c[k] == 3:
                            c[k] = "star"
                    columnName = k.replace("tcs_cat_", "").replace("_", " ")
                    value = c[k]
                    if k not in dontFormat:

                        try:
                            ordDict[columnName] = "%(value)0.2f" % locals()
                        except:
                            ordDict[columnName] = value
                    else:
                        ordDict[columnName] = value

            printCrossmatches.append(ordDict)

        from fundamentals.renderer import list_of_dictionaries
        dataSet = list_of_dictionaries(
            log=self.log,
            listOfDictionaries=printCrossmatches
        )
        tableData = dataSet.table(filepath=None)

        print tableData

        self.log.debug('completed the ``_print_results_to_stdout`` method')
        return None

Response: Prints the classification and crossmatch results for a single transient object to stdout.


Instruction:
How would you explain what the following Python 3 function does
def _consolidate_coordinateList(
            self,
            coordinateList):
        """*match the coordinate list against itself with the parameters of the NED search queries to minimise duplicated NED queries*

        **Key Arguments:**
            - ``coordinateList`` -- the original coordinateList.

        **Return:**
            - ``updatedCoordinateList`` -- the coordinate list with duplicated search areas removed

        **Usage:**
            ..  todo::

                - add usage info
                - create a sublime snippet for usage
                - update package tutorial if needed

            .. code-block:: python

                usage code

        .. todo ::

            - update key arguments values and definitions with defaults
            - update return values and definitions
            - update usage examples and text
            - update docstring text
            - check sublime snippet exists
            - clip any useful text to docs mindmap
            - regenerate the docs and check redendering of this docstring

        """
        self.log.debug('starting the ``_consolidate_coordinateList`` method')

        raList = []
        raList[:] = np.array([c[0] for c in coordinateList])
        decList = []
        decList[:] = np.array([c[1] for c in coordinateList])

        nedStreamRadius = self.settings[
            "ned stream search radius arcec"] / (60. * 60.)
        firstPassNedSearchRadius = self.settings[
            "first pass ned search radius arcec"] / (60. * 60.)
        radius = nedStreamRadius - firstPassNedSearchRadius

        # LET'S BE CONSERVATIVE
        # radius = radius * 0.9

        xmatcher = sets(
            log=self.log,
            ra=raList,
            dec=decList,
            radius=radius,  # in degrees
            sourceList=coordinateList,
            convertToArray=False
        )
        allMatches = xmatcher.match

        updatedCoordianteList = []
        for aSet in allMatches:
            updatedCoordianteList.append(aSet[0])

        self.log.debug('completed the ``_consolidate_coordinateList`` method')
        return updatedCoordianteList

Response: consolidate the coordinate list against itself with the parameters of the NED search queries to minimise duplicated NED queries


Instruction:
Implement a Python 3 function for
adding a detialed classification annotation to each crossmatch in the sherlock_classifications table

Response:
def classification_annotations(
            self):
        """*add a detialed classification annotation to each classification in the sherlock_classifications table*

        **Key Arguments:**
            # -

        **Return:**
            - None

        **Usage:**
            ..  todo::

                - add usage info
                - create a sublime snippet for usage
                - write a command-line tool for this method
                - update package tutorial with command-line tool info if needed

            .. code-block:: python

                usage code

        .. todo ::

            - update key arguments values and definitions with defaults
            - update return values and definitions
            - update usage examples and text
            - update docstring text
            - check sublime snippet exists
            - clip any useful text to docs mindmap
            - regenerate the docs and check redendering of this docstring

        """
        self.log.debug('starting the ``classification_annotations`` method')

        from fundamentals.mysql import readquery
        sqlQuery = u"""
            select * from sherlock_classifications cl, sherlock_crossmatches xm where cl.transient_object_id=xm.transient_object_id and cl.annotation is null
        """ % locals()
        topXMs = readquery(
            log=self.log,
            sqlQuery=sqlQuery,
            dbConn=self.transientsDbConn
        )

        for xm in topXMs:
            annotation = []
            classType = xm["classificationReliability"]
            if classType == 1:
                annotation.append("is synonymous with")
            elif classType in [2, 3]:
                annotation.append("is possibly associated with")

            print xm["catalogue_object_id"]

        self.log.debug('completed the ``classification_annotations`` method')
        return None