Ejemplo n.º 1
0
def test_gini_mercator_upper_corner():
    """Test that the upper corner of the Mercator coordinates is correct."""
    f = GiniFile(get_test_data('HI-REGIONAL_4km_3.9_20160616_1715.gini'))
    ds = f.to_dataset()
    lat = ds.variables['lat']
    lon = ds.variables['lon']

    # 2nd corner lat/lon are at the "upper right" corner of the pixel, so need to add one
    # more grid point
    assert_almost_equal(lon[-1, -1] + (lon[-1, -1] - lon[-1, -2]), f.proj_info.lo2, 4)
    assert_almost_equal(lat[-1, -1] + (lat[-1, -1] - lat[-2, -1]), f.proj_info.la2, 4)
Ejemplo n.º 2
0
def test_gini_dataset():
    'Test the dataset interface for GINI'
    f = GiniFile(get_test_data('WEST-CONUS_4km_WV_20151208_2200.gini'))
    ds = f.to_dataset()
    assert 'x' in ds.variables
    assert 'y' in ds.variables
    assert 'WV' in ds.variables
    assert hasattr(ds.variables['WV'], 'grid_mapping')
    assert ds.variables['WV'].grid_mapping in ds.variables
    assert_almost_equal(ds.variables['lon'][0, 0], f.prod_desc.lo1, 4)
    assert_almost_equal(ds.variables['lat'][0, 0], f.prod_desc.la1, 4)
Ejemplo n.º 3
0
 def test_dataset():
     'Test the dataset interface for GINI'
     f = GiniFile(get_test_data('WEST-CONUS_4km_WV_20151208_2200.gini'))
     ds = f.to_dataset()
     assert 'x' in ds.variables
     assert 'y' in ds.variables
     assert 'WV' in ds.variables
     assert hasattr(ds.variables['WV'], 'grid_mapping')
     assert ds.variables['WV'].grid_mapping in ds.variables
     assert_almost_equal(ds.variables['lon'][0, 0], f.prod_desc.lo1, 4)
     assert_almost_equal(ds.variables['lat'][0, 0], f.prod_desc.la1, 4)
Ejemplo n.º 4
0
def test_gini_ak_regional_dataset():
    'Test the dataset interface for GINI of a AK REGIONAL file'
    f = GiniFile(get_test_data('AK-REGIONAL_8km_3.9_20160408_1445.gini'))
    ds = f.to_dataset()
    assert 'x' in ds.variables
    assert 'y' in ds.variables
    assert 'IR' in ds.variables
    assert hasattr(ds.variables['IR'], 'grid_mapping')
    assert ds.variables['IR'].grid_mapping in ds.variables
    assert_almost_equal(ds.variables['lon'][0, 0], f.prod_desc.lo1, 4)
    assert_almost_equal(ds.variables['lat'][0, 0], f.prod_desc.la1, 4)
Ejemplo n.º 5
0
def test_gini_dataset():
    "Test the dataset interface for GINI"
    f = GiniFile(get_test_data("WEST-CONUS_4km_WV_20151208_2200.gini"))
    ds = f.to_dataset()
    assert "x" in ds.variables
    assert "y" in ds.variables
    assert "WV" in ds.variables
    assert hasattr(ds.variables["WV"], "grid_mapping")
    assert ds.variables["WV"].grid_mapping in ds.variables
    assert_almost_equal(ds.variables["lon"][0, 0], f.prod_desc.lo1, 4)
    assert_almost_equal(ds.variables["lat"][0, 0], f.prod_desc.la1, 4)
Ejemplo n.º 6
0
def test_gini_ak_regional_dataset():
    'Test the dataset interface for GINI of a AK REGIONAL file'
    f = GiniFile(get_test_data('AK-REGIONAL_8km_3.9_20160408_1445.gini'))
    ds = f.to_dataset()
    assert 'x' in ds.variables
    assert 'y' in ds.variables
    assert 'IR' in ds.variables
    assert hasattr(ds.variables['IR'], 'grid_mapping')
    assert ds.variables['IR'].grid_mapping in ds.variables
    assert_almost_equal(ds.variables['lon'][0, 0], f.prod_desc.lo1, 4)
    assert_almost_equal(ds.variables['lat'][0, 0], f.prod_desc.la1, 4)
    assert_almost_equal(ds.variables['Polar_Stereographic'].longitude_of_projection_origin,
                        210.0)
    assert_almost_equal(ds.variables['Polar_Stereographic'].latitude_of_projection_origin,
                        90.0)
Ejemplo n.º 7
0
def test_gini_ak_regional():
    'Test reading of AK Regional Gini file'
    f = GiniFile(get_test_data('AK-REGIONAL_8km_3.9_20160408_1445.gini'))
    pdb = f.prod_desc
    assert pdb.source == 1
    assert pdb.creating_entity == 'GOES-15'
    assert pdb.sector_id == 'Alaska Regional'
    assert pdb.channel == 'IR (3.9 micron)'
    assert pdb.num_records == 408
    assert pdb.record_len == 576
    assert pdb.datetime, datetime(2016, 4, 8, 14, 45, 20 == 0)
    assert pdb.projection == GiniProjection.polar_stereographic
    assert pdb.nx == 576
    assert pdb.ny == 408
    assert_almost_equal(pdb.la1, 42.0846, 4)
    assert_almost_equal(pdb.lo1, -175.641, 4)

    proj = f.proj_info
    assert proj.reserved == 0
    assert_almost_equal(proj.lov, 210.0, 1)
    assert_almost_equal(proj.dx, 7.9375, 4)
    assert_almost_equal(proj.dy, 7.9375, 4)
    assert proj.proj_center == 0

    pdb2 = f.prod_desc2
    assert pdb2.scanning_mode == [False, False, False]
    assert_almost_equal(pdb2.lat_in, 0.0, 4)
    assert pdb2.resolution == 8
    assert pdb2.compression == 0
    assert pdb2.version == 1
    assert pdb2.pdb_size == 512
    assert pdb2.nav_cal == 0

    assert f.data.shape, (pdb.num_records == pdb.record_len)
Ejemplo n.º 8
0
def test_gini_basic():
    'Basic test of GINI reading'
    f = GiniFile(get_test_data('WEST-CONUS_4km_WV_20151208_2200.gini'))
    pdb = f.prod_desc
    assert pdb.source == 1
    assert pdb.creating_entity == 'GOES-15'
    assert pdb.sector_id == 'West CONUS'
    assert pdb.channel == 'WV (6.5/6.7 micron)'
    assert pdb.num_records == 1280
    assert pdb.record_len == 1100
    assert pdb.datetime, datetime(2015, 12, 8, 22, 0, 19 == 0)
    assert pdb.projection == GiniProjection.lambert_conformal
    assert pdb.nx == 1100
    assert pdb.ny == 1280
    assert_almost_equal(pdb.la1, 12.19, 4)
    assert_almost_equal(pdb.lo1, -133.4588, 4)

    proj = f.proj_info
    assert proj.reserved == 0
    assert_almost_equal(proj.lov, -95.0, 4)
    assert_almost_equal(proj.dx, 4.0635, 4)
    assert_almost_equal(proj.dy, 4.0635, 4)
    assert proj.proj_center == 0

    pdb2 = f.prod_desc2
    assert pdb2.scanning_mode == [False, False, False]
    assert_almost_equal(pdb2.lat_in, 25.0, 4)
    assert pdb2.resolution == 4
    assert pdb2.compression == 0
    assert pdb2.version == 1
    assert pdb2.pdb_size == 512

    assert f.data.shape, (pdb.num_records == pdb.record_len)
Ejemplo n.º 9
0
def test_raw_gini(filename, pdb, pdb2, proj_info):
    """Test raw GINI parsing."""
    f = GiniFile(get_test_data(filename))
    assert f.prod_desc == pdb
    assert f.prod_desc2 == pdb2
    assert f.proj_info == proj_info
    assert f.data.shape == (pdb.num_records, pdb.record_len)
Ejemplo n.º 10
0
def test_gini_mercator():
    'Test reading of GINI file with Mercator projection (from HI)'
    f = GiniFile(get_test_data('HI-REGIONAL_4km_3.9_20160616_1715.gini'))
    pdb = f.prod_desc
    assert pdb.source == 1
    assert pdb.creating_entity == 'GOES-15'
    assert pdb.sector_id == 'Hawaii Regional'
    assert pdb.channel == 'IR (3.9 micron)'
    assert pdb.num_records == 520
    assert pdb.record_len == 560
    assert pdb.datetime == datetime(2016, 6, 16, 17, 15, 18)

    assert pdb.projection == GiniProjection.mercator
    assert pdb.nx == 560
    assert pdb.ny == 520
    assert_almost_equal(pdb.la1, 9.343, 4)
    assert_almost_equal(pdb.lo1, -167.315, 4)

    proj = f.proj_info
    assert proj.resolution == 0
    assert_almost_equal(proj.la2, 28.0922, 4)
    assert_almost_equal(proj.lo2, -145.878, 4)
    assert proj.di == 0
    assert proj.dj == 0

    pdb2 = f.prod_desc2
    assert pdb2.scanning_mode == [False, False, False]
    assert_almost_equal(pdb2.lat_in, 20.0, 4)
    assert pdb2.resolution == 4
    assert pdb2.compression == 0
    assert pdb2.version == 1
    assert pdb2.pdb_size == 512
    assert pdb2.nav_cal == 0

    assert f.data.shape, (pdb.num_records == pdb.record_len)
Ejemplo n.º 11
0
def test_gini_str():
    """Test the str representation of GiniFile."""
    f = GiniFile(get_test_data('WEST-CONUS_4km_WV_20151208_2200.gini'))
    truth = ('GiniFile: GOES-15 West CONUS WV (6.5/6.7 micron)\n'
             '\tTime: 2015-12-08 22:00:19\n\tSize: 1280x1100\n'
             '\tProjection: lambert_conformal\n'
             '\tLower Left Corner (Lon, Lat): (-133.4588, 12.19)\n\tResolution: 4km')
    assert str(f) == truth
Ejemplo n.º 12
0
def test_gini_mercator_dataset():
    'Test the dataset interface for a GINI file with Mercator projection'
    f = GiniFile(get_test_data('HI-REGIONAL_4km_3.9_20160616_1715.gini'))
    ds = f.to_dataset()
    assert 'x' in ds.variables
    assert 'y' in ds.variables
    assert 'IR' in ds.variables
    assert hasattr(ds.variables['IR'], 'grid_mapping')
    assert ds.variables['IR'].grid_mapping in ds.variables
    lat = ds.variables['lat']
    lon = ds.variables['lon']
    assert_almost_equal(lon[0, 0], f.prod_desc.lo1, 4)
    assert_almost_equal(lat[0, 0], f.prod_desc.la1, 4)
    # 2nd corner lat/lon are at the "upper right" corner of the pixel, so need to add one
    # more grid point
    assert_almost_equal(lon[-1, -1] + (lon[-1, -1] - lon[-1, -2]), f.proj_info.lo2, 4)
    assert_almost_equal(lat[-1, -1] + (lat[-1, -1] - lat[-2, -1]), f.proj_info.la2, 4)
    assert_almost_equal(ds.variables['Mercator'].longitude_of_projection_origin, -167.315)
    assert_almost_equal(ds.variables['Mercator'].latitude_of_projection_origin, 9.343)
Ejemplo n.º 13
0
def test_gini_mercator_dataset():
    'Test the dataset interface for a GINI file with Mercator projection'
    f = GiniFile(get_test_data('HI-REGIONAL_4km_3.9_20160616_1715.gini'))
    ds = f.to_dataset()
    assert 'x' in ds.variables
    assert 'y' in ds.variables
    assert 'IR' in ds.variables
    assert hasattr(ds.variables['IR'], 'grid_mapping')
    assert ds.variables['IR'].grid_mapping in ds.variables
    lat = ds.variables['lat']
    lon = ds.variables['lon']
    assert_almost_equal(lon[0, 0], f.prod_desc.lo1, 4)
    assert_almost_equal(lat[0, 0], f.prod_desc.la1, 4)
    # 2nd corner lat/lon are at the "upper right" corner of the pixel, so need to add one
    # more grid point
    assert_almost_equal(lon[-1, -1] + (lon[-1, -1] - lon[-1, -2]),
                        f.proj_info.lo2, 4)
    assert_almost_equal(lat[-1, -1] + (lat[-1, -1] - lat[-2, -1]),
                        f.proj_info.la2, 4)
    assert_almost_equal(
        ds.variables['Mercator'].longitude_of_projection_origin, -167.315)
    assert_almost_equal(ds.variables['Mercator'].latitude_of_projection_origin,
                        9.343)
Ejemplo n.º 14
0
def test_gini_dataset(filename, bounds, data_var, proj_attrs):
    """Test the dataset interface for GINI."""
    f = GiniFile(get_test_data(filename))
    ds = f.to_dataset()

    # Check our calculated x and y arrays
    x0, x1, y0, y1 = bounds
    x = ds.variables['x']
    assert_almost_equal(x[0], x0, 4)
    assert_almost_equal(x[-1], x1, 4)

    y = ds.variables['y']
    assert_almost_equal(y[0], y0, 4)
    assert_almost_equal(y[-1], y1, 4)

    # Check the projection metadata
    proj_name = ds.variables[data_var].grid_mapping
    proj_var = ds.variables[proj_name]
    for attr, val in proj_attrs.items():
        assert getattr(proj_var, attr) == val, 'Values mismatch for ' + attr

    # Check the lon/lat corner
    assert_almost_equal(ds.variables['lon'][0, 0], f.prod_desc.lo1, 4)
    assert_almost_equal(ds.variables['lat'][0, 0], f.prod_desc.la1, 4)
Ejemplo n.º 15
0
def mapimagery():

    link = [
        'http://thredds.ucar.edu/thredds/catalog/satellite/WV/EAST-CONUS_4km/current/catalog.xml',
        'http://thredds.ucar.edu/thredds/catalog/satellite/IR/EAST-CONUS_4km/current/catalog.xml',
        'http://thredds.ucar.edu/thredds/catalog/satellite/VIS/EAST-CONUS_1km/current/catalog.xml'
    ]
    keywords = ['WV', 'IR', 'Visible']
    descriptors = ['Water Vapor', 'Infrared', 'Visible']
    index = random.randint(
        0,
        len(link) -
        1)  #random index that picks either wv, ir, or visible image to plot
    image = []
    for i in range(
            1, 14, 4
    ):  #loops through the first 4 hours, pulls out image from every hour
        fig = plt.figure(figsize=(10, 10))
        plt.subplots_adjust(hspace=0.03,
                            wspace=0,
                            top=1,
                            left=0,
                            right=0.85,
                            bottom=0.0)
        plt.style.use('ggplot')
        plt.axis('off')
        figuretext = """Satellite Imagery from GOES East Satellite (Imagery retrieved from UCAR/Unidata)
To explore more, check out the following links:
http://www.weather.gov/satellite               http://www.goes.noaa.gov/ 
http://www.ssec.wisc.edu/data/geo-new/#/animation
        
To learn how to interpret satellite imagery, check out the following links:
https://www.wunderground.com/about/satellite.asp 
http://www.weather.cod.edu/labs/satellitelab/satlab.ppt"""
        plt.figtext(0.05,
                    0.20,
                    figuretext,
                    horizontalalignment='left',
                    verticalalignment='top',
                    fontsize=16,
                    color='white',
                    bbox=dict(facecolor='gray', alpha=0.85))

        cat = TDSCatalog(link[index])  ##current wv image
        dataset_name = sorted(cat.datasets.keys())[
            -i]  #pulls the last one in the list above (most recent)
        dataset = cat.datasets[
            dataset_name]  #saves that file into a dataset object
        remote_gini_file = urllib2.urlopen(dataset.access_urls['HTTPServer'])
        gini = GiniFile(
            remote_gini_file
        )  ## MetPy's built in function to read gini files and parse them for you
        gini_ds = gini.to_dataset()  ## converts to more comprehensive dataset
        x = gini_ds.variables['x'][:]
        y = gini_ds.variables['y'][:]
        dat = gini_ds.variables[str(keywords[index])]

        proj_var = gini_ds.variables[
            dat.grid_mapping]  #pulls out the grid information (projection)
        #print(proj_var)

        # Create CartoPy projection information for the file
        globe = ccrs.Globe(ellipse='sphere',
                           semimajor_axis=proj_var.earth_radius,
                           semiminor_axis=proj_var.earth_radius)

        proj = ccrs.LambertConformal(
            central_longitude=proj_var.longitude_of_central_meridian,
            central_latitude=proj_var.latitude_of_projection_origin,
            standard_parallels=[proj_var.standard_parallel],
            globe=globe)

        # Create a feature for States/Admin 1 regions at 1:50m from Natural Earth
        states_provinces = cfeature.NaturalEarthFeature(
            category='cultural',
            name='admin_1_states_provinces_lines',
            scale='50m',
            facecolor='none')

        lakes = cfeature.NaturalEarthFeature(category='physical',
                                             name='lakes',
                                             scale='110m',
                                             facecolor='none')

        ax = fig.add_subplot(1, 1, 1, projection=proj)
        ax.add_feature(states_provinces, edgecolor='black', linewidth=2.0)
        ax.add_feature(lakes, edgecolor='black', linewidth=2.0)
        ax.coastlines(resolution='50m', zorder=2, color='black', linewidth=2.0)
        ax.add_feature(cfeature.BORDERS,
                       linewidth=2.0)  #find way to make higher res

        if 'WV' in link[index]:  #for wv color
            map_norm, map_cmap = registry.get_with_steps('WVCIMSS', 0,
                                                         1)  #color ramp
            im = ax.imshow(dat[:],
                           cmap=map_cmap,
                           norm=map_norm,
                           zorder=0,
                           extent=(x.min(), x.max(), y.min(), y.max()),
                           origin='upper')
        else:  #for vis/ir color
            im = ax.imshow(dat[:],
                           extent=(x.min(), x.max(), y.min(), y.max()),
                           origin='upper',
                           cmap='gray',
                           norm=plt.Normalize(0, 255))

        time_var = gini_ds.variables['time']
        timestamp = num2date(time_var[:].squeeze(), time_var.units)

        text = ax.text(0.99,
                       0.95,
                       timestamp.strftime('%d %B %Y %H%MZ'),
                       horizontalalignment='right',
                       transform=ax.transAxes,
                       color='white',
                       fontsize=20,
                       weight='bold')
        title = descriptors[index] + ' Satellite Image'
        title_text = ax.text(0.99,
                             0.9,
                             title,
                             horizontalalignment='right',
                             transform=ax.transAxes,
                             color='white',
                             fontsize=20,
                             weight='bold')
        title_text.set_path_effects([
            patheffects.Stroke(linewidth=2, foreground='black'),
            patheffects.Normal()
        ])
        text.set_path_effects([
            patheffects.Stroke(linewidth=2, foreground='black'),
            patheffects.Normal()
        ])
        fig.tight_layout()
        #plt.show()
        plt.savefig('Satellite_Figure_' + str(i) + '.png',
                    bbox_inches='tight',
                    pad_inches=0)
        image.append('Satellite_Figure_' + str(i) + '.png')
        plt.close()
    return image
