def test_nansat_reproject(self): if len(self.test_data.asar)==0: raise IOError('No ASAR data - try adding some as ' \ 'described in templates/openwind_local_archive.py' ) asar = Nansat(self.test_data.asar[0]) asar.resize(pixelsize=500, eResampleAlg=1) mw = Nansat(self.test_data.ncep4asar[0]) mw.reproject(asar, eResampleAlg=1) if sys.version_info < (2, 7): type(mw[1]) == np.ndarray else: self.assertIsInstance(mw[1], np.ndarray)
def test_nansat_reproject(self): if len(self.test_data.asar) == 0: raise IOError('No ASAR data - try adding some as ' \ 'described in templates/openwind_local_archive.py' ) asar = Nansat(self.test_data.asar['agulhas']) asar.resize(pixelsize=500, eResampleAlg=1) mw = Nansat(self.test_data.ncep4asar['agulhas']) mw.reproject(asar, eResampleAlg=1) if sys.version_info < (2, 7): type(mw[1]) == np.ndarray else: self.assertIsInstance(mw[1], np.ndarray)
def resize(self, rsfile): sys.stderr.write('\nresize:'+rsfile+'\n') n = Nansat(rsfile) inc_max = float(n.get_metadata()['FAR_RANGE_INCIDENCE_ANGLE'])+0.5 n.resize(0.5, eResampleAlg=0) assert (np.nanmax(n['incidence_angle']) <= inc_max) n.undo() n.resize(0.5, eResampleAlg=1) assert (np.nanmax(n['incidence_angle']) <= inc_max) n.undo() n.resize(0.5, eResampleAlg=2) assert (np.nanmax(n['incidence_angle']) <= inc_max) n.undo() n.resize(0.5, eResampleAlg=3) assert (np.nanmax(n['incidence_angle']) <= inc_max) n.undo() n.resize(0.5, eResampleAlg=4) assert (np.nanmax(n['incidence_angle']) <= inc_max) n.undo()
def resize(self, rsfile): sys.stderr.write("\nresize:" + rsfile + "\n") n = Nansat(rsfile) inc_max = float(n.get_metadata()["FAR_RANGE_INCIDENCE_ANGLE"]) + 0.5 n.resize(0.5, eResampleAlg=0) assert np.nanmax(n["incidence_angle"]) <= inc_max n.undo() n.resize(0.5, eResampleAlg=1) assert np.nanmax(n["incidence_angle"]) <= inc_max n.undo() n.resize(0.5, eResampleAlg=2) assert np.nanmax(n["incidence_angle"]) <= inc_max n.undo() n.resize(0.5, eResampleAlg=3) assert np.nanmax(n["incidence_angle"]) <= inc_max n.undo() n.resize(0.5, eResampleAlg=4) assert np.nanmax(n["incidence_angle"]) <= inc_max n.undo()
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) # set Dataset entry_title ds.entry_title = 'SAR NRCS' ds.save() # Unless reprocess==True, we may not need to do the following... (see # managers.py in sar doppler processor) #visExists = ... # check if visualization(s) already created #if visExists and not reprocess: # warnings.warn('NO VISUALISATIONS CREATED - update managers.py') # return ds, created n = Nansat(nansat_filename(uri)) n.reproject_GCPs() n.resize(pixelsize=500) lon, lat = n.get_corners() lat_max = min(lat.max(), 85) d = Domain( NSR(3857), '-lle %f %f %f %f -ts %d %d' % (lon.min(), lat.min(), lon.max(), lat_max, n.shape()[1], n.shape()[0])) # Get all NRCS bands s0bands = [] pp = [] for key, value in n.bands().iteritems(): try: if value['standard_name'] == standard_name: s0bands.append(key) pp.append(value['polarization']) except KeyError: continue ''' Create data products ''' mm = self.__module__.split('.') module = '%s.%s' % (mm[0], mm[1]) mp = media_path(module, n.fileName) # ppath = product_path(module, n.fileName) # Create png's for each band num_products = 0 for band in s0bands: print 'Visualize', band s0_tmp = n[band] n_tmp = Nansat(domain=n, array=s0_tmp) n_tmp.reproject_GCPs() n_tmp.reproject(d) s0 = n_tmp[1] n_tmp = None mask = np.ones(s0.shape, np.uint8) mask[np.isnan(s0) + (s0 <= 0)] = 0 s0 = np.log10(s0) * 10. meta = n.bands()[band] product_filename = '%s_%s.png' % (meta['short_name'], meta['polarization']) nansatFigure(s0, mask, polarization_clims[meta['polarization']][0], polarization_clims[meta['polarization']][1], mp, product_filename) # Get DatasetParameter param = Parameter.objects.get(short_name=meta['short_name']) dsp, created = DatasetParameter.objects.get_or_create( dataset=ds, parameter=param) # 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, product_filename), title='%s %s polarization' % (param.standard_name, meta['polarization']), geographic_location=geom) # Create VisualizationParameter vp, created = VisualizationParameter.objects.get_or_create( visualization=vv, ds_parameter=dsp) return ds, True