def _get_sitype_track(self, l2): """ Extract ice type and ice type uncertainty along the track :param l2: :return: sitype (array), sitype_uncertainty (array) """ # --- Extract sea ice type and its uncertainty along the trajectory --- griddef = self.cfg.options[l2.hemisphere] grid_lons, grid_lats = self._data.lon, self._data.lat grid2track = GridTrackInterpol(l2.track.longitude, l2.track.latitude, grid_lons, grid_lats, griddef) sitype = grid2track.get_from_grid_variable(self._data.ice_type[0, :, :], flipud=True) uncertainty = grid2track.get_from_grid_variable(self._data.uncertainty[0, :, :], flipud=True) # --- Translate the flags in the file into MYI-fractions --- # The fill value of the sea ice type as changed for different product version # To assure backwards compatibility the fill value defaults to -1 (sea ice type v1p0) # an for newer versions it must be specified in the options fill_value = self.cfg.options.get("fill_value", -1) fillvalue_locations = np.where(sitype == fill_value)[0] sitype[fillvalue_locations] = 5 sitype = np.array([*map(self.flag_translator, sitype)]) # --- Ensure uncertainty units are fractions and not percent --- # In the sea-ice type cdr/icdr v1.0 the unit of uncertainty in percent # while from v2.0 on the unit is fraction. Therefore a switch has been # introduced for v2.0 that turn the unit conversion (default) off uncertainty_unit_is_percent = self.cfg.options.get("uncertainty_unit_is_percent", True) if uncertainty_unit_is_percent: uncertainty = uncertainty / 100. # All done, return values return sitype, uncertainty
def _get_sitype_track(self, l2): # Extract from grid griddef = self.cfg.options[l2.hemisphere] grid_lons, grid_lats = self._data.lon, self._data.lat grid2track = GridTrackInterpol(l2.track.longitude, l2.track.latitude, grid_lons, grid_lats, griddef) sitype = grid2track.get_from_grid_variable(self._data.ice_type[0, :, :], flipud=True) # set fill values to flag 0 -> nan fillvalues = np.where(sitype == -1)[0] sitype[fillvalues] = 0 # --- Translate sea-ice type codes into myi fraction --- # flag_meanings: -1: fill value, 1: open_water, 2: first_year_ice, 3: multi_year_ice, 4: ambiguous translator = np.array([np.nan, np.nan, 0.0, 1.0, 0.5]) sitype = np.array([translator[value] for value in sitype]) # --- Get Uncertainty --- # NOTE: There has been a change in OSI-403-d, when the `confidence_level` # variable was replaced by uncertainty. try: # Translate confidence level into myi fraction uncertainty # flag_meaning: 0: unprocessed, 1: erroneous, 2: unreliable, 3: acceptable, 4: good, 5: excellent confidence_level = grid2track.get_from_grid_variable(self._data.confidence_level[0, :, :], flipud=True) translator = np.array([np.nan, 1., 0.5, 0.2, 0.1, 0.0]) sitype_uncertainty = np.array([translator[value] for value in confidence_level]) except AttributeError: sitype_uncertainty = grid2track.get_from_grid_variable(self._data.uncertainty[0, :, :], flipud=True) return sitype, sitype_uncertainty
def _get_sic_track(self, l2): """ Simple extraction along trajectory""" # Extract from grid griddef = self.cfg.options[l2.hemisphere] grid_lons, grid_lats = self._data.lon, self._data.lat grid2track = GridTrackInterpol(l2.track.longitude, l2.track.latitude, grid_lons, grid_lats, griddef) sic = grid2track.get_from_grid_variable(self._data.ice_conc, flipud=True) return sic
def get_l2_track_vars(self, l2): # Extract from grid griddef = self.cfg.options[l2.hemisphere] grid_lons, grid_lats = self._data.longitude, self._data.latitude grid2track = GridTrackInterpol(l2.track.longitude, l2.track.latitude, grid_lons, grid_lats, griddef) region_code = grid2track.get_from_grid_variable(self._data.region_id, flipud=False) # Register the variable self.register_auxvar("reg_code", "region_code", region_code, None)
def _get_sic_track(self, l2: "Level2Data") -> np.ndarray: """ Simple extraction along trajectory :param l2: :return: sea ice concentration array """ # Extract from grid griddef = self.cfg.options[l2.hemisphere] grid_lons, grid_lats = self._data.lon, self._data.lat grid2track = GridTrackInterpol(l2.track.longitude, l2.track.latitude, grid_lons, grid_lats, griddef) sic = grid2track.get_from_grid_variable(self._data.ice_conc, flipud=True) return sic
def get_l2_track_vars(self, l2): """ API method to map gridded region id on the trajectory :param l2: :return: """ # Extract from grid griddef = self.cfg.options[l2.hemisphere] grid_lons, grid_lats = self.nc.longitude.values, self.nc.latitude.values grid2track = GridTrackInterpol(l2.track.longitude, l2.track.latitude, grid_lons, grid_lats, griddef) region_code = grid2track.get_from_grid_variable( self.nc.region_id.values, flipud=False) # Register the variable self.register_auxvar("reg_code", "region_code", region_code, None)
def _get_snow_track(self, l2): """ Extract the snow depth and density track along the l2 track :param l2: :return: """ # Extract track data from grid griddef = self.cfg.options[l2.hemisphere] grid_lons, grid_lats = self._data.get_lonlat() grid2track = GridTrackInterpol(l2.track.longitude, l2.track.latitude, grid_lons, grid_lats, griddef) # Extract data (Map the extracted tracks directly on the snow parameter container) var_map = self.cfg.options.variable_map snow = SnowParameterContainer() for var_name in var_map.keys(): source_name = var_map[var_name] sdgrid = self._data.get_var(source_name, self._requested_date) setattr(snow, var_name, grid2track.get_from_grid_variable(sdgrid)) # Extract the W99 weight w99_weight = grid2track.get_from_grid_variable(self._data.w99_weight) # Apply the same modification as the Warren climatology # Apply ice_type (myi_fraction correction) but this time modified by the regional weight # of the Warren climatology. The weight ranges from 0 to 1 and make sure no fyi scaling is # applied over the AMSR2 region data scale_factor = (1.0 - l2.sitype ) * self.cfg.options.fyi_correction_factor * w99_weight # The scaling factor affects the snow depth ... snow.depth = snow.depth - scale_factor * snow.depth # ... and the uncertainty. Here it is assumed that the uncertainty # is similar affected by the scaling factor. snow.depth_uncertainty = snow.depth_uncertainty - scale_factor * snow.depth_uncertainty # the uncertainty of the myi fraction is acknowledged by adding # an additional term that depends on snow depth, the magnitude of # scaling and the sea ice type uncertainty scaling_uncertainty = snow.depth * scale_factor * l2.sitype.uncertainty * w99_weight snow.depth_uncertainty = snow.depth_uncertainty + scaling_uncertainty return snow
def _get_sitype_track(self, l2): """ Extract ice type and ice type uncertainty along the track """ # Extract from grid griddef = self.cfg.options[l2.hemisphere] grid_lons, grid_lats = self._data.lon, self._data.lat grid2track = GridTrackInterpol(l2.track.longitude, l2.track.latitude, grid_lons, grid_lats, griddef) sitype = grid2track.get_from_grid_variable(self._data.ice_type[0, :, :], flipud=True) uncertainty = grid2track.get_from_grid_variable(self._data.uncertainty[0, :, :], flipud=True) # Convert flags to myi fraction translator = np.array([np.nan, np.nan, 0.0, 1.0, 0.5, np.nan]) fillvalues = np.where(sitype == -1)[0] sitype[fillvalues] = 5 sitype = np.array([translator[value] for value in sitype]) # Uncertainty in product is in % sitype_uncertainty = uncertainty / 100. return sitype, sitype_uncertainty
def _get_snow_track(self, l2): """ Extract snow depth from grid """ # Extract from grid griddef = self.cfg.options[l2.hemisphere] grid_lons, grid_lats = self._data.lon, self._data.lat grid2track = GridTrackInterpol(l2.track.longitude, l2.track.latitude, grid_lons, grid_lats, griddef) # Extract snow depth along track data from grid sd_parameter_name = self.cfg.options.snow_depth_nc_variable sdgrid = getattr(self._data, sd_parameter_name)[0, :, :] snow_depth = grid2track.get_from_grid_variable(sdgrid, flipud=True) snow_depth[snow_depth < 0.0] = np.nan # Extract snow depth uncertainty unc_parameter_name = self.cfg.options.snow_depth_uncertainty_nc_variable uncgrid = getattr(self._data, unc_parameter_name)[0, :, :] snow_depth_uncertainty = grid2track.get_from_grid_variable(uncgrid, flipud=True) snow_depth_uncertainty[snow_depth_uncertainty < 0.0] = np.nan return snow_depth, snow_depth_uncertainty