def __init__(self, **info): """Create a new `CloseApproach`. :param info: A dictionary of excess keyword arguments supplied to the constructor. """ # onto attributes named `_designation`, `time`, `distance`, # and `velocity`. # You should coerce these values to their appropriate data type # and handle any edge cases. # The `cd_to_datetime` function will be useful. # parse the keyword parameters for key, value in info.items(): # assign the designation parameter if key.lower() == 'des': # check the value of the parameter to avoid # an inappropriate value try: # if the type of value is not string self._designation = str(value) except ValueError: # print the text message print(f'The type of {key} is not string') # assign the time parameter elif key.lower() == 'cd': # check the value of the parameter to avoid # an inappropriate value try: # if the type of value is not string self.time = str(value) self.time = cd_to_datetime(self.time) except ValueError: # print the text message print(f'The type of {key} is not string') # assign the distance parameter elif key.lower() == 'dist': # check the value of the parameter to avoid # an inappropriate value try: # if the type of value is not float self.distance = float(value) except ValueError: # print the text message print(f'The type of {key} is not float') # assign the velocity parameter elif key.lower() == 'v_rel': # check the value of the parameter to avoid # an inappropriate value try: # if the type of value is not float self.velocity = float(value) except ValueError: # print the text message print(f'The type of {key} is not float') self.neo = self._designation
def __init__(self, **info): """Create a new `CloseApproach`. :param info: A dictionary of excess keyword arguments supplied to the constructor. """ # Assign information from the arguments passed to the constructor # onto attributes named `_designation`, `time`, `distance`, and `velocity`. if 'des' in info and info['des']: self._designation = info['des'] else: raise KeyError('The unique designation for CA is missing.') if 'cd' in info and info['cd']: self.time = cd_to_datetime(info['cd']) else: self.time = None if 'dist' in info and info['dist']: self.distance = float(info['dist']) else: self.distance = 0.0 if 'v_rel' in info and info['v_rel']: self.velocity = float(info['v_rel']) else: self.velocity = 0.0 # Create an attribute for the referenced NEO, originally None. self.neo = None
def __init__(self, **info): """Create a new `CloseApproach`. :param info: A dictionary of excess keyword arguments supplied to the constructor. """ # onto attributes named `_designation`, `time`, `distance`, and `velocity`. # You should coerce these values to their appropriate data type and handle any edge cases. # The `cd_to_datetime` function will be useful. for key, value in info.items(): if key.lower() == 'des': try: self.designation = str(value) except ValueError: print(f'The {key} is not type of string') elif key.lower() == 'cd': try: self.time = self.time = cd_to_datetime(str(value)) except ValueError: print('f{key} is not type time') elif key.lower() == 'dist': try: self.distance = float(value) except ValueError: print(f'The type of {key} is not float') elif key.lower() == 'v_rel': try: self.velocity = float(value) except ValueError: # print the text message print(f'The type of {key} is not float') # Create an attribute for the referenced NEO, originally None. self.neo = None
def __init__(self, designation, time=None, distance=float(0.0), velocity=float(0.0)): """Create a new `CloseApproach`. :param info: A dictionary of excess keyword arguments supplied to the constructor. """ # onto attributes named `_designation`, `time`, `distance`, and `velocity`. # You should coerce these values to their appropriate data type and handle any edge cases. # The `cd_to_datetime` function will be useful. # self._designation = info.get('designation', '') # self.time = info.get('time', None) # if self.time: # self.time = cd_to_datetime(self.time) # self.distance = float(info.get('distance', 0.0)) # self.velocity = float(info.get('velocity', 0.0)) self._designation = designation self.time = cd_to_datetime(time) self.distance = distance self.velocity = velocity # Create an attribute for the referenced NEO, originally None. self.neo = None
def __init__(self, **info): """Create a new `CloseApproach`. :param info: A dictionary of excess keyword arguments supplied to the constructor. """ try: self.designation = str(info['des']) except KeyError: self.designation = None try: self.time = cd_to_datetime(info['cd']) except KeyError: self.time = None try: self.velocity = float(info['v_rel']) # validating/setting valocity except KeyError: self.velocity = float('nan') except ValueError: self.distance = float('nan') try: self.distance = float(info['dist']) # validating/setting distance except KeyError: self.distance = float('nan') except ValueError: self.distance = float('nan') # Create an attribute for the referenced NEO, originally None. self.neo = None
def __init__(self, designation, time, distance, velocity): """Create a new `CloseApproach`. :param designation: The primary designation of the close approach's NEO :type designation: str :param time: The UTC date and time at which the NEO passes closest to Earth in YYYY-bb-DD hh:mm format :type time: str :param distance: The nominal approach distance of the NEO to Earth at the closes point in astronomical units :type distance: str :param velocity: The velocity of the NEO relative to Earth at the closes point in kilometers per second :type velocity: str """ self._designation = designation self.time = cd_to_datetime(time) try: self.distance = float(distance) except ValueError: self.distance = float('nan') try: self.velocity = float(velocity) except ValueError: self.velocity = float('nan') # Create an attribute for the referenced NEO, originally None. self.neo = None
def __init__(self, **info): #"""Create a new `CloseApproach`. #:param info: A dictionary of excess keyword arguments supplied to the constructor. #""" # TODO: Assign information from the arguments passed to the constructor # onto attributes named `_designation`, `time`, `distance`, and `velocity`. # You should coerce these values to their appropriate data type and handle any edge cases. # The `cd_to_datetime` function will be useful. try: self._designation = str(info.get("designation") or "") except: self._designation = '' try: self.time = cd_to_datetime(info.get("time")) except: self.time = None # TODO: Use the cd_to_datetime function for this attribute. try: self.distance = float(info.get("distance") or "") except: self.distance = 0.0 try: self.velocity = float(info.get("velocity") or "") except: self.velocity = 0.0 # Create an attribute for the referenced NEO, originally None. try: self.neo = info.get("neos") except: self.neo = None
def __init__(self, **info): """Create a new `CloseApproach`. :param info: A dictionary of excess keyword arguments supplied to the constructor. """ try: self._designation = info.get("des", None) except ValueError: print("The designation value is falsy") try: self.time = cd_to_datetime(info.get("cd", None)) except ValueError: print("The time value is falsy") try: self.distance = info.get("dist", float("nan")) self.distance = float(self.distance) except ValueError: print("The distance value is falsy") try: self.velocity = info.get("v_rel", float("nan")) self.velocity = float(self.velocity) except ValueError: print("The velocity value is falsy") # Create an attribute for the referenced NEO, originally None. try: self.neo = info.get("neo", None) except ValueError: print("The neo value is falsy")
def __init__(self, **info): """Create a new `CloseApproach`. :param info: A dictionary of excess keyword arguments supplied to the constructor. """ self._designation = info['designation'] self.time = cd_to_datetime(info['time']) self.distance = info['distance'] self.velocity = info['velocity'] self.neo = None
def __init__(self, designation='', time=None, distance=0.0, velocity=0.0): """Create a new `CloseApproach`. :param info: A dictionary of excess keyword arguments supplied to the constructor. """ self._designation = designation self.time = cd_to_datetime(time) self.distance = distance self.velocity = velocity self.neo = None
def __init__(self, **info): """Create a new `CloseApproach`. :param info: A dictionary of excess keyword arguments supplied to the constructor. """ self._designation = info["designation"] self.time = cd_to_datetime(info["time"]) self.distance = float(info.get("distance", "nan")) self.velocity = float(info["velocity"]) self.neo = None
def __init__(self, **info): """Create a new `CloseApproach`. :param info: A dictionary of excess keyword arguments supplied to the constructor. """ self._designation = info['des'] self.time = cd_to_datetime(info['cd']) self.distance = float(info['dist']) self.velocity = float(info['v_rel']) # Create an attribute for the referenced NEO, originally None. self.neo = None
def __init__(self, **info): """Create a new `CloseApproach`. :param info: A dictionary of excess keyword arguments supplied to the constructor. """ self._designation = (str(info['designation']) if info['designation'] else '') self.time = (cd_to_datetime(info['time']) if info['time'] else None) self.distance = (float(info['distance']) if info['distance'] else float('nan')) self.velocity = (float(info['velocity']) if info['velocity'] else float('nan')) self.neo = None
def __init__(self, **info): """Create a new `CloseApproach`. :param info: A dictionary of excess keyword arguments supplied to the constructor. """ self._designation = info.get('designation', '') self.time = cd_to_datetime(info.get('time', None)) self.distance = info.get('distance', 0.0) self.velocity = info.get('velocity', 0.0) # Create an attribute for the referenced NEO, originally None. self.neo = None
def __init__(self, **info): """Create a new `CloseApproach`. :param info: A dictionary of excess keyword arguments supplied to the constructor. """ self._designation = info.get('designation', '') self.time = cd_to_datetime(info.get('time')) self.distance = (lambda x: 0.0 if x == '' else float(x))(info.get('distance', 0.0)) self.velocity = (lambda x: 0.0 if x == '' else float(x))(info.get('velocity', 0.0)) self.neo = info.get('neo', None)
def __init__(self, **info): """Create a new `CloseApproach`. :param info: A dictionary of excess keyword arguments supplied to the constructor. """ self._designation = str(info.get('_designation', None)) self.time = cd_to_datetime(info.get('time', None)) try: self.distance = float(info.get('distance', None)) self.velocity = float(info.get('velocity', None)) except ValueError as err: print(f"{err} diameter and/or velocity should numbers") self.neo = None
def __init__(self, info): """Create Close Approach Attribute.""" for key, value in info.items(): if key == 'cd': self.time = cd_to_datetime(value) elif key == 'dist': self.distance = float(value) elif key == 'v_rel': self.velocity = float(value) elif key == 'des': self._designation = value else: pass self.neo = None
def __init__(self, *, des, cd, dist, v_rel, **info): """Create a new `CloseApproach`. :param des: A designation for the Object :param cd: Time of close-approach :param dist: Nominal approach distance :param v_rel: Velocity relative to the approach body at close approach (km/s) :param info: A dictionary of excess keyword arguments supplied to the constructor. """ self._designation = des self.time = cd_to_datetime(cd) self.distance = float(dist) self.velocity = float(v_rel) # Create an attribute for the referenced NEO, originally None. self.neo = None
def __init__(self, **info): """Create a new `CloseApproach`. :param info: A dictionary of excess keyword arguments supplied to the constructor. """ # onto attributes named `_designation`, `time`, `distance`, and `velocity`. # You should coerce these values to their appropriate data type and handle any edge cases. # The `cd_to_datetime` function will be useful. self._designation = info['designation'] self.time = cd_to_datetime(info['time']) self.distance = float(info['distance']) self.velocity = float(info['velocity']) # Create an attribute for the referenced NEO, originally None. self.neo = None
def __init__(self, time, distance, velocity, designation=''): """Create a new `CloseApproach`. :param time: The date and time, in UTC, at which the NEO passes closest to Earth. :param distance: The nominal approach distance, in astronomical units, of the NEO to Earth at the closest point. :param velocity: The velocity, in kilometers per second, of the NEO relative to Earth at the closest point. :param designation: Referenced NEO """ self._designation = designation self.time = cd_to_datetime(time) self.distance = distance self.velocity = velocity # Create an attribute for the referenced NEO, originally None. self.neo = None
def __init__(self, designation, time=None, distance=float(0.0), velocity=float(0.0)): """Create a new `CloseApproach`. :param info: A dictionary of excess keyword arguments supplied to the constructor. """ self._designation = designation self.time = cd_to_datetime(time) self.distance = distance self.velocity = velocity # Create an attribute for the referenced NEO, originally None. self.neo = None
def __init__(self, _designation, time, distance, velocity, neo=None): """Create a new `CloseApproach`. :param _designation: The primary designation of the NEO associated with this close-approach. :param time: Time of close-approach :param distance: Nominal approach distance :param velocity: Velocity relative to the approach body at close approach (km/s) :param neo: The NEO object associated with this close-approach """ self._designation = _designation self.time = cd_to_datetime(time) self.distance = float(distance) self.velocity = float(velocity) # Create an attribute for the referenced NEO, originally None. self.neo = neo
def __init__(self, designation, time, distance, velocity, neo=None): self._designation = designation if type(time) == str: self.time = cd_to_datetime(time) if type(distance) == float: self.distance = distance else: self.distance = float(distance) if type(velocity) == float: self.velocity = velocity else: self.velocity = float(velocity) if neo: self.neo = neo else: self.neo = None
def __init__(self, des, close_approach_time, dist_au, velocity, **info): """Create a new `CloseApproach`. :param des: primary designation of the asteroid or comet (e.g., 443, 2000 SG344) :param close_approach_time: time of close-approach :param info: A dictionary of excess keyword arguments supplied to the constructor. """ # onto attributes named `_designation`, `time`, `distance`, and `velocity`. # You should coerce these values to their appropriate data type and handle any edge cases. # The `cd_to_datetime` function will be useful. self._designation = des self.time = helpers.cd_to_datetime( close_approach_time ) # Use the cd_to_datetime function for this attribute. self.distance = float(dist_au) self.velocity = float(velocity) # Create an attribute for the referenced NEO, originally None. self.neo: NearEarthObject = None
def __init__(self, des, time, distance=float('nan'), velocity=float('nan'), neo=None): """Create a new `CloseApproach`. :param info: required unique designation (str), can be passed from the neo type' required date (str); optional: distance (float), velocity (bool), neo (neo). """ self._designation = des self.time = cd_to_datetime(time) self.distance = distance self.velocity = velocity self.neo = neo
def __init__( self, designation, time, distance, velocity, neo: NearEarthObject = None, ): """Create a new `CloseApproach`. :param neo: A Near earth object. :param time: Time of close approach in NASA-formatted calendar date/time format. :param distance: Approach distance in astronomical units. :param velocity: relative approach velocity in kilometers per second """ self._designation = designation self.time = cd_to_datetime(time) if time else None self.distance = float(distance) if distance else float("nan") self.velocity = float(velocity) if velocity else float("nan") self.neo = neo
def __init__(self, designation: str = '', time: str = '', distance: float = 0.0, velocity: float = 0.0, neo: NearEarthObject = None): """Create a new `CloseApproach`. :param info: A dictionary of excess keyword arguments supplied to the constructor. """ # TODO: Assign information from the arguments passed to the constructor # onto attributes named `_designation`, `time`, `distance`, and `velocity`. # You should coerce these values to their appropriate data type and handle any edge cases. # The `cd_to_datetime` function will be useful. self._designation = str(designation) self.time: datetime.datetime = cd_to_datetime(time) self.distance = float(distance) self.velocity = float(velocity) # Create an attribute for the referenced NEO, originally None. self.neo = neo
def __init__(self, **info): """Create a new `CloseApproach`. :param info: A dictionary of excess keyword arguments supplied to the constructor. """ self._designation = info['_designation'] self.time = cd_to_datetime(info['time']) try: self.distance = float(info['distance']) if self.distance < 0: raise ValueError("Sorry, no numbers below zero") except ValueError as er: print(er) try: self.velocity = float(info['velocity']) if self.velocity < 0: raise ValueError("Sorry, no numbers below zero") except ValueError as er: print(er) self.neo = None
def __init__(self, designation, time, distance, velocity, **info): """Create a new `CloseApproach`. :param designation: (str) unique id of NEO :param time: (UTC date and time) closest approach to earth in format %Y-%b-%d %H:%M :param distance: (float) closest distance to earth :param velocity: (float) in km/s when passing earth :param neo: A NEO object :param info: A dictionary of excess keyword arguments supplied to the constructor. """ self._designation = str(designation) self.time = cd_to_datetime(time) try: self.distance = float(distance) except ValueError: self.distance = float("nan") self.velocity = float(velocity) # Create an attribute for the referenced NEO, originally None. self.neo = None
def __init__(self, time, distance, velocity, designation): self.time = cd_to_datetime(time) self._designation = designation self.distance = distance self.velocity = velocity self.neo = None