コード例 #1
0
    def grid(self):
        """ Create and fill a RATP grid
        """

        spc = self.scene
        grid_pars = {
            'latitude': self.localisation['latitude'],
            'longitude': self.localisation['longitude'],
            'timezone': self.timezone,
            'idecaly': self.idecaly,
            'orientation': self.orientation,
            'rs': self.rsoil,
            'nent': self.n_entities()
        }
        grid_pars.update(self.smart_grid.ratp_grid_parameters())
        ratp_grid = Grid.initialise(**grid_pars)
        grid_indices = self.smart_grid.grid_index(spc.x,
                                                  spc.y,
                                                  spc.z,
                                                  check=True)
        jx, jy, jz = self.smart_grid.ratp_grid_index(*grid_indices)
        entity = self.entity_code - 1  # Grid.fill expect python indices
        nitrogen = [self.nitrogen] * spc.size
        ratp_grid, _ = Grid.fill_from_index(entity, jx, jy, jz, spc.area,
                                            nitrogen, ratp_grid)
        # RATPScene grid indices of individual surfacic points
        jx, jy, jz = grid_indices
        grid_indices = pandas.DataFrame({
            'point_id': range(len(jx)),
            'jx': jx,
            'jy': jy,
            'jz': jz
        })

        return ratp_grid, grid_indices
コード例 #2
0
ファイル: RatpScene.py プロジェクト: PIAFINRA/PyRATP
    def grid(self, rsoil=0.20):
        """ Create and fill a RATP grid 

        :Parameters:
        - rsoil : soil reflectances in the PAR and NIR band

        :Output:
            - grid3d : ratp fortran grid object
            - vox_id : list of ratp voxel_id for all primitive in the grid
            - sh_id : list of shape_id for all primitive in the grid
            - area : list of radiative object area for all primitive in the grid
        """
    
        grid_pars = {'latitude': self.localisation['latitude'],
                     'longitude':self.localisation['longitude'],
                     'timezone': RatpScene.timezone,
                     'idecaly': RatpScene.idecaly,
                     'orientation': self.grid_orientation,
                     'toric': self.toric}
        
        grid_size = self.fit_grid()
        grid_pars.update(grid_size)
        
        entity, x, y, z, s, n, sh_id, theta = self.scene_transform()
        nent = max(entity) + 1
        
        if not hasattr(rsoil, '__len__'):
            rsoil = [rsoil]
        
        grid_pars.update({'rs':rsoil,'nent':nent})
        
        grid = Grid.initialise(**grid_pars)
        # store parameters for provenance
        self.grid_pars = grid_pars

        grid, mapping = Grid.fill_1(entity, x, y, z, s, n, grid) # mapping is a {str(python_x_list_index) : python_k_gridvoxel_index}
        # in RATP output, VoxelId is for the fortran_k_voxel_index (starts at 1, cf prog_RATP.f90, lines 489 and 500)
        index = range(len(x))
        vox_id = [mapping[str(i)] + 1 for i in index]
        # and one additional map that allows retrieving shape_id from python_x_index
        sh_id = [sh_id[i] for i in index]

        # save coordinates of centers of filled voxels
        self.voxel_map = voxel_map(grid)
        
        # compute distributions of orientation
        orientation = numpy.degrees(numpy.abs(theta)) % 90
        def _dist(inc):
            dist = numpy.histogram(inc, self.nbincli, (0,90))[0]
            return dist.astype('float') / dist.sum()
        df = pandas.DataFrame({'entity':[self.entity[sid] for sid in sh_id], 'inc':orientation})
        self.inc_data = df
        self.distinc = df.sort_values('entity').groupby('entity').apply(_dist).tolist()

        # estimate clumping
        self.mu = estimate_clumping(entity, x, y, z, s, mapping, grid)
        if any(map(numpy.isnan, self.mu)):
            raise ValueError('Cannot estimate mu')
        
        return grid, vox_id, sh_id, s
コード例 #3
0
def test_initialise():
    pars = {
        'latitude': 0,
        'longitude': 0,
        'timezone': 0,
        'nent': 1,
        'rs': (0, 0),
        'idecaly': 0,
        'orientation': 0
    }
    pars.update({
        'njx': 2,
        'njy': 2,
        'njz': 2,
        'dx': 0.5,
        'dy': 0.5,
        'dz': [0.5] * 2,
        'xorig': 0,
        'yorig': 0,
        'zorig': 0
    })

    grid = Grid.initialise(**pars)
    assert (grid.njx, grid.njy, grid.njz) == (2, 2, 2)
    assert 0.49 <= grid.dx <= 0.51
