def _create_scene(self):
        """Create a scene object from available data.

        Returns
        -------
         satpy.scene.Scene
            Inialized scene object
        """
        data = self.message.data
        filter_parameters = {
            "start_time": data["start_time"] - ORBIT_SLACK,
            "end_time": data["end_time"] + ORBIT_SLACK,
            "platform_name": data["platform_name"],
        }
        filenames = find_files_and_readers(
            base_dir="/viirs/sdr",
            reader="viirs_sdr",
            filter_parameters=filter_parameters,
        )
        try:
            scene = Scene(filenames=filenames, reader="viirs_sdr")
        except ValueError as e:
            logger.exception("Loading files didn't go well: %s", filenames)
            raise e

        return scene
Beispiel #2
0
def step_impl(context):
    from satpy import Scene, find_files_and_readers
    from datetime import datetime
    os.chdir("/tmp/")
    reader_files = find_files_and_readers(sensor="viirs",
                                          start_time=datetime(2015, 3, 11, 11, 20),
                                          end_time=datetime(2015, 3, 11, 11, 26))
    scn = Scene(filenames=reader_files)
    context.available_dataset_ids = scn.available_dataset_ids()
Beispiel #3
0
def step_impl_user_checks_availability(context):
    from satpy import Scene, find_files_and_readers
    from datetime import datetime
    os.chdir("/tmp/")
    reader_files = find_files_and_readers(sensor="viirs",
                                          start_time=datetime(2015, 3, 11, 11, 20),
                                          end_time=datetime(2015, 3, 11, 11, 26))
    scn = Scene(filenames=reader_files)
    context.available_dataset_ids = scn.available_dataset_ids()
Beispiel #4
0
def step_impl(context):
    from satpy import Scene, find_files_and_readers
    from datetime import datetime
    os.chdir("/tmp/")
    readers_files = find_files_and_readers(sensor='viirs',
                                           start_time=datetime(2015, 3, 11, 11, 20),
                                           end_time=datetime(2015, 3, 11, 11, 26))
    scn = Scene(filenames=readers_files)
    scn.load(["M02"])
    context.scene = scn
Beispiel #5
0
def step_impl_user_loads_no_config(context):
    from satpy import Scene, find_files_and_readers
    from datetime import datetime
    os.chdir("/tmp/")
    readers_files = find_files_and_readers(sensor='viirs',
                                           start_time=datetime(2015, 3, 11, 11, 20),
                                           end_time=datetime(2015, 3, 11, 11, 26))
    scn = Scene(filenames=readers_files)
    scn.load(["M02"])
    context.scene = scn
def create_image(path: tp.Optional[str] = None) -> (Scene, tp.Optional[str]):
    """
    Create image of the given satellite data of a SentinelSat-2 satellite
    :param path: Path to the raw satellite data
    :return: (Scene, str), Scene of the satellite image, full path to the .tif create
    """
    files = find_files_and_readers(base_dir=path, reader='msi_safe')

    _scn = Scene(filenames=files)
    _scn.load(['true_color'])

    filename = None
    if path is not None:
        filename = os.path.join(path, 'RGB.tif')
        if not os.path.exists(filename):
            _scn.save_dataset('true_color',
                              filename,
                              writer='simple_image',
                              fill_value=0)
    return _scn, filename
Beispiel #7
0
def return_files(time, hrit_files):
    from satpy import find_files_and_readers
    from datetime import datetime

    first = 0
    last = len(time) - 1
    yearF, monthF, dayF, hourF, minuteF, secondF = time[first].tt_calendar()
    yearL, monthL, dayL, hourL, minuteL, secondL = time[last].tt_calendar()
    if len(time) == 1:
        time[last].tt = time[last].tt + 1 / 3600
        yearL, monthL, dayL, hourL, minuteL, secondL = time[last].tt_calendar()

    files = find_files_and_readers(base_dir=hrit_files,
                                   start_time=datetime(yearF, monthF, dayF,
                                                       hourF, minuteF),
                                   end_time=datetime(yearL, monthL, dayL,
                                                     hourL, minuteL),
                                   reader='seviri_l1b_hrit')

    return files
Beispiel #8
0
def simple_export(hrit_files, time, dpi, photo_path, load_photo=['VIS006']):
    from satpy import Scene
    from satpy import find_files_and_readers
    from datetime import datetime
    import matplotlib as mpl
    mpl.rcParams['figure.dpi'] = dpi
    # load_photo = 'VIS006'

    first = 0
    last = len(time) - 1
    # print(len(time),last)

    yearF, monthF, dayF, hourF, minuteF, secondF = time[first].tt_calendar()
    yearL, monthL, dayL, hourL, minuteL, secondL = time[last].tt_calendar()
    # IT IS NOT WORKING FIND SOLUTION - Adding a minute in case there is only one point on map
    if len(time) == 1:
        time[last].tt = time[last].tt + 1 / 3600
        yearL, monthL, dayL, hourL, minuteL, secondL = time[last].tt_calendar()
        # print("It works")

    # print(yearF, monthF, dayF, hourF, minuteF, secondF )
    # print(yearL, monthL, dayL, hourL, minuteL, secondL)
    # time[0].tt_calendar()[0]
    files = find_files_and_readers(base_dir=hrit_files,
                                   start_time=datetime(yearF, monthF, dayF,
                                                       hourF, minuteF),
                                   end_time=datetime(yearL, monthL, dayL,
                                                     hourL, minuteL),
                                   reader='seviri_l1b_hrit')
    scn = Scene(filenames=files)

    scn.load(load_photo)
    file = photo_path + 'globe_' + load_photo[
        0] + '_{date:%Y-%m-%d_%H_%M_%S}.png'.format(date=scn.start_time)
    scn.save_dataset(load_photo[0],
                     writer='simple_image',
                     filename=file,
                     num_threads=8)

    return ()
Beispiel #9
0
# Exercise 6
from pathlib import Path

input_dir = Path("data")

# 1. Read the Scene that you downloaded from the data directory using SatPy. [2P]
from satpy import Scene, find_files_and_readers, writers, composites

