How to use nansat - 10 common examples

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

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

github nansencenter / sea_ice_drift / sea_ice_drift / tests.py View on Github external
def setUp(self):
        ''' Load test data '''
        testDir = os.getenv('ICE_DRIFT_TEST_DATA_DIR')
        if testDir is None:
            sys.exit('ICE_DRIFT_TEST_DATA_DIR is not defined')
        testFiles = glob.glob(os.path.join(testDir, 'S1?_*tif'))
        if len(testFiles) < 2:
            sys.exit('Not enough test files in %s' % testDir)
        # sort by date
        dates = [os.path.basename(f).split('_')[4] for f in testFiles]
        self.testFiles = [str(f) for f in np.array(testFiles)[np.argsort(dates)]]
        self.n1 = Nansat(self.testFiles[0])
        self.n2 = Nansat(self.testFiles[1])
        self.imgMin = 0.001
        self.imgMax = 0.013
        self.nFeatures = 5000
        self.img1 = get_uint8_image(self.n1['sigma0_HV'], self.imgMin, self.imgMax, 0, 0)
        self.img2 = get_uint8_image(self.n2['sigma0_HV'], self.imgMin, self.imgMax, 0, 0)
github nansencenter / nansat / nansat_integration_tests / test_netcdf_cf_mappers.py View on Github external
def test_reproject_arome_to_SAR(self):
        sar = Nansat(self.s1bIW)
        wind = Nansat(self.test_file_arome_metcoop, netcdf_dim={'time':
            np.datetime64(sar.time_coverage_start)},
            bands=['y_wind','x_wind'])
        self.assertTrue(wind['x_wind_10m'].any())
        self.assertTrue(wind['y_wind_10m'].any())
        wind.reproject(sar, addmask=False)
        self.assertTrue(wind['x_wind_10m'].any())
        self.assertTrue(wind['y_wind_10m'].any())
github nansencenter / nansat / nansat_integration_tests / test_netcdf_cf_mappers.py View on Github external
def test_reproject_arome_to_SAR(self):
        sar = Nansat(self.s1bIW)
        wind = Nansat(self.test_file_arome_metcoop, netcdf_dim={'time':
            np.datetime64(sar.time_coverage_start)},
            bands=['y_wind','x_wind'])
        self.assertTrue(wind['x_wind_10m'].any())
        self.assertTrue(wind['y_wind_10m'].any())
        wind.reproject(sar, addmask=False)
        self.assertTrue(wind['x_wind_10m'].any())
        self.assertTrue(wind['y_wind_10m'].any())
github nansencenter / nansat / nansat_integration_tests / test_netcdf_cf_mappers.py View on Github external
def test_arome_mapper_is_used(self):
        n = Nansat(self.test_file_arome_arctic)
        self.assertEqual(n.mapper, 'arome')
        n = Nansat(self.test_file_arome_metcoop)
        self.assertEqual(n.mapper, 'arome')
        self.assertTrue(n['x_wind_10m'].any())
        self.assertTrue(n['y_wind_10m'].any())
github nansencenter / sea_ice_drift / sea_ice_drift / tests.py View on Github external
def test_get_invalid_mask_with_error(self):
        n = Nansat(self.testFiles[0])
        n.watermask = MagicMock(return_value=None, side_effect=KeyError('foo'))
        img = n[1]
        mask = get_invalid_mask(img, n, 20)
        self.assertFalse(np.any(mask))
github nansencenter / nansat / tutorial / test_domain.py View on Github external
meanLat = sum(lats, 0.0) / 4.

# get string with WKT representation of the border polygon
print 'BorderPolygon:', d.get_border_polygon(), '\n'

# longitude and latitude grids representing the full data grid
longitude, latitude = d.get_geolocation_grids()
print 'longitude shape: :', longitude.shape, '\n'

# make KML file with image borders (to be opened in Googe Earth)
d.write_kml(kmlFileName=oFileName + '03_preview.kml')

# -- Create Domain with stereographic projection and resolution 1000m
srsString = "+proj=stere +lon_0=5 +lat_0=60"
extentString = '-te -1000000 -1000000 1000000 1000000 -tr 1000 1000'
d = Domain(srsString, extentString)
d.write_map(oFileName + '02_stereo_map.png')
print 'Stereo Domain:', d, '\n'


print '\n*** domain_test completed successfully. Output files are found here:' + oFileName
github nansencenter / nansat / tutorial / test_domain.py View on Github external
''' Domain class is a container for geographical reference of a raster

A Domain object describes all attributes of geographical
reference of a raster:
    width and height, pixel size,
    relation between pixel/line coordinates and geographical coordinates,
    type of data projection (e.g. geographical or stereographic)

'''

# Create Domain object. It describes the desired grid of reprojected image:
# projection, resolution, size, etc. In this case it is geographic projection;
# -10 - 30 E, 50 - 70 W; 2000 x 2000 pixels
d = Domain("+proj=latlong +datum=WGS84 +ellps=WGS84 +no_defs",
           "-te 25 70 35 72 -ts 2000 2000")
d = Domain(4326, "-te 25 70 35 72 -ts 2000 2000")
d.write_map(oFileName + '01_latlong_map.png')
print 'Latlong Domain:', d, '\n'

# get shape
print 'shape:', d.shape(), '\n'

# Generate two vectors with values of lat/lon for the border of domain
lonVec, latVec = d.get_border()
print 'lonVec :', lonVec, '\n'
print 'latVec :', latVec, '\n'

# Get upwards azimuth direction of domain.
bearing_center = d.upwards_azimuth_direction()
print 'bearing_center :', bearing_center, '\n'

# Create domain with stereographic projection
github nansencenter / sea_ice_drift / sea_ice_drift / tests.py View on Github external
sid = SeaIceDrift(self.testFiles[0], self.testFiles[1])

        lon1b, lat1b = sid.n1.get_border()
        lon1pm, lat1pm = np.meshgrid(np.linspace(lon1b.min(), lon1b.max(), 50),
                             np.linspace(lat1b.min(), lat1b.max(), 50))
        uft, vft, lon1ft, lat1ft, lon2ft, lat2ft = sid.get_drift_FT()
        upm, vpm, apm, rpm, hpm, lon2pm, lat2pm = sid.get_drift_PM(
                                            lon1pm, lat1pm,
                                            lon1ft, lat1ft,
                                            lon2ft, lat2ft)

        lon1, lat1 = sid.n1.get_border()
        lon2, lat2 = sid.n2.get_border()
        ext_str = '-te %s %s %s %s -ts 500 500' % (lon1b.min(), lat1b.min(), lon1b.max(), lat1b.max())
        sid.n1.reproject(Domain(NSR().wkt, ext_str))
        s01 = sid.n1['sigma0_HV']
        sid.n2.reproject(Domain(NSR().wkt, ext_str))
        s02 = sid.n2['sigma0_HV']
        extent=[lon1b.min(), lon1b.max(), lat1b.min(), lat1b.max()]
        plt.imshow(s01, extent=extent, cmap='gray', aspect=10)
        plt.quiver(lon1ft, lat1ft, uft, vft, color='r',
                   angles='xy', scale_units='xy', scale=0.2)
        plt.plot(lon2, lat2, '.-r')
        plt.xlim([lon1b.min(), lon1b.max()])
        plt.ylim([lat1b.min(), lat1b.max()])
        plt.savefig('sea_ice_drift_tests_%s_img1_ft.png' % inspect.currentframe().f_code.co_name,
                    dpi=150, bbox_inches='tight', pad_inches=0)
        plt.close('all')

        plt.imshow(s02, extent=extent, cmap='gray', aspect=10)
        gpi = hpm*rpm > 4
github nansencenter / nansat / tutorial / test_nsr.py View on Github external
#               Dmitry Petrenko, Evgeny Morozov
# Created:      13.02.2014
# Copyright:    (c) NERSC 2011 - 2013
# Licence:
# This file is part of NANSAT.
# NANSAT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
# http://www.gnu.org/licenses/gpl-3.0.html
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

from nansat import osr, NSR

print 'NSR(None)', NSR(None), '\n\n\n'
print 'NSR()', NSR(), '\n\n\n'
print 'NSR(+proj=longlat)', NSR('+proj=longlat'), '\n\n\n'
try:
    n = NSR('crap')
except:
    print 'NSR(crap) raises Error', '\n\n\n'
else:
    print n, '\n\n\n'
print 'NSR(osr.SRS_WKT_WGS84)', NSR(osr.SRS_WKT_WGS84), '\n\n\n'
print 'NSR(4326)', NSR(4326), '\n\n\n'
srs = osr.SpatialReference(NSR(4326).wkt)
print 'NSR(osr.SpatialReference())', NSR(srs), '\n\n\n'
print 'NSR(NSR(4326))', NSR(NSR(4326)), '\n\n\n'
print 'NSR(+proj=stere +datum=WGS84 +ellps=WGS84 +lat_0=75 +lon_0=10 +no_defs)', NSR('+proj=stere +datum=WGS84 +ellps=WGS84 +lat_0=75 +lon_0=10 +no_defs'), '\n\n\n'

print '\n*** nsr_test completed successfully.\n\n\n'
github nansencenter / nansat / tutorial / test_nsr.py View on Github external
# but WITHOUT ANY WARRANTY without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

from nansat import osr, NSR

print 'NSR(None)', NSR(None), '\n\n\n'
print 'NSR()', NSR(), '\n\n\n'
print 'NSR(+proj=longlat)', NSR('+proj=longlat'), '\n\n\n'
try:
    n = NSR('crap')
except:
    print 'NSR(crap) raises Error', '\n\n\n'
else:
    print n, '\n\n\n'
print 'NSR(osr.SRS_WKT_WGS84)', NSR(osr.SRS_WKT_WGS84), '\n\n\n'
print 'NSR(4326)', NSR(4326), '\n\n\n'
srs = osr.SpatialReference(NSR(4326).wkt)
print 'NSR(osr.SpatialReference())', NSR(srs), '\n\n\n'
print 'NSR(NSR(4326))', NSR(NSR(4326)), '\n\n\n'
print 'NSR(+proj=stere +datum=WGS84 +ellps=WGS84 +lat_0=75 +lon_0=10 +no_defs)', NSR('+proj=stere +datum=WGS84 +ellps=WGS84 +lat_0=75 +lon_0=10 +no_defs'), '\n\n\n'

print '\n*** nsr_test completed successfully.\n\n\n'