Exemplo n.º 1
0
 def set_index_file(self, lat_corr, lon_corr, height_corr, pixc_index):
     # 1 - Open PixcvecRiver cloud file in adding mode
     pixc_reader = my_nc.MyNcReader(self.pixc_main_file, mode='a')
     pixc_main = pixc_reader.content
     var = pixc_main.createVariable('pixc_index', pixc_index.dtype,
                                    ('record', ))
     var[:] = pixc_index[:]
     pixc_main.variables["latitude_vectorproc"][:] = lat_corr
     pixc_main.variables["longitude_vectorproc"][:] = lon_corr
     pixc_main.variables["height_vectorproc"][:] = height_corr
     pixc_main.close()
Exemplo n.º 2
0
    def from_pixc(cls, pixc_file):
        """
        Constructor of Sensor
            :param pixc_file: full path of Sensor file
            :type pixc_file: string

        Variables of the object:
        - nadir_[x|y|z] / 1D-array of float: [x|y|z] cartesian coordinates of each nadir pixel (= variables named [x|y|z] in L2_HR_PIXC file)
        - nadir_[vx|vy|vz] / 1D-array of float: velocity vector of each nadir pixel in cartesian coordinates (= variables named velocity_unit_[x|y|z]
        in L2_HR_PIXC file)
        - ref_leverarm_[x|y|z] / 1D-array of float: [x|y|z]: reference of level arm 
        - sef_leverarm_[x|y|z] / 1D-array of float: [x|y|z]: level arm value
        """

        self = cls()
        # 1 - Initiate logging service
        logger = logging.getLogger(self.__class__.__name__)
        logger.info("Sensor init with %s pixc_file", pixc_file)

        try:
            # 2 - Open sensor file in reading mode
            sensor_reader = my_nc.MyNcReader(pixc_file)
            ifp = sensor_reader.content

            # 3 - Initialization of the Sensor variables
            self.time = np.array(ifp.groups['tvp']['time'])
            self.nadir_x = np.array(ifp.groups['tvp']['x'])
            self.nadir_y = np.array(ifp.groups['tvp']['y'])
            self.nadir_z = np.array(ifp.groups['tvp']['z'])
            self.nadir_vx = np.array(ifp.groups['tvp']['vx'])
            self.nadir_vy = np.array(ifp.groups['tvp']['vy'])
            self.nadir_vz = np.array(ifp.groups['tvp']['vz'])
            self.ref_leverarm_x = np.array(
                ifp.groups['tvp']['plus_y_antenna_x'])
            self.ref_leverarm_y = np.array(
                ifp.groups['tvp']['plus_y_antenna_y'])
            self.ref_leverarm_z = np.array(
                ifp.groups['tvp']['plus_y_antenna_z'])
            self.sec_leverarm_x = np.array(
                ifp.groups['tvp']['minus_y_antenna_x'])
            self.sec_leverarm_y = np.array(
                ifp.groups['tvp']['minus_y_antenna_y'])
            self.sec_leverarm_z = np.array(
                ifp.groups['tvp']['minus_y_antenna_z'])

            # 4 - Close Sensor file
            sensor_reader.close()

        except Exception as exc:
            message = str(exc.__class__) + str(exc)
            logger.debug(message)
            raise

        return self