files = find_files_and_readers(
    base_dir="C:/Users/Kochti/Desktop/Studium/Python/exercise-6-TLKoch/data/",
    reader="seviri_l1b_nc")
scn = Scene(filenames=files)

# 2. Load the composites "natural_color" and "convection" [2P]
scn.load(["natural_color"])
scn.load(["convection"])

# 3. Resample the fulldisk to the Dem. Rep. Kongo and its neighbours [4P]
#    by defining your own area in Lambert Azimuthal Equal Area.
#    Use the following settings:
#      - lat and lon of origin: -3/23
#      - width and height of the resulting domain: 500px
#      - projection x/y coordinates of lower left: -15E5
#      - projection x/y coordinates of upper right: 15E5

from pyresample.geometry import AreaDefinition

area_id = "Dem. Rep. Kongo"
description = "Dem. Rep. Kongo and its adjacent areas in Lambert Azimuthal Equal Area projection"
proj_id = "Kongo"
proj_dict = {"proj": "laea", "lat_0": -3, "lon_0": 23}
                                                    time_slot)
    #global_data = GeostationaryFactory.create_scene("meteosat", "10", "seviri", time_slot)

    # read data that you like to correct for parallax and the Cloud Top Height product of the NWC-SAF
    ## ----------------------------------------------------------------------------------------------
    global_data.load(channels)
    if verbose:
        loaded_channels = [c.name for c in global_data.loaded_channels()]
        print loaded_channels

    # read CTH with satpy
    from satpy import Scene, find_files_and_readers
    files_nwc = find_files_and_readers(
        sensor='seviri',
        start_time=time_slot,
        end_time=time_slot,
        #base_dir=time_slot.strftime("/data/COALITION2/database/meteosat/SAFNWC_v2013/%Y/%m/%d/"),
        base_dir=time_slot.strftime(
            "/data/COALITION2/database/meteosat/SAFNWC_v2016/%Y/%m/%d/CTTH/"),
        reader='nc_nwcsaf_msg')
    #print files_nwc
    #files = dict(files_sat.items() + files_nwc.items())
    files = dict(files_nwc.items())
    global_nwc = Scene(filenames=files)
    #global_nwc.load(nwcsaf.product['cloud_top_height']) # this will load a RGB representation
    global_nwc.load(['ctth_alti'])
    if verbose:
        print type(global_nwc['ctth_alti'].values)

    # reproject data to your desired projection
    ## ----------------------------------------
    #area="EuropeCanaryS95"
Beispiel #11
0
def photo_of_area(hrit_files,
                  central_lat,
                  central_lon,
                  elevation,
                  time,
                  dpi,
                  photo_path,
                  load_photo='VIS006',
                  all_lines=True):
    """Return path of photo
    Parameters
    ----------
    parameter_name : parameter_type
        Quick description of it.
    Returns
    -------
    photos: array
        Array of saved on disc files.

    """
    # Loading decompressed previously photos
    from satpy import Scene
    # from glob import glob
    import matplotlib.pyplot as plt
    from satpy import find_files_and_readers
    from datetime import datetime
    import cartopy.crs as ccrs
    import matplotlib as mpl
    mpl.rcParams['figure.dpi'] = dpi
    # load_photo = 'VIS006'

    first = 0
    last = len(time) - 1
    # print(len(time),last)

    yearF, monthF, dayF, hourF, minuteF, secondF = time[first].tt_calendar()
    yearL, monthL, dayL, hourL, minuteL, secondL = time[last].tt_calendar()
    # IT IS NOT WORKING FIND SOLUTION - Adding a minute in case there is only one point on map
    if (len(time) == 1):
        time[last].tt = time[last].tt + 1 / 3600
        yearL, monthL, dayL, hourL, minuteL, secondL = time[last].tt_calendar()
        # print("udalosie")

    # print(yearF, monthF, dayF, hourF, minuteF, secondF )
    # print(yearL, monthL, dayL, hourL, minuteL, secondL)
    time[0].tt_calendar()[0]
    files = find_files_and_readers(base_dir=hrit_files,
                                   start_time=datetime(yearF, monthF, dayF,
                                                       hourF, minuteF),
                                   end_time=datetime(yearL, monthL, dayL,
                                                     hourL, minuteL),
                                   reader='seviri_l1b_hrit')
    scn = Scene(filenames=files)

    scn.load([load_photo])
    new_scn = scn
    crs = new_scn[load_photo].attrs['area'].to_cartopy_crs()

    div = 30
    y, x = polygon_surrounding_sat(central_lat, central_lon, elevation, div)
    extent = calculate_extent(x, y)
    ax = plt.axes(projection=ccrs.Sinusoidal(central_lon, central_lat))
    ax.set_extent(extent)

    if (all_lines):
        ax.gridlines()
        ax.coastlines(resolution='50m', color='red')
        ax.coastlines()

    # ax.gridlines()
    # ax.set_global()
    plt.imshow(new_scn[load_photo],
               transform=crs,
               extent=crs.bounds,
               origin='upper',
               cmap='gray')
    # cbar = plt.colorbar()
    # cbar.set_label("Kelvin")
    # plt.imsave('imsave.png', im, cmap='gray')
    name_img = photo_path + load_photo + "_" + datetime(
        yearF, monthF, dayF, hourF, minuteF).__str__() + '.png'
    plt.savefig(name_img, dpi=dpi)
    # print(name_img)

    return name_img
from satpy.utils import debug_on

debug_on()

from satpy import find_files_and_readers, Scene
from datetime import datetime

files_sat = find_files_and_readers(
    sensor='seviri',
    start_time=datetime(2015, 7, 7, 12, 0),
    end_time=datetime(2015, 7, 7, 12, 0),
    base_dir=
    "/data/COALITION2/database/meteosat/radiance_HRIT/case-studies/2015/07/07/",
    reader="seviri_l1b_hrit")

files = dict(files_sat.items())
global_scene = Scene(
    filenames=files)  # not allowed any more: reader="hrit_msg",
global_scene.load([10.8])

