Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dembuilder example and environment #3

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0d1a47a
delete file contents as was causing issues
mcuttler May 24, 2019
4f0208b
create file for pilbara islands
mcuttler May 24, 2019
f0702f1
create environment dependencies
mcuttler May 24, 2019
1cc6f0e
initial test adding dependences to c3dis-2019 environment
mcuttler May 24, 2019
c2f3619
add islands bathy .xyz files
mcuttler May 24, 2019
320286d
update back to original
mcuttler May 24, 2019
0b55810
add plot_island function with different vertical scale
mcuttler May 24, 2019
2832636
create script to run example from jupyter notebook
mcuttler May 24, 2019
b7890ed
create script for adding pilbara islands bathy
mcuttler May 24, 2019
dde51a6
outputs from scripts and original bathy file
mcuttler May 24, 2019
0392d4f
remove output files for bad runs
mcuttler May 24, 2019
2cb3da2
update run file
mcuttler May 24, 2019
1f6cea1
re-add original bathy file
mcuttler May 24, 2019
4702ec0
update resample method to be number instead of words
mcuttler May 24, 2019
3a3f5e8
update to run
mcuttler May 24, 2019
8681a1d
output .tfi
mcuttler May 24, 2019
61879b6
save environment dependencies
mcuttler May 24, 2019
e96ddcb
comment run files
mcuttler May 24, 2019
9e12044
comment example script
mcuttler May 24, 2019
953296d
comment example script
mcuttler May 24, 2019
a8ea50e
re-arrange so bathy incorporated in correct hierarchy
mcuttler May 24, 2019
fc4f6a4
upload output files
mcuttler May 24, 2019
945245e
update bounding box to full pilbara domain
mcuttler May 24, 2019
6a9b72d
add example script (converted from notebook example)
mcuttler May 27, 2019
c15316e
create environment file
mcuttler May 27, 2019
dc05da7
update example for merge
mcuttler Jun 4, 2019
cc3d34b
update example and Perth Metro file
mcuttler Jun 4, 2019
d0a80f9
add thubs.db
mcuttler Sep 23, 2020
7722b56
Merge branch 'pbranson:master' into master
mcuttler Aug 9, 2022
a5428de
remove old files
mcuttler Aug 9, 2022
af60bb6
testing dembuilder for dampier
mcuttler Aug 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ dask-worker-space/
# Sync tools
Icon*

.ipynb_checkpoints
.ipynb_checkpoints
Thumbs.db
14 changes: 14 additions & 0 deletions dembuilder/dembuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,20 @@ def plot(self,vmin=-20,vmax=0,margin=250):
cb.set_label('z')
# pl.show()
return fig, ax

def plot_island(self,vmin=-10,vmax=10,margin=250):

fig = pl.figure(figsize=(12, 8))
ax = fig.add_subplot(111)
x_min, y_min, x_max, y_max = self.bbox
pc=pl.pcolormesh(self.xBinEdges, self.yBinEdges, self.z, vmin=vmin, vmax=vmax)
ax.axis('image')
ax.set_xlim([x_min - margin, x_max + margin])
ax.set_ylim([y_min - margin, y_max + margin])
cb=pl.colorbar(pc)
cb.set_label('z')
# pl.show()
return fig, ax

def interpolate(self,x,y):
F = RegularGridInterpolator((self.yBinCentres,self.xBinCentres),self.z,bounds_error=False,fill_value=0.)
Expand Down
102 changes: 102 additions & 0 deletions dembuilder_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# -*- coding: utf-8 -*-
"""
Example script demonstrating functionality of dembuilder
Code copied from P Branson's jupyter notebook - basically just so MC doesn't have to keep flipping between
google chrome and spyder

M Cuttler
May 2019

"""
#%% Example from P Branson notebook

#import python modules
import os
import sys
import numpy as np

#import p branson modules
import dembuilder as db

sys.path.append('../')

#%%

#define bounding box of new raster
bbox=np.zeros(4)
bbox[0] = 220000 #left
bbox[1] = 7570000 #bottom
bbox[2] = 270000 #right
bbox[3] = 7620000 #top
newRaster = db.Raster(bbox=bbox, resolution=500, epsgCode=28350)

#read bathy file and crop to bounding box

filepath = os.path.join(os.getcwd(),'notebooks')
filename = 'Pilbara_200m_Composite_Linear.tif'
sampleReader = db.SamplePointReader(os.path.join(filepath, filename),cropTo=bbox)
samples = sampleReader.load()

#dispay samples (x,y,z, arrays)
samples

#%%

#show options for boundary types
[t for t in db.BoundaryPolygonType]

#use Box boundary
samples.generateBoundary(type=db.BoundaryPolygonType.Box)

#plot samples
samples.plot()

#%% create 'random' secondary bathymetry points

#define random samples to incorporate into bathy; could also load another bathy file (.tif, .xyz, .mat, .nc)
x = np.random.rand(100) * 10000 + 240000
y = np.random.rand(100) * 10000 + 7590000
z = np.random.rand(100) * 10 - 15

#create samples from x,y,z arrays defined above
randomSamples = db.SamplePoints(x,y,z)
#show random samples
randomSamples.plot()

#generate a concave hull boundary and thresold distance to 1500
randomSamples.generateBoundary(type=db.BoundaryPolygonType.ConcaveHull,threshold=1500)

#%% interpolate new bathy to raster object

#show resampling methods
[t for t in db.ResampleMethods]

#resample using linear interpolation
randomSamples.resample(newRaster,method=db.ResampleMethods.Linear)

#plot new raster with interpolated bathy (only has randomSamples)
newRaster.plot()

#%% compile multiple bathy sets together

#include bathy from Pilbara_200m_composite
samples.resample(newRaster,method=db.ResampleMethods.BlockAvg)

#display composite bathy dataset
newRaster.plot()

#save raster to .tif
newRaster.saveToFile('tempRaster.tiff')
#export raster as .xyz
newRaster.getSamples().saveXYZ('tempRaster.xyz')


#%% save raster to current directory as .tif
newRaster.saveToFile('tempRaster.tiff')
#export raster to current directory as .xyz
newRaster.getSamples().saveXYZ('tempRaster.xyz')
#%% can also load existing rasters

loadedRaster = db.Raster.loadFromFile('tempRaster.tiff')
loadedRaster.plot()

35 changes: 35 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: dembuild
channels:
- defaults
- conda-forge
dependencies:
- conda=4.6.3
- python=3.7
- numpy=1.16.3
- matplotlib=3.0.3
- gdal=2.3.3
- pandas=0.24.2
- geopandas=0.4.1
- pytz=2019.1
- scikit-image=0.15.0
- geos=3.7.1
- scikit-learn=0.20.3
- shapely=1.6.4
- scipy=1.2.1
- spyder=3.3.4
- notebook=5.7.8
- pyproj=1.9.6
- xarray=0.12.1
- bumpversion=0.5.3
- wheel=0.32.1
- flake8=3.5.0
- tox=3.5.2
- coverage=4.5.1
- Sphinx=1.8.1
- twine=1.12.1
- pip=18.1





68 changes: 40 additions & 28 deletions notebooks/Example_1 Simple composite - Samples and Raster.ipynb

Large diffs are not rendered by default.

555 changes: 555 additions & 0 deletions notebooks/dampier.ipynb

Large diffs are not rendered by default.