Exemplo n.º 3
0
    def from_file(cls, in_pixc_file):
        """
        Constructor of pixel cloud
            :param in_pixc_file: full path of L2_HR_PIXC file
            :type in_pixc_file: string

        Variables of the object:
        - illumination_time / 1D-array of float:Time of illumination of each pixel
        - azimuth_index / 1D-array of int: azimuth indices of water pixels
        - range_index / 1D-array of int: range indices of water pixels
        - num_rare_looks / 1D-array of float Number of rare looks
        - wavelength / wavelength of the satellite measuring instrument
        - near_range / 1D-array of float: near range distance for each nadir point
        - range_spacing / float: nominal slant range spacing
        - azimuth_spacing / float: nominal slant azimuth spacing
        - tile_ref / list of string : list of tile references to process
        - nr_lines / int : number of tines to process
        - nb_pixels / int : number of pixels to process
        """

        self = cls()
        # 1 - Initiate logging service
        logger = logging.getLogger(self.__class__.__name__)
        logger.info("PixelCloud init with %s file", in_pixc_file)

        try:
            # 2 - Open pixel cloud file in reading mode
            pixc_reader = my_nc.MyNcReader(in_pixc_file)
            data_dict = pixc_reader.content.groups['pixel_cloud']
            attr_id = pixc_reader.content.groups['pixel_cloud']

            # 3 - Initialization of the pixel cloud variables
            self.illumination_time = np.array(data_dict["illumination_time"])
            self.azimuth_index = np.array(data_dict["azimuth_index"])
            self.range_index = np.array(data_dict["range_index"])
            self.num_rare_looks = np.array(data_dict["num_rare_looks"])
            self.wavelength = pixc_reader.get_att_value("wavelength")
            self.near_range = pixc_reader.get_att_value("near_range")
            self.range_spacing = pixc_reader.get_att_value(
                "nominal_slant_range_spacing")
            self.azimuth_spacing = 21.875
            self.tile_ref = pixc_reader.get_att_value("tile_name")
            self.nr_lines = int(attr_id.interferogram_size_azimuth)
            self.nr_pixels = int(attr_id.interferogram_size_range)

            # 4 - Close pixel cloud file
            pixc_reader.close()

        except Exception as exc:
            logger.debug(exc)
            raise

        return self
Exemplo n.º 4
0
    def from_file(cls, in_pixc_sensor_file):
        """
            :param in_pixc_sensor_file: full path of Sensor file
            :type in_pixc_sensor_file: string
        """

        self = cls()
        # 1 - Initiate logging service
        logger = logging.getLogger(self.__class__.__name__)
        logger.info("Sensor init with %s file sensor", in_pixc_sensor_file)
        try:
            # 2 - Open Sensor file in reading mode
            pixc_reader = my_nc.MyNcReader(in_pixc_sensor_file)
            pixc_sensor = pixc_reader.content

            # 3 - Initialization of the Sensor variables
            self.time = np.array(pixc_sensor.variables["time"])
            self.nadir_x = np.array(pixc_sensor.variables["x"])
            self.nadir_y = np.array(pixc_sensor.variables["y"])
            self.nadir_z = np.array(pixc_sensor.variables["z"])
            self.nadir_vx = np.array(pixc_sensor.variables["vx"])
            self.nadir_vy = np.array(pixc_sensor.variables["vy"])
            self.nadir_vz = np.array(pixc_sensor.variables["vz"])
            self.ref_leverarm_x = np.array(
                pixc_sensor.variables["plus_y_antenna_x"])
            self.ref_leverarm_y = np.array(
                pixc_sensor.variables["plus_y_antenna_y"])
            self.ref_leverarm_z = np.array(
                pixc_sensor.variables["plus_y_antenna_z"])
            self.sec_leverarm_x = np.array(
                pixc_sensor.variables["minus_y_antenna_x"])
            self.sec_leverarm_y = np.array(
                pixc_sensor.variables["minus_y_antenna_y"])
            self.sec_leverarm_z = np.array(
                pixc_sensor.variables["minus_y_antenna_z"])

            # 4 - Close Sensor file
            pixc_sensor.close()

        except Exception as exc:
            message = str(exc.__class__) + str(exc)
            logger.debug(message)
            raise

        return self
Exemplo n.º 5
0
    def read_nc(self, in_river_main_file):
        # 1 - Initiate logging service
        logger = logging.getLogger(self.__class__.__name__)
        logger.info("RiverTile init with %s netcdf file", in_river_main_file)

        # 2 - Open pixel RiverTile file in reading mode
        riverfile_reader = my_nc.MyNcReader(in_river_main_file)
        riverfile = riverfile_reader.content
        nodes = riverfile.groups["nodes"].variables
        try:
            # 2 - Initialization of the RiverTile variables
            self.reach_indx = np.array(nodes["reach_indx"])
            self.node_indx = np.array(nodes["node_indx"])
            self.s = np.array(nodes["s"])
            self.h_n_ave = np.array(nodes["h_n_ave"])
            self.h_n_ave_fit = copy.deepcopy(np.array(nodes["h_n_ave"]))

            # 3 - Close rivertile file
            riverfile_reader.close()

        except Exception as exc:
            message = str(exc.__class__) + str(exc)
            logger.debug(message)
            raise
