Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 2 additions & 6 deletions combine_features.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env python

"""
This script takes a file containing one or more feature definitions, pointed
This script takes a file containing one or more feature definitions, pointed
to by the -f flag, and a new name for the combined feature, provided through
the -n flag. The geometry of the feature definitions are combined into a
single feature definition, which is placed in (or appended to)
the file pointed to with the -o flag (features.geojson by default).

Author: Xylar Asay-Davis
Last Modified: 09/29/2016
Last Modified: 10/16/2016
"""

import json
Expand All @@ -32,9 +32,6 @@
parser.add_argument("-n", "--new_feature_name", dest="new_feature_name",
help="The new name of the combined feature",
metavar="NAME", required=True)
parser.add_argument("-g", "--groupName", dest="groupName",
help="Feature group name.",
metavar="GROUPNAME", default="unspecifiedGroupName")
parser.add_argument("-o", "--output", dest="output_file_name",
help="Output file, e.g., features.geojson.",
metavar="PATH", default="features.geojson")
Expand Down Expand Up @@ -100,7 +97,6 @@
feature['properties']['constituents'] = '; '.join(list(set(featureNames)))
feature['geometry'] = shapely.geometry.mapping(combinedShape)
features['features'].append(feature)
features['groupName'] = args.groupName

if feature['geometry']['type'] == 'GeometryCollection':
print "Error: combined geometry from %s is of type GeometryCollection."%(args.feature_file)
Expand Down
13 changes: 4 additions & 9 deletions difference_features.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env python
"""
This script takes a file containing one or more feature definitions, that is
pointed to by the -f flag and a second set of one or more masking feature
pointed to by the -f flag and a second set of one or more masking feature
definition, pointed to with the -m flag. The masking features are masked out
of (i.e. removed from) the original feature definitions. The resulting
features are placed in (or appended to) the output file pointed to with the
of (i.e. removed from) the original feature definitions. The resulting
features are placed in (or appended to) the output file pointed to with the
-o flag (features.geojson by default).

Authors: Xylar Asay-Davis
Last Modified: 09/29/2016
Last Modified: 10/16/2016
"""

import json
Expand All @@ -31,9 +31,6 @@
help="Feature file with one or more features whose overlap "
"with features in feature_file should be removed",
metavar="FILE2", required=True)
parser.add_argument("-g", "--groupName", dest="groupName",
help="Feature group name.",
metavar="GROUPNAME", default="unspecifiedGroupName")
parser.add_argument("-o", "--output", dest="output_file_name",
help="Output file, e.g., features.geojson.",
metavar="PATH", default="features.geojson")
Expand Down Expand Up @@ -111,8 +108,6 @@
else:
print "%s has been removed."%name

features['groupName'] = args.groupName

write_all_features(features, out_file_name, indent=4)

# vim: foldmethod=marker ai ts=4 sts=4 et sw=4 ft=python
67 changes: 0 additions & 67 deletions driver_scripts/setup_MOC_basins.py

This file was deleted.

184 changes: 157 additions & 27 deletions driver_scripts/setup_ocean_basins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
"""
This script creates 6 major ocean basins. No arguments are required. The
This script creates 6 major ocean basins. No arguments are required. The
optional --plot flag can be used to produce plots of each basin.
"""
import os
Expand All @@ -12,35 +12,165 @@ def spcall(args): #{{{
return subprocess.check_call(args, env=os.environ.copy()) #}}}


def build_basins(): #{{{
basinGroupName = 'OceanBasinRegionsGroup'
basinFileName = 'oceanBasins.geojson'

# temp file names that we delete later
tempSeparateBasinFileName = 'temp_separate_basins.geojson'
tempCombinedBasinFileName = 'temp_combined_basins.geojson'

# remove old files so we don't unintentionally append features
for fileName in [basinFileName,
tempSeparateBasinFileName,
tempCombinedBasinFileName]:
if os.path.exists(fileName):
os.remove(fileName)

# build ocean basins from regions with the appropriate tags
for oceanName in ['Atlantic', 'Pacific', 'Indian', 'Arctic', 'Southern_Ocean',
'Mediterranean']:

tag = '%s_Basin'%oceanName

print " * merging features to make %s Basin"%oceanName
spcall(['./merge_features.py', '-d', 'ocean/region', '-t', tag,
'-o', tempSeparateBasinFileName])

#merge the the features into a single file
print " * combining features into single feature named %s_Basin"%oceanName
spcall(['./combine_features.py', '-f', tempSeparateBasinFileName,
'-n', '%s_Basin'%oceanName,
'-o', tempCombinedBasinFileName])

if(options.plot):
spcall(['./plot_features.py', '-f', tempCombinedBasinFileName,
'-o', '%s_Basin.png'%oceanName, '-m', 'cyl'])

spcall(['./merge_features.py', '-f', tempCombinedBasinFileName,
'-o', basinFileName])

# remove temp files
for fileName in [tempSeparateBasinFileName, tempCombinedBasinFileName]:
os.remove(fileName)


spcall(['./set_group_name.py', '-f', basinFileName,
'-g', basinGroupName])

if(options.plot):
spcall(['./plot_features.py', '-f', basinFileName,
'-o', 'oceanBasins.png', '-m', 'cyl']) #}}}


def build_MOC_basins(): #{{{
MOCFileName = 'MOCBasins.geojson'
MOCGroupName = 'MOCBasinRegionsGroup'

