def get_declination(app_long: FlexNum, oblique_corr: FlexNum): """ solar declination angle at ref_datetime""" sal = radians(app_long) oc = radians(oblique_corr) declination = degrees(arcsin((sin(oc) * sin(sal)))) return declination
def get_right_ascension(app_long: FlexNum, oblique_corr: FlexNum): """ calculates the suns right ascension angle """ sal = radians(app_long) oc = radians(oblique_corr) right_ascension = degrees(arctan2(cos(oc) * sin(sal), cos(sal))) return right_ascension
def get_zenith(declination: FlexNum, hour_angle: FlexNum, lat_r: FlexNum): """ calculates solar zenith angle at ref_datetime""" d = radians(declination) ha = radians(hour_angle) lat = lat_r zenith = degrees(arccos(sin(lat) * sin(d) + cos(lat) * cos(d) * cos(ha))) return zenith
def get_hour_angle_sunrise(declination: FlexNum, lat_r: FlexNum): """ calculates the hour angle of sunrise """ d = radians(declination) lat = lat_r # radians hour_angle_sunrise = degrees( arccos( (cos(radians(90.833)) / (cos(lat) * cos(d)) - tan(lat) * tan(d)))) return hour_angle_sunrise
def sat_az(R_u, R_sat, deg=True): """ Azimuth of some certain sat. relative to the user's position :param R_u: (X,Y,Z) -- user's coordinates in ECEF (numpy array) :param R_sat: (X,Y,Z) -- satellite's coordinates in ECEF (numpy array) :param deg: whether to return angle in degrees :return: azimuth of the satellite """ enu = sat_in_enu(R_u, R_sat) az = atan2(enu[0], enu[1]) if deg: return degrees(az) else: return az
def sat_elev(R_u, R_sat, deg=True): """ Zenith angle of some certain sat. relative to the user's position :param R_u: (X,Y,Z) -- user's coordinates in ECEF (numpy array) :param R_sat: (X,Y,Z) -- satellite's coordinates in ECEF (numpy array) :param deg: whether to return angle in degrees :return: elevation angle of the satellite """ elev = arcsin(sat_in_enu(R_u, R_sat)[2]) # print "Elev angle = %.1f deg" % elev if deg: return degrees(elev) else: return elev
def get_equation_of_time(oblique_corr: FlexNum, geomean_long: FlexNum, geomean_anom: FlexNum, earth_eccent: FlexNum): """ calculates the equation of time in minutes """ oc = radians(oblique_corr) gml = radians(geomean_long) gma = radians(geomean_anom) ec = earth_eccent vary = tan(oc / 2)**2 equation_of_time = 4 * degrees( vary * sin(2 * gml) - 2 * ec * sin(gma) + \ 4 * ec * vary * sin(gma) * cos(2 * gml) - \ 0.5 * vary * vary * sin(4 * gml) - \ 1.25 * ec * ec * sin(2 * gma)) return equation_of_time
def _get_slope(self, start: int, end: int, hr: list) -> dict: x = [] y = [] result = {} for count in range(start, end + 1): x.append(count - start) y.append(hr[count]) slope, intercept, r_value, p_value, std_err = linregress(x, y) height = abs((hr[end] - hr[start])) width = len(x) - 1 tan_theta = degrees(math.atan(height / width)) result.update({'slope': slope}) result.update({'height': height}) result.update({'width': width}) result.update({'tan': tan_theta}) return result
def convert_to_drawable(to_draw: convertible_types, time_step: int = 0) -> Optional[drawable_types]: """ Converts the given object to a representation which can be draw on a plot using draw(...). :param to_draw: The object to draw. :param time_step: This parameter defines the time step to calculate the occupancy for in the case of DynamicObstacles. :return: The plottable representation of the given object. """ from common import MyState if isinstance(to_draw, (Scenario, LaneletNetwork, Lanelet, StaticObstacle, GoalRegion, List)): # FIXME Use List[plottable_types] converted = to_draw elif isinstance(to_draw, DynamicObstacle): shape: Shape = to_draw.occupancy_at_time(time_step).shape left, bottom = shape.center / 2 angle: float = to_draw.initial_state.orientation * 360 / 2 / pi converted = Rectangle((left, bottom), shape.length, shape.width, angle=angle) elif isinstance(to_draw, MyState): converted = DrawHelp.convert_to_drawable(to_draw.state) elif isinstance(to_draw, State): pos = CoordsHelp.center_to_right_bottom_pos( to_draw.position, to_draw.orientation, DrawConfig.car_length, DrawConfig.car_width) converted = Rectangle( pos, DrawConfig.car_length, DrawConfig.car_width, degrees(to_draw.orientation), fill=False, edgecolor=DrawConfig.colors[to_draw.time_step % len(DrawConfig.colors)]) else: error("Could not convert an object of type " + str(type(to_draw)) + ".") converted = None return converted
def test_degrees(self): assert_almost_equal(ncu.degrees(np.pi), 180.0) assert_almost_equal(ncu.degrees(-0.5 * np.pi), -90.0)
def check_radians(self): assert_almost_equal(ncu.radians(180.0), pi) assert_almost_equal(ncu.degrees(-90.0), -0.5 * pi)
def check_degrees(self): assert_almost_equal(ncu.degrees(pi), 180.0) assert_almost_equal(ncu.degrees(-0.5 * pi), -90.0)
def get_azimuth(lat_r: FlexNum, declination: FlexNum, hour_angle: FlexNum, zenith: FlexNum) -> FlexNum: """ calculates solar azimuth angle. Function requires special treatment of different cases of combine vectorize inputs Case 1: all scalar inputs all scalar inputs are simple, and a scalar will be output. Case 2: Time constant, spatial variation (declination is scalar) lat_r: vector (x,y) declination: scalar (z) hour_angle: vector (x,y) zenith: vector (x,y) azimuth output vector (x,y) Case 3: Space constant, time variation (lat_r in radians is scalar) lat_r: scalar (x) declination: vector (y) hour_angle: vector (y) zenith: vector (y) azimuth output vector (y) case 4: Both space and time variation lat_r: vector (x,y,z) # duplicated across z axis declination: vector (z) # will be duplicated to dims (x,y,z) hour_angle: vector (x,y,z) # duplicated across z axis zenith: vector (x,y,z) # duplicated across z axis azimuth output vector (x,y,z) # duplicated across z axis In either case 2 or 3, all vector inputs must be identical shapes. """ lat = lat_r d = radians(declination) # always returns numpy arrays, even if 1x1 ha = radians(hour_angle) # always returns numpy arrays, even if 1x1 z = radians(zenith) # always returns numpy arrays, even if 1x1 # are the inputs vectorized in space? (lat_r will be a vector) if isinstance(lat_r, np.ndarray): if lat_r.shape: lat_vec = True else: lat_vec = False # ndarray with no dimensions is a scalar! else: lat_vec = False if isinstance(d, np.ndarray): if d.shape: time_vec = True else: time_vec = False # ndarray with no dimensions is a scalar! else: time_vec = False # Case 4: Both space and time variation if time_vec and lat_vec: # if both time and space are vectorized, we must cast declination(time) # to the third dimension. by duplicating for all lat/lon pairs. if len(lat_r.shape) == 3 and len(d.shape) == 1: if lat_r.shape[2] == d.shape[0]: d = np.repeat(d[np.newaxis, :], lat_r.shape[1], axis=0) d = np.repeat(d[np.newaxis, :], lat_r.shape[0], axis=0) az = ha * 0 ha_p = (ha > 0) # positive ha indices ha_n = (ha <= 0) # negative ha indices az_ha_p = arccos(((sin(lat[ha_p]) * cos(z[ha_p])) - sin(d[ha_p])) / (cos(lat[ha_p]) * sin(z[ha_p]))) az[ha_p] = (degrees(az_ha_p) + 180) % 360 az_ha_n = arccos(((sin(lat[ha_n]) * cos(z[ha_n])) - sin(d[ha_n])) / (cos(lat[ha_n]) * sin(z[ha_n]))) az[ha_n] = (540 - degrees(az_ha_n)) % 360 azimuth = az # Case 3: Space constant, time variation (lat_r in radians is scalar) elif time_vec and not lat_vec: az = ha * 0 ha_p = (ha > 0) # positive ha indices ha_n = (ha <= 0) # negative ha indices az_ha_p = arccos(((sin(lat) * cos(z[ha_p])) - sin(d[ha_p])) / (cos(lat) * sin(z[ha_p]))) az[ha_p] = (degrees(az_ha_p) + 180) % 360 az_ha_n = arccos(((sin(lat) * cos(z[ha_n])) - sin(d[ha_n])) / (cos(lat) * sin(z[ha_n]))) az[ha_n] = (540 - degrees(az_ha_n)) % 360 azimuth = az # Case 2: Time constant, spatial variation (declination is scalar) elif lat_vec and not time_vec: az = ha * 0 ha_p = (ha > 0) # positive ha indices ha_n = (ha <= 0) # negative ha indices az_ha_p = arccos(((sin(lat[ha_p]) * cos(z[ha_p])) - sin(d)) / (cos(lat[ha_p]) * sin(z[ha_p]))) az[ha_p] = (degrees(az_ha_p) + 180) % 360 az_ha_n = arccos(((sin(lat[ha_n]) * cos(z[ha_n])) - sin(d)) / (cos(lat[ha_n]) * sin(z[ha_n]))) az[ha_n] = (540 - degrees(az_ha_n)) % 360 azimuth = az # case 1, all inputs are scalar. else: if ha > 0: azimuth = (degrees( arccos(((sin(lat) * cos(z)) - sin(d)) / (cos(lat) * sin(z)))) + 180) % 360 else: azimuth = (540 - degrees( arccos(((sin(lat) * cos(z)) - sin(d)) / (cos(lat) * sin(z))))) % 360 return azimuth