Package: pobatch
pobatch: porder wrapper for Ordersv2 Batch ClientThis tool is an add-on to the porder tool, soread about the project hereand make sure you take additional installation steps before starting with this. This tool fits the need to order large orders in terms of spatial and temporal grids, splitting them into smaller manageable orders while keeping in mind the concurrency limits(number of orders you can place simultaneously). In this case, the user sets a concurrency limit, and the tool automatically checks and waits before placing the next order. The tool can also estimate order size in terms of bytes per order download. The last step is to perform the same, download using porder's downloaders and an order list as created by multiorder tools. The design of this tool is kept simple, meaning you are relying on mixed use orporderandpobatchto perform these operations.Ordersv2 is the next iteration of Planet's APIin getting Analysis Ready Data (ARD) delivered to you. Orders v2 allows you to improved functionality in this domain, including the capability to submit an number of images in a batch order, and perform operations such as top of atmospheric reflectance, compression, coregistration and also enhanced notifications such as email and webhooks.Please note: This tool is in no way an official tool or Planet offering, but is a personal project created and maintained by Samapriya RoyIf you find this tool useful, star and cite it as belowSamapriya Roy. (2019, August 26). samapriya/pobatch: pobatch: porder wrapper for Ordersv2 Batch Client (Version 0.0.7). Zenodo.
http://doi.org/10.5281/zenodo.3376975Table of contentsInstallationGetting startedporder wrapper for Ordersv2 Batch ClientversionquotaidlistidsplitmultiorderstatusstatsordsizedownloaderExample SetupInstallationThis assumes that you have native python & pip installed in your system, you can test this by going to the terminal (or windows command prompt) and tryingpythonand thenpip listIf you get no errors and you have python 2.7.14 or higher you should be good to go. Please note that I have tested this only on python 2.7.15 but it should run on python 3.Shapely is notoriously tricky as a library to install on windows machines so follow the steps mentioned fromShapely’s PyPI package page. You can download and install from theUnofficial Wheel files from heredownload depending on the python version you have. You will get a wheel file or a file ending with .whl. You can now simply browse to the folder or migrate to it in your command prompt, for example in my case I was running Python 2.7.15 and win32 version so the command waspip install Shapely-1.6.4.post1-cp27-cp27m-win32.whlOr you can useanaconda to install. Again, both of these options are mentioned onShapely’s Official PyPI page.Fionais a recommended install used by the simplify tool, but it is not necessary. You can find installation instructionshereOnce you have shapely configured. To installpobatch: porder wrapper for Ordersv2 Batch Clientyou can install using two methodspip install pobatchon Ubuntu I found it helps to specify the pip type and use sudosudo pip2 install pobatch or sudo pip3 install pobatchor you can also trygit clone https://github.com/samapriya/pobatch.git
cd pobatch
python setup.py installFor linux use sudo or --user.Installation is an optional step; the application can also be run directly by executing pobatch.py script. The advantage of having it installed is being able to execute pobatch as any command line tool. I recommend installation within a virtual environment. If you don't want to install, browse into the pobatch folder and trypython pobatch.pyto get to the same result.Getting startedMake sure you initialized planet client by typingplanet initorexportorset PL_API_KEY=Your API KeyAs usual, to print help:usage: pobatch [-h]
               {version,quota,idlist,idsplit,bundles,multiorder,status,stats,ordsize,downloader}
               ...

porder wrapper for Ordersv2 Batch Client

positional arguments:
  {version,quota,idlist,idsplit,bundles,multiorder,status,stats,ordsize,downloader}
    version             Prints porder version and exists
    quota               Prints your Planet Quota Details
    idlist              Get idlist using geometry & filters
    idsplit             Splits ID list incase you want to run them in small
                        batches
    bundles             Check bundles of assets for given item type
    multiorder          Place multiple orders based on idlists in folder
    status              Check order status on submitted orders
    stats               Prints number of orders queued and running for org &
                        user
    ordsize             Estimates total download size for each completed
                        order(Takes times)
    downloader          Download using order url list

