home/exp1000/acquire_and_label_images.py
def collect_metadata(self, filename_png, label, confidence, keep):
        """Collect metadata for the image acquired at the given timestamp."""

        # Track if tle compuation is successful or not.
        # If not successful then fallback to minimum metadata collection that does not depend on TLE.
        tle_compute_success = False

        # Image acquisition timestamp.
        timestamp = None
        
        # The dictionary that will contain the image's computed metadata.
        metadata = None

        # The filename without the path and without the extension
        filename = filename_png.replace(BASE_PATH + "/", "").replace(".png", "")

        try:
            # Extract timestamp from filename.
            timestamp = int(re.match(".*" + IMG_FILENAME_PREFIX + "(\d+)_\d+", filename).group(1))
        
        except:
            logger.exception("Failed to extract timestamp from the image filename.")

        if timestamp is not None and self.tle is not None:
            try: 

                # Image acquisition datetime.
                d = datetime.datetime.utcfromtimestamp(timestamp / 1000.0)

                # Image acquisition ephem datetime object.
                d_ephem = ephem.Date(d)

                # Compute based on reference TLE and acquisition datetime.
                self.tle.compute(d_ephem)

                # Build the metadata dictionary for the acquired image.
                metadata = {
                    'filename': filename,                 # Filename without extension.
                    'label': label,                       # Label applied to the image by the image classifier.
                    'confidence': confidence,             # Confidence level of th the applied label.
                    'keep': keep,                         # Whether the image was kept or not.
                    'gain_r': self.gains[0],              # Camera gain setting for red channel.
                    'gain_g': self.gains[1],              # Camera gain setting for green channel.
                    'gain_b': self.gains[2],              # Camera gain setting for blue channel.
                    'exposure': self.exposure,            # Camera exposure setting (ms).
                    'acq_ts': timestamp,                  # Image acquisition timestamp.
                    'acq_dt': str(d_ephem),               # Image acquisition datetime.
                    'ref_dt': str(self.tle._epoch),       # Reference epoch.
                    'tle_age': d_ephem - self.tle._epoch, # TLE age (days).
                    'lat': self.tle.sublat / ephem.degree,# Latitude (deg).
                    'lng': self.tle.sublong / ephem.degree,# Longitude (deg).
                    'h': self.tle.elevation,              # Geocentric height above sea level (m).
                    'tle_ref_line1': self.tle_line1,      # Reference TLE line 1.
                    'tle_ref_line2': self.tle_line2       # Rererence TLE line 2.
                }

                # TLE computer success.
                tle_compute_success = True

            except:
                # Log exception.
                logger.exception("Failed TLE computation with image timestamp: " + str(timestamp))


        # Computing some metadata with the available TLE failed.
        # Try collecting basic metadata that does not depend on TLE.
        if not tle_compute_success:

            try:
                # Limited metadata in case of TLE error.
                metadata = {
                    'filename': filename,                 # Filename without extension.
                    'label': label,                       # Label applied to the image by the image classifier.
                    'confidence': confidence,             # Confidence level of th the applied label.
                    'keep': keep,                         # Whether the image was kept or not.
                    'gain_r': self.gains[0],              # Camera gain setting for red channel.
                    'gain_g': self.gains[1],              # Camera gain setting for green channel.
                    'gain_b': self.gains[2],              # Camera gain setting for blue channel.
                    'exposure': self.exposure,            # Camera exposure setting (ms).
                    'acq_ts': timestamp,                  # Image acquisition timestamp.
                    'tle_ref_line1': self.tle_line1,      # Reference TLE line 1.
                    'tle_ref_line2': self.tle_line2       # Rererence TLE line 2.
                }

            except:
                # No reason for this to occur but here nevertheless, just in case.
                logger.exception("Failed to collect metadata.")

        # Return the metadata. Will be None in case of error.
        return metadata
