Skip to content

Commit

Permalink
updated v0.3.2
Browse files Browse the repository at this point in the history
- idlist tool can no use a multipolygon and iteratively look for scenes
- Orders clip tool can now handle multipolygon clip
- Added new tool zipall to handle single archive download download in format ordername_date.zip
  • Loading branch information
samapriya committed May 20, 2019
1 parent 855763d commit bb73bf5
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 24 deletions.
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ porder idlist --input "Path to geojson file" --start "YYYY-MM-DD" --end "YYYY-MM
porder 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 20
```

The idlist tool can no use a multipolygon and iteratively look for scenes.

### difflist
It is possible you already downloaded some images or metadata files, and your you want a difference idlist to create orders for only assets and item types you do not have. It takes in your local folder path, type image or metadata and some basic filters,including geometry, start and end date and cloud cover. If no cloud cover is specified everything form 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.

Expand Down Expand Up @@ -151,7 +153,33 @@ A simple setup would be
![porder_idcheck_setup](https://user-images.githubusercontent.com/6677629/57543933-d5d3fc00-7323-11e9-946f-200a4791f5e8.png)

### order
This tool allows you to actually place the order using the idlist that you created earlier. the ```--op``` argument allows you to take operations, delivery and notifications in a sequence for example ```--op toar clip email``` performs 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. You 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 include
This tool allows you to actually place the order using the idlist that you created earlier. the ```--op``` argument allows you to take operations, delivery and notifications in a sequence for example ```--op toar clip email``` performs 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. The list of operations are below and **order is important**

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|sr

<center>

op | description |
------------------|-------------------------------------------------------------------------------|
clip | Clip imagery can handle single and multi polygon verify or create geojson.io
toar | Top of Atmosphere Reflectance imagery generated for imagery
composite | Composite number of images in a given order
zip | Zip bundles together and creates downloads (each asset has a single bundle so multiple zip files)
zipall | Create a single zip file containing all assets
compression | Use image compression
projection | Reproject before downloaing image
aws | Option called to specify delivery to AWS
azure | Option called to specify delivery to AZURE
gcs | Option called to specify delivery to GCS
email | Email notification to your planet registered email

</center>


You 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 include

<center>

Expand Down Expand Up @@ -224,6 +252,11 @@ A simple setup would be

## Changelog

### v0.3.2
- idlist tool can no use a multipolygon and iteratively look for scenes
- Orders clip tool can now handle multipolygon clip
- Added new tool zipall to handle single archive download download in format ordername_date.zip

### v0.3.1
- Can now support an additional string and range filter
- Check total area and clip area estimates from any idlist using idcheck.
Expand Down
Binary file removed dist/porder-0.3.1-py2.py3-none-any.whl
Binary file not shown.
Binary file removed dist/porder-0.3.1.tar.gz
Binary file not shown.
Binary file added dist/porder-0.3.2-py2.py3-none-any.whl
Binary file not shown.
Binary file added dist/porder-0.3.2.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion porder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

__author__ = 'Samapriya Roy'
__email__ = '[email protected]'
__version__ = '0.3.1'
__version__ = '0.3.2'
46 changes: 31 additions & 15 deletions porder/geojson2id.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,27 @@
client = api.ClientV1(PL_API_KEY)


temp={"coordinates":[],"type":"Polygon"}
temp={"coordinates":[],"type":"MultiPolygon"}
tempsingle={"coordinates":[],"type":"Polygon"}
stbase={'config': [], 'field_name': [], 'type': 'StringInFilter'}
rbase={'config': {'gte': [], 'lte': []},'field_name': [], 'type': 'RangeFilter'}
aoi = {
"type": "Polygon",
"coordinates": []
}

# Area lists
ar = []
far = []

# get coordinates list depth
def list_depth(dic, level = 1):
counter = 0
str_dic = str(dic)
if "[[[[" in str_dic:
if "[[[[[" in str_dic:
counter += 2
elif "[[[[" in str_dic:
counter += 1
elif "[[[" in str_dic:
counter += 0
return(counter)

# Area lists
ar = []
far = []
ovall=[]

# Function to use the client and then search
def idl(**kwargs):
Expand All @@ -72,12 +73,22 @@ def idl(**kwargs):
if infile.endswith('.geojson'):
with open(infile) as aoi:
aoi_resp = json.load(aoi)
if list_depth(aoi_resp['features'][0]['geometry']['coordinates'])==0:
aoi_geom = aoi_resp['features'][0]['geometry']['coordinates']
elif list_depth(aoi_resp['features'][0]['geometry']['coordinates'])==1:
aoi_geom = aoi_resp['features'][0]['geometry']['coordinates'][0]
for things in aoi_resp['features']:
ovall.append(things['geometry']['coordinates'])
#print(list_depth(ovall))
if len(ovall)>1:
aoi_geom=ovall
else:
if list_depth(ovall)==0:
aoi_geom = ovall
elif list_depth(ovall)==1:
aoi_geom = ovall[0]
elif list_depth(ovall)==2:
aoi_geom = ovall[0][0]
else:
print('Please check GeoJSON: Could not parse coordinates')
aoi_geom==aoi_geom
#print(aoi_geom)
elif infile.endswith('.json'):
with open (infile) as aoi:
aoi_resp=json.load(aoi)
Expand Down Expand Up @@ -169,7 +180,12 @@ def idl(**kwargs):
print('Running search for a maximum of: ' + str(num) + ' assets')
l=0
[head,tail]=os.path.split(outfile)
temp['coordinates']=aoi_geom
if len(ovall)>1:
temp={"coordinates":[],"type":"MultiPolygon"}
temp['coordinates']=aoi_geom
else:
temp=tempsingle
temp['coordinates']=aoi_geom
sgeom=filters.geom_filter(temp)
aoi_shape = shape(temp)
date_filter = filters.date_range('acquired', gte=start,lte=end)
Expand Down
49 changes: 44 additions & 5 deletions porder/order_now.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import csv
import sys
import pendulum
import json
import yaml
import requests
Expand All @@ -30,9 +31,23 @@

x = PrettyTable()

ovall=[]

# get coordinates list depth
def list_depth(dic, level = 1):
counter = 0
str_dic = str(dic)
if "[[[[[" in str_dic:
counter += 2
elif "[[[[" in str_dic:
counter += 1
elif "[[[" in str_dic:
counter += 0
return(counter)

##Setup for bundles
dbundle = {'name': [], 'order_type': 'partial', 'products': [{'item_ids': [], 'item_type': [],'product_bundle': []}],'tools':[]}
dclip = {"clip": {"aoi": {"type": "Polygon","coordinates": []}}}
dclip = {"clip": {"aoi": {"type": "MultiPolygon","coordinates": []}}}
dtoar = {'toar': {'scale_factor': 10000}}
dzip = {"delivery":{"archive_filename":"{{name}}.zip","archive_type":"zip"}}
dcomposite ={"composite":{}}
Expand All @@ -43,7 +58,7 @@
dazure={"delivery":{"azure_blob_storage":{"account":[],"container":[],"sas_token":[],"storage_endpoint_suffix":[],"path_prefix":[]}}}
dgcs={"delivery": {"google_cloud_storage": {"bucket": [],"credentials": [],"path_prefix": []}}}
dbmath={"bandmath":{}}

dszip={"delivery":{"archive_filename":"Explorer_{{name}}.zip","archive_type":"zip","single_archive":True}}
try:
PL_API_KEY = find_api_key()
except:
Expand Down Expand Up @@ -80,13 +95,16 @@ def order(**kwargs):
k=dbundle
for key,value in kwargs.items():
if key=='op' and value!=None:
ordname=k['name']
for items in value:
if items=='clip':
dbundle['tools'].append(dclip)
elif items=='toar':
dbundle['tools'].append(dtoar)
elif items=='zip':
dbundle.update(dzip)
elif items=='zipall':
dbundle.update(dszip)
elif items=='email':
dbundle.update(demail)
elif items=='aws':
Expand Down Expand Up @@ -128,16 +146,36 @@ def order(**kwargs):
dbmath['bandmath'].update(dmsavi2)
elif items=='compression':
dbundle['tools'].append(dtiff)

#dbundle[]
for key,value in kwargs.items():
if key=='boundary' and value!=None:
for items in k['tools']:
if items.get('clip'):
try:
if value.endswith('.geojson'):
with open(value) as aoi:
aoi_resp = json.loads(aoi.read())
items['clip']['aoi']['coordinates']= aoi_resp['features'][0]['geometry']['coordinates']
aoi_resp = json.load(aoi)
for things in aoi_resp['features']:
ovall.append(things['geometry']['coordinates'])
#print(list_depth(ovall))
if len(ovall)>1:
aoi_geom=ovall
items['clip']['aoi']['coordinates']=aoi_geom
else:
if list_depth(ovall)==0:
aoi_geom = ovall
items['clip']['aoi']['type']="Polygon"
items['clip']['aoi']['coordinates']=aoi_geom
elif list_depth(ovall)==1:
aoi_geom = ovall[0]
items['clip']['aoi']['type']="Polygon"
items['clip']['aoi']['coordinates']=aoi_geom
elif list_depth(ovall)==2:
aoi_geom = ovall[0][0]
items['clip']['aoi']['type']="Polygon"
items['clip']['aoi']['coordinates']=aoi_geom
else:
print('Please check GeoJSON: Could not parse coordinates')
elif value.endswith('.json'):
with open (value) as aoi:
aoi_resp=json.load(aoi)
Expand Down Expand Up @@ -224,6 +262,7 @@ def order(**kwargs):
#print(dbmath)

#print(payload)
payload=payload.replace("Explorer_{{name}}.zip",ordname+'_'+str(pendulum.now()).split("T")[0]+".zip")
headers = {'content-type': 'application/json',
'cache-control': 'no-cache'}
response = requests.request('POST', url, data=payload, headers=headers,
Expand Down
2 changes: 1 addition & 1 deletion porder/porder.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def main(args=None):
optional_named.add_argument('--aws', help='AWS cloud credentials config yml file',default=None)
optional_named.add_argument('--azure', help='Azure cloud credentials config yml file',default=None)
optional_named.add_argument('--gcs', help='GCS cloud credentials config yml file',default=None)
optional_named.add_argument('--op', nargs='+',help="Add operations, delivery & notification clip|toar|composite|zip|compression|projection|kernel|aws|azure|gcs|email <Choose indices from>: ndvi|gndvi|bndvi|ndwi|tvi|osavi|evi2|msavi2|sr",default=None)
optional_named.add_argument('--op', nargs='+',help="Add operations, delivery & notification clip|toar|composite|zip|zipall|compression|projection|kernel|aws|azure|gcs|email <Choose indices from>: ndvi|gndvi|bndvi|ndwi|tvi|osavi|evi2|msavi2|sr",default=None)

parser_order.set_defaults(func=order_from_parser)

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ pyyaml>=3.12
prettytable>=0.7.2
pyproj>=1.9.5.1
geopandas>=0.5.0
pendulum>=2.0.4
visvalingamwyatt>=0.1.2
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ def readme():
return f.read()
setuptools.setup(
name='porder',
version='0.3.1',
version='0.3.2',
packages=['porder'],
url='https://github.com/samapriya/porder',
package_data={'': ['bundles.json']},
install_requires=['requests>=2.19.1','planet>=1.2.1','retrying>=1.3.3',
'progressbar2>=3.38.0',
'geopandas>=0.5.0',
'visvalingamwyatt>=0.1.2',
'pendulum>=2.0.4',
'pySmartDL==1.2.5;python_version<"3.4"',
'pySmartDL>=1.3.1;python_version>"3.4"',
'shapely>=1.6.4;platform_system!="Windows"',
Expand Down

0 comments on commit bb73bf5

Please sign in to comment.