Exemplo n.º 6
0
 def set_variable(self, varname, array):
     # 1 - Open PixcvecRiver cloud file in adding mode
     pixc_reader = my_nc.MyNcReader(self.pixc_main_file, mode='a')
     pixc_main = pixc_reader.content
     pixc_main.variables[varname][:] = array
     pixc_main.close()
Exemplo n.º 7
0
    def __init__(self, pixcvec_file):
        """
        Constructor of PixcvecRiver
          :param pixcvec_file: full_path_to_PIXCVecRiver_file
          :type pixcvec_file: string
        Variables of the object:
           - pixc_main_file / full_path_to_PIXCVecRiver_file
           - cycle_num / int: cycle number
           - pass_num / int: pass number
           - tile_ref / list of string : list of tile references to process ex: ['42N-R', '43N-R', '44N-R', '45N-R']
           - range_idx / 1D-array of int: range indices of water pixels
           - azimuth_idx / 1D-array of int: azimuth indices of water pixels
           - longitude / 1D-array of float: longitude of water pixels
           - latitude / 1D-array of float: latitude of water pixels
           - height / 1D-array of float: height of water pixels
           - node_index / 1D-array of float: tag associated to river node database
           - range_idx / 1D-array of int: range indices of water pixels
           - river tag / 1D-array of str: tag associated to river database
           - along_reach / 1D-array of float: along reach water for each pixel
           - cross_reach / 1D-array of float: cross reach water for each pixel
           - distance_to_node / 1D-array of float: distance for each pixel to node
           - range_spacing / int:nominal slant range spacing
           - near_range / 1D-array of float: near range distance for each nadir point
        """

        # 0 - Initiate logging service
        logger = logging.getLogger(self.__class__.__name__)
        logger.info(" PixcvecRiver init with %s file", pixcvec_file)
        try:
            # 1 - Open PixcvecRiver cloud file in reading mode
            pixc_reader = my_nc.MyNcReader(pixcvec_file)
            pixc_main = pixc_reader.content

            # 2 - Initialization of the PixcvecRiver variables
            self.pixc_main_file = pixcvec_file
            self.cycle_num = pixc_main.getncattr("cycle_number")
            self.pass_num = pixc_main.getncattr("pass_number")
            self.tile_ref = pixc_main.getncattr("tile_name")
            self.range_idx = np.array(pixc_main.variables["range_index"])
            self.azimuth_idx = np.array(pixc_main.variables["azimuth_index"])
            self.longitude = np.array(
                pixc_main.variables["longitude_vectorproc"])
            self.latitude = np.array(
                pixc_main.variables["latitude_vectorproc"])
            self.height = np.array(pixc_main.variables["height_vectorproc"])
            self.node_index = np.array(pixc_main.variables["node_index"])
            self.reach_index = np.array(pixc_main.variables["reach_index"])
            self.along_reach = np.array(pixc_main.variables["along_reach"])
            self.cross_reach = np.array(pixc_main.variables["cross_reach"])
            self.distance_to_node = np.array(
                pixc_main.variables["distance_to_node"])
            self.range_spacing = pixc_main.getncattr(
                "nominal_slant_range_spacing")

            near_range = pixc_main.getncattr("near_range")
            if isinstance(near_range, collections.Iterable):
                print("Warning, near_range is a list.")
                self.near_range = 0
            else:
                self.near_range = near_range

            # 3 - Close PixcvecRiver file
            pixc_main.close()

        except Exception as exc:
            message = str(exc.__class__) + str(exc)
            logger.debug(message)
            raise
Exemplo n.º 8
0
    def set_from_pixcvec_file(self, in_pixcvec_file):
        """
        Set variables from PIXCVec file
        
        :param in_pixcvec_file: full path of pixel cloud complementary file 
                                    (L2_HR_PIXCVecRiver file if from PGE_RiverTile 
                                    or LakeTile_piexcvec if from PGE_LakeTile)
        :type in_pixcvec_file: string
        """
        logger = logging.getLogger(self.__class__.__name__)
        if self.product_type == "TILE":
            logger.info("L2_HR_PIXCVec file = %s", in_pixcvec_file)
        elif self.product_type == "SP":
            logger.info("LakeTile_pixcvec file = %s", in_pixcvec_file)
        else:
            logger.debug("Product type %s unknown, set to TILE" %
                         self.product_type)
            self.product_type = "TILE"

        # 1 - Open file in reading mode
        pixcvec_reader = my_nc.MyNcReader(in_pixcvec_file)

        # 2 - Retrieve the number of records
        try:
            self.nb_water_pix = pixcvec_reader.get_dim_value("points")
        except:
            logger.info(
                "Warning, using record instead of points for nb_water_pixels")
            self.nb_water_pix = pixcvec_reader.get_dim_value("record")

        # 3 - Retrieve needed global attributes
        pixcvec_keys = pixcvec_reader.get_list_att()
        for key, value in self.pixcvec_metadata.items():
            if key in pixcvec_keys:
                self.pixcvec_metadata[key] = pixcvec_reader.get_att_value(key)

        # 4 - Retrieve variables if there are river pixels
        if self.nb_water_pix != 0:

            # 4.1 - Range index
            self.range_index = pixcvec_reader.get_var_value("range_index")
            # 4.2 - Azimuth index
            self.azimuth_index = pixcvec_reader.get_var_value("azimuth_index")
            # 4.3 - Longitude
            self.longitude_vectorproc = my_tools.convert_to_m180_180(
                pixcvec_reader.get_var_value("longitude_vectorproc"))
            # 4.4 - Latitude
            self.latitude_vectorproc = pixcvec_reader.get_var_value(
                "latitude_vectorproc")
            # 4.5 - Height
            try:
                self.height_vectorproc = pixcvec_reader.get_var_value(
                    "wse_vectorproc")  # new variable name
            except:
                logger.debug(
                    "wse_vectorproc variable not in PIXCVec file => height_vectorproc used instead"
                )
                self.height_vectorproc = pixcvec_reader.get_var_value(
                    "height_vectorproc")  # old variable name
            # 4.6 - References entities
            # Node identifier
            try:
                tmp_id = [
                    str(i) for i in pixcvec_reader.get_var_value("node_id")
                ]  # new variable name
            except:
                logger.debug(
                    "node_id variable not in PIXCVec file => node_index used instead"
                )
                tmp_id = [
                    str(i) for i in pixcvec_reader.get_var_value("node_index")
                ]  # old variable name
            self.node_id = np.array(tmp_id, dtype=object)
            # Specific in LakeTile product for LakeSP product
            if self.product_type == "SP":
                tmp_id = [
                    str(i) for i in pixcvec_reader.get_var_value("lakedb_id")
                ]
                self.lakedb_id = np.array(tmp_id, dtype=object)
                tmp_id = [
                    str(i) for i in pixcvec_reader.get_var_value("lakeobs_id")
                ]
                self.lakeobs_id = np.array(tmp_id, dtype=object)
            # 4.7 - Ice flags
            # Climato
            try:
                self.ice_clim_flag = pixcvec_reader.get_var_value(
                    "ice_clim_flag")
            except:
                logger.debug(
                    "ice_clim_flag variable not in PIXCVec file => set to 1D-array of _FillValue"
                )
                self.ice_clim_flag = np.zeros(
                    self.nb_water_pix,
                    dtype=np.uint8) + my_var.FV_NETCDF['uint8']
            # Dynamical
            try:
                self.ice_dyn_flag = pixcvec_reader.get_var_value(
                    "ice_dyn_flag")
            except:
                logger.debug(
                    "ice_dyn_flag variable not in PIXCVec file => set to 1D-array of _FillValue"
                )
                self.ice_dyn_flag = np.zeros(
                    self.nb_water_pix,
                    dtype=np.uint8) + my_var.FV_NETCDF['uint8']

            # 5 - Reject river pixels from the list of pixel to process
            if self.product_type == "TILE":
                self.compute_river_pix(pixcvec_reader)

        # 6 - Close file
        pixcvec_reader.close()