コード例 #4
0
def ratp(date):
    vegfile = 'canratp_%s.txt' % (date)
    gridfile = 'grid_%s.grd' % (date)
    vfnfile = 'entities_%s.vfn' % (date)
    skyfile = 'skyvaultsoc.skv'
    metfile = 'meteo_diffuseUnitSky1.mto'
    outfile = 'output_%s.txt' % (date)
    mapfile = 'mapratp_%s.txt' % (date)

    grid = Grid.read(gridfile)
    entity, x, y, z, s, n = readveg(vegfile)
    grid, map = Grid.fill(entity, x, y, z, s, n, grid)
    vegetation = Vegetation.read(vfnfile)
    sky = Skyvault.read(skyfile)
    met = MicroMeteo.read(metfile)

    t = zip(map.keys(), map.values())
    np.savetxt(mapfile, t)

    res = runRATP.DoIrradiation(grid, vegetation, sky, met)

    np.savetxt(outfile, res)
コード例 #5
0
def test_read():
    fn = 'essaiRATP2/RATP/grille/grid3Da_2004.grd'
    g = Grid()
    g = Grid.read(fn)
    assert (g.njx, g.njy, g.njz) == (19, 20, 18)
    assert 0.19 <= g.dx <= 0.21
コード例 #6
0
def test_grid_index():
    # a X+-North oriented 2x2x2 grid, one corner at (0,0,0), with 0.5 cell size in all directions
    #cell boundaries are thus (0, 0.5, 1)
    pars = {
        'latitude': 0,
        'longitude': 0,
        'timezone': 0,
        'nent': 1,
        'rs': (0, 0),
        'idecaly': 0,
        'orientation': 0
    }
    pars.update({
        'njx': 2,
        'njy': 2,
        'njz': 2,
        'dx': 0.5,
        'dy': 0.5,
        'dz': [0.5] * 2,
        'xorig': 0,
        'yorig': 0,
        'zorig': 0
    })

    grid = Grid.initialise(**pars)

    # test x,y,z cell centers
    centers = numpy.arange(0.25, 1, 0.5)
    x, y, z = [centers] * 3
    expected = ([0, 1], [1, 0], [1, 0])
    computed = grid_index(x, y, z, grid, toric=False)
    numpy.testing.assert_array_equal(
        computed, expected,
        'Centers of voxel have not been positioned in the corect RATP voxel')
    jx, jy, jz = map(numpy.array, computed)
    decoded = decode_index(jx + 1, jy + 1, jz + 1, grid)
    numpy.testing.assert_array_equal(decoded, (x, y, z), 'bad decoding')

    # test x,y,z cell boundaries, non toric
    boundaries = numpy.arange(0, 1.5, 0.5)
    expected = ([0, 1, -1], [1, 0, -1], [1, 0, -1])
    x, y, z = [boundaries] * 3
    computed = grid_index(x, y, z, grid, toric=False)
    numpy.testing.assert_array_equal(
        computed, expected,
        'Boundaries of voxel have not been positioned in the corect RATP voxel'
    )

    # test x,y,z cell boundaries, toric
    boundaries = numpy.arange(0, 1.5, 0.5)
    expected = ([0, 1, 0], [1, 0, 1], [1, 0, -1])
    x, y, z = [boundaries] * 3
    computed = grid_index(x, y, z, grid, toric=True)
    numpy.testing.assert_array_equal(
        computed, expected,
        'Toric boundaries of voxel have not been positioned in the corect RATP voxel'
    )

    # test x,y,z left outer points, toric
    pts = numpy.arange(-.5, 1., 0.25)
    #array([-0.5 , -0.25,  0.  ,  0.25,  0.5 ,  0.75])
    expected = ([1, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0], [-1, -1, 1, 1, 0, 0])
    x, y, z = [pts] * 3
    computed = grid_index(x, y, z, grid, toric=True)
    numpy.testing.assert_array_equal(
        computed, expected,
        'outer left x,y points have not been positioned correctly in the toric grid'
    )

    # test x,y,z left outer points, z translation,  toric
    pars.update({'zorig': 0.5})  # origin is shited 0.5 toward the soil
    grid = Grid.initialise(**pars)
    pts = numpy.arange(-.5, 1., 0.25)
    #array([-0.5 , -0.25,  0.  ,  0.25,  0.5 ,  0.75])
    expected = ([1, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0], [1, 1, 0, 0, -1, -1])
    x, y, z = [pts] * 3
    computed = grid_index(x, y, z, grid, toric=True)
    numpy.testing.assert_array_equal(
        computed, expected,
        'outer left x,y,z points have not been positioned correctly after z translation in the toric grid'
    )