Sampling cubemap

I have rewritten my original question for I thought there might not be enough background information

I want to use OpenGL to sample a depth cubemap in order to generate a 2D image where x represents horizontal angles and y vertical angles and the values of the image depth (flattened spherical representation). However, I am do not how to proceed after I generated the depth cubemap.

As background here is what I have done before.

I used the following the following procedure to generate a depth cubemap,

    def create_depthcube(self) -> None:
        '''Generates a cubemap with depth values'''

        #                   pitch, yaw, rel_pitch, rel_yaw, name, location
        rotation_dict = {0: [   0,  90,         0,      90, 'X+', 'Right'],
                         1: [   0, -90,         0,    -180, 'X-', 'Left'],
                         2: [  90, 180,       -90,      90, 'Y+', 'Top'],
                         3: [ -90, 180,       180,       0, 'Y-', 'Bottom'],
                         4: [   0,   0,       -90,     180, 'Z+', 'Back'],
                         5: [   0, 180,         0,    -180, 'Z-', 'Front']}
        
        # create empty cubemap
        self.create_empty_cubemap()
        
        # generate a cubemap camera
        cubemap_camera = Camera(self.camera.position)
        cubemap_camera.width = 1024
        cubemap_camera.height = 1024
        cubemap_camera.zoom = 90.0

        # # bind depth map  buffer
        glBindFramebuffer(GL_FRAMEBUFFER, self.depth_map_fbo)
        
        # set viewport size to cubemap size
        glViewport(0, 0, CM*1024, CM*1024)

        # create a projection matrix
        projection = glm.perspective(glm.radians(90.0), 1.0, 0.1, 100)
        self.cubemap_shader.set_uniform_mat4('projection', projection)        

        # RENDER TO DEPTH CUBEMAP
        for i in range(6):

            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X+i,
                                    self.depth_tex, 0)
            
            # all fine?
            if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE):
                raise RuntimeError("ERROR.FRAMEBUFFER. Framebuffer is not complete!")

            # clear colors and buffers
            glClearColor(0.1,0.1,0.1,0.1)
            glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT)

            # rotate camera
            cubemap_camera.pitch = rotation_dict[i][0] #0
            cubemap_camera.yaw =  rotation_dict[i][1] #1
            cubemap_camera.update_camera_vectors()
            
            # update view (lookat matrix)?
            view = cubemap_camera.get_matrix_view()
            self.cubemap_shader.set_uniform_mat4('view',view)

            # render scene
            self.render2(self.cubemap_shader, cubemap_camera, projection)

            # #output ?
            zbuffer = glReadPixelsf(0, 0, 1024, 1024, GL_DEPTH_COMPONENT, GL_FLOAT)
            zbuffer = zbuffer.reshape((1024, 024))
            np.save(f'{rotation_dict[i][5]}_cube', np.flipud(zbuffer))

        # unbind fbo
        glBindFramebuffer(GL_FRAMEBUFFER, 0)

        # reset viewport dimensions to display dimensions
        glViewport(0,0, self.camera.width, self.camera.height) 

and the following two shaders: vertex shader,

#version 330 core
layout (location = 0) in vec3 aPos;

uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

void main()
{   
    gl_Position = projection * view * model * vec4(aPos, 1.0);
}

and fragment shader,

#version 330 core

void main(){
    gl_FragDepth = gl_FragCoord.z;
}

After I created the cubemap (using the procedure above), how would I sample so that I cover certain vertical and horizontal angular ranges at a particular angular increment? Would I sample using shaders? If so, what would I use as my vertex shader? I can think of the fragment shader as something like the following,

#version 330 core
uniform vec3 hangle; // horizontal angular range and increment
uniform vec3 vangle; // vertical angular range and increment
uniform samplerCube cubetex;

void main(){
    for (float theta = vangle[0]; theta < vangle[1]; theta+= vangle[2]){
        for (float psi = hangle[0]; hangle < hangle[1]; psi+= hangle[2]){
            float x = sin(radians(theta)) * cos(radians(psi));
            float y = sin(radians(theta)) * sin(radians(psi));
            float z = cos(radians(theta));
            gl_FragDepth = texture(cubetex, vec3(x,y,z));
        }
    }
}

Would I generate a framebuffer and then run a shader like the one above to store the results?