def get_or_create(self, uri, reprocess=False, *args, **kwargs): # ingest file to db ds, created = super(DatasetManager, self).get_or_create(uri, *args, **kwargs) fn = nansat_filename(uri) n = Nansat(fn) # Reproject to leaflet projection xlon, xlat = n.get_corners() d = Domain( NSR(3857), '-lle %f %f %f %f -tr 1000 1000' % (xlon.min(), xlat.min(), xlon.max(), xlat.max())) n.reproject(d) # Get band numbers of required bands according to standard names speedBandNum = n._get_band_number({'standard_name': 'wind_speed'}) dirBandNum = n._get_band_number( {'standard_name': 'wind_from_direction'}) # Get numpy arrays of the bands speed = n[speedBandNum] dir = n[dirBandNum] ## It probably wont work with nansatmap... #nmap = Nansatmap(n, resolution='l') #nmap.pcolormesh(speed, vmax=18) #nmap.quiver(-speed*np.sin(dir), speed*np.cos(dir), step=10, scale=300, # width=0.002) # Set paths - this code should be inherited but I think there is an # issue in generalising the first line that defines the current module mm = self.__module__.split('.') module = '%s.%s' % (mm[0], mm[1]) mp = media_path(module, n.fileName) ppath = product_path(module, n.fileName) filename = os.path.basename(n.fileName).split('.')[0] + '.' + \ os.path.basename(n.fileName).split('.')[1] + '.png' # check uniqueness of parameter param1 = Parameter.objects.get(standard_name=n.get_metadata( bandID=speedBandNum, key='standard_name')) param2 = Parameter.objects.get(standard_name=n.get_metadata( bandID=dirBandNum, key='standard_name')) n.write_figure(os.path.join(mp, filename), bands=speedBandNum, mask_array=n['swathmask'], mask_lut={0: [128, 128, 128]}, transparency=[128, 128, 128]) # Get DatasetParameter dsp1, created = DatasetParameter.objects.get_or_create( dataset=ds, parameter=param1) # Create Visualization geom, created = GeographicLocation.objects.get_or_create( geometry=WKTReader().read(n.get_border_wkt())) vv, created = Visualization.objects.get_or_create( uri='file://localhost%s/%s' % (mp, filename), title='%s' % (param1.standard_name), geographic_location=geom) # Create VisualizationParameter vp, created = VisualizationParameter.objects.get_or_create( visualization=vv, ds_parameter=dsp1) return ds, True
from nansat.nansat import Nansat, Domain iFileName = os.path.join(home, 'python/nansat/nansat/tests/data/gcps.tif') # Open an input satellite image with Nansat n = Nansat(iFileName) # List bands and georeference of the object print n # Write picture with map of the file location n.write_map('map.png') # Write indexed picture with data from the first band n.write_figure('rgb.png', clim='hist') # Reproject input image onto map of Norwegian Coast # 1. Create domain describing the desired map # 2. Transform the original satellite image # 3. Write the transfromed image into RGB picture dLatlong = Domain("+proj=latlong +datum=WGS84 +ellps=WGS84 +no_defs", "-te 27 70.2 31 71.5 -ts 2000 2000") n.reproject(dLatlong) n.write_figure('pro.png', bands=[1,2,3], clim=[0, 100]) # Export projected satelite image into NetCDF format n.export('gcps_projected.nc') # Collect values from interactively drawn transect # 1. draw transect interactively