MOCSouthernBoundaryFileName = 'MOCSounthernBoundaries.geojson'
MOCSouthernBoundaryGroupName = 'MOCSouthernBoundaryGroup'

MOCSubBasins = {'Atlantic': ['Atlantic', 'Mediterranean'],
'IndoPacific': ['Pacific', 'Indian'],
'Pacific': ['Pacific'],
'Indian': ['Indian']}


MOCSouthernBoundary = {'Atlantic': '34S',
'IndoPacific': '34S',
'Pacific': '6S',
'Indian': '6S'}

# temp file names that we delete later
tempSeparateBasinFileName = 'temp_separate_basins.geojson'
tempCombinedBasinFileName = 'temp_combined_basins.geojson'
tempMOCFileName = 'temp_MOC.geojson'
tempSouthernBoundaryFileName = 'temp_southern_boundary.geojson'
tempSouthernBoundaryRenamedFileName = 'temp_southern_boundary_renamed.geojson'

# remove old files so we don't unintentionally append features
for fileName in [MOCFileName,
MOCSouthernBoundaryFileName,
tempSeparateBasinFileName,
tempCombinedBasinFileName,
tempMOCFileName,
tempSouthernBoundaryFileName,
tempSouthernBoundaryRenamedFileName]:
if os.path.exists(fileName):
os.remove(fileName)


# build MOC basins
for basinName in MOCSubBasins:

imageName = '%s_MOC.png'%basinName

MOCMaskFileName = 'ocean/region/MOC_mask_%s/region.geojson' \
% MOCSouthernBoundary[basinName]

MOCSouternBoundaryFileName = 'ocean/transect/MOC_%s/transect.geojson' \
% MOCSouthernBoundary[basinName]

print " * merging features to make %s Basin"%basinName

for oceanName in MOCSubBasins[basinName]:
spcall(['./merge_features.py', '-d', 'ocean/region',
'-t', '%s_Basin'%oceanName,
'-o', tempSeparateBasinFileName])

#merge the the features into a single file
print " * combining features into single feature named %s_MOC"%basinName
spcall(['./combine_features.py', '-f', tempSeparateBasinFileName,
'-n', '%s_MOC'%basinName,
'-o', tempCombinedBasinFileName])

print " * masking out features south of MOC region"
spcall(['./difference_features.py', '-f', tempCombinedBasinFileName,
'-m', MOCMaskFileName,
'-o', tempMOCFileName])

spcall(['./merge_features.py', '-f', tempMOCFileName,
'-o', MOCFileName])

if options.plot:
spcall(['./plot_features.py', '-f', tempMOCFileName, '-o', imageName,
'-m', 'cyl'])

print " * make feature for southern boundary of MOC region"
spcall(['./intersect_features.py', '-f', tempCombinedBasinFileName,
'-i', MOCSouternBoundaryFileName,
'-o', tempSouthernBoundaryFileName])

# use combine_features to rename the feature
spcall(['./combine_features.py', '-f', tempSouthernBoundaryFileName,
'-n', '%s_MOC_southern_boundary'%basinName,
'-o', tempSouthernBoundaryRenamedFileName])

spcall(['./merge_features.py', '-f', tempSouthernBoundaryRenamedFileName,
'-o', MOCSouthernBoundaryFileName])

# remove temp files
for fileName in [tempSeparateBasinFileName, tempCombinedBasinFileName,
tempMOCFileName, tempSouthernBoundaryFileName,
tempSouthernBoundaryRenamedFileName]:
os.remove(fileName)

spcall(['./set_group_name.py', '-f', MOCFileName,
'-g', MOCGroupName])

spcall(['./set_group_name.py', '-f', MOCSouthernBoundaryFileName,
'-g', MOCSouthernBoundaryGroupName])

if options.plot:
spcall(['./plot_features.py', '-f', MOCFileName,
'-o', 'MOCBasins.png', '-m', 'cyl'])

parser = OptionParser()
parser.add_option("--plot", action="store_true", dest="plot")

options, args = parser.parse_args()

groupName = 'OceanBasinRegionsGroup'

for oceanName in 'Atlantic', 'Pacific', 'Indian', 'Arctic', 'Southern_Ocean', 'Mediterranean':

tag = '%s_Basin'%oceanName
basinFileNameName = '%s_Basin_separate.geojson'%oceanName
basinCombinedFileName = '%s_Basin.geojson'%oceanName
imageName = '%s_Basin.png'%oceanName

# remove old files (to ensure there isn't double-appending via merge_features
for afile in [basinFileNameName, basinCombinedFileName, imageName]:
if os.path.exists(afile):
os.remove(afile)

print " * merging features to make %s Basin"%oceanName
args = ['./merge_features.py', '-d', 'ocean/region', '-t', tag, '-o', basinFileNameName]
subprocess.check_call(args, env=os.environ.copy())

#merge the the features into a single file
print " * combining features into single feature named %s_Basin"%oceanName
spcall(['./combine_features.py', '-f', basinFileNameName, '-n', '%s_Basin'%oceanName,
'-g', groupName, '-o', basinCombinedFileName])

if(options.plot):
args = ['./plot_features.py', '-f', basinCombinedFileName, '-o', imageName, '-m', 'cyl']
subprocess.check_call(args, env=os.environ.copy())
build_basins()
build_MOC_basins()

# vim: foldmethod=marker ai ts=4 sts=4 et sw=4 ft=python
Loading