How to use the nansat.Nansat function in nansat

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 / 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 / nansat / cli / nansat_add_coastline.py View on Github external
def main():
    if (len(sys.argv) < 1):
        Usage()
    
    inFileName = sys.argv[1]
    try:
        n = Nansat(inFileName)
    except:
        Usage()
    
    # Currently only implemented for lonlat-projection (Plate Carree)
    if n.vrt.dataset.GetProjection()[0:4] != 'GEOG':
        sys.exit('Utility currently only implemented for datasets with '\
               'geographical (lonlat / Plate Carree) coordiante systems')
    
    try:
        outFileName = sys.argv[2]
    except:
        outFileName = inFileName + '_coastline.png'
    
    imsize = n.vrt.dataset.RasterXSize, n.vrt.dataset.RasterYSize
    lon, lat = n.get_corners()
    fig = plt.figure()
github nansencenter / openwind / openwind / sar_wind.py View on Github external
import argparse
from datetime import datetime

import numpy as np

try:
    import matplotlib.pyplot as plt
    from matplotlib.cm import jet
except:
    print 'WARNING: Matplotlib not available, cannot make plots'

from nansat import Nansat, Domain
from cmod5n import cmod5n_inverse


class SARWind(Nansat, object):
    '''
    A class for calculating wind speed from SAR images using CMOD
    '''

    def __init__(self, sar_image, winddir=None, pixelsize=500):
        '''
            Parameters
            -----------
            sar_image : string or Nansat object
                SAR image filename (original, raw file)
            winddir : int, string, Nansat, None
                Auxiliary wind field information needed to calculate
                SAR wind (must be or have wind direction)
        '''
        if isinstance(sar_image, str) or isinstance(sar_image, unicode):
            super(SARWind, self).__init__(sar_image)
github nansencenter / nansat / nansat / cli / nansat_geotiffimage.py View on Github external
def main():
    if (len(sys.argv) <= 2):
        Usage()
    
    try:
        bandNo = int(sys.argv[1])
        infileName = sys.argv[2]
        outfileName = sys.argv[3]
    except:
        Usage()
    
    n = Nansat(infileName)
    n.write_geotiffimage(outfileName, bandNo)
github nansencenter / nansat / nansat / cli / nansat_show.py View on Github external
def main():
    if (len(sys.argv) < 3):
        Usage()
    
    bandNo = int(sys.argv[1])
    try:
        n = Nansat(sys.argv[2])
    except:
        Usage()
    
    try:
        outfile = sys.argv[3]
        delete = False
    except:
        outfile = 'tmp.png'
        delete = True
    
    n.write_figure(outfile, bandNo, legend=True)
    Image.open(outfile).show()
    
    if delete:
        os.remove(outfile)
github nansencenter / sea_ice_drift / sea_ice_drift / lib.py View on Github external
pmax : float
        upper percentile for data scaling if vmax is None
    **kwargs : dummy parameters for
        get_denoised_object()

    Returns
    -------
        n : Nansat object with one band scaled to UInt8

    """
    if denoise:
        # run denoising
        n = get_denoised_object(filename, bandName, factor, **kwargs)
    else:
        # open data with Nansat and downsample
        n = Nansat(filename)
        if factor != 1:
            n.resize(factor, resample_alg=-1)
    # get matrix with data
    img = n[bandName]
    # convert to dB
    if not denoise and dB:
        img[img <= 0] = np.nan
        img = 10 * np.log10(img)
    if correct_hh:
        img = hh_angular_correction(n, img, bandName, correct_hh_factor)
    if mask_invalid:
        mask = get_invalid_mask(img, n, landmask_border)
        img[mask] = np.nan
    if remove_spatial_mean:
        img -= get_spatial_mean(img)
    # convert to 0 - 255
github nansencenter / sea_ice_drift / sea_ice_drift / lib.py View on Github external
def get_denoised_object(filename, bandName, factor, **kwargs):
    ''' Use sentinel1denoised and preform thermal noise removal
    Import is done within the function to make the dependency not so strict
    '''
    from sentinel1denoised.S1_EW_GRD_NoiseCorrection import Sentinel1Image
    s = Sentinel1Image(filename)
    s.add_denoised_band('sigma0_HV', **kwargs)
    s.resize(factor, eResampleAlg=-1)
    img = s[bandName + '_denoised']

    n = Nansat(domain=s)
    n.add_band(img, parameters=s.get_metadata(bandID=bandName))
    n.set_metadata(s.get_metadata())

    return n
github nansencenter / django-geo-spaas / geospaas / processing_hab / tools / modis_l2_image.py View on Github external
self.reproject(dtsDomain)
            except:
                print 'Cannot reproject %s. Skipping' % fileName
                return 1
            else:
                Rrsw_412 = self['Rrsw_412']
                if Rrsw_412 is None:
                    return 1
                # process input with BOREALI
                b = Boreali(model='northsea', zone='northsea')
                cImg = b.process_lm(self, wavelen=[412, 443, 488, 531, 555, 667],
                                          start=opts['start'],
                                          minmax=borMinMax)

                # generate Nansat with results
                img2 = Nansat(domain=self)
                for i, pn in enumerate(opts['prods']):
                    img2.add_band(array=cImg[i, :, :], parameters={'name': pn})
                img2.add_band(array=self['mask'], parameters={'name': 'mask'})

                # export results into NC-file
                img2.export(ncName)

                # write images with concentrations
                for pn in opts['prods']:
                    pnd = pnDefaults[pn]
                    img2.write_figure(prodFileNames[pn], pn, clim=[pnd[0], pnd[1]], legend=True, logarithm=pnd[2])

        return 0