def geo_filter(pdf, outside=True, areaid='euron1'):
    """
    Filter data according to position. All data inside area are ignored
    """
    from pyresample import spherical_geometry, utils

    area = utils.load_area(
        '/local_disk/src/mpop-devel/mpop-smhi/etc/areas.def', areaid)

    # lons = np.array([ pdf['lon'][i] for i in pdf.index ])
    # lats = np.array([ pdf['lat'][i] for i in pdf.index ])

    idx_selected = []
    for idx in pdf.index:
        try:
            loc = spherical_geometry.Coordinate(pdf['lon'][idx],
                                                pdf['lat'][idx])
        except ValueError:
            import pdb
            pdb.set_trace()

        is_inside = spherical_geometry.point_inside(loc, area.corners)
        if ((outside and not is_inside) or (not outside and is_inside)):
            idx_selected.append(idx)

    return pdf.loc[idx_selected, :]
def geo_filter(pdf, outside=True, areaid='euron1'):
    """
    Filter data according to position. All data inside area are ignored
    """
    from pyresample import spherical_geometry, utils

    area = utils.load_area(
        '/local_disk/src/mpop-devel/mpop-smhi/etc/areas.def', areaid)

    # lons = np.array([ pdf['lon'][i] for i in pdf.index ])
    # lats = np.array([ pdf['lat'][i] for i in pdf.index ])

    idx_selected = []
    for idx in pdf.index:
        try:
            loc = spherical_geometry.Coordinate(
                pdf['lon'][idx], pdf['lat'][idx])
        except ValueError:
            import pdb
            pdb.set_trace()

        is_inside = spherical_geometry.point_inside(loc, area.corners)
        if ((outside and not is_inside) or
                (not outside and is_inside)):
            idx_selected.append(idx)

    return pdf.loc[idx_selected, :]
Esempio n. 3
0
 def test_norotation_yaml(self):
     yamlDef = """regionB:
       description: regionB
       projection:
         a: 6378137.0
         b: 6378137.0
         lon_0: -34
         proj: merc
         x_0: 0
         y_0: 0
         k_0: 1
       shape:
         height: 548
         width: 800
       area_extent:
         lower_left_xy: [-7761424.714818418, -4861746.639279127]
         upper_right_xy: [11136477.43264252, 8236799.845095873]
       units: m"""
     fyaml = "/tmp/TestProjRotation_test_rotation_yaml.txt"
     f = open(fyaml, "w")
     f.write(yamlDef)
     f.close()
     test_area = load_area(fyaml, 'regionB')
     self.assertEqual(test_area.rotation, 0)
     os.remove(fyaml)
def format_conversion(mda, scene, job_id, publish_q):
    """Read the hdf5 file and add parameters and convert to netCDF

    """
    try:
        LOG.debug("IASI L2 format converter: Start...")

        dummy, fname = os.path.split(scene['filename'])
        tempfile.tempdir = OUTPUT_PATH

        area_def = pr_utils.load_area(AREA_DEF_FILE, AREA_ID)

        # Check if the granule is inside the area of interest:
        inside = granule_inside_area(scene['starttime'],
                                     scene['endtime'],
                                     scene['platform_name'],
                                     area_def)

        if not inside:
            LOG.info("Data outside area of interest. Ignore...")
            return

        # File conversion hdf5 -> nc:
        LOG.info("Read the IASI hdf5 file %s", scene['filename'])
        l2p = iasilvl2(scene['filename'])
        nctmpfilename = tempfile.mktemp()
        l2p.ncwrite(nctmpfilename)
        local_path_prefix = os.path.join(OUTPUT_PATH, fname.split('.')[0])
        result_file = local_path_prefix + '_vprof.nc'
        LOG.info("Rename netCDF file %s to %s", l2p.nc_filename, result_file)
        os.rename(l2p.nc_filename, result_file)

        pubmsg_vprof = create_message(result_file, mda)
        LOG.info("Sending: " + str(pubmsg_vprof))
        publish_q.put(pubmsg_vprof)

        nctmpfilename = tempfile.mktemp()
        result_file = local_path_prefix + '_vcross.nc'
        l2p.ncwrite(nctmpfilename, vprof=False)
        LOG.info("Rename netCDF file %s to %s", l2p.nc_filename, result_file)
        os.rename(l2p.nc_filename, result_file)

        pubmsg = create_message(result_file, mda)
        LOG.info("Sending: " + str(pubmsg))
        publish_q.put(pubmsg)

        if isinstance(job_id, datetime):
            dt_ = datetime.utcnow() - job_id
            LOG.info("IASI level-2 netCDF file " + str(job_id) +
                     " finished. It took: " + str(dt_))
        else:
            LOG.warning(
                "Job entry is not a datetime instance: " + str(job_id))

    except:
        LOG.exception('Failed in IASI L2 format converter...')
        raise
Esempio n. 5
0
def wrapper(date):
    print date
    test1 = datetime.datetime.now()

    # Pull out cloud mask data to be regridded and added to the nc file
    # glob is used for a wildcard
    try:
        clouddata = pygrib.open(
            glob.glob(
                '/soge-home/projects/seviri_dust/raw_seviri_data/cloudmask_grib/MSG*-'
                'SEVI-MSGCLMK-0100-0100-' + date.strftime("%Y%m%d%H%M%S") +
                '*')[0])
        grb = clouddata.select()[0]
        cloudmaskarray = grb.values[:, ::-1]
        cloudlats, cloudlons = grb.latlons()

        cloudmaskarray[cloudmaskarray >= 3] = np.nan
        cloudlats[cloudlats > 90] = np.nan
        cloudlons[cloudlons > 180] = np.nan

        target_area = utils.load_area(
            '/soge-home/projects/seviri_dust/areas.def', 'NorthAfrica')
        lons, lats = target_area.get_lonlats()

        # Generate a regular lat/lon grid for the cloud mask
        #regular_lons = np.linspace(np.min(lons), np.max(lons), lons.shape[1])
        #regular_lats = np.linspace(np.min(lats), np.max(lats), lats.shape[0])

        # Regrid cloud mask data to the same grid as the BT data
        cloudmask_regridded = pinkdust.regrid_data(cloudlons,
                                                   cloudlats,
                                                   lons,
                                                   lats,
                                                   cloudmaskarray,
                                                   mesh=True)

        f = tables.open_file(
            '/soge-home/projects/seviri_dust/raw_seviri_data'
            '/intermediary_files/cloudmask/cloudmask_' +
            date.strftime('%Y%m%d%H%M%S.hdf'), 'w')
        atom = tables.Atom.from_dtype(cloudmask_regridded.dtype)
        filters = tables.Filters(complib='blosc', complevel=5)
        ds = f.create_carray(f.root,
                             'data',
                             atom,
                             cloudmask_regridded.shape,
                             filters=filters)
        ds[:] = cloudmask_regridded
        f.close()
    except:
        with open(
                '/soge-home/projects/seviri_dust'
                '/raw_seviri_data/bt_native/missing_msgnative_dates'
                '.txt', 'a') as my_file:
            my_file.write('\n')
            my_file.write(date.strftime('%Y%m%d%H%M%S') + ' clouds')
Esempio n. 6
0
    def test_load_area(self):
        ease_nh = utils.load_area(os.path.join(os.path.dirname(__file__), 
                                                              'test_files', 
                                                              'areas.cfg'), 'ease_nh')
        nh_found = (ease_nh.__str__() =="""Area ID: ease_nh
Name: Arctic EASE grid
Projection ID: ease_nh
Projection: {'a': '6371228.0', 'lat_0': '90', 'lon_0': '0', 'proj': 'laea', 'units': 'm'}
Number of columns: 425
Number of rows: 425
Area extent: (-5326849.0625, -5326849.0625, 5326849.0625, 5326849.0625)""")
        self.assertTrue(nh_found, msg='Failed to load area correctly') 
Esempio n. 7
0
    def test_load_area(self):
        ease_nh = utils.load_area(
            os.path.join(os.path.dirname(__file__), 'test_files', 'areas.cfg'),
            'ease_nh')
        nh_found = (ease_nh.__str__() == """Area ID: ease_nh
Name: Arctic EASE grid
Projection ID: ease_nh
Projection: {'a': '6371228.0', 'lat_0': '90', 'lon_0': '0', 'proj': 'laea', 'units': 'm'}
Number of columns: 425
Number of rows: 425
Area extent: (-5326849.0625, -5326849.0625, 5326849.0625, 5326849.0625)""")
        self.assertTrue(nh_found, msg='Failed to load area correctly')
Esempio n. 8
0
    def test_load_area(self):
        from pyresample import utils
        ease_nh = utils.load_area(
            os.path.join(os.path.dirname(__file__), 'test_files', 'areas.cfg'),
            'ease_nh')
        nh_str = """Area ID: ease_nh
Description: Arctic EASE grid
Projection ID: ease_nh
Projection: {'a': '6371228.0', 'lat_0': '90.0', 'lon_0': '0.0', 'proj': 'laea', 'units': 'm'}
Number of columns: 425
Number of rows: 425
Area extent: (-5326849.0625, -5326849.0625, 5326849.0625, 5326849.0625)"""
        self.assertEqual(nh_str, ease_nh.__str__())
Esempio n. 9
0
 def test_norotation_legacy(self):
     legacyDef = """REGION: regionB {
     NAME:          regionB
     PCS_ID:        regionB
     PCS_DEF:       proj=merc, lon_0=-34, k=1, x_0=0, y_0=0, a=6378137, b=6378137
     XSIZE:         800
     YSIZE:         548
     AREA_EXTENT:   (-7761424.714818418, -4861746.639279127, 11136477.43264252, 8236799.845095873)
     };"""
     flegacy = "/tmp/TestProjRotation_test_rotation_legacy.txt"
     f = open(flegacy, "w")
     f.write(legacyDef)
     f.close()
     test_area = load_area(flegacy, 'regionB')
     self.assertEqual(test_area.rotation, 0)
     os.remove(flegacy)
Esempio n. 10
0
# Define custom fog colormap
fogcol = Colormap((0., (0.0, 0.0, 0.8)),
                  (1., (250 / 255.0, 200 / 255.0, 40 / 255.0)))

# Define geos projection boundaries for Germany.
# area_extent: (x_ll, y_ll, x_ur, y_ur)
prj = pyproj.Proj(proj='geos',
                  lon_0=0.0,
                  a=6378144.0,
                  b=6356759.0,
                  h=35785831.0,
                  rf=295.49)
x_ll, y_ll = prj(3, 47)
x_ur, y_ur = prj(19, 55)
ger_extent = (x_ll, y_ll, x_ur, y_ur)
germ_areadef = utils.load_area(
    os.path.join(os.getenv("PPP_CONFIG_DIR"), "areas.yaml"), 'germ')
germ_extent = germ_areadef.area_extent_ll
x_ll, y_ll = prj(*germ_extent[0:2])
x_ur, y_ur = prj(*germ_extent[2:])
ger_extent = (x_ll, y_ll, x_ur, y_ur)

# Import geoftiff with DEM information
tiff = "/media/nas/satablage/Thomas/Grassdata/srtm_germany_dsm.tif"
params, dem = gtiff.read_geotiff(tiff)
tiffarea = gtiff.tiff2areadef(params['projection'], params['geotransform'],
                              dem.shape)

elevation = image.ImageContainerQuick(dem, tiffarea)

# Directory for cloud physical properties
cpp_dir = '/media/nas/satablage/Thomas/Nebel/CMSAF_microphysics'
Esempio n. 11
0
import os
import numpy as np
import fogpy
from datetime import datetime
from pyresample import image, geometry
from pyresample import utils
from satpy.scene import Scene
from satpy.dataset import Dataset
from trollimage.colormap import Colormap
from satpy.utils import debug_on

debug_on()
# Define geos projection boundaries for Germany.
# area_extent: (x_ll, y_ll, x_ur, y_ur)
germ_areadef = utils.load_area('/home/mastho/git/satpy/satpy/etc/areas.def',
                               'germ')
euro_areadef = utils.load_area('/home/mastho/git/satpy/satpy/etc/areas.def',
                               'euro4')
germ_extent = germ_areadef.area_extent_ll
print(dir(germ_extent))
geos_areadef = utils.load_area('/home/mastho/git/satpy/satpy/etc/areas.def',
                               'EuropeCanary')
print(germ_extent[0::2], germ_extent[1::2])
print(list(germ_extent[1::2]))
x, y = geos_areadef.get_xy_from_lonlat(list(germ_extent[0::2]),
                                       list(germ_extent[1::2]))
print(x, y)
print(y[0])
xproj, yproj = geos_areadef.get_proj_coords()
xll, xur = xproj[y, x]
yll, yur = yproj[y, x]
Esempio n. 12
0
                     [232, 232, 232],
                     [246, 246, 246],
                     [255, 255, 255]]) 
 pal_mch = pal_mch / 255.0
 fig = plt.figure(frameon=False)
 fig.set_size_inches(3.712,3.712)
 ax = plt.Axes(fig, [0., 0., 1., 1.])
 ax.set_axis_off()
 fig.add_axes(ax)
 cm = LinearSegmentedColormap.from_list('ctthpal',pal)
 cm_mch = LinearSegmentedColormap.from_list('ctthpal_mch',pal_mch)
 #ax.imshow(z, cmap=cm)
 ax.imshow(z2, cmap=cm_mch)
 fig.savefig('tmp_'+fname, dpi=1000)
 
 area_src = load_area('/opt/users/cll/PyTroll/etc/areas.def', 'SeviriDiskFull00')
 area_target = load_area('/opt/users/cll/PyTroll/etc/areas.def', 'mpef-ceu')
 
 im = PIL.Image.open('tmp_'+fname)
 #im = PIL.Image.fromarray(z, mode='P')
 #tt=pal2.reshape(pal2.shape[0]*3)
 #im.putpalette(tt)
 z = np.array(im)
 
 os.remove('tmp_'+fname)
 nn = image.ImageContainerNearest(z, area_src, radius_of_influence=50000)
 area_con_quick = nn.resample(area_target)
 scipy.misc.imsave(fname,area_con_quick.image_data)
 
 cw = ContourWriterAGG('/opt/pytroll/shapes')
 cw.add_coastlines_to_file(fname, area_target, resolution='l', level=1, outline=(255, 255, 255))
Esempio n. 13
0
def wrapper(date):
    print date
    test1 = datetime.datetime.now()
    date_1 = date+datetime.timedelta(minutes=13)
    global_data, time_slot = pinkdust.load_channels(date, date_1)
    #print 'Loading data to a scene object:', datetime.datetime.now() - test1
    # Reproject it to North Africa - note that this requires a custom
    # projection in areas.def config file
    test2 = datetime.datetime.now()
    # projected_data = global_data.project("NorthAfrica")
    msg_area = utils.load_area('/soge-home/projects/seviri_dust/areas.def',
                               'met09globeFull')
    target_area = utils.load_area('/soge-home/projects/seviri_dust/areas.def',
                                  'NorthAfrica')

    # print global_data.data
    data_087 = global_data[8.7].data
    data_108 = global_data[10.8].data
    data_120 = global_data[12.0].data
    data = np.zeros((data_087.shape[0], data_087.shape[1], 3))

    data[:, :, 0] = data_087
    data[:, :, 1] = data_108
    data[:, :, 2] = data_120

    lons, lats = target_area.get_lonlats()
    if (data.shape[0] != msg_area.shape[0]) or (data.shape[1] !=
                                                    msg_area.shape[1]):
        print 'Native file data has wrong dimensions - this array will be ' \
              'filled with NaNs'
        print 'Adding date to list of missing dates'
        with open('/soge-home/projects/seviri_dust'
                  '/raw_seviri_data/bt_native/missing_msgnative_dates'
                  '.txt', 'a') as my_file:
            my_file.write('\n')
            my_file.write(date.strftime('%Y%m%d%H%M%S'))
        data = np.zeros((msg_area.shape[0], msg_area.shape[1], 3))
        data[:] = np.nan

    msg_con_nn = image.ImageContainerNearest(data, msg_area,
                                             radius_of_influence=50000)
    area_con_nn = msg_con_nn.resample(target_area)
    result_data_nn = area_con_nn.image_data

    bt_data = np.zeros((3, lons.shape[0], lons.shape[1]))
    bt_data[0] = result_data_nn[:, :, 0]
    bt_data[1] = result_data_nn[:, :, 1]
    bt_data[2] = result_data_nn[:, :, 2]

    f = tables.open_file('/soge-home/projects/seviri_dust/raw_seviri_data'
                         '/intermediary_files/BT_087_' + date.strftime(
        '%Y%m%d%H%M%S.hdf'),
                         'w')
    atom = tables.Atom.from_dtype(bt_data[0].dtype)
    filters = tables.Filters(complib='blosc', complevel=5)
    ds = f.create_carray(f.root, 'data', atom,
                         bt_data[0].shape,
                         filters=filters)
    ds[:] = bt_data[0]
    f.close()

    print 'Writing', date, 'to HDF'

    f = tables.open_file('/soge-home/projects/seviri_dust/raw_seviri_data'
                         '/intermediary_files/BT_108_' + date.strftime(
        '%Y%m%d%H%M%S.hdf'), 'w')
    atom = tables.Atom.from_dtype(bt_data[1].dtype)
    filters = tables.Filters(complib='blosc', complevel=5)
    ds = f.create_carray(f.root, 'data', atom,
                         bt_data[0].shape,
                         filters=filters)
    ds[:] = bt_data[1]
    f.close()

    f = tables.open_file('/soge-home/projects/seviri_dust/raw_seviri_data'
                         '/intermediary_files/BT_120_' + date.strftime(
        '%Y%m%d%H%M%S.hdf'), 'w')
    atom = tables.Atom.from_dtype(bt_data[2].dtype)
    filters = tables.Filters(complib='blosc', complevel=5)
    ds = f.create_carray(f.root, 'data', atom,
                         bt_data[0].shape,
                         filters=filters)
    ds[:] = bt_data[2]
    f.close()

    # f = tables.open_file('/soge-home/projects/seviri_dust/raw_seviri_data'
    #                     '/intermediary_files/cloudmask_
    # '+date.strftime(
    #    '%Y%m%d%H%M%S.hdf'), 'w')
    # atom = tables.Atom.from_dtype(cloudmask_regridded.dtype)
    # filters = tables.Filters(complib='blosc', complevel=5)
    # ds = f.create_carray(f.root, 'data', atom,
    #                     data_regridded[:, :, 0].shape,
    #                     filters=filters)
    # ds[:] = cloudmask_regridded
    f.close()