optional arguments:
  -h, --help            show this help message and exitTo obtain help for a specific functionality, simply call it withhelpswitch, e.g.:pobatch idsplit -h. If you didn't install pobatch, then you can run it just by going topobatchdirectory and runningpython pobatch.py [arguments go here]porder wrapper for Ordersv2 Batch ClientThe tool is built as a wrapper around theporder tool. Theporder toolcontains additionally useful tools such as convert shapefile to geojson, base64 encode your gcs credentials, simplify your geometry to fit the 500 vertices requirements and so on. So the idea is to use both of those tools in conjunction and make desired pipelines as needed. This tools is created to give the user some control over long and tedious order queue and implement push and pull of data in a batch manner.versionThis prints the tool version and escapes. Simple use would bepobatch versionquotaJust a simple tool to print your planet subscription quota quickly.pobatch quotaidlistCreate an idlist for your geometry based on some basic filters, including geometry, start and end date and cloud cover. If no cloud cover is specified, everything from 0 to 100% cloud cover is included. For now the tool can handle geojson,json and kml files. The output is a csv file with ids. The tool also allows you to make sure you get percentage overlap, when selecting image, for clip operations adjust it accordingly (usally --ovp 1 for orders not to fail during clip). The tool now also prints estimated area in Square kilometers for the download and estimated area if you clipped your area with the geometry you are searching (just estimates).I have changed the setup to now do the following two thingsThe number option is optional, so it can look for all images in the time range, but be careful if the area is too large,use at own risk. A better option is to supply the number.It is possible to often forget about the different asset types, so you can now not pass an item and the script will return every possible type of asset for each item type depending on the bundle.pobatch idlist -h
usage: pobatch idlist [-h] --input INPUT --start START --end END --item ITEM
                      [--asset ASSET] --outfile OUTFILE [--cmin CMIN]
                      [--cmax CMAX] [--number NUMBER] [--overlap OVERLAP]
                      [--filters FILTERS [FILTERS ...]]

optional arguments:
  -h, --help            show this help message and exit

Required named arguments.:
  --input INPUT         Input geometry file for now geojson/json/kml
  --start START         Start date in format YYYY-MM-DD
  --end END             End date in format YYYY-MM-DD
  --item ITEM           Item Type PSScene4Band|PSOrthoTile|REOrthoTile etc
  --asset ASSET         Asset Type analytic, analytic_sr,visual etc
  --outfile OUTFILE     Output csv file

Optional named arguments:
  --cmin CMIN           Minimum cloud cover
  --cmax CMAX           Maximum cloud cover
  --number NUMBER       Total number of assets, give a large number if you are
                        not sure
  --overlap OVERLAP     Percentage overlap of image with search area range
                        between 0 to 100
  --filters FILTERS [FILTERS ...]
                        Add an additional string or range filterA simple setup would be the following for 800 max item ids and an overlap of 5% with the geometry we pass to the filterpobatch idlist --input "path to geometry.geojson" --start "YYYY-MM-DD" --end "YYYY-MM-DD" --item "PSScene4Band" --asset "analytic_sr" --number 800 --outfile "path to idlist.csv file" --overlap 5To run an experiment to add additional filter, you can now pass an additional string or range filter or both flag for string and range filters, a setup would be. The additional filters are optionalpobatch idlist --input "Path to geojson file" --start "YYYY-MM-DD" --end "YYYY-MM-DD" --item "PSScene4Band" --asset "analytic" --outfile "Path to idlist.csv" --filters range:clear_percent:55:100 --number 20

pobatch idlist --input "Path to geojson file" --start "YYYY-MM-DD" --end "YYYY-MM-DD" --item "PSScene4Band" --asset "analytic" --outfile "Path to idlist.csv" --filters string:satellite_id:"1003,1006,1012,1020,1038" --number 20

pobatch idlist --input "Path to geojson file" --start "YYYY-MM-DD" --end "YYYY-MM-DD" --item "PSScene4Band" --asset "analytic" --outfile "Path to idlist.csv" --filters string:satellite_id:"1003,1006,1012,1020,1038" range:clear_percent:55:100 --number 20The idlist tool can now use a multipolygon and iteratively look for scenes.idsplitThis allows you to split your idlist into small csv files to created batches of orders.usage: pobatch idsplit [-h] [--idlist IDLIST] [--lines LINES] [--local LOCAL]

