<jupyter_start><jupyter_text>Specify the data directories where input data is stored and where output data will be stored:<jupyter_code>data_dir = os.path.join('..', 'data')
out_dir = os.path.join('..', 'output/impact')<jupyter_output><empty_output><jupyter_text>The data is in CDF format so we first need to open the dataset and then access the variables:<jupyter_code>file_name = 'FAO/gaez/res03_ehb22020h_sihr0_wpo.tif'

area_raster = mr.MyRaster(os.path.join(data_dir, file_name))
area = area_raster.get_array().astype('int16')
area[area == 0] = -1
area[area == 9] = -1
area[area == 8] = 0
area[(area > 0) & (area < 6)] = 2
area[(area == 6) | (area == 7)] = 1
area = mr.cut_array_yboundaries(array=area, pixelHeight=area_raster.pixelHeight,
                                y_min_old=-90, y_min_new=-56, y_max_old=90, y_max_new=84)
fig = plt.figure(figsize=(16,9))

plt.imshow(area);
out_filename = 'suitable_area'
mr.array2geotiff(area, os.path.join(out_dir, out_filename),
                 -1, area.shape[1], area.shape[0],
                 -180, 84, area_raster.pixelWidth, area_raster.pixelHeight)
nogo = np.zeros(area.shape)
nogo[area == 0] = 1
marginal = np.zeros(area.shape)
marginal[area == 1] = 1
file_name = 'impact_potato_pot_area.tif'

impact_raster = mr.MyRaster(os.path.join(out_dir, file_name))
impact = impact_raster.get_array()
shapefile_name = 'shapefiles/countries.shp'
shapefile = os.path.join(data_dir, shapefile_name)
gdf = gpd.read_file(shapefile)
filename = 'crop_area.shp'
gdf2 = gpd.read_file(os.path.join(out_dir, filename))
cdict1 = {'red':   ((0.0,  0.0, 0.0),
                    (1.0,  1.0, 1.0)),

          'green': ((0.0,  0.0, 0.0),
                    (1.0,  0.0, 0.0)),

          'blue':  ((0.0,  0.0, 0.0),
                    (1.0,  0.0, 0.0)),

          'alpha': ((0.0,  0.0, 0.0),
                    (1.0,  1.0, 1.0))}
plt.register_cmap(name='Red', data=cdict1)
cdict2 = {'red':   ((0.0,  0.0, 0.0),
                    (1.0,  0.4, 0.4)),

          'green': ((0.0,  0.0, 0.0),
                    (1.0,  0.8, 0.8)),

          'blue':  ((0.0,  0.0, 0.0),
                    (1.0,  0.0, 0.0)),

          'alpha': ((0.0,  0.0, 0.0),
                    (1.0,  1.0, 1.0))}
plt.register_cmap(name='Green', data=cdict2)
np.percentile(impact[impact >= 0], 0.98)
vmin = 0
vmax = 0.5
%%time

fig = plt.figure(figsize=(16, 9))
ax = fig.add_subplot(111)

ax.set_xlim([-180, 180])
ax.set_ylim([-56, 84])
ax.set_xticks([])
ax.set_yticks([])
ax.set_frame_on(False)

gdf.plot(ax=ax, facecolor='none', edgecolor='#000000', linewidths=0.3)

gdf2.plot(ax=ax, facecolor='none', edgecolor='#000000', linewidths=0, hatch='////')

ax.imshow(impact, extent=[-180, 180, -56, 84], cmap='Greys', vmin=vmin, vmax=vmax)

ax.imshow(nogo, extent=[-180, 180, -56, 84], cmap='Red', alpha=0.15)

ax.imshow(marginal, extent=[-180, 180, -56, 84], cmap='Green', alpha=0.25)

norm = matplotlib.colors.Normalize(vmin, vmax, clip = False)

cax1 = fig.add_axes([0.2, 0.25, 0.01, 0.3]) # xmin, ymin, dx, dy
matplotlib.colorbar.ColorbarBase(cax1, cmap='Greys', norm=norm)
cax1.yaxis.set_ticks_position('left')

plt.savefig(os.path.join(out_dir, 'impact_potato_pot_area.png'),
            dpi=300, bbox_inches='tight', pad_inches=0.1)
filename = 'crop_area.shp'
gdf2 = gpd.read_file(os.path.join(out_dir, filename))
%%time

fig = plt.figure(figsize=(16, 9))
ax = fig.add_subplot(111)

ax.set_xlim([-180, 180])
ax.set_ylim([-56, 84])
ax.set_xticks([])
ax.set_yticks([])
ax.set_frame_on(False)

gdf.plot(ax=ax, facecolor='none', edgecolor='#000000', linewidths=0.3)

gdf2.plot(ax=ax, facecolor='none', edgecolor='#000000', linewidths=0, hatch='////')

ax.imshow(impact, extent=[-180, 180, -56, 84], cmap='Greys', vmin=vmin, vmax=vmax)

ax.imshow(nogo, extent=[-180, 180, -56, 84], cmap='Red', alpha=0.15)

ax.imshow(marginal, extent=[-180, 180, -56, 84], cmap='Green', alpha=0.25)

norm = matplotlib.colors.Normalize(vmin, vmax, clip = False)

cax1 = fig.add_axes([0.2, 0.25, 0.01, 0.3]) # xmin, ymin, dx, dy
matplotlib.colorbar.ColorbarBase(cax1, cmap='Greys', norm=norm)
cax1.yaxis.set_ticks_position('left')

plt.savefig(os.path.join(out_dir, 'impact_potato_pot_area.png'),
            dpi=300, bbox_inches='tight', pad_inches=0.1)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.197423887587822, 'fraction_numerical': 0.0765807962529274, 'mean_word_length': 3.5728051391862956, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '497072', 'license': 'MIT', 'n_tokens_mistral': 2046, 'n_tokens_neox': 1839, 'n_words': 323, 'path': 'python/6Ac_impact_potato_non-crop-area.ipynb', 'repo_name': 'ethz-esd/compaction_stoessel_2018', 'size': '4270'}