def export_band(self, rsfile): sys.stderr.write('\nexport_band:'+rsfile+'\n') orig = Nansat(rsfile) ncfile = 'test.nc' orig.export(ncfile, bands=[orig.get_band_number('incidence_angle')]) copy = Nansat(ncfile) inc0 = orig['incidence_angle'] inc1 = copy['incidence_angle'] np.testing.assert_allclose(inc0, inc1) os.unlink(ncfile)
def _get_aux_wind_from_str(self, aux_wind_source, *args, **kwargs): import nansat.nansat mnames = [key.replace('mapper_','') for key in nansat.nansat.nansatMappers] # check if aux_wind_source is like 'ncep_wind_online', i.e. only # mapper name is given. By adding the SAR image time stamp, we # can then get the data online if aux_wind_source in mnames: aux_wind_source = aux_wind_source + \ datetime.strftime(self.SAR_image_time, ':%Y%m%d%H%M') aux = Nansat(aux_wind_source, netcdf_dim={ 'time': np.datetime64(self.SAR_image_time), 'height2': 10, # height dimension used in AROME arctic # datasets 'height3': 10, }, bands = [ # CF standard names of desired bands 'x_wind_10m', 'y_wind_10m', # or..: 'x_wind', 'y_wind', # or..: 'eastward_wind', 'northward_wind', ]) # Set filename of source wind in metadata try: wind_u_bandNo = aux.get_band_number({ 'standard_name': 'eastward_wind', }) except ValueError: try: wind_u_bandNo = aux.get_band_number({ 'standard_name': 'x_wind', }) except: wind_u_bandNo = aux.get_band_number({ 'standard_name': 'x_wind_10m', }) self.set_metadata('WIND_DIRECTION_SOURCE', aux_wind_source) wdir, wdir_time, wspeed = self._get_wind_direction_array(aux, *args, **kwargs) return wdir, wdir_time, wspeed
def export_band(self, rsfile): sys.stderr.write('\nexport_band:' + rsfile + '\n') orig = Nansat(rsfile) ncfile = 'test.nc' orig.export(ncfile, bands=[orig.get_band_number('incidence_angle')]) copy = Nansat(ncfile) inc0 = orig['incidence_angle'] inc1 = copy['incidence_angle'] np.testing.assert_allclose(inc0, inc1) os.unlink(ncfile)
def _get_masked_windspeed(self, landmask=True, icemask=True, windspeedBand='windspeed'): try: sar_windspeed = self[windspeedBand] except: raise ValueError('SAR wind has not been calculated, ' \ 'execute calculate_wind(wind_direction) first.') sar_windspeed[sar_windspeed<0] = 0 palette = jet if landmask: try: # Land mask sar_windspeed = np.ma.masked_where( self.watermask(tps=True)[1]==2, sar_windspeed) palette.set_bad([.3, .3, .3], 1.0) # Land is masked (bad) except: print('Land mask not available') if icemask: try: # Ice mask try: # first try local file ice = Nansat('metno_local_hires_seaice_' + self.SAR_image_time.strftime('%Y%m%d'), mapperName='metno_local_hires_seaice') except: # otherwise Thredds ice = Nansat('metno_hires_seaice:' + self.SAR_image_time.strftime('%Y%m%d')) ice.reproject(self, tps=True) iceBandNo = ice.get_band_number( {'standard_name': 'sea_ice_area_fraction'}) sar_windspeed[ice[iceBandNo]>0] = -1 palette.set_under('w', 1.0) # Ice is 'under' (-1) except: print('Ice mask not available') return sar_windspeed, palette