Skip to content

Instantly share code, notes, and snippets.

View ao-picterra's full-sized avatar

Andrea Orlandi ao-picterra

  • Picterra
  • Lausanne
  • 14:57 (UTC +02:00)
View GitHub Profile
@ao-picterra
ao-picterra / workflow1.cwl
Created November 13, 2020 10:41
Experimental Picterra Workflow 1
#!/usr/bin/env cwl-runner
cwlVersion: v1.0
class: Workflow
label: Create detector from folder
doc: Given a folder and a name, creates a detector with this name and trainable on the rasters in the folder
inputs:
api_key: string
api_server: string
raster_folder_id: string
@ao-picterra
ao-picterra / main.js
Last active October 24, 2019 16:17
Upload and detection at scale on a folder
const fs = require('fs')
const path = require('path')
const fetch = require('node-fetch')
const Headers = fetch.Headers
const sleep = ms => new Promise(resolve=> setTimeout(resolve,ms))
const apiKey = "123456789"
const apiServer = 'https://app.picterra.ch/public/api/v1'
if (process.argv.length <= 3) {
console.log("Usage: " + __filename + " path/to/directory detector_name");
@ao-picterra
ao-picterra / detect.py
Last active October 30, 2019 08:09
detect on a raster
def detect(detector_id, raster_id):
server_url = "https://picterra.ch/public/api/v1" # Picterra Public API server
headers = { 'X-Api-Key': "123456789" } # Get API key on the Picterra platform
url = server_url + ("/detectors/%s/run/" % detector_id)
requests.post(url, headers=headers, data={'raster_id': raster_id})
response = r.json() # Start prediction
result_id = response["result_id"]
poll_interval = response["poll_interval"] # Waiting interval
url = server_url + ("/results/%s/" % result_id)
while True: # Wait until prediction is finished
@ao-picterra
ao-picterra / upload_and_commit.py
Last active October 25, 2019 08:27
upload and process images
def upload_and_commit(file_path, file_name):
api_key = "123456789" # Get it on the platform
server_url = "https://app.picterra.ch/public/api/v1"
headers = { 'X-Api-Key': api_key }
url = server_url + "/rasters/upload/file/" # Endpoint to get remote upload URL
r = requests.post(url, headers=headers, data={'name': file_name})
response = r.json()
upload_url = response["upload_url"] # Save upload URL
raster_id = response["raster_id"] # Save raster identifier
size = os.stat(file_path).st_size
@ao-picterra
ao-picterra / detect_function.js
Last active October 24, 2019 13:05
detection
async function detect(raster, detectorId, directory) {
const rasterId = raster.id
const rasterName = raster.name
const sleep = s => new Promise(resolve=> setTimeout(resolve, s * 1000))
const apiKey = "123456789"
const apiServer = "https://app.picterra.ch/public/api/v1"
let options = {
method: 'POST',
headers: new Headers({
'Content-Type': 'application/json',
@ao-picterra
ao-picterra / upload_and_commit_functions.js
Last active October 24, 2019 13:04
medium-api-article-1-gist
async function upload(filePath, fileName) {
const sleep = s => new Promise(resolve=> setTimeout(resolve, s * 1000))
const apiKey = "123456789"
const apiServer = "https://app.picterra.ch/public/api/v1"
let options = {
method: 'POST',
headers: new Headers({
'Content-Type': 'application/json',
'X-Api-Key': apiKey}),
body: JSON.stringify({'name': fileName})}
@ao-picterra
ao-picterra / folderRasterUpload.js
Last active October 22, 2019 10:03
multiple upload and detections
const fs = require('fs')
const path = require('path')
const fetch = require('node-fetch')
const Headers = fetch.Headers
const sleep = ms => new Promise(resolve=> setTimeout(resolve,ms))
const apiKey = ""
const apiServer = 'https://app-testing.picterra.ch/public/api/v1'
if (process.argv.length <= 2) {
console.log("Usage: " + __filename + " path/to/directory");