Esempio n. 14
0
def wrapper(date):
    print date
    test1 = datetime.datetime.now()
    global_data, time_slot = pinkdust.load_channels(date)
    print 'Loading data to a scene object:', datetime.datetime.now() - test1

    # Reproject it to North Africa - note that this requires a custom
    # projection in areas.def config file
    test2 = datetime.datetime.now()
    #projected_data = global_data.project("NorthAfrica")
    msg_area = utils.load_area('/soge-home/projects/seviri_dust/areas.def',
                               'met09globeFull')
    target_area = utils.load_area('/soge-home/projects/seviri_dust/areas.def',
                                  'NorthAfrica')

    #print global_data.data
    data = global_data[8.7].data
    msg_con_nn = image.ImageContainerNearest(data,
                                             msg_area,
                                             radius_of_influence=50000)
    area_con_nn = msg_con_nn.resample(target_area)
    result_data_nn = area_con_nn.image_data
    lons, lats = target_area.get_lonlats()
    print np.min(lons)
    print np.max(lons)
    print np.min(lats)
    print np.max(lats)
    """

    print 'Constraining the scene to North Africa:', datetime.datetime.now() \
                                                     - test2

    test3 = datetime.datetime.now()
    netcdf4.save(projected_data,
                 '/soge-home/projects/seviri_dust/raw_seviri_data/bt_nc/'
                 + date.strftime(
                     "%B%Y") + '/North_Africa_SEVIRI_BTs_' + str(
                     date.strftime("%Y%m%d%H%M")) + '.nc',
                 compression=True,
                 dtype=np.int16,
                 band_axis=2) #area_aggregation=True
    # #time_dimension=True
    print 'Saving to netCDF:', datetime.datetime.now() - test3
    test4 = datetime.datetime.now()

    # Pull a netCDF dataset object out so the projection coordinates can
    # be obtained
    ncdata = Dataset(
        '/soge-home/projects/seviri_dust/raw_seviri_data/bt_nc/'
                 + date.strftime(
                     "%B%Y") + '/North_Africa_SEVIRI_BTs_' + str(
                     date.strftime("%Y%m%d%H%M")) + '.nc')
    print 'Loading from netCDF:', datetime.datetime.now() - test4


    # Reproject the original geos projection coordinates
    test5 = datetime.datetime.now()
    lons, lats = pinkdust.reproject_to_latlon(ncdata)
    print 'Reprojecting to lat/lon:', datetime.datetime.now() - test5



    # Regrid the irregular to regular lat lon
    test7 = datetime.datetime.now()
    data_array = np.zeros((lons.shape[0], lats.shape[1], 3))
    data_array_ordered = np.zeros((lons.shape[0], lats.shape[1], 3))

    data_labels = np.array(
        [ncdata.variables['band0'][:][0], ncdata.variables['band1'][:][0],
         ncdata.variables['band2'][:][0]])

    data_array[:, :, 0] = ncdata.variables['Image0'][:]
    data_array[:, :, 1] = ncdata.variables['Image1'][:]
    data_array[:, :, 2] = ncdata.variables['Image2'][:]

    IR_indices = np.array([0, 1, 2])

    data_array_ordered[:, :, 0] = data_array[:, :,
                                  IR_indices[data_labels == 'IR_087'][0]]
    data_array_ordered[:, :, 1] = data_array[:, :,
                                  IR_indices[data_labels == 'IR_108'][0]]
    data_array_ordered[:, :, 2] = data_array[:, :,
                                  IR_indices[data_labels == 'IR_120'][0]]

    data_regridded = pinkdust.regrid_data_to_regular(lons, lats,
                                                 data_array_ordered)
    print 'Regridding to a regular lat/lon:', datetime.datetime.now() - test7



    # Pull out cloud mask data to be regridded and added to the nc file
    # glob is used for a wildcard
    #clouddata = pygrib.open(glob.glob(
    #    '/soge-home/projects/seviri_dust/raw_seviri_data/cloudmask_grib/MSG*-'
    #    'SEVI-MSGCLMK-0100-0100-' + date.strftime(
    #        "%Y%m%d%H%M%S") + '*')[0])
    #grb = clouddata.select()[0]
    #cloudmaskarray = grb.values[:, ::-1]
    #cloudlats, cloudlons = grb.latlons()

    #cloudmaskarray[cloudmaskarray >= 3] = np.nan
    #cloudlats[cloudlats > 90] = np.nan
    #cloudlons[cloudlons > 180] = np.nan

    # Generate a regular lat/lon grid for the cloud mask
    regular_lons = np.linspace(np.min(lons), np.max(lons), lons.shape[1])
    regular_lats = np.linspace(np.min(lats), np.max(lats), lats.shape[0])

    # Regrid the cloud mask to the above regular grid (note a new
    # function was defined as it was needed for a previous version of
    # the code...)
    #cloudmask_regridded = pinkdust.regrid_data(cloudlons, cloudlats,
    #                                         regular_lons,
    #                                  regular_lats, cloudmaskarray)
    time = num2date(ncdata.variables['time'][:],
                    ncdata.variables['time'].units)

    """

    f = tables.open_file(
        '/soge-home/projects/seviri_dust/raw_seviri_data'
        '/intermediary_files/BT_087_' + date.strftime('%Y%m%d%H%M%S.hdf'), 'w')
    atom = tables.Atom.from_dtype(data_regridded[:, :, 0].dtype)
    filters = tables.Filters(complib='blosc', complevel=5)
    ds = f.create_carray(f.root,
                         'data',
                         atom,
                         data_regridded[:, :, 0].shape,
                         filters=filters)
    ds[:] = data_regridded[:, :, 0]
    f.close()

    f = tables.open_file(
        '/soge-home/projects/seviri_dust/raw_seviri_data'
        '/intermediary_files/BT_108_' + date.strftime('%Y%m%d%H%M%S.hdf'), 'w')
    atom = tables.Atom.from_dtype(data_regridded[:, :, 1].dtype)
    filters = tables.Filters(complib='blosc', complevel=5)
    ds = f.create_carray(f.root,
                         'data',
                         atom,
                         data_regridded[:, :, 0].shape,
                         filters=filters)
    ds[:] = data_regridded[:, :, 1]
    f.close()

    f = tables.open_file(
        '/soge-home/projects/seviri_dust/raw_seviri_data'
        '/intermediary_files/BT_120_' + date.strftime('%Y%m%d%H%M%S.hdf'), 'w')
    atom = tables.Atom.from_dtype(data_regridded[:, :, 2].dtype)
    filters = tables.Filters(complib='blosc', complevel=5)
    ds = f.create_carray(f.root,
                         'data',
                         atom,
                         data_regridded[:, :, 0].shape,
                         filters=filters)
    ds[:] = data_regridded[:, :, 2]
    f.close()

    #f = tables.open_file('/soge-home/projects/seviri_dust/raw_seviri_data'
    #                     '/intermediary_files/cloudmask_
    # '+date.strftime(
    #    '%Y%m%d%H%M%S.hdf'), 'w')
    #atom = tables.Atom.from_dtype(cloudmask_regridded.dtype)
    #filters = tables.Filters(complib='blosc', complevel=5)
    #ds = f.create_carray(f.root, 'data', atom,
    #                     data_regridded[:, :, 0].shape,
    #                     filters=filters)
    #ds[:] = cloudmask_regridded
    f.close()

    ncdata.close()
Esempio n. 15
0
import os
from satpy import Scene
from datetime import datetime
from satpy.utils import debug_on
import pyninjotiff
from glob import glob
from pyresample.utils import load_area
import copy
debug_on()


chn = "IR_108"
ninjoRegion = load_area("areas.def", "nrEURO3km")

filenames = glob("data/*__")
global_scene = Scene(reader="hrit_msg", filenames=filenames)
global_scene.load([chn])
local_scene = global_scene.resample(ninjoRegion)
local_scene.save_dataset(chn, filename="msg.tif", writer='ninjotiff',
                      # ninjo product name to look for in .cfg file
                      ninjo_product_name="IR_108",
                      # custom configuration file for ninjo tiff products
                      # if not specified PPP_CONFIG_DIR is used as config file directory
                      ninjo_product_file="/config_dir/ninjotiff_products.cfg")
Esempio n. 16
0
import os
from satpy import Scene
from datetime import datetime
from satpy.utils import debug_on
import pyninjotiff
from glob import glob
from pyresample.utils import load_area
import copy
debug_on()

chn = "C13"
ninjoRegion = load_area("areas.def", "NinJoGOESWregion")
filenames = glob("/var/tmp/cll/goes17/*")
global_scene = Scene(reader="abi_l1b", filenames=filenames)
global_scene.load([chn])
local_scene = global_scene.resample(ninjoRegion, cache_dir="/var/tmp/cll")
local_scene[chn].clip(-87.5 - 273.15, 40 - 273.15)
local_scene.save_dataset(chn,
                         filename="goes17.tif",
                         writer='ninjotiff',
                         sat_id=6300014,
                         chan_id=900015,
                         data_cat='GORN',
                         data_source='EUMCAST',
                         physic_unit='C',
                         ch_max_measurement_unit=40,
                         ch_min_measurement_unit=-87.5,
                         zero_seconds=True,
                         invert_colorscale=True)
Esempio n. 17
0
                                                          bt_087,
                                                bt_108,
                                            bt_120,
                                            None, day_datetimes[j])

                print 'Day ' + str(days[i]) + ' done'
                ncfile.close()
            print 'Month ' + str(months[k]) + ' done'


if __name__ == '__main__':

    years_list = [2016]
    days_list = [1]
    target_area = utils.load_area(
        '/soge-home/projects/seviri_dust/areas.def',
        'NorthAfrica')
    lons, lats = target_area.get_lonlats()

    msg_area = utils.load_area('/soge-home/projects/seviri_dust/areas.def',
                               'met09globeFull')

    day_array = np.zeros((96, target_area.shape[0], target_area.shape[1], 3))

    # Make a lonlats file
    lonlatsnc = pinkdust. \
        create_lonlats_file('/soge-home/projects/seviri_dust/'
                            'raw_seviri_data/cloudmask_nc/cloudmask_lonlats.nc',
                            lats, lons)
    lonlatsnc.close()
Esempio n. 18
0
epoch = datetime.utcfromtimestamp(0)

def unix_time_sec(dt):
    return (dt - epoch).total_seconds()

#metopa_url="http://oiswww.eumetsat.org/metopTLEs/html/data_out/latest_m02_tle.txt"
#metopb_url="http://oiswww.eumetsat.org/metopTLEs/html/data_out/latest_m01_tle.txt"

#metopa = urllib.URLopener()
#metopa.retrieve(metopa_url, "metopa.txt")

#metopb = urllib.URLopener()
#metopb.retrieve(metopb_url, "metopb.txt")

cw = ContourWriterAGG('/opt/pytroll/shapes')
europe = load_area(os.environ['PPP_CONFIG_DIR']+"/areas.def", 'ccs4large')
world = load_area(os.environ['PPP_CONFIG_DIR']+"/areas.def", 'world_plat_1350_675')


for sat in ["M01", "M02", "M03"]:
 
    fnames = glob(dataDir+"AVHR_xxx_*"+sat+"*")
    if not fnames:
        continue
    glbl = Scene(reader="avhrr_eps_l1b", filenames=fnames)
    if sat == "M01":
        satname="B"
    if sat == "M02":
        satname="A"
    if sat == "M03":
        satname="C"
import os
from satpy import Scene
from datetime import datetime
from satpy.utils import debug_on
import pyninjotiff
from glob import glob
from pyresample.utils import load_area
debug_on()


chn = "airmass"
ninjoRegion = load_area("areas.def", "nrEURO3km")

filenames = glob("data/*__")
global_scene = Scene(reader="hrit_msg", filenames=filenames)
global_scene.load([chn])
local_scene = global_scene.resample(ninjoRegion)
local_scene.save_dataset(chn, filename="airmass.tif", writer='ninjotiff',
                      sat_id=6300014,
                      chan_id=6500015,
                      data_cat='GPRN',
                      data_source='EUMCAST',
                      nbits=8)
