Package: demix-lib
DEMIX libraryThe DEMIX Library allow you to get scores for specific DEMIX tiles and DEM.You also can download DEMIX Tile associated DEM Layers like SourceMask, Heights, ...Table of contents:InstallationDEMIX lib functions2.1Getting DEMIX Tile ID2.2Getting Scores2.3Getting DEMUtility functionsAvailable DEMs and criterions4.1Dem list4.2Criterion list4.3Layer listUsage example5.1Jupyter Notebook5.2Getting a DEMIX layer and compute an indicatorInstallationTo install the DEMIX library on your python environment :pip install demix_libDEMIX lib functionsThis section is a step-by-step guide on how to use the DEMIX lib functions. By getting through this guide, you'll learn how to:*   Get a DEMIX tile id from a given longitude and latitude*   Apply a criterion to a DEM, over a given DEMIX tile*   Retrieve a raster of DEM layer over a DEMIX tileGetting DEMIX Tile IDThe DEMIX api enables you to get a DEMIX tile id from a given longitude and latitude.importdemix_libasdllon=14.44799lat=35.81923print(dl.get_demix_tile_info(lon,lat))print(dl.get_demix_tile_name(lon,lat))Getting ScoresFirst thing first, you can use the demix api to get directly stats from the desired DEMIX Tile and CriterionIn order to get scores to specific dem and tile, you need to choose a criterion.
The criterion list is availablehere. List of supported dems is also visiblehere.importdemix_libasdl#getting the list of implemented criterionscriterions=dl.get_criterion_list()#getting the list of supported demsdems=dl.get_supported_dem_list()#defining the wanted DEMIX Tile namedemix_tile_name="N35YE014F"#getting the score of each dem, for the criterionfordemindems:forcriterionincriterions:print(dl.get_score(demix_tile_name=demix_tile_name,dem=dem,criterion=criterion))Getting DEMTo go further :
You can always use your own criterions by downloading the wanted layer on your DEMIX tile and apply custom code to it.To download a DEM layer for a specific DEMIX Tile :importdemix_libasdlimportmatplotlibasplt#we use matplotlib to visualise the downloaded layerfrommatplotlibimportcm#we use cm to make a legend/colormapfrommatplotlib.linesimportLine2D#to add colored line in the legend#defining wanted tiledemix_tile_name="N35YE014F"#asking for the SourceMask layer for the CopDEM_GLO-30 dem and the tile N64ZW019Cresponse=dl.download_layer(demix_tile_name=demix_tile_name,dem="CopDEM_GLO-30",layer="SourceMask")#creating legend for the plotlegend_handle=list(map(int,response['values'].keys()))legend_label=list(response['values'].values())#defining the colormap for the layer (the layer has 6 values)color_map=cm.get_cmap("rainbow",6)#we use plt to look at the dataplt.imshow(response["data"],interpolation='none',cmap=color_map,vmin=0,vmax=6)#creating legend values using the color map and the values storedcustom_handles=[]forvalueinlegend_handle:custom_handles.append(Line2D([0],[0],color=color_map(value),lw=4))plt.legend(custom_handles,legend_label)#show the layer with custom legend and color mapplt.show()Utility functionsThe DEMIX lib give you some utility functions that allow you to get or print informations about currently implemented criterions, available DEMs, layers...importdemix_libasdl#get or show the layers that you can ask in a download_layer functionlayer_list=dl.get_layer_list()dl.print_layer_list()#get or show the full dem listdem_list=dl.get_dem_list()dl.print_dem_list()#get or show the supported dem listsupported_dem_list=dl.get_supported_dem_list()dl.print_supported_dem_list()#get or show the implemented criterion listcriterion_list=dl.get_criterion_list()dl.print_criterion_list()#get or show the implemented colormapscriterion_list=dl.get_colormap_list()dl.print_colormap_list()Available DEMs and criterionsDEMs listDEM namesupportedALOS World 3DyesASTERGDEMyesCopDEM GLO-30yesCopDEM GLO-90yesEU-DEMyesNASADEMyesSRTMGL1yesCriterion listCriterion nameCriterion idversionAuthorDateCategoryTargetDescriptionProduct fractional coverA010.1Peter Strobl20211103A-completenessAllreadValid data fractionA020.1Peter Strobl20211103A-completenessAllPrimary dataA030.1Peter Strobl20211103A-completenessAllValid land fractionA040.1Peter Strobl20211103A-completenessAllPrimary land fractionA050.1Peter Strobl20211103A-completenessAllLayer listLayer nameHeightsvalidMaskSourceMasklandWaterMaskUsage exampleJupyter NotebookA jupyter notebook has been made to demonstrate how can be used the DEMIX lib.Download the latest Jupyter Notebook file of the following repository and execute it in you favorite jupyter 
environnement (likeColabfor example) to get an
idea of what is possible.Jupyter notebook repositoryGetting a DEMIX layer and compute an indicatorIn this section, we will use the DEMIX lib to compute our own criterion on the SRTMGL1.1 Define the criterionFirst, we define a criteriondefmax_height_custom_criterion(response):"""take height data and return a score based on altitude, if a point is higher than Everest highest point,score is reduce by maximum_value / everest_max_height *10"""maximum_value=response["data"][0][0]everest_max_height=8848forlineinresponse["data"]:ifmax(line)>maximum_value:maximum_value=max(line)#if result < 1, score = 100, else :result=maximum_value/everest_max_heightifresult<1:return100else:return100-(result*10)returnscore2 Get the wanted layerSecond, we use the DEMIX lib to download the wanted tile and layer for SRTMGL1lat=27.986065lon=86.922623response=dl.download_layer(demix_tile_name=dl.get_demix_tile_name(lon,lat),dem='SRTMGL1',layer='heights',print_request=False)3 Compute the criterion on the layerFinally, we compute the criterion on the downloaded layer and we plot the resultprint(max_height_custom_criterion(response))