In [1]:
import logging
root = logging.getLogger()
root.addHandler(logging.StreamHandler())
import matplotlib.pyplot as plt
%matplotlib inline

In [2]:
from iSDM.species import IUCNSpecies
turtles = IUCNSpecies(name_species='Pelusios rhodesianus')
turtles.load_shapefile('../data/FW_TURTLES/FW_TURTLES.shp')


Loading data from: ../data/FW_TURTLES/FW_TURTLES.shp
The shapefile contains data on 181 species.

In [3]:
turtles.find_species_occurrences()


Loaded species: ['Pelusios rhodesianus'] 
Out[3]:
binomial category citation class_name compiler dist_comm family_nam genus_name geometry id_no ... presence seasonal shape_area shape_leng source species_na subpop subspecies tax_comm year
156 Pelusios rhodesianus LR/lc CRF REPTILIA Rhodin None PELOMEDUSIDAE Pelusios (POLYGON ((12.44598388671875 -6.02496337890625... 16530.0 ... 1.0 1.0 341.941542 248.22574 CBFTT rhodesianus None None None 2013.0

1 rows × 26 columns


In [4]:
type(turtles)


Out[4]:
iSDM.species.IUCNSpecies

In [5]:
turtles.plot_species_occurrence()



In [6]:
turtles.save_shapefile("../data/filtered_turtles_again.shp")


Saved data: ../data/filtered_turtles_again.shp 

In [7]:
from iSDM.environment import ClimateLayer
worldclim_max_june =  ClimateLayer(file_path="../data/tmax1/tmax6.bil") 
worldclim_max_june.load_data()


Loading data from ../data/tmax1/tmax6.bil 
Metadata: {'affine': Affine(0.041666666666667, 0.0, -180.00000000000335,
       0.0, -0.041666666666667, 90.00000000000003),
 'count': 1,
 'crs': {'init': 'epsg:4326'},
 'driver': 'EHdr',
 'dtype': 'int16',
 'height': 3600,
 'nodata': -9999.0,
 'transform': (-180.00000000000335,
               0.041666666666667,
               0.0,
               90.00000000000003,
               0.0,
               -0.041666666666667),
 'width': 8640} 
Resolution: (0.041666666666667, 0.041666666666667) 
Bounds: BoundingBox(left=-180.00000000000335, bottom=-60.000000000001165, right=179.9999999999995, top=90.00000000000003) 
Dataset loaded. Use .read() or .read_masks() to access the layers.
Out[7]:
<open RasterReader name='../data/tmax1/tmax6.bil' mode='r'>

In [8]:
worldclim_data = worldclim_max_june.read(1) # read band_1
# get the min (ignoring nodata=-9999)/max values to adjust the spectrum.
vmin = worldclim_data[worldclim_data!=worldclim_max_june.metadata["nodata"]].min()
vmax = worldclim_data.max()

In [9]:
fig, ax = plt.subplots(figsize=(18, 18))
ax.imshow(worldclim_max_june.read(1), cmap="coolwarm", interpolation="none", vmin=vmin, vmax=vmax)


Out[9]:
<matplotlib.image.AxesImage at 0x7fa244b2dcc0>

In [10]:
worldclim_max_june.overlay(turtles)
# if i don't limit the plot to vmin/vmax, the image is almost white, because low values are really low. 
# So we need scaling of the colormap
vmin = worldclim_max_june.masked_data.data[worldclim_max_june.masked_data.data!=worldclim_max_june.metadata['nodata']].min()
vmax=worldclim_max_june.masked_data.data.max()


Overlayed raster climate data with the given range map.
Use the .masked_data attribute to access it.

In [11]:
fig, ax = plt.subplots(figsize=(18, 18))
ax.imshow(worldclim_max_june.masked_data, cmap="coolwarm", interpolation="none", vmin=vmin, vmax=vmax) # vmin/vmax for better contrast?


Out[11]:
<matplotlib.image.AxesImage at 0x7fa24515db00>

In [12]:
worldclim_max_june.masked_data # there are .data and .mask arrays


Out[12]:
masked_array(data =
 [[-- -- -- ..., -- -- --]
 [-- -- -- ..., -- -- --]
 [-- -- -- ..., -- -- --]
 ..., 
 [-- -- -- ..., -- -- --]
 [-- -- -- ..., -- -- --]
 [-- -- -- ..., -- -- --]],
             mask =
 [[ True  True  True ...,  True  True  True]
 [ True  True  True ...,  True  True  True]
 [ True  True  True ...,  True  True  True]
 ..., 
 [ True  True  True ...,  True  True  True]
 [ True  True  True ...,  True  True  True]
 [ True  True  True ...,  True  True  True]],
       fill_value = 999999)

In [13]:
worldclim_max_june.masked_data.mask


Out[13]:
array([[ True,  True,  True, ...,  True,  True,  True],
       [ True,  True,  True, ...,  True,  True,  True],
       [ True,  True,  True, ...,  True,  True,  True],
       ..., 
       [ True,  True,  True, ...,  True,  True,  True],
       [ True,  True,  True, ...,  True,  True,  True],
       [ True,  True,  True, ...,  True,  True,  True]], dtype=bool)

In [14]:
worldclim_max_june.masked_data.data


Out[14]:
array([[  274,   275,   275, ...,   335,   337,   338],
       [  274,   275,   275, ...,   333,   335,   336],
       [  277,   278,   278, ...,   331,   333,   335],
       ..., 
       [-9999, -9999, -9999, ..., -9999, -9999, -9999],
       [-9999, -9999, -9999, ..., -9999, -9999, -9999],
       [-9999, -9999, -9999, ..., -9999, -9999, -9999]], dtype=int16)

In [15]:
# convert to lower resolution?
worldclim_max_june.reproject(destination_file="../data/reprojected.adf", resolution=1, driver='AIG')


Calculated default transformation:
Affine:
| 1.00, 0.00,-180.00|
| 0.00,-1.00, 90.00|
| 0.00, 0.00, 1.00| 
 width=361, height=151
Reprojected data in ../data/reprojected.adf 

In [16]:
# load the lower resolution file? or should reprojecting "overwrite" the original data
worldclim_max_june.load_data("../data/reprojected.adf")


Loading data from ../data/reprojected.adf 
Metadata: {'affine': Affine(1.0, 0.0, -180.000000000003,
       0.0, -1.0, 90.0),
 'count': 1,
 'crs': {'init': 'epsg:4326'},
 'driver': 'EHdr',
 'dtype': 'int16',
 'height': 151,
 'nodata': -9999.0,
 'transform': (-180.000000000003, 1.0, 0.0, 90.0, 0.0, -1.0),
 'width': 361} 
Resolution: (1.0, 1.0) 
Bounds: BoundingBox(left=-180.000000000003, bottom=-61.0, right=180.999999999997, top=90.0) 
Dataset loaded. Use .read() or .read_masks() to access the layers.
Out[16]:
<open RasterReader name='../data/reprojected.adf' mode='r'>

In [17]:
fig, ax = plt.subplots(figsize=(18, 18))
vmin = worldclim_max_june.masked_data.data[worldclim_max_june.masked_data.data!=worldclim_max_june.metadata['nodata']].min()
vmax=worldclim_max_june.masked_data.data.max()
ax.imshow(worldclim_max_june.read(1), cmap="coolwarm", interpolation="none", vmin=vmin, vmax=vmax)


Out[17]:
<matplotlib.image.AxesImage at 0x7fa2460eb860>

In [18]:
worldclim_max_june.overlay(turtles)
# if i don't limit the plot to vmin/vmax, the image is almost white, because low values are really low. 
# So we need scaling of the colormap
vmin = worldclim_max_june.masked_data.data[worldclim_max_june.masked_data.data!=worldclim_max_june.metadata['nodata']].min()
vmax = worldclim_max_june.masked_data.data.max()


Overlayed raster climate data with the given range map.
Use the .masked_data attribute to access it.

In [19]:
fig, ax = plt.subplots(figsize=(18, 18))
ax.imshow(worldclim_max_june.masked_data, cmap="coolwarm", interpolation="none", vmin=vmin, vmax=vmax) # vmin/vmax for better contrast?


Out[19]:
<matplotlib.image.AxesImage at 0x7fa2442ff9e8>

Overlaying DEM data with shapefiles is analogous


In [ ]: