Skip to content

Commit

Permalink
Merge pull request #21 from ASFHyP3/bugfix
Browse files Browse the repository at this point in the history
HOTFIX: browse and ISCE version bugfixes
  • Loading branch information
jhkennedy authored Sep 23, 2020
2 parents 4741a83 + 8f07a6b commit cfbefca
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [PEP 440](https://www.python.org/dev/peps/pep-0440/)
and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.1](https://github.com/ASFHyP3/hyp3-autorift/compare/v0.1.0...v0.1.1)

### Added
* Browse and thumbnail images are now created and uploaded for hyp3v2

### Fixes
* Restrict ISCE version to 2.4.0 which includes autoRIFT 1.0.6

## [0.1.0](https://github.com/ASFHyP3/hyp3-autorift/compare/v0.0.0...v0.1.0)

Initial release of hyp3-autorift, a HyP3 plugin for feature tracking processing
Expand Down
3 changes: 2 additions & 1 deletion conda-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ dependencies:
- wheel
# For running
- hyp3lib=1.5
- isce2>=2.4
- isce2=2.4.0
- importlib_metadata
- numpy
- pillow
- psycopg2 # missing hyp3proclib dep
- requests
- scikit-image # missing autoRIFT dep
Expand Down
22 changes: 18 additions & 4 deletions hyp3_autorift/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from mimetypes import guess_type

import boto3
from PIL import Image
from hyp3proclib import (
build_output_name_pair,
earlier_granule_first,
Expand Down Expand Up @@ -49,6 +50,16 @@ def entry():


# v2 functions
def create_thumbnail(input_image, size=(100, 100)):
filename, ext = os.path.splitext(input_image)
thumbnail_name = f'{filename}_thumb{ext}'

output_image = Image.open(input_image)
output_image.thumbnail(size)
output_image.save(thumbnail_name)
return thumbnail_name


def write_netrc_file(username, password):
netrc_file = os.path.join(os.environ['HOME'], '.netrc')
if os.path.isfile(netrc_file):
Expand Down Expand Up @@ -110,9 +121,16 @@ def main_v2():
product_name = f'{outname}.nc'
netcdf_file = glob.glob('*nc')[0]
os.rename(netcdf_file, product_name)
browse_name = f'{outname}.png'
browse_file = glob.glob('*.png')[0]
os.rename(browse_file, browse_name)

if args.bucket:
upload_file_to_s3(product_name, 'product', args.bucket, args.bucket_prefix)
upload_file_to_s3(browse_name, 'browse', args.bucket, args.bucket_prefix)
thumbnail_name = create_thumbnail(browse_name)
upload_file_to_s3(thumbnail_name, 'thumbnail', args.bucket, args.bucket_prefix)
# End v2 functions


def hyp3_process(cfg, n):
Expand All @@ -139,10 +157,6 @@ def hyp3_process(cfg, n):
out_name = build_output_name_pair(g1, g2, cfg['workdir'], cfg['suffix'])
log.info(f'Output name: {out_name}')

# TODO:
# * browse images
# * citation
# * phase_png (?)
if extra_arg_is(cfg, 'intermediate_files', 'no'):
product_glob = os.path.join(cfg['workdir'], cfg['ftd'], '*.nc')
netcdf_files = glob.glob(product_glob)
Expand Down
30 changes: 30 additions & 0 deletions hyp3_autorift/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
import shutil
from pathlib import Path

import numpy as np
from hyp3lib.execute import execute
from hyp3lib.file_subroutines import mkdir_p
from hyp3lib.get_orb import downloadSentinelOrbitFile
from hyp3lib.makeAsfBrowse import makeAsfBrowse
from osgeo import gdal

from hyp3_autorift import geometry
from hyp3_autorift import io
Expand All @@ -22,10 +25,18 @@
_PRODUCT_LIST = [
'offset.tif',
'velocity.tif',
'velocity_browse.tif',
'velocity_browse.kmz',
'velocity_browse.png',
'velocity_browse.png.aux.xml',
'window_chip_size_max.tif',
'window_chip_size_min.tif',
'window_location.tif',
'window_offset.tif',
'window_rdr_off2vel_x_vec.tif',
'window_rdr_off2vel_y_vec.tif',
'window_search_range.tif',
'window_stable_surface_mask.tif',
]


Expand Down Expand Up @@ -124,6 +135,25 @@ def process(reference, secondary, download=False, polarization='hh', orbits=None
f' -csmax window_chip_size_max.tif -nc S'
execute(cmd, logfile=f, uselogging=True)

velocity_tif = gdal.Open('velocity.tif')
x_velocity = np.ma.masked_invalid(velocity_tif.GetRasterBand(1).ReadAsArray())
y_velocity = np.ma.masked_invalid(velocity_tif.GetRasterBand(2).ReadAsArray())
velocity = np.sqrt(x_velocity**2 + y_velocity**2)

browse_file = Path('velocity_browse.tif')
driver = gdal.GetDriverByName('GTiff')
browse_tif = driver.Create(
str(browse_file), velocity.shape[1], velocity.shape[0], 1, gdal.GDT_Byte, ['COMPRESS=LZW']
)
browse_tif.SetProjection(velocity_tif.GetProjection())
browse_tif.SetGeoTransform(velocity_tif.GetGeoTransform())
velocity_band = browse_tif.GetRasterBand(1)
velocity_band.WriteArray(velocity)

del velocity_band, browse_tif, velocity_tif

makeAsfBrowse(str(browse_file), browse_file.stem)

if product:
mkdir_p(product_dir)
for f in _PRODUCT_LIST:
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
'hyp3lib==1.5',
'hyp3proclib',
'importlib_metadata',
'pillow',
'numpy',
'scipy',
],
Expand Down

0 comments on commit cfbefca

Please sign in to comment.