Collect metadata for the image acquired at the given timestamp.
Collect metadata for the image acquired at the given timestamp.
Collect metadata for the image acquired at the given timestamp .
def collect_metadata(self, filename_png, label, confidence, keep):
        tle_compute_success = False
        timestamp = None
        metadata = None
        filename = filename_png.replace(BASE_PATH + "/", "").replace(".png", "")
        try:
            timestamp = int(re.match(".*" + IMG_FILENAME_PREFIX + "(\d+)_\d+", filename).group(1))
        except:
            logger.exception("Failed to extract timestamp from the image filename.")
        if timestamp is not None and self.tle is not None:
            try: 
                d = datetime.datetime.utcfromtimestamp(timestamp / 1000.0)
                d_ephem = ephem.Date(d)
                self.tle.compute(d_ephem)
                metadata = {
                    'filename': filename,                 
                    'label': label,                       
                    'confidence': confidence,             
                    'keep': keep,                         
                    'gain_r': self.gains[0],              
                    'gain_g': self.gains[1],              
                    'gain_b': self.gains[2],              
                    'exposure': self.exposure,            
                    'acq_ts': timestamp,                  
                    'acq_dt': str(d_ephem),               
                    'ref_dt': str(self.tle._epoch),       
                    'tle_age': d_ephem - self.tle._epoch, 
                    'lat': self.tle.sublat / ephem.degree,
                    'lng': self.tle.sublong / ephem.degree,
                    'h': self.tle.elevation,              
                    'tle_ref_line1': self.tle_line1,      
                    'tle_ref_line2': self.tle_line2       
                }
                tle_compute_success = True
            except:
                logger.exception("Failed TLE computation with image timestamp: " + str(timestamp))
        if not tle_compute_success:
            try:
                metadata = {
                    'filename': filename,                 
                    'label': label,                       
                    'confidence': confidence,             
                    'keep': keep,                         
                    'gain_r': self.gains[0],              
                    'gain_g': self.gains[1],              
                    'gain_b': self.gains[2],              
                    'exposure': self.exposure,            
                    'acq_ts': timestamp,                  
                    'tle_ref_line1': self.tle_line1,      
                    'tle_ref_line2': self.tle_line2       
                }
            except:
                logger.exception("Failed to collect metadata.")
        return metadata
def collect_metadata ( self , filename_png , label , confidence , keep ) : tle_compute_success = False timestamp = None metadata = None filename = filename_png . replace ( BASE_PATH + "/" , "" ) . replace ( ".png" , "" ) try : timestamp = int ( re . match ( ".*" + IMG_FILENAME_PREFIX + "(\d+)_\d+" , filename ) . group ( 1 ) ) except : logger . exception ( "Failed to extract timestamp from the image filename." ) if timestamp is not None and self . tle is not None : try : d = datetime . datetime . utcfromtimestamp ( timestamp / 1000.0 ) d_ephem = ephem . Date ( d ) self . tle . compute ( d_ephem ) metadata = { 'filename' : filename , 'label' : label , 'confidence' : confidence , 'keep' : keep , 'gain_r' : self . gains [ 0 ] , 'gain_g' : self . gains [ 1 ] , 'gain_b' : self . gains [ 2 ] , 'exposure' : self . exposure , 'acq_ts' : timestamp , 'acq_dt' : str ( d_ephem ) , 'ref_dt' : str ( self . tle . _epoch ) , 'tle_age' : d_ephem - self . tle . _epoch , 'lat' : self . tle . sublat / ephem . degree , 'lng' : self . tle . sublong / ephem . degree , 'h' : self . tle . elevation , 'tle_ref_line1' : self . tle_line1 , 'tle_ref_line2' : self . tle_line2 } tle_compute_success = True except : logger . exception ( "Failed TLE computation with image timestamp: " + str ( timestamp ) ) if not tle_compute_success : try : metadata = { 'filename' : filename , 'label' : label , 'confidence' : confidence , 'keep' : keep , 'gain_r' : self . gains [ 0 ] , 'gain_g' : self . gains [ 1 ] , 'gain_b' : self . gains [ 2 ] , 'exposure' : self . exposure , 'acq_ts' : timestamp , 'tle_ref_line1' : self . tle_line1 , 'tle_ref_line2' : self . tle_line2 } except : logger . exception ( "Failed to collect metadata." ) return metadata
Collect metadata for the image acquired at the given timestamp.
Collect metadata for the image acquired at the given timestamp .
"""Collect metadata for the image acquired at the given timestamp.""" # Track if tle compuation is successful or not. # If not successful then fallback to minimum metadata collection that does not depend on TLE. # Image acquisition timestamp. # The dictionary that will contain the image's computed metadata. # The filename without the path and without the extension # Extract timestamp from filename. # Image acquisition datetime. # Image acquisition ephem datetime object. # Compute based on reference TLE and acquisition datetime. # Build the metadata dictionary for the acquired image. # Filename without extension. # Label applied to the image by the image classifier. # Confidence level of th the applied label. # Whether the image was kept or not. # Camera gain setting for red channel. # Camera gain setting for green channel. # Camera gain setting for blue channel. # Camera exposure setting (ms). # Image acquisition timestamp. # Image acquisition datetime. # Reference epoch. # TLE age (days). # Latitude (deg). # Longitude (deg). # Geocentric height above sea level (m). # Reference TLE line 1. # Rererence TLE line 2. # TLE computer success. # Log exception. # Computing some metadata with the available TLE failed. # Try collecting basic metadata that does not depend on TLE. # Limited metadata in case of TLE error. # Filename without extension. # Label applied to the image by the image classifier. # Confidence level of th the applied label. # Whether the image was kept or not. # Camera gain setting for red channel. # Camera gain setting for green channel. # Camera gain setting for blue channel. # Camera exposure setting (ms). # Image acquisition timestamp. # Reference TLE line 1. # Rererence TLE line 2. # No reason for this to occur but here nevertheless, just in case. # Return the metadata. Will be None in case of error.
self
filename_png
label
confidence
keep