area = "EuropeCanaryS95"
local_scene = global_scene.resample(area)

import numpy as np
from satpy.composites import BWCompositor
from satpy.enhancements import colorize
from satpy.writers import to_image

arr = np.array([[0, 0, 0], [255, 0, 0]])
np.save("/tmp/binary_colormap.npy", arr)
Beispiel #13
0
#                               end_time=datetime(2017, 10, 11, 12, 59),
#                               base_dir="/home/a001673/data/satellite/Sentinel-3",
#                               reader='nc_olci_l1b')
#scn = Scene(filenames=files)"

#def find_files_and_readers(start_time=None, end_time=None, base_dir=None,
#                           reader=None, sensor=None, ppp_config_dir=get_environ_config_dir(),
#                           filter_parameters=None, reader_kwargs=None):

make_rgb = False
if make_rgb:

    files_sat = find_files_and_readers(
        sensor='seviri',
        start_time=datetime(2015, 7, 7, 12, 0),
        end_time=datetime(2015, 7, 7, 12, 0),
        base_dir=
        "/data/COALITION2/database/meteosat/radiance_HRIT/case-studies/2015/07/07/",
        reader='seviri_l1b_hrit')

    global_scene = Scene(filenames=files_sat)
    # global_scene.readers
    # {'seviri_l1b_hrit': <satpy.readers.yaml_reader.GEOSegmentYAMLReader object at 0x7ff6be969df0>}

    #global_scene.load([0.6, 0.8, 10.8])
    #global_scene.load(['IR_120', 'IR_134'])
    global_scene.load(['overview', 0.6, 0.8])
    #print(global_scene.keys())
    #print(global_scene.datasets)

    global_scene.available_dataset_names()
#from satpy.utils import debug_on
#debug_on()

# new version of satpy after 0.8
#################################
from satpy import Scene, find_files_and_readers
from datetime import datetime

#def find_files_and_readers(start_time=None, end_time=None, base_dir=None,
#                           reader=None, sensor=None, ppp_config_dir=get_environ_config_dir(),
#                           filter_parameters=None, reader_kwargs=None):

files = find_files_and_readers(
    sensor='radar',
    start_time=datetime(2018, 4, 27, 12, 0),
    end_time=datetime(2018, 4, 27, 12, 15),
    base_dir="/data/COALITION2/database/radar/odyssey/2018/04/27",
    reader='h5_odyssey')

#print files
global_scene = Scene(filenames=files)

global_scene.load(['rr'])

global_scene.available_dataset_names()
#print(global_scene[0.6])            # works only if you load also the 0.6 channel, but not an RGB that contains the 0.6
#!!# print(global_scene['overview']) ### this one does only work in the develop version

#from satpy import DatasetID
#my_channel_id = DatasetID(name='IR_016', calibration='radiance')
#global_scene.load([my_channel_id])
    - 'NUCAPS-sciEDR_{am_pm:2s}_{platform_shortname:3s}_s{start_time:%Y%m%d%H%M%S}_e{end_time:%Y%m%d%H%M%S}_STC_fsr.nc'

