コード例 #1
0
    def get_or_create(self, uri, force):
        # Validate uri - this should raise an exception if the uri doesn't
        # point to a valid file or stream
        validate_uri(uri)
        # Several datasets can refer to the same uri (e.g., scatterometers and svp drifters), so we
        # need to pass uri_filter_args
        uris = DatasetURI.objects.filter(uri=uri)
        # If the ingested uri is already in the database and not <force> ingestion then stop
        if uris.exists() and not force:
            return uris[0].dataset, False
        elif uris.exists() and force:
            uris[0].dataset.delete()
        # Open file with Nansat
        n = Nansat(nansat_filename(uri))
        # get metadata from Nansat and get objects from vocabularies
        n_metadata = n.get_metadata()
        # set compulsory metadata (source)
        platform, _ = Platform.objects.get_or_create(
            json.loads(n_metadata['platform']))
        instrument, _ = Instrument.objects.get_or_create(
            json.loads(n_metadata['instrument']))
        specs = n_metadata.get('specs', '')
        source, _ = Source.objects.get_or_create(platform=platform,
                                                 instrument=instrument,
                                                 specs=specs)
        footprint = Polygon(list(zip(*n.get_border())))
        geolocation = GeographicLocation.objects.get_or_create(
            geometry=footprint)[0]
        data_center = DataCenter.objects.get_or_create(
            json.loads(n_metadata['Data Center']))[0]
        iso_category = ISOTopicCategory.objects.get_or_create(
            pti.get_iso19115_topic_category('Oceans'))[0]
        location = Location.objects.get_or_create(
            json.loads(n_metadata['gcmd_location']))[0]
        # create dataset
        ds, created = Dataset.objects.get_or_create(
            time_coverage_start=make_aware(n.time_coverage_start),
            time_coverage_end=make_aware(
                n.time_coverage_start +
                timedelta(hours=23, minutes=59, seconds=59)),
            source=source,
            geographic_location=geolocation,
            ISO_topic_category=iso_category,
            data_center=data_center,
            summary='',
            gcmd_location=location,
            access_constraints='',
            entry_id=lambda: 'NERSC_' + str(uuid.uuid4()))

        ds_uri, _ = DatasetURI.objects.get_or_create(
            name=FILE_SERVICE_NAME,
            service=LOCAL_FILE_SERVICE,
            uri=uri,
            dataset=ds)
        return ds, created
コード例 #2
0
ファイル: nansatExampleASAR.py プロジェクト: whigg/PySOL
#n = Nansat(iPath + fileName)

# list bands and georeference of the object
print n

# get dictionary with all bands metadata
print n.bands()

# get size of the object (Y and X dimensions, to follow Numpy style)
print n.shape()

# get list with coordinates of the object corners
print n.get_corners()

# get lists with coordinates of the object borders
print n.get_border()

raw_counts = n[1]
inc_angle = n[2]

#~ sigma0 = n[3]

sigma0 = raw_counts**2.0 * sin(deg2rad(inc_angle))
sigma0 = 10*log10(sigma0)
n.add_band(bandID=4, array=sigma0)

# 1. Remove speckle noise (using Lee-Wiener filter)
speckle_filter('wiener', 7)

# Reprojected image into Lat/Lon WGS84 (Simple Cylindrical) projection
# 1. Cancel previous reprojection
コード例 #3
0
ファイル: tutorial.py プロジェクト: magican/nansat
n = Nansat(iFileName, mapperName='generic', logLevel=10)

# list bands and georeference of the object
print 'Raw Nansat:', n

# get dictionary with metadata from all bands
print 'Bands:', n.bands()

# get size of the object (Y and X dimensions, to follow Numpy style)
print 'Shape:', n.shape()

# get list with coordinates of the object corners
print 'Corners:', n.get_corners()

# get lists with coordinates of the object borders
print 'Border:', n.get_border()

# get time of the image aquisition
print 'Time:', n.get_time()[0]

# Get band data and do some operations
# 1. Get data from 1st band as numpy array
# 2. Plot the array (pyplot image is save to a PNG file)
# 3. Save as Matlab file
a = n[1]
plt.imshow(a);plt.colorbar();plt.savefig(oFileName + '_imshow.png');plt.close()
savemat(oFileName + '.mat', {'band_1': a})

# make simple indexed image from 1st band with default colormap
n.write_figure(oFileName + '.png')