Esempio n. 20
0
def get_area_def_from_file(area_name):
    area_filepath = get_area_filepath()
    return utils.load_area(area_filepath, area_name)
        # save png file for SATLive
        ##############################
        if area == "cosmo1x150" or area == "cosmo1":
            png_file = start_time.strftime('/data/cinesat/out/MSG_lscl-' +
                                           area + '_%y%m%d%H%M.png')
            from trollimage.colormap import spectral, greys, ylorrd, rdgy
            imgarr = np.array(local_scene['lscl'].data)
            from trollimage.image import Image as Timage
            img = Timage(imgarr, mode="L")
            img.colorize(rdgy.reverse())
            img.save(png_file)

            # local_scene.save_dataset( 'lscl', png_file )
            from pyresample.utils import load_area
            swiss = load_area("/opt/users/hau/monti-pytroll/etc/areas.def",
                              area)

            from pycoast import ContourWriterAGG
            cw = ContourWriterAGG('/opt/users/common/shapes')
            cw.add_borders_to_file(png_file,
                                   swiss,
                                   outline="green",
                                   resolution='i',
                                   level=3,
                                   width=2)

            img = Image.open(png_file)
            draw = ImageDraw.Draw(img)
            draw.rectangle([(0, 0), (img.size[0] * 0.7, 25)],
                           fill=(0, 0, 0, 200))
            font = ImageFont.truetype(
Esempio n. 22
0
        s.starttls()
        s.login(gmail_user, gmail_password)
        s.sendmail(sent_from, to, email_text)
        s.close()

        """

        years = np.unique(np.asarray(([j.year for j in datetimes])))

        months = np.unique(np.asarray(([j.month for j in datetimes])))

        days = np.unique(np.asarray(([j.day for j in datetimes])))

        # Pull a netCDF dataset object out so the projection coordinates can
        # be obtained
        target_area = utils.load_area(
            '/soge-home/projects/seviri_dust/areas.def', 'NorthAfrica')
        lons, lats = target_area.get_lonlats()

        # Make a lonlats file
        lonlatsnc = pinkdust.\
            create_lonlats_file('/soge-home/projects/seviri_dust/'
                            'raw_seviri_data/cloudmask_nc/cloudmask_lonlats.nc',
                                lats, lons)
        lonlatsnc.close()

        for m in np.arange(0, len(years)):

            for k in np.arange(0, len(months)):

                for i in np.arange(0, len(days)):
                    day_datetimes_bool = np.asarray([
Esempio n. 23
0
global_scene = Scene(reader="hrit_msg", filenames=filenames)

# first try, it stays here only for the memory
# global_scene.load(["HRV", "IR_108"])
# local_scene = global_scene.resample("ccs4")
# lonlats = local_scene["HRV"].area.get_lonlats()
# sza = sun_zenith_angle(local_scene.start_time, lonlats[0], lonlats[1])
# ds = DataArray(sza, dims=['y','x'])
# local_scene['sza'] = ds
# end of the first try, stuff below here is working again

global_scene.load(["ir108", "hrv", "IR_108", "hrv_with_ir"])
local_scene = global_scene.resample("ccs4")
local_scene.load(["hrv_with_ir", "IR_108"])

swiss = load_area("/opt/users/cll/cllwork/etc_work/areas.def", "ccs4")
tmpFileA = "/tmp/welcome.png"
tmpFileB = "/tmp/welcome-ir.png"
outputFile = "/var/tmp/cll/out/PY_visir-ch_"+yearS+monthS+dayS+hourS+minS+".png" 
bgFile = "/opt/users/cll/cllwork/ccs4.png"
local_scene.save_dataset("hrv_with_ir", tmpFileA)
local_scene.save_dataset("ir108", tmpFileB)

background = Image.open(bgFile)
foreground = Image.open(tmpFileA)
background = background.convert("RGBA")
foreground.putalpha(foreground.convert('L'))
foreground = foreground.convert("RGBA")
Image.alpha_composite(background, foreground).save(outputFile)

cw = ContourWriterAGG('/opt/pytroll/shapes')
Esempio n. 24
0
from cll_composites import *


debug_on()
my_example_nc_file = "MSG2_ccs4_201712250900_rad.nc"
fname = "MSG2_ccs4_201712250900_rad.png"
fh = Dataset(my_example_nc_file, mode='r')
z = fh.variables['HRV'][:]
z = z.reshape(640,710)
fh.close()

fig = plt.figure(frameon=False)
fig.set_size_inches(7.1,6.4)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
ax.imshow(z)
fig.savefig(fname, dpi=300)

area_src = load_area('/opt/users/cll/PyTroll/etc/areas.def', 'ccs4')
area_target = load_area('/opt/users/cll/PyTroll/etc/areas.def', 'SwitzerlandStereo500m')

nn = image.ImageContainerNearest(z, area_src, radius_of_influence=5000)
area_con_quick = nn.resample(area_target)
scipy.misc.imsave(fname,area_con_quick.image_data)

cw = ContourWriterAGG('/opt/pytroll/shapes')
#cw.add_coastlines_to_file(ofilePifir, area_def, resolution='i', level=2, outline=(255, 255, 0), fill=(255, 255, 0))
cw.add_borders_to_file(fname, area_target, outline=(255, 255, 255),resolution='i')

Esempio n. 25
0
# Define custom fog colormap
fogcol = Colormap((0., (0.0, 0.0, 0.8)),
                  (1., (250 / 255.0, 200 / 255.0, 40 / 255.0)))

# Define geos projection boundaries for Germany.
# area_extent: (x_ll, y_ll, x_ur, y_ur)
prj = pyproj.Proj(proj='geos',
                  lon_0=0.0,
                  a=6378144.0,
                  b=6356759.0,
                  h=35785831.0,
                  rf=295.49)
x_ll, y_ll = prj(3, 47)
x_ur, y_ur = prj(19, 55)
ger_extent = (x_ll, y_ll, x_ur, y_ur)
germ_areadef = utils.load_area('/data/tleppelt/Pytroll/config/areas.def',
                               'germ')
germ_extent = germ_areadef.area_extent_ll
x_ll, y_ll = prj(*germ_extent[0:2])
x_ur, y_ur = prj(*germ_extent[2:])
ger_extent = (x_ll, y_ll, x_ur, y_ur)

# Import geoftiff with DEM information
tiff = "/media/nas/satablage/Thomas/Grassdata/srtm_germany_dsm.tif"
params, dem = gtiff.read_geotiff(tiff)
tiffarea = gtiff.tiff2areadef(params['projection'], params['geotransform'],
                              dem.shape)

elevation = image.ImageContainerQuick(dem, tiffarea)

# Directory for cloud physical properties
cpp_dir = '/media/nas/satablage/Thomas/Nebel/CMSAF_microphysics'