"""

#from satpy.utils import debug_on
#debug_on()
from satpy import Scene, find_files_and_readers
import numpy as np
from datetime import datetime

start_time = datetime.strptime("202003020000070", "%Y%m%d%H%M%S%f")
end_time = datetime.strptime("202003020000370", "%Y%m%d%H%M%S%f")

files_sat = find_files_and_readers(
    start_time=start_time,
    end_time=end_time,  # creation_time=creation_time,
    base_dir="/data/COALITION2/database/NUCAPS/2020/03/02",
    reader='nucaps')
print(files_sat)

global_scene = Scene(reader="nucaps", filenames=files_sat)

var = "H2O_MR"
global_scene.load([var], pressure_levels=True)

#print(global_scene)
#print("============")
print(global_scene[var])
print(type(global_scene[var].data))

var_np = global_scene[var].data.compute()
Beispiel #16
0
def show_overall(hrit_files,
                 central_lat,
                 central_lon,
                 elevation,
                 time,
                 dpi,
                 photo_path,
                 all_lines=False,
                 pro='PlateCarree',
                 load_photo=['VIS006'],
                 save=False):
    """Return path of photo
    Parameters
    ----------
    pro : string
        PlateCarree
        Sinusoidal
    Returns
    -------
    photos: array
        Array of saved on disc files.

    """
    from satpy.scene import Scene
    from satpy import find_files_and_readers
    from datetime import datetime
    import cartopy.crs as ccrs
    import cartopy.feature as cfeature
    import numpy as np
    # %matplotlib inline
    import matplotlib.pyplot as plt

    ### START - CALCULATES OVERALL EXTENT ###
    div = 30
    x, y = [], []
    for i in range(len(central_lat)):
        y_temp, x_temp = polygon_surrounding_sat(central_lat[i],
                                                 central_lon[i], elevation[i],
                                                 div)
        x = np.append(x, x_temp)
        y = np.append(y, y_temp)

    extent = calculate_extent(x, y)
    ### END - CALCULATES OVERALL EXTENT ###

    first = 0
    last = len(time) - 1

    yearF, monthF, dayF, hourF, minuteF, secondF = time[first].tt_calendar()
    yearL, monthL, dayL, hourL, minuteL, secondL = time[last].tt_calendar()
    if len(time) == 1:
        time[last].tt = time[last].tt + 1 / 3600
        yearL, monthL, dayL, hourL, minuteL, secondL = time[last].tt_calendar()

    # print(yearF, monthF, dayF, hourF, minuteF, secondF )
    # print(yearL, monthL, dayL, hourL, minuteL, secondL)
    # time[0].tt_calendar()[0]
    files = find_files_and_readers(base_dir=hrit_files,
                                   start_time=datetime(yearF, monthF, dayF,
                                                       hourF, minuteF),
                                   end_time=datetime(yearL, monthL, dayL,
                                                     hourL, minuteL),
                                   reader='seviri_l1b_hrit')
    scn = Scene(filenames=files)
    scn.load(load_photo)
    new_scn = scn
    crs = new_scn[load_photo[0]].attrs['area'].to_cartopy_crs()
    # ax = plt.axes(projection=crs)
    central_lon, central_lat = (extent[0] + extent[1]) / 2, (extent[2] +
                                                             extent[3]) / 2

    if pro == 'PlateCarree':
        ax = plt.axes(projection=ccrs.PlateCarree())
        pro_name = '_PlateCarree_'
        ax.set_global()
    if pro == 'Sinusoidal':
        ax = plt.axes(projection=ccrs.Sinusoidal(central_lon, central_lat))
        ax.set_extent(extent)
        pro_name = '_Sinusoidal_'

    if all_lines:
        ax.coastlines(color='red')
        ax.gridlines(color='red')
        ax.add_feature(cfeature.BORDERS, color='red')
        pro_name = pro_name + 'lines_'

    plt.imshow(new_scn[load_photo[0]],
               transform=crs,
               extent=crs.bounds,
               origin='upper',
               cmap='gray')

    if save:
        if isinstance(load_photo[0], float):
            photo_type = str(load_photo[0])
        else:
            photo_type = load_photo[0]
        name = photo_path + photo_type + pro_name + '_{date:%Y-%m-%d_%H_%M_%S}.png'.format(
            date=scn.start_time)
        plt.savefig(name, dpi=dpi)
    if not save:
        plt.show()

    return ()
Beispiel #17
0
def set_of_photos(hrit_files,
                  central_lat,
                  central_lon,
                  elevation,
                  time,
                  dpi,
                  photo_path,
                  all_lines=False,
                  load_photo=['VIS006']):
    """Return path of photo
    Parameters
    ----------
    parameter_name : parameter_type
        Quick description of it.
    Returns
    -------
    photos: array
        Array of saved on disc files.

    """
    # Loading decompressed previously photos
    from satpy import Scene
    import numpy as np
    # from glob import glob
    import matplotlib.pyplot as plt
    from satpy import find_files_and_readers
    from datetime import datetime
    import cartopy.crs as ccrs
    import matplotlib as mpl
    mpl.rcParams['figure.dpi'] = dpi
    # load_photo = 'VIS006'

    first = 0
    last = len(time) - 1
    # print(len(time),last)

    yearF, monthF, dayF, hourF, minuteF, secondF = time[first].tt_calendar()
    yearL, monthL, dayL, hourL, minuteL, secondL = time[last].tt_calendar()
    # IT IS NOT WORKING FIND SOLUTION - Adding a minute in case there is only one point on map
    if len(time) == 1:
        time[last].tt = time[last].tt + 1 / 3600
        yearL, monthL, dayL, hourL, minuteL, secondL = time[last].tt_calendar()
        # print("udalosie")

    # print(yearF, monthF, dayF, hourF, minuteF, secondF )
    # print(yearL, monthL, dayL, hourL, minuteL, secondL)
    # time[0].tt_calendar()[0]
    files = find_files_and_readers(base_dir=hrit_files,
                                   start_time=datetime(yearF, monthF, dayF,
                                                       hourF, minuteF),
                                   end_time=datetime(yearL, monthL, dayL,
                                                     hourL, minuteL),
                                   reader='seviri_l1b_hrit')
    scn = Scene(filenames=files)
    load_photo = scn.available_dataset_names()
    # HRV does not work properly
    load_photo.remove('HRV')
    # print(load_photo)
    # print(scn.available_dataset_names())

    div = 30
    name_img = []
    for photo_type in load_photo:
        # print(photo_type)
        scn.load([photo_type])
        # print(scn)
        for i in range(len(time)):
            new_scn = scn
            # print(new_scn)
            crs = new_scn[photo_type].attrs['area'].to_cartopy_crs()
            y, x = polygon_surrounding_sat(central_lat[i], central_lon[i],
                                           elevation[i], div)
            extent = calculate_extent(x, y)
            ax = plt.axes(
                projection=ccrs.Sinusoidal(central_lon[i], central_lat[i]))
            ax.set_extent(extent)

            if (all_lines):
                ax.gridlines()
                ax.coastlines(resolution='50m', color='red')
                ax.coastlines()

            # ax.gridlines()
            # ax.set_global()
            plt.imshow(new_scn[photo_type],
                       transform=crs,
                       extent=crs.bounds,
                       origin='upper',
                       cmap='gray')
            # cbar = plt.colorbar()
            # cbar.set_label("Kelvin")
            # plt.imsave('imsave.png', im, cmap='gray')
            name = photo_path + photo_type + "_" + time[i].utc_iso() + '.png'
            plt.savefig(name, dpi=dpi)
            name_img = np.append(name_img, name)

    return (name_img)
Beispiel #18
0
from datetime import datetime
from satpy import Scene, find_files_and_readers
from pyresample import load_area

from eoana.config import Settings

if __name__ == '__main__':
    settings = Settings()

    sen3_data_l2 = 'C:/Temp/Satellit/sentinel_data'

    # datetime(YEAR, MOMNTH, DAY, HOUR, MINUTE)
    filenames = find_files_and_readers(
        start_time=datetime(2021, 7, 25, 7, 20),
        end_time=datetime(2021, 7, 25, 11, 25),
        base_dir=sen3_data_l2,
        reader='olci_l2',
        sensor='olci',
    )
    """ Create Scene object """
    scn = Scene(filenames=filenames)
    """ Load selected datasets 
        Available OLCI Level 2 datasets are:
            'chl_nn.nc','chl_oc4me.nc',
            'iop_nn.nc','iwv.nc','par.nc','trsp.nc','tsm_nn.nc','w_aer.nc',
            'Oa01_reflectance.nc','Oa02_reflectance.nc','Oa03_reflectance.nc','Oa04_reflectance.nc',
            'Oa05_reflectance.nc','Oa06_reflectance.nc','Oa07_reflectance.nc','Oa08_reflectance.nc',
            'Oa09_reflectance.nc','Oa10_reflectance.nc','Oa11_reflectance.nc','Oa12_reflectance.nc',
            'Oa16_reflectance.nc','Oa17_reflectance.nc','Oa18_reflectance.nc','Oa21_reflectance.nc',
            'wqsf.nc'
    """
Beispiel #19
0
def read_GOES_satpy(date_str, channel, zoom = True):


    # Extract the channel wavelength using the input string
    # -----------------------------------------------------
    channel = channel_dict[str(channel)]['wavelength']

    # Determine the correct GOES files associated with the date
    # ---------------------------------------------------------
    dt_date_str = datetime.strptime(date_str,"%Y%m%d%H%M")
    dt_date_str_end = dt_date_str + timedelta(minutes = 10)

    # Use the Satpy find_files_and_readers to grab the files
    # ------------------------------------------------------
    files = find_files_and_readers(start_time = dt_date_str, \
        end_time = dt_date_str_end, base_dir = data_dir, reader = 'abi_l1b')

    print(files)

    # Extract the goes true-color plot limits
    # ----------------------------------------
    lat_lims = [29.5, 48.0]
    lon_lims = [-122.0, -100.5]

    # Use satpy (Scene) to open the file
    # ----------------------------------
    scn = Scene(reader = 'abi_l1b', filenames = files)

    # Load the desired channel data
    # -----------------------------
    scn.load([channel], calibration = [calib_dict[channel]])

    ## Set the map projection and center the data
    ## ------------------------------------------
    #my_area = scn[channel].attrs['area'].compute_optimal_bb_area({\
    #    'proj':'lcc', 'lon_0': lon_lims[0], 'lat_0': lat_lims[0], \
    #    'lat_1': lat_lims[0], 'lat_2': lat_lims[0]})
    #new_scn = scn.resample(my_area)

    ##!## Enhance the image for plotting
    ##!## ------------------------------
    ##!#var = get_enhanced_image(scn[channel]).data
    ##!#var = var.transpose('y','x','bands')

    # Zoom the image on the desired area
    # ----------------------------------
    if(zoom):
        scn = scn.crop(ll_bbox = (lon_lims[0] + 0.65, lat_lims[0], \
            lon_lims[1] - 0.65, lat_lims[1]))


    # Extract the lats, lons, and data
    # -----------------------------------------------------
    lons, lats = scn[channel].attrs['area'].get_lonlats()
    var = scn[channel].data

    # Extract the map projection from the data for plotting
    # -----------------------------------------------------
    crs = scn[channel].attrs['area'].to_cartopy_crs()

    # Extract the appropriate units
    # -----------------------------
    units = label_dict[channel]
    #units = scn[channel].units
    plabel = calib_dict[channel].title() + ' [' + units + ']'

    return var, crs, lons, lats, lat_lims, lon_lims, plabel
    # substracting one scan time (as the start time of scan is returned)
    t1 -= timedelta(seconds=nmin * 60)
    LOG.info("    start time of last scan: " + str(t1))

    return t1


sat = "MSG3"

start_time = get_last_SEVIRI_date(True, delay=5)
print(start_time)

files_sat = find_files_and_readers(sensor='seviri',
                                   start_time=start_time,
                                   end_time=start_time,
                                   base_dir="/data/cinesat/in/eumetcast1/",
                                   reader='seviri_l1b_hrit')

files = deepcopy(files_sat['seviri_l1b_hrit'])
for f in files:
    if not (sat in f):
        files_sat['seviri_l1b_hrit'].remove(f)
        continue

global_scene = Scene(reader="seviri_l1b_hrit", filenames=files_sat)

print("")
print("=======================")
print(dir(global_scene))
print("=======================")
    show_interactively = False
    save_black_white_png = False

    print("")
    print("")
    print("*** Creating LSCL (low stratus confidence level) product")
    print("")

    # read MSG (full disk service) L2
    #################################
    print("... read " + sat + " L1.5 data")
    print("    search for HRIT files in " + base_dir_sat)

    files_sat = find_files_and_readers(sensor='seviri',
                                       start_time=start_time,
                                       end_time=start_time,
                                       base_dir=base_dir_sat,
                                       reader='seviri_l1b_hrit')

    files = deepcopy(files_sat['seviri_l1b_hrit'])
    #print("    found SEVIRI files: ", files_sat)
    for f in files:
        if not (sat in f):
            files_sat['seviri_l1b_hrit'].remove(f)
            continue
        if ("HRV" in f) or ("VIS006" in f) or ("VIS008" in f) or (
                "IR_016" in f) or ("IR_039" in f):
            files_sat['seviri_l1b_hrit'].remove(f)
            continue
        if ("WV_062" in f) or ("WV_073" in f) or ("IR_097" in f) or (
                "IR_108" in f) or ("IR_134" in f):
    def colorplot_with_band(self,
                            band,
                            HSD_Dir,
                            imgFile,
                            *args,
                            axLatRange=[20, 60],
                            axLonRange=[90, 140],
                            cmap=None,
                            pixels=100,
                            **kwargs):
        """
        colorplot the variables together with radiance data.

        Parameters
        ----------
        band: int
            band number [1-16]. See band specification in
            `../doc/2018_A_Yamashita.md`
        HSD_Dir: str
            path for hosting the HSD files.
        imgFile: str
            filename of the exported image
        Keywords
        --------
        axLatRange: list
            latitude range of the plot (default: [20, 60]). [degree]
        axLonRange: list
            longitude range of the plot (default: [90, 140]). [degree]
        cmap: str
            colormap name.
        pixels: int
            resampled pixels of the band data (default: 100). Take care of
            time consumption when pixels > 1000!
        History
        -------
        2020-02-24 First version.
        """

        files = find_files_and_readers(
            start_time=(self.mTime - dt.timedelta(seconds=300)),
            end_time=(self.mTime + dt.timedelta(seconds=300)),
            base_dir=HSD_Dir,
            reader='ahi_hsd')

        matched_files = []
        for file in files['ahi_hsd']:
            if fnmatch.fnmatch(
                    os.path.basename(file),
                    'HS_H08_*_B{0:02d}_FLDK_*_S0[1234]*DAT*'.format(band)):
                matched_files.append(file)

        h8_scene = Scene(filenames=matched_files,
                         reader='ahi_hsd',
                         sensor='ahi')
        band_label = 'B{0:02d}'.format(band)
        h8_scene.load([band_label])

        roi = create_area_def('roi', {
            'proj': 'eqc',
            'ellps': 'WGS84'
        },
                              width=pixels,
                              height=pixels,
                              area_extent=[
                                  axLonRange[0], axLatRange[0], axLonRange[1],
                                  axLatRange[1]
                              ],
                              units='degrees')
        roi_scene = h8_scene.resample(roi)

        # read China boundaries
        with open(os.path.join(PROJECTDIR, 'include', 'CN-border-La.dat'),
                  'r') as fd:
            context = fd.read()
            blocks = [cnt for cnt in context.split('>') if len(cnt) > 0]
            borders = [
                np.fromstring(block, dtype=float, sep=' ') for block in blocks
            ]

        LON, LAT = np.meshgrid(self.lon, self.lat)
        fig = plt.figure(figsize=[8, 8])
        plt.tight_layout(False)

        # Set projection and plot the main figure
        ax1 = plt.axes([0.1, 0.1, 0.8, 0.8], projection=ccrs.PlateCarree())

        # Add ocean, land, rivers and lakes
        ax1.add_feature(cfeature.OCEAN.with_scale('50m'))
        ax1.add_feature(cfeature.LAND.with_scale('50m'))
        ax1.add_feature(cfeature.RIVERS.with_scale('50m'))
        ax1.add_feature(cfeature.LAKES.with_scale('50m'))

        # Plot border lines
        for line in borders:
            ax1.plot(line[0::2],
                     line[1::2],
                     '-',
                     lw=1,
                     color='k',
                     transform=ccrs.Geodetic())

        # loading colormap
        if cmap is None:
            cmap = chiljet_colormap()

        # Plot gridlines
        crs = roi.to_cartopy_crs()
        pcmesh_band = ax1.imshow(roi_scene[band_label],
                                 transform=crs,
                                 origin='upper',
                                 extent=crs.bounds,
                                 cmap='Greys')
        pcmesh = ax1.pcolormesh(LON,
                                LAT,
                                self.data,
                                vmin=kwargs['vmin'],
                                vmax=kwargs['vmax'],
                                cmap=cmap,
                                transform=ccrs.PlateCarree())

        ax1.set_xticks(
            np.linspace(axLonRange[0], axLonRange[1], 5, endpoint=True))
        ax1.set_yticks(
            np.linspace(axLatRange[0], axLatRange[1], 5, endpoint=True))
        lon_formatter = LongitudeFormatter(number_format='.1f',
                                           degree_symbol='',
                                           dateline_direction_label=True)
        lat_formatter = LatitudeFormatter(number_format='.1f',
                                          degree_symbol='')
        ax1.xaxis.set_major_formatter(lon_formatter)
        ax1.yaxis.set_major_formatter(lat_formatter)
        ax1.set_ylim(axLatRange)
        ax1.set_xlim(axLonRange)

        ax1.set_title('{0} {1}'.format(
            self.mTime.strftime('%Y-%m-%d %H:%M (Himawari-8)'),
            self.long_name))

        if 'cb_ticks' not in kwargs.keys():
            kwargs['cb_ticks'] = np.linspace(kwargs['vmin'],
                                             kwargs['vmax'],
                                             5,
                                             endpoint=True)

        cbar = fig.colorbar(pcmesh,
                            fraction=0.03,
                            ticks=kwargs['cb_ticks'],
                            orientation='vertical')
        cbar.ax.tick_params(direction='out', labelsize=15, pad=5)
        cbar.ax.set_title(self.unit, fontsize=10)

        if 'cb_ticklabels' in kwargs.keys():
            cbar.ax.set_yticklabels(kwargs['cb_ticklabels'])

        # Show figure
        # plt.show()
        plt.savefig(imgFile)
        plt.close()
Beispiel #23
0
    def __init__(self,
                 filenames=None,
                 reader=None,
                 filter_parameters=None,
                 reader_kwargs=None,
                 ppp_config_dir=get_environ_config_dir(),
                 base_dir=None,
                 sensor=None,
                 start_time=None,
                 end_time=None,
                 area=None):
        """Initialize Scene with Reader and Compositor objects.

        To load data `filenames` and preferably `reader` must be specified. If `filenames` is provided without `reader`
        then the available readers will be searched for a Reader that can support the provided files. This can take
        a considerable amount of time so it is recommended that `reader` always be provided. Note without `filenames`
        the Scene is created with no Readers available requiring Datasets to be added manually::

            scn = Scene()
            scn['my_dataset'] = Dataset(my_data_array, **my_info)

        Args:
            filenames (iterable or dict): A sequence of files that will be used to load data from. A ``dict`` object
                                          should map reader names to a list of filenames for that reader.
            reader (str or list): The name of the reader to use for loading the data or a list of names.
            filter_parameters (dict): Specify loaded file filtering parameters.
                                      Shortcut for `reader_kwargs['filter_parameters']`.
            reader_kwargs (dict): Keyword arguments to pass to specific reader instances.
            ppp_config_dir (str): The directory containing the configuration files for satpy.
            base_dir (str): (DEPRECATED) The directory to search for files containing the
                            data to load. If *filenames* is also provided,
                            this is ignored.
            sensor (list or str): (DEPRECATED: Use `find_files_and_readers` function) Limit used files by provided
                                  sensors.
            area (AreaDefinition): (DEPRECATED: Use `filter_parameters`) Limit used files by geographic area.
            start_time (datetime): (DEPRECATED: Use `filter_parameters`) Limit used files by starting time.
            end_time (datetime): (DEPRECATED: Use `filter_parameters`) Limit used files by ending time.

        """
        super(Scene, self).__init__()
        # Set the PPP_CONFIG_DIR in the environment in case it's used elsewhere in pytroll
        LOG.debug("Setting 'PPP_CONFIG_DIR' to '%s'", ppp_config_dir)
        os.environ["PPP_CONFIG_DIR"] = self.ppp_config_dir = ppp_config_dir

        if not filenames and (start_time or end_time or base_dir):
            import warnings
            warnings.warn(
                "Deprecated: Use " +
                "'from satpy import find_files_and_readers' to find files")
            from satpy import find_files_and_readers
            filenames = find_files_and_readers(
                start_time=start_time,
                end_time=end_time,
                base_dir=base_dir,
                reader=reader,
                sensor=sensor,
                ppp_config_dir=self.ppp_config_dir,
                reader_kwargs=reader_kwargs,
            )
        elif start_time or end_time or area:
            import warnings
            warnings.warn(
                "Deprecated: Use " +
                "'filter_parameters' to filter loaded files by 'start_time', "
                + "'end_time', or 'area'.")
            fp = filter_parameters if filter_parameters else {}
            fp.update({
                'start_time': start_time,
                'end_time': end_time,
                'area': area,
            })
            filter_parameters = fp
        if filter_parameters:
            if reader_kwargs is None:
                reader_kwargs = {}
            reader_kwargs.setdefault('filter_parameters',
                                     {}).update(filter_parameters)

        if filenames and isinstance(filenames, str):
            raise ValueError(
                "'filenames' must be a list of files: Scene(filenames=[filename])"
            )

        self.readers = self.create_reader_instances(
            filenames=filenames, reader=reader, reader_kwargs=reader_kwargs)
        self.attrs.update(self._compute_metadata_from_readers())
        self.datasets = DatasetDict()
        self.cpl = CompositorLoader(self.ppp_config_dir)
        comps, mods = self.cpl.load_compositors(self.attrs['sensor'])
        self.wishlist = set()
        self.dep_tree = DependencyTree(self.readers, comps, mods)
        self.resamplers = {}
# Exercise 6
from pathlib import Path
import satpy
from pyresample.geometry import AreaDefinition
from utils import createResArea

input_dir = Path("data")
input_dir.mkdir(parents=True, exist_ok=True)
plot_dir = Path("plots")
plot_dir.mkdir(parents=True, exist_ok=True)
# 1. Read the Scene that you downloaded from the data directory using SatPy. [2P]
files = satpy.find_files_and_readers(base_dir=input_dir)
scn = satpy.Scene(files)

# 2. Load the composites "natural_color" and "convection" [2P]
scn.load(["natural_color", "convection"])

# 3. Resample the fulldisk to the Dem. Rep. Kongo and its neighbours [4P]
#    by defining your own area in Lambert Azimuthal Equal Area.
#    Use the following settings:
#      - lat and lon of origin: -3/23
#      - width and height of the resulting domain: 500px
#      - projection x/y coordinates of lower left: -15E5
#      - projection x/y coordinates of upper right: 15E5

# resample to defined area (using function from utils)
def_area = createResArea(
    area_ID="Kongo",
    description=
    "The Kongo and neighbouring countries in Lambert Equal Area projection",
    proj_id="LambertEqualArea",
Beispiel #25
0
del(combined.attrs['wavelength'])
del(combined.attrs['resolution'])
del(combined.attrs['polarization'])
del(combined.attrs['calibration'])
del(combined.attrs['level'])
del(combined.attrs['start_time'])
del(combined.attrs['end_time'])

from satpy import Scene, find_files_and_readers
from datetime import datetime

start_time    = datetime.strptime("202002031333190", "%Y%m%d%H%M%S%f")
end_time      = datetime.strptime("202002031333190", "%Y%m%d%H%M%S%f")

files_sat = find_files_and_readers(start_time=start_time, end_time=end_time, 
                           base_dir="/data/COALITION2/database/NUCAPS/2020/02/03",
                           reader='nucaps',prerequisites=[DatasetID('hej')])  
global_scene = Scene(reader="nucaps", filenames=files_sat)
global_scene.load(["Temperature"],pressure_levels=True)



del(global_scene[var].attrs['wavelength'])
del(global_scene[var].attrs['resolution'])
del(global_scene[var].attrs['polarization'])
del(global_scene[var].attrs['calibration'])
del(global_scene[var].attrs['level'])
del(global_scene[var].attrs['modifiers'])
global_scene[var].attrs.shape = (120,100)
global_scene[var].attrs['start_time'] = str(global_scene[var].attrs['start_time'])
global_scene[var].attrs['end_time'] = str(global_scene[var].attrs['end_time'])
# Exercise 6
from satpy import Scene, find_files_and_readers, writers, composites


input_dir  = "/home/eike/Documents/studium/10_Semester/python_kurs/exercise-6-eikeschott/data/"
output_dir= "/home/eike/Documents/studium/10_Semester/python_kurs/exercise-6-eikeschott/data/output"

# 1. Read the Scene that you downloaded from the data directory using SatPy. [2P]
files = find_files_and_readers(base_dir=input_dir, reader="seviri_l1b_nc")
scn = Scene(filenames=files)

# 2. Load the composites "natural_color" and "convection" [2P]
scn.load(["natural_color"])
scn.load(["convection"])

# 3. Resample the fulldisk to the Dem. Rep. Kongo and its neighbours [4P] 
#    by defining your own area in Lambert Azimuthal Equal Area. 
#    Use the following settings:
#      - lat and lon of origin: -3/23
#      - width and height of the resulting domain: 500px
#      - projection x/y coordinates of lower left: -15E5
#      - projection x/y coordinates of upper right: 15E5 

area_id = "Dem. Rep. Kongo"
description = "Dem. Rep. Kongo und Umgebung in der Lambert Azimuthal Equal Area Projektion"
proj_id = "Dem. Rep. Kongo"
proj_dict = {"proj": "laea", "lat_ts": -3, "lon_0": 23}

width = 500
height = 500
Beispiel #27
0
# -*- coding: utf-8 -*-
"""
Created on Tue May 28 11:09:38 2019

@author: bav
"""

from satpy.scene import Scene
from satpy import find_files_and_readers
from datetime import datetime

files = find_files_and_readers(sensor='olci',
                               start_time=datetime(2017, 7, 15, 0, 0, 0),
                               end_time=datetime(2017, 7, 16, 0, 0, 0),
                               base_dir=".\OLCI scenes",
                               reader='olci_l1b')

scn = Scene(filenames=files)
scn.load(['true_color'])

scn.save_dataset('true_color', filename='scene' + '.png')
Beispiel #28
0
# Exercise 6
from pathlib import Path

main_dir = Path("./")
output_dir = main_dir / "results"
import utils as uts
# 1. Read the Scene that you downloaded from the data directory using SatPy. [2P]
import satpy as satpy

files = satpy.find_files_and_readers(base_dir="./data", reader="seviri_l1b_nc")
scn = satpy.Scene(filenames=files)  #save it as a satpy scene
scn.available_composite_names()  #to check which composites are aviable
# 2. Load the composites "natural_color" and "convection" [2P]
scn.load(["natural_color"])  # can be skipped thanks to function printSatImg
scn.load(["convection"])  # can be skipped thanks to function printSatImg
# 3. Resample the fulldisk to the Dem. Rep. Kongo and its neighbours [4P]
#    by defining your own area in Lambert Azimuthal Equal Area.
#    Use the following settings:
#      - lat and lon of origin: -3/23
#      - width and height of the resulting domain: 500px
#      - projection x/y coordinates of lower left: -15E5
#      - projection x/y coordinates of upper right: 15E5
# see function printSatImg in Task 4
# 4. Save both loaded composites of the resampled Scene as simple png images. [2P]
uts.dirCreate(output_dir)
uts.printSatImg(scn=scn,
                scene="natural_color",
                proj="laea",
                lat_or=-3,
                lon_or=23,
                width=500,
Beispiel #29
0
# import os
# os.environ['PROJ_LIB'] = '/_PYTHON_INSTALLATION_PATH_/Library/share/proj'

import numpy as np
from datetime import datetime
from satpy import Scene, find_files_and_readers
from senplot.plotting.map import PlotSatProd

if __name__ == '__main__':
    sen3_data_l2 = 'C:/Temp/Satellit/sentinel_data'

    # datetime(YEAR, MOMNTH, DAY, HOUR, MINUTE)
    filenames = find_files_and_readers(
        start_time=datetime(2020, 6, 1, 7, 10),
        end_time=datetime(2020, 6, 1, 12, 50),
        base_dir=sen3_data_l2,
        reader='slstr_l2',
        sensor='slstr_l2',
    )
    """ Create Scene object """
    scn = Scene(filenames=filenames)
    """ Load selected datasets 
        Available SLSTR Level 2 datasets are: 
            'sea_surface_temperature', 'longitude', 'latitude'
    """
    datasets = ['sea_surface_temperature', 'longitude', 'latitude']
    scn.load(datasets)
    """ Resample data to grid (projecting) """
    # area_spec = 'baws'  # 1000 m resolution grid over the Baltic Sea incl. Kattegatt and Skagerrak
    # scn = scn.resample(area_spec, radius_of_influence=1000)
    """ Temperature data are stored as Kelvin degrees. Convert to Celsius values: """
        start_time = get_last_SEVIRI_date(False, delay=3)
        end_time = start_time
        base_dir = "/data/cinesat/in/eumetcast1/"

    #file_pattern='S_NWC_' + product + '_' + sat_id + '_*_' + timestamp_NWCSAF + extension
    #if glob.glob(file_pattern):
    #    print ("NWCSAF data product " + product + " exists and is readable")
    #    # creates list of available products
    #    product_list_to_process.append(nwcsaf.product.get(product)[:])
    #else:
    #    print ("NWCSAF data product " + product + " is missing or is not readable")

    print("... search files in " + base_dir)
    files_nwc = find_files_and_readers(sensor='seviri',
                                       start_time=start_time,
                                       end_time=end_time,
                                       base_dir=base_dir,
                                       reader='nwcsaf-geo')
    #print (files_nwc)
    #files = dict(files_sat.items() + files_nwc.items())
    files = dict(list(files_nwc.items()))

    global_scene = Scene(filenames=files)

    global_scene.available_dataset_names()
    #!!# print(global_scene['overview']) ### this one does only work in the develop version
    print("")
    print("available_composite_names")
    print(global_scene.available_composite_names())

    if make_images:
Beispiel #31
0
# import os
# os.environ['PROJ_LIB'] = '/_PYTHON_INSTALLATION_PATH_/Library/share/proj'

import numpy as np
from datetime import datetime
from satpy import Scene, find_files_and_readers
from senplot.plotting.map import PlotSatProd

if __name__ == '__main__':
    sen3_data_l2 = 'C:/Temp/Satellit/sentinel_data'

    # datetime(YEAR, MOMNTH, DAY, HOUR, MINUTE)
    filenames = find_files_and_readers(
        start_time=datetime(2021, 2, 13, 7, 10),
        end_time=datetime(2021, 2, 13, 12, 50),
        base_dir=sen3_data_l2,
        reader='olci_l2',
        sensor='olci',
    )
    """ Create Scene object """
    scn = Scene(filenames=filenames)
    """ Load selected datasets 
        Available OLCI Level 2 datasets are:
            'chl_nn.nc','chl_oc4me.nc',
            'iop_nn.nc','iwv.nc','par.nc','trsp.nc','tsm_nn.nc','w_aer.nc',
            'Oa01_reflectance.nc','Oa02_reflectance.nc','Oa03_reflectance.nc','Oa04_reflectance.nc','Oa05_reflectance.nc','Oa06_reflectance.nc','Oa07_reflectance.nc','Oa08_reflectance.nc','Oa09_reflectance.nc','Oa10_reflectance.nc','Oa11_reflectance.nc','Oa12_reflectance.nc','Oa16_reflectance.nc','Oa17_reflectance.nc','Oa18_reflectance.nc','Oa21_reflectance.nc',
            'wqsf.nc'
    """
    datasets = [
        'chl_nn',
        # 'chl_oc4me',