Ejemplo n.º 16
0
def test_gini_bad_size():
    'Test reading a GINI file that reports a bad header size'
    f = GiniFile(get_test_data('NHEM-MULTICOMP_1km_IR_20151208_2100.gini'))
    pdb2 = f.prod_desc2
    assert pdb2.pdb_size == 512  # Catching bad size
Ejemplo n.º 17
0
def mapimagery():
    
    link = ['http://thredds.ucar.edu/thredds/catalog/satellite/WV/EAST-CONUS_4km/current/catalog.xml', 
             'http://thredds.ucar.edu/thredds/catalog/satellite/IR/EAST-CONUS_4km/current/catalog.xml',
             'http://thredds.ucar.edu/thredds/catalog/satellite/VIS/EAST-CONUS_1km/current/catalog.xml']
    keywords = ['WV', 'IR', 'Visible']
    descriptors = ['Water Vapor', 'Infrared', 'Visible']
    index = random.randint(0, len(link)-1) #random index that picks either wv, ir, or visible image to plot
    image = []
    for i in range(1,14,4): #loops through the first 4 hours, pulls out image from every hour
        fig = plt.figure(figsize = (10, 10))
        plt.subplots_adjust(hspace=0.03, wspace=0, top = 1, left = 0, right = 0.85, bottom = 0.0)
        plt.style.use('ggplot')
        plt.axis('off')
        figuretext ="""Satellite Imagery from GOES East Satellite (Imagery retrieved from UCAR/Unidata)
To explore more, check out the following links:
http://www.weather.gov/satellite               http://www.goes.noaa.gov/ 
http://www.ssec.wisc.edu/data/geo-new/#/animation
        
To learn how to interpret satellite imagery, check out the following links:
https://www.wunderground.com/about/satellite.asp 
http://www.weather.cod.edu/labs/satellitelab/satlab.ppt"""
        plt.figtext(0.05, 0.20, figuretext, horizontalalignment='left', verticalalignment='top',
                    fontsize = 16, color = 'white', bbox=dict(facecolor='gray', alpha = 0.85))
        
        cat = TDSCatalog(link[index]) ##current wv image
        dataset_name = sorted(cat.datasets.keys())[-i] #pulls the last one in the list above (most recent)
        dataset = cat.datasets[dataset_name] #saves that file into a dataset object
        remote_gini_file = urllib2.urlopen(dataset.access_urls['HTTPServer'])
        gini = GiniFile(remote_gini_file) ## MetPy's built in function to read gini files and parse them for you
        gini_ds = gini.to_dataset() ## converts to more comprehensive dataset
        x = gini_ds.variables['x'][:]
        y = gini_ds.variables['y'][:]
        dat = gini_ds.variables[str(keywords[index])]
            
        proj_var = gini_ds.variables[dat.grid_mapping] #pulls out the grid information (projection)
        #print(proj_var)
        
        # Create CartoPy projection information for the file
        globe = ccrs.Globe(ellipse='sphere', semimajor_axis=proj_var.earth_radius,
                            semiminor_axis=proj_var.earth_radius)

        proj = ccrs.LambertConformal(central_longitude=proj_var.longitude_of_central_meridian,
                                     central_latitude=proj_var.latitude_of_projection_origin,
                                     standard_parallels=[proj_var.standard_parallel], globe=globe)
        
        # Create a feature for States/Admin 1 regions at 1:50m from Natural Earth
        states_provinces = cfeature.NaturalEarthFeature(
            category='cultural',
            name='admin_1_states_provinces_lines',
            scale='50m',
            facecolor='none')

        lakes = cfeature.NaturalEarthFeature(
            category='physical',
            name='lakes',
            scale='110m',
            facecolor='none')

        ax = fig.add_subplot(1,1,1, projection=proj)
        ax.add_feature(states_provinces, edgecolor='black', linewidth=2.0) 
        ax.add_feature(lakes, edgecolor='black', linewidth=2.0) 
        ax.coastlines(resolution='50m', zorder=2, color='black', linewidth=2.0)
        ax.add_feature(cfeature.BORDERS, linewidth=2.0) #find way to make higher res
            
        if 'WV' in link[index]: #for wv color
            map_norm, map_cmap = registry.get_with_steps('WVCIMSS', 0, 1) #color ramp
            im = ax.imshow(dat[:], cmap=map_cmap, norm=map_norm, zorder=0,
                           extent=(x.min(), x.max(), y.min(), y.max()), origin='upper')
        else: #for vis/ir color
            im = ax.imshow(dat[:], extent=(x.min(), x.max(), y.min(), y.max()), origin='upper',
                           cmap='gray', norm=plt.Normalize(0, 255)) 

        time_var = gini_ds.variables['time']
        timestamp = num2date(time_var[:].squeeze(), time_var.units)

        text = ax.text(0.99, 0.95, timestamp.strftime('%d %B %Y %H%MZ'),
                       horizontalalignment='right', transform=ax.transAxes,
                       color='white', fontsize=20, weight='bold')
        title = descriptors[index] + ' Satellite Image' 
        title_text = ax.text(0.99, 0.9, title, horizontalalignment='right', transform=ax.transAxes,
                             color='white', fontsize=20, weight='bold')
        title_text.set_path_effects([patheffects.Stroke(linewidth=2, foreground='black'), patheffects.Normal()])
        text.set_path_effects([patheffects.Stroke(linewidth=2, foreground='black'), patheffects.Normal()])
        fig.tight_layout()
        #plt.show()
        plt.savefig('Satellite_Figure_' + str(i) + '.png', bbox_inches='tight', pad_inches=0)
        image.append('Satellite_Figure_' + str(i) + '.png')
        plt.close()
    return image