How to use pyorbital - 10 common examples

To help you get started, we’ve selected a few pyorbital examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pytroll / fogpy / fogpy / composites.py View on Github external
def __call__(self, projectables, *args, **kwargs):
        (area, lat, lon) = self._get_area_lat_lon(projectables)

        sza = pyorbital.astronomy.sun_zenith_angle(
                projectables[0].start_time, lon, lat)

        maskproj = self._convert_xr_to_ma(projectables)

        flsinput = {'ir108': maskproj[1],
                    'ir039': maskproj[0],
                    'sza': sza,
                    'lat': lat,
                    'lon': lon,
                    'time': projectables[0].start_time
                    }

        # Compute fog mask
        flsalgo = NightFogLowStratusAlgorithm(**flsinput)
        fls, mask = flsalgo.run()
github pytroll / satpy / mpop / channel.py View on Github external
self.info['sun_zen_corrected'] to the original channel, so
        this can be used as a pointer to the corrected data.
        '''

        try:
            from pyorbital import astronomy
        except ImportError:
            LOG.warning("Could not load pyorbital.astronomy")
            return None

        if lons is None or lats is None:
            # Read coordinates
            lons, lats = self.area.get_lonlats()
    
        # Calculate Sun zenith angles and the cosine
        zen_angles = astronomy.sun_zenith_angle(time_slot, 
                                                lons, lats)
        cos_zen = astronomy.cos_zen(time_slot, lons, lats)

        # Copy the channel
        new_ch = copy.deepcopy(self)
        # Update the name
        if name is None:
            new_ch.name += '_SZC'
        else:
            new_ch.name = name

        if mode == 'cos':
            # Cosine correction
            lim_y, lim_x = np.where(zen_angles < limit)
            new_ch.data[lim_y, lim_x] /= cos_zen[lim_y, lim_x]
            # Use constant value (the limit) for larger zenith
github pytroll / satpy / satpy / composites / viirs.py View on Github external
def get_angles(self, vis):
        """Get sun and satellite angles to use in crefl calculations."""
        from pyorbital.astronomy import get_alt_az, sun_zenith_angle
        from pyorbital.orbital import get_observer_look
        lons, lats = vis.attrs['area'].get_lonlats(chunks=vis.data.chunks)
        lons = da.where(lons >= 1e30, np.nan, lons)
        lats = da.where(lats >= 1e30, np.nan, lats)
        suna = get_alt_az(vis.attrs['start_time'], lons, lats)[1]
        suna = np.rad2deg(suna)
        sunz = sun_zenith_angle(vis.attrs['start_time'], lons, lats)
        sat_lon, sat_lat, sat_alt = get_satpos(vis)
        sata, satel = get_observer_look(
            sat_lon,
            sat_lat,
            sat_alt / 1000.0,  # km
            vis.attrs['start_time'],
            lons, lats, 0)
        satz = 90 - satel
        return sata, satz, suna, sunz
github pytroll / satpy / satpy / composites / __init__.py View on Github external
def get_angles(self, vis):
        """Get the sun and satellite angles from the current dataarray."""
        from pyorbital.astronomy import get_alt_az, sun_zenith_angle
        from pyorbital.orbital import get_observer_look

        lons, lats = vis.attrs['area'].get_lonlats(chunks=vis.data.chunks)
        sunalt, suna = get_alt_az(vis.attrs['start_time'], lons, lats)
        suna = np.rad2deg(suna)
        sunz = sun_zenith_angle(vis.attrs['start_time'], lons, lats)

        sat_lon, sat_lat, sat_alt = get_satpos(vis)
        sata, satel = get_observer_look(
            sat_lon,
            sat_lat,
            sat_alt / 1000.0,  # km
            vis.attrs['start_time'],
            lons, lats, 0)
        satz = 90 - satel
        return sata, satz, suna, sunz
github pytroll / fogpy / fogpy / fogpy.py View on Github external
fog_mask = fog_mask | ice_mask
    filters['ice'] = np.nansum(fog_mask) - prev
    prev += filters['ice']

    # Thin cirrus is detected by means of the split-window IR channel
    # brightness temperature difference (T10.8 –T12.0 ). This difference is
    # compared to a threshold dynamically interpolated from a lookup table
    # based on satellite zenith angle and brightness temperature at 10.8 μm
    # (Saunders and Kriebel, 1988)
    chn120_ma = np.ma.masked_where(cloud_mask | snow_mask | ice_mask, chn120)
    chn108_ma = np.ma.masked_where(cloud_mask | snow_mask | ice_mask, chn108)

    bt_diff = chn108 - chn120

    # Calculate sun zenith angles
    sza = astronomy.sun_zenith_angle(time, lon, lat)

    minsza = np.min(sza)
    maxsza = np.max(sza)
    logger.debug("Found solar zenith angles from %s to %s°" % (minsza,
                                                               maxsza))

    # Calculate secant of sza
    # secsza = np.ma.masked_where(cloud_mask | snow_mask | ice_mask,
    #                             (1 / np.cos(np.deg2rad(sza))))
    secsza = 1 / np.cos(np.deg2rad(sza))

    # Lookup table for BT difference thresholds at certain sec(sun zenith
    # angles) and 10.8 μm BT
    lut = {260: {1.0: 0.55, 1.25: 0.60, 1.50: 0.65, 1.75: 0.90, 2.0: 1.10},
           270: {1.0: 0.58, 1.25: 0.63, 1.50: 0.81, 1.75: 1.03, 2.0: 1.13},
           280: {1.0: 1.30, 1.25: 1.61, 1.50: 1.88, 1.75: 2.14, 2.0: 2.30},
github pytroll / satpy / satpy / composites / __init__.py View on Github external
Uses pyspectral.
        """
        from pyspectral.rayleigh import Rayleigh

        (vis, red) = projectables
        if vis.shape != red.shape:
            raise IncompatibleAreas
        try:
            (sata, satz, suna, sunz) = optional_datasets
        except ValueError:
            from pyorbital.astronomy import get_alt_az, sun_zenith_angle
            from pyorbital.orbital import get_observer_look
            lons, lats = vis.attrs['area'].get_lonlats_dask(CHUNK_SIZE)
            sunalt, suna = get_alt_az(vis.attrs['start_time'], lons, lats)
            suna = np.rad2deg(suna)
            sunz = sun_zenith_angle(vis.attrs['start_time'], lons, lats)
            sata, satel = get_observer_look(vis.attrs['satellite_longitude'],
                                            vis.attrs['satellite_latitude'],
                                            vis.attrs['satellite_altitude'],
                                            vis.attrs['start_time'],
                                            lons, lats, 0)
            satz = 90 - satel
            del satel
        LOG.info('Removing Rayleigh scattering and aerosol absorption')

        # First make sure the two azimuth angles are in the range 0-360:
        sata = sata % 360.
        suna = suna % 360.
        ssadiff = abs(suna - sata)
        ssadiff = xu.minimum(ssadiff, 360 - ssadiff)
        del sata, suna
github pytroll / fogpy / fogpy / fogpy_old.py View on Github external
fog_mask = fog_mask | ice_mask
    filters['ice'] = np.nansum(fog_mask) - prev
    prev += filters['ice']

    # Thin cirrus is detected by means of the split-window IR channel
    # brightness temperature difference (T10.8 –T12.0 ). This difference is
    # compared to a threshold dynamically interpolated from a lookup table
    # based on satellite zenith angle and brightness temperature at 10.8 μm
    # (Saunders and Kriebel, 1988)
    chn120_ma = np.ma.masked_where(cloud_mask | snow_mask | ice_mask, chn120)
    chn108_ma = np.ma.masked_where(cloud_mask | snow_mask | ice_mask, chn108)

    bt_diff = chn108 - chn120

    # Calculate sun zenith angles
    sza = astronomy.sun_zenith_angle(time, lon, lat)

    minsza = np.min(sza)
    maxsza = np.max(sza)
    logger.debug("Found solar zenith angles from %s to %s°" % (minsza,
                                                               maxsza))

    # Calculate secant of sza
    # secsza = np.ma.masked_where(cloud_mask | snow_mask | ice_mask,
    #                             (1 / np.cos(np.deg2rad(sza))))
    secsza = 1 / np.cos(np.deg2rad(sza))

    # Lookup table for BT difference thresholds at certain sec(sun zenith
    # angles) and 10.8 μm BT
    lut = {260: {1.0: 0.55, 1.25: 0.60, 1.50: 0.65, 1.75: 0.90, 2.0: 1.10},
           270: {1.0: 0.58, 1.25: 0.63, 1.50: 0.81, 1.75: 1.03, 2.0: 1.13},
           280: {1.0: 1.30, 1.25: 1.61, 1.50: 1.88, 1.75: 2.14, 2.0: 2.30},
github pytroll / satpy / satpy / readers / hrpt.py View on Github external
if self.times is None:
            self.times = time_seconds(self._data["timecode"], self.year)
        scanline_nb = len(self.times)
        scan_points = np.arange(0, 2048, 32)
        # scan_points = np.arange(2048)

        sgeom = avhrr(scanline_nb, scan_points, apply_offset=False)
        # no attitude error
        rpy = [0, 0, 0]
        s_times = sgeom.times(
            self.times[:, np.newaxis]).ravel()
        # s_times = (np.tile(sgeom._times[0, :], (scanline_nb, 1)).astype(
        #    'timedelta64[s]') + self.times[:, np.newaxis]).ravel()

        orb = Orbital(self.platform_name)

        pixels_pos = compute_pixels(orb, sgeom, s_times, rpy)
        lons, lats, alts = get_lonlatalt(pixels_pos, s_times)
        self.lons, self.lats = geo_interpolate(
            lons.reshape((scanline_nb, -1)), lats.reshape((scanline_nb, -1)))

        return self.lons, self.lats
github plotly / dash-docs / tutorial / examples / live_updates.py View on Github external
def update_graph_live():
    satellite = Orbital('TERRA')
    data = {
        'time': [],
        'Latitude': [],
        'Longitude': [],
        'Altitude': []
    }

    # Collect some data
    for i in range(180):
        time = datetime.datetime.now() - datetime.timedelta(seconds=i*20)
        lon, lat, alt = satellite.get_lonlatalt(
            time
        )
        data['Longitude'].append(lon)
        data['Latitude'].append(lat)
        data['Altitude'].append(alt)
github sungchun12 / iot-python-webapp / archive / demos / app.py View on Github external
def update_graph_live(n):
    satellite = Orbital("TERRA")
    data = {"time": [], "Latitude": [], "Longitude": [], "Altitude": []}

    # Collect some data
    for i in range(180):
        time = datetime.datetime.now() - datetime.timedelta(seconds=i * 20)
        lon, lat, alt = satellite.get_lonlatalt(time)
        data["Longitude"].append(lon)
        data["Latitude"].append(lat)
        data["Altitude"].append(alt)
        data["time"].append(time)

    # Create the graph with subplots
    fig = plotly.tools.make_subplots(rows=2, cols=1, vertical_spacing=0.2)
    fig["layout"]["margin"] = {"l": 30, "r": 10, "b": 30, "t": 10}
    fig["layout"]["legend"] = {"x": 0, "y": 1, "xanchor": "left"}