optional arguments:
  -h, --help       show this help message and exit
  --idlist IDLIST  Idlist txt file to split
  --lines LINES    Maximum number of lines in each split files
  --local LOCAL    Output folder where split files will be exportedA simple setup would bepobatch idsplit --idlist "path to idlist.csv" --lines "number of lines in each idlist" --local "folder path to export split id lists"multiorderThis tool allows you to actually place the order using the idlist that you created earlier. the--opargument allows you to take operations, delivery and notifications in a sequence for example--op toar clip emailperforms Top of Atmospheric reflectance, followed by clipping to your geometry and send you an email notification once the order has completed, failed or had any any change of status. An important changes is the concept of passing bundles instead of using assets. Bundles are predefined meaning all assets in a bundle are not available for an item your attempt at downloading that attempt will fail.For example if an item id '20181227_125554_0f4c' does not have surface reflectance asset type. So if you try to download this using bundle type analytic_sr_udm2 it will not work, similary if you order an item where a specific operation cannot be performed for example if you order visual and then try to do bandmath with four bands. These examples and more are wherefallback bundlescome in handy. Think of this as providing a list of bundles to keep trying if one bundle type fails. The priority goes left to right. You can provide comma seperated fallback bundles for example asanalytic_sr_udm2,analyticinstead ofanalytic_sr_udm2to avoid certain items from failing to download.The list of operations for the--opare below and ** the order of these operations is important**clip|toar|comp
osite|zip|zipall|compression|projection|kernel|aws|azu
re|gcs|email :
ndvi|gndvi|bndvi|ndwi|tvi|osavi|evi2|msavi2|sropdescriptionclipClip imagery can handle single and multi polygon verify or create geojson.iotoarTop of Atmosphere Reflectance imagery generated for imageryharmonizeHarmonize Dove R (instrument type PS2.SD) data to classic dove (instrument type PS)compositeComposite number of images in a given orderzipZip bundles together and creates downloads (each asset has a single bundle so multiple zip files)zipallCreate a single zip file containing all assetscompressionUse image compressionprojectionReproject before downloaing imageawsOption called to specify delivery to AWSazureOption called to specify delivery to AZUREgcsOption called to specify delivery to GCSemailEmail notification to your planet registered emailYou can now add some predefined indices for PlanetScope 4 band items with a maximum of 5 indices for a single setup . This is experimental. The list of indices includeIndexSourceSimple ratio (SR)Jordan 1969Normalized Difference Vegetation Index (NDVI)Rouse et al 1973Green Normalized Difference Index (GNDVI)Gitelson et al 1996Blue Normalized Difference Vegetation Index (BNDVI)Wang et al 2007Transformed Vegetation Index (TVI)Broge and Leblanc 2000Optimized Soil Adjusted Vegetation Index (OSAVI)Rondeaux et al 1996Enhanced Vegetation Index (EVI2)Jian et al 2008Normalized Difference Water Index (NDWI)McFeeters 1996Modified Soil-adjusted Vegetation Index v2 (MSAVI2)Qi 1994This tool makes use of the FIFO (first in first out) concept in queue implementation in python. It checks to see if you have reached your concurrent order limit and then waits for 5 minutes before trying to place the order again iteratively.pobatch multiorder -h
usage: pobatch multiorder [-h] --infolder INFOLDER --outfile OUTFILE
                          --errorlog ERRORLOG --max MAX --item ITEM --bundle
                          BUNDLE [--sid SID] [--boundary BOUNDARY]
                          [--projection PROJECTION] [--kernel KERNEL]
                          [--compression COMPRESSION] [--aws AWS]
                          [--azure AZURE] [--gcs GCS] [--op OP [OP ...]]

optional arguments:
  -h, --help            show this help message and exit

Required named arguments.:
  --infolder INFOLDER   Folder with multiple order list
  --outfile OUTFILE     CSV file with list of order urls
  --errorlog ERRORLOG   Path to idlist it could not submit,error message log
                        csv file
  --item ITEM           Item Type PSScene4Band|PSOrthoTile|REOrthoTile etc
  --bundle BUNDLE       Bundle Type: analytic, analytic_sr,analytic_sr_udm2

Optional named arguments:
  --sid SID             Subscription ID
  --boundary BOUNDARY   Boundary/geometry for clip operation geojson|json|kml
  --projection PROJECTION
                        Projection for reproject operation of type "EPSG:4326"
  --kernel KERNEL       Resampling kernel used "near", "bilinear", "cubic",
                        "cubicspline", "lanczos", "average" and "mode"
  --compression COMPRESSION
                        Compression type used for tiff_optimize tool,
                        "lzw"|"deflate"
  --aws AWS             AWS cloud credentials config yml file
  --azure AZURE         Azure cloud credentials config yml file
  --gcs GCS             GCS cloud credentials config yml file
  --op OP [OP ...]      Add operations, delivery & notification clip|toar|comp
                        osite|zip|zipall|compression|projection|kernel|aws|azu
                        re|gcs|email <Choose indices from>:
                        ndvi|gndvi|bndvi|ndwi|tvi|osavi|evi2|msavi2|srstatusThe status tool takes the order list created from the multiorder tool and simply queries the current status of the orders in the list. It prints out the index, order name and order status and is for a quick check on multiple orders.usage: pobatch status [-h] [--orderlist ORDERLIST]

optional arguments:
  -h, --help            show this help message and exit
  --orderlist ORDERLIST
                        Orderlist created earlierstatsThe tool allows you to check on number of running and queued orders for both organization and user level. Using this is simplepobatch statsoutput should look like this:Checking on all running orders...
Total queued order for organization: 0
Total running orders for organization: 1

Total queued orders for user: 0
Total running orders for user: 0ordsizeThe ordersize tool allows you to print the order sizes in human readable format like KB, MB, GB.usage: pobatch ordsize [-h] --infile INFILE

optional arguments:
  -h, --help       show this help message and exit

Required named arguments.:
  --infile INFILE  CSV file with order listdownloaderThe tool now allows you to estimate the total download size for a specific order.usage: pobatch downloader [-h] --infile INFILE --folder FOLDER --method METHOD

optional arguments:
  -h, --help       show this help message and exit

Required named arguments.:
  --infile INFILE  CSV file with order list
  --folder FOLDER  Local folder to save order files
  --method METHOD  Method to be utilized for downloading
                   download|multipart|multiprocExample SetupGet idlist for geometry using porder (porder is installed as a dependency for this tool)pobatch idlist --input "geometry file.geojson" --start "2018-01-01" --end "2019-02-01" --item "PSScene4Band" --asset "analytic" --outfile "path to idlist.csv"Split idlist into smaller subpartspobatch idsplit --idlist "idlist file created earlier" --lines "number of lines in split files" --local "folder where we save the split id files"Now place order using idlists that you created. This requires you to set up a limit on the maximum number of concurrent orders you can place. This setups clips the image to a geometry, zips them and send you an email notification on completion.pobatch multiorder --infolder "folder where we save the split id files" --outfile "path to an orderlist with order url" --item "PSScene4Band" --asset "analytic" --boundary "path to geometry.geojson" --op clip zip emailLet us quickly get the status of the orders placed.pobatch --orderlist "Full path to the order list"Let us now get the stats for our order number of order running and queuing for the organization and you as the user.pobatch statsEstimate order download size for each order (This is optional)pobatch ordsize --infile "Path to order url list"Finally download the order, and choose the download method (choose from sequential download or download| multipart download or multiproc or multiprocessing download)pobatch downloader --infile "Path to order url list" --folder "download folder" --method "multipart"Changelogv0.0.8Cleaned multiorder tool now uses stats endpoint instead concurreny check.Enhanced downloaders from porder v0.5.5 with much cleaner file check and download.Added status tool to check status of orders placed and stats tool to check on running and queued orders.General improvements to tool.v0.0.7Added bundle and subscription id arguments to multiorder tool.Updated idlist tool to handle multipolygon geometry betterGeneral improvements.v0.0.6Fixed bundles and removed deprecated bundle types.Created errorlog if issues submitting ordersNow downloads both complete and partial order outputs.v0.0.5Fixed issues with utf decodingLogging and verbose call issue fixedNow returns number of items found while searching using idlistv0.0.4Added quota tool to main to prevent compatability issuesFixed issues with handling with and without op ordersAdded improvements to make shell runs function properly.v0.0.3Added queue support to downloader for better handling order listGeneral improvements to overall tool