Skip to content

Commit

Permalink
Ensure we do stats for each lifestage, and add option to calculate st…
Browse files Browse the repository at this point in the history
…ats while using map a grass MASK
  • Loading branch information
ferrouswheel committed Jun 21, 2013
1 parent d0a104b commit c69a700
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
54 changes: 33 additions & 21 deletions mdig/mdig/actions/analysis.py
Expand Up @@ -227,6 +227,12 @@ def add_options(self):
"output with MDiG)",
action="store_false",
dest="analysis_add_to_xml")
self.parser.add_option("-m","--mask",
help="Set this map as a mask before calculating statistics",
action="store",
dest="mask",
default=None,
type="string")

def act_on_options(self, options):
super(StatsAction, self).act_on_options(options)
Expand All @@ -251,32 +257,38 @@ def do_instances(self, mdig_model, instances):
g=grass.get_g()
if self.options.combined_analysis:
if self.options.analysis_step == "all":
for i in instances:
self.log.info("Calculating stats for instance %d" % i.get_index())
maps = i.get_occupancy_envelopes()[ls]
i.change_mapset()
stats=g.get_univariate_stats(maps)
fn = os.path.split(i.get_occ_envelope_img_filenames(ls=ls,
extension=False,gif=True)[:-5])
fn = os.path.join(fn[0], self.options.analysis_filename_base + fn[1])
self.write_stats_to_file(stats,fn)
self.files_written.append(fn)
for l in ls:
for i in instances:
self.log.info("Calculating stats for instance %d" % i.get_index())
maps = i.get_occupancy_envelopes()[l]
i.change_mapset()
g.make_mask(self.options.mask)
stats=g.get_univariate_stats(maps)
fn = os.path.split(i.get_occ_envelope_img_filenames(ls=l,
extension=False,gif=True)[:-5])
g.make_mask(None)
fn = os.path.join(fn[0], self.options.analysis_filename_base + fn[1])
self.write_stats_to_file(stats,fn)
self.files_written.append(fn)
else:
# just run on last map
raise NotImplementedError("Only supports running all maps current")
else:
if self.options.analysis_step == "all":
for i in instances:
i.change_mapset()
for r in i.replicates:
self.log.info("Calculating stats for instance %d, rep %d" % \
(i.get_index(), r.r_index))
maps = r.get_saved_maps(ls)
stats = g.get_univariate_stats(maps)
fn = os.path.split(r.get_base_filenames(ls, single_file=True))
fn = os.path.join(fn[0], self.options.analysis_filename_base + fn[1])
self.write_stats_to_file(stats, fn)
self.files_written.append(fn)
for l in ls:
for i in instances:
i.change_mapset()
g.make_mask(self.options.mask)
for r in i.replicates:
self.log.info("Calculating stats for instance %d, rep %d" % \
(i.get_index(), r.r_index))
maps = r.get_saved_maps(l)
stats = g.get_univariate_stats(maps)
fn = os.path.split(r.get_base_filenames(l, single_file=True))
fn = os.path.join(fn[0], self.options.analysis_filename_base + fn[1])
self.write_stats_to_file(stats, fn)
self.files_written.append(fn)
g.make_mask(None)
else:
# just run on last map
raise NotImplementedError("Only supports running all maps current")
Expand Down
2 changes: 1 addition & 1 deletion mdig/mdig/grass.py
Expand Up @@ -729,7 +729,7 @@ def mapcalc(self, map_name, expression):
map_name='"' + map_name + '"'
self.run_command("r.mapcalc", to_input="%s = %s\nend\n"%(map_name,expression))

def make_mask(self,mask_name):
def make_mask(self, mask_name):
if mask_name is None:
self.run_command('r.mask -r');
else:
Expand Down

0 comments on commit c69a700

Please sign in to comment.