Skip to content

Instantly share code, notes, and snippets.

@jlaura
Created July 12, 2019 15:17
Show Gist options
  • Save jlaura/cab90d704554d2a4898da2508ba77963 to your computer and use it in GitHub Desktop.
Save jlaura/cab90d704554d2a4898da2508ba77963 to your computer and use it in GitHub Desktop.
Code block for testing pfeffernusse response when errors are being thrown. Toss this into a notebook and alter the URL to test different instances of pfeffernusse.
import csmapi
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
import os
import json
def requests_retry_session(retries=1, backoff_factor=0.3, status_forcelist=(500, 502, 504), session=None):
session = session or requests.Session()
retry = Retry(total=retries, read=retries, connect=retries, backoff_factor=backoff_factor, status_forcelist=status_forcelist)
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)
return session
def create_camera(geodata):
# Create the camera entry
label = pvl.dumps(geodata.metadata).decode()
#url = 'http://smalls:5051/v1/pds/'
url = 'http://pfeffer.wr.usgs.gov/v1/pds'
#url = 'http://astrovm4:5050/v1/pds/'
response = requests_retry_session().post(url, json={'label':label})
if response == None:
response = requests_retry_session().post(url, json={'label':label})
response = response.json()
print(response)
model_name = response.get('name_model', None)
if model_name is None:
return (None, None)
isdpath = os.path.splitext(geodata.file_name)[0] + '.json'
try:
with open(isdpath, 'w') as f:
json.dump(response, f)
except Exception as e:
warnings.warn('Failed to write JSON ISD for image {}.\n{}'.format(geodata.file_name, e))
isd = csmapi.Isd(geodata.file_name)
plugin = csmapi.Plugin.findPlugin('UsgsAstroPluginCSM')
camera = plugin.constructModelFromISD(isd, model_name)
serialized_camera = camera.getModelState()
cam = Cameras(camera=serialized_camera)
return cam, camera
import pvl
from plio.io.io_gdal import GeoDataset
gd = GeoDataset('/scratch/jlaura/elysium/cal/K02_053994_1943_XI_14N180W.cal.cub')
#gd = GeoDataset('/scratch/jlaura/elysium/cal/P02_001632_2085_XI_28N194W.cal.cub')
create_camera(gd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment