Skip to content

Commit 0d8781a

Browse files
committed
Fixed git conflicts issue
1 parent 0e26e4a commit 0d8781a

File tree

1 file changed

+2
-109
lines changed

1 file changed

+2
-109
lines changed

python/extpar_art_to_buffer.py

Lines changed: 2 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -69,145 +69,38 @@ def generate_memory_map(raw_lus, soiltype_memmap_filename,
6969
return lus, idxs
7070

7171

72-
<<<<<<< Updated upstream
73-
def calculate_soil_fraction(tg, lus, idxs, ncpu=2):
74-
"""
75-
lus: LU classes from HWSD data
76-
idxs: indices corrsponding to icon grid for each grid in HWSD data
77-
tg: ICON grid
78-
"""
79-
soil_types = np.arange(1, 14)
80-
fracs = np.zeros((tg.lons.size, soil_types.size))
81-
grid_ids, grid_counts = np.unique(idxs, return_counts=True)
82-
83-
def get_fraction_per_soil_type(lu):
84-
grid_class, grid_count = np.unique(np.where(lus == lu, idxs, -1),
85-
return_counts=True)
86-
for grid_id in np.arange(tg.lons.size):
87-
frac = np.array(grid_count[grid_class == grid_id] /
88-
grid_counts[grid_ids == grid_id])
89-
if len(frac) != 0:
90-
fracs[grid_id, lu - 1] = frac
91-
92-
Parallel(n_jobs=ncpu,
93-
max_nbytes='100M',
94-
mmap_mode='w+',
95-
backend='threading')(delayed(get_fraction_per_soil_type)(lu)
96-
for lu in tqdm(soil_types))
97-
return fracs
98-
99-
100-
def calculate_soil_fraction_optimized(target_grid,
101-
soil_types_raw,
102-
nearest_target_cell_to_raw_cells,
103-
ncpu=2):
104-
=======
10572
def calculate_soil_fraction(target_grid, soil_types_raw, nearest_target_cell_to_raw_cells, ncpu=13):
106-
>>>>>>> Stashed changes
10773
"""
10874
target_grid: target ICON grid
10975
soil_types_raw: landuse class for each cell from the HWSD dataset (LU variable)
110-
nearest_target_cell_to_raw_cells: indices of the cell from the target ICON grid which is nearest to each cell of the raw grid (from HWSD dataset)
76+
nearest_target_cell_to_raw_cell: indices of the cell from the target ICON grid which is nearest to each cell of the raw grid (from HWSD dataset)
11177
"""
11278
ncells_target = target_grid.lons.size
11379
nsoil_types = 13
11480
nthreads = min(nsoil_types, ncpu)
11581

116-
soil_ids = np.arange(1, nsoil_types + 1)
82+
soil_ids = np.arange(1, nsoil_types+1)
11783
soil_fractions_target = np.zeros((ncells_target, nsoil_types))
11884

119-
<<<<<<< Updated upstream
120-
target_cells, n_nearest_raw_cells = np.unique(
121-
nearest_target_cell_to_raw_cells, return_counts=True)
122-
123-
for soil_id in tqdm(soil_ids[:1]):
124-
125-
target_cells_with_soil_type, n_nearest_raw_cells_with_soil_type = np.unique(
126-
np.where(soil_types_raw == soil_id,
127-
nearest_target_cell_to_raw_cells, -1),
128-
return_counts=True)
129-
=======
13085
n_nearest_raw_cells = np.bincount(nearest_target_cell_to_raw_cells.ravel(), minlength=ncells_target)
13186

13287
def get_fraction_per_soil_type(soil_id):
13388
n_nearest_raw_cells_with_soil_type = np.bincount(nearest_target_cell_to_raw_cells[soil_types_raw == soil_id], minlength=ncells_target)
134-
>>>>>>> Stashed changes
13589

13690
np.divide( n_nearest_raw_cells_with_soil_type,
13791
n_nearest_raw_cells,
13892
out = soil_fractions_target[:, soil_id-1],
13993
where = n_nearest_raw_cells != 0 )
14094

141-
<<<<<<< Updated upstream
142-
soil_fraction = np.array(
143-
n_nearest_raw_cells_with_soil_type[target_cells_with_soil_type
144-
== target_cell_id] /
145-
n_nearest_raw_cells[target_cells == target_cell_id])
146-
147-
if len(soil_fraction) != 0:
148-
soil_fractions_target[target_cell_id,
149-
soil_id - 1] = soil_fraction
150-
=======
15195
Parallel(n_jobs=nthreads,
15296
max_nbytes='100M',
15397
mmap_mode='w+',
15498
backend='threading')(delayed(get_fraction_per_soil_type)(soil_id)
15599
for soil_id in tqdm(soil_ids))
156-
>>>>>>> Stashed changes
157100

158101
return soil_fractions_target
159102

160103

161-
<<<<<<< Updated upstream
162-
def calculate_soil_fraction_test(tg, lus, idxs, ncpu=2):
163-
"""
164-
lus: LU classes from HWSD data
165-
idxs: indices corrsponding to icon grid for each grid in HWSD data
166-
tg: ICON grid
167-
"""
168-
soil_types = np.arange(1, 14)
169-
fracs = np.zeros((tg.lons.size, soil_types.size))
170-
grid_ids, grid_counts = np.unique(idxs, return_counts=True)
171-
print("soil_types:", soil_types.shape)
172-
print("fracs:", fracs.shape)
173-
print("grid_ids:", grid_ids.shape)
174-
print("grid_counts:", grid_counts.shape)
175-
176-
def get_fraction_per_soil_type(lu):
177-
print("lus:", lus.shape)
178-
print("idxs:", idxs.shape)
179-
test = np.where(lus == lu, idxs, -1)
180-
print("test:", test.shape)
181-
start = perf_counter()
182-
grid_class, grid_count = np.unique(np.where(lus == lu, idxs, -1),
183-
return_counts=True)
184-
end = perf_counter()
185-
print("grid_class:", grid_class.shape)
186-
print("grid_count:", grid_count.shape)
187-
print("Sect 1:", end - start)
188-
start = perf_counter()
189-
for grid_id in grid_class:
190-
frac = np.array(grid_count[grid_class == grid_id] /
191-
grid_counts[grid_ids == grid_id])
192-
if len(frac) != 0:
193-
fracs[grid_id, lu - 1] = frac
194-
end = perf_counter()
195-
print("Sect 2:", end - start)
196-
197-
#Parallel(n_jobs=13,
198-
# max_nbytes='100M',
199-
# mmap_mode='w+',
200-
# backend='threading')(delayed(get_fraction_per_soil_type)(lu)
201-
# for lu in tqdm(soil_types))
202-
203-
for lu in tqdm(soil_types[:1]):
204-
get_fraction_per_soil_type(lu)
205-
206-
return fracs
207-
208-
209-
=======
210-
>>>>>>> Stashed changes
211104
# --------------------------------------------------------------------------
212105
# --------------------------------------------------------------------------
213106
# initialize logger

0 commit comments

Comments
 (0)