def algorithm_serialization(args, options): nat_env_file = args[0] nat_env_name = args[1] alg_id = args[2] occ_file = args[3] spp_name = args[4] if not omtest.checkArguments(options, "algorithm", alg_id): return ('skip', None) coordSys = "GEOGCS[\"WGS84\", DATUM[\"WGS84\", SPHEROID[\"WGS84\", 6378137.0, 298.257223563]], PRIMEM[\"Greenwich\", 0.0], UNIT[\"degree\", 0.017453292519943295], AXIS[\"Longitude\",EAST], AXIS[\"Latitude\",NORTH]]" (nat_env_list, nat_env_mask) = omtest.get_env_list(nat_env_file, nat_env_name, "../data") (presences, absences) = omtest.get_occurrences(occ_file, spp_name, coordSys, 0, 1, 2, None) alg_params = omtest.get_alg_default_params(alg_id) filename_prefix = "ser_%s_%s" % (alg_id, spp_name.replace(" ", "_")) bmp_filename = filename_prefix + "_projection.bmp" xml_filename = filename_prefix + ".xml" expected_filename = filename_prefix + "_expected.bmp" mod = om.OpenModeller() mod.setOccurrences(presences, absences) mod.setEnvironment([], nat_env_list, nat_env_mask) mod.setAlgorithm(alg_id, alg_params) mod.run() cfg = mod.getModelConfiguration() om.Configuration.writeXml(cfg, xml_filename) # write native projection (to be used as expected map) mf = om.MapFormat() mf.setFormat(om.MapFormat.GreyBMP) mod.projectNativeRange(expected_filename, mf) # now load it all from xml and try to project again mod2 = om.OpenModeller() cfg2 = om.Configuration.readXml(xml_filename) mod2.setModelConfiguration(cfg2) mf2 = om.MapFormat() mf2.setFormat(om.MapFormat.GreyBMP) mod2.projectNativeRange(bmp_filename, mf2) result = omtest.get_map_results_obj(mod, None, presences, absences, "algs/" + bmp_filename, "algs/" + expected_filename, "algs/" + xml_filename) return ('success', result)
def algorithm_absences(args, options): nat_env_file = args[0] nat_env_name = args[1] alg_id = args[2] uses_absences = args[3] occ_file = args[4] spp_name = args[5] # disregar whether the alg uses absences or not # test whether alg runs if absence points are present #if not uses_absences: # return ('skip', None) if not omtest.checkArguments(options, "algorithm", alg_id): return ('skip', None) coordSys = "GEOGCS[\"WGS84\", DATUM[\"WGS84\", SPHEROID[\"WGS84\", 6378137.0, 298.257223563]], PRIMEM[\"Greenwich\", 0.0], UNIT[\"degree\", 0.017453292519943295], AXIS[\"Longitude\",EAST], AXIS[\"Latitude\",NORTH]]" (nat_env_list, nat_env_mask) = omtest.get_env_list(nat_env_file, nat_env_name, "../data") (presences, absences) = omtest.get_occurrences(occ_file, spp_name, coordSys, 0, 1, 2, 3) alg_params = omtest.get_alg_default_params(alg_id) filename_prefix = "abs_%s_%s" % (alg_id, spp_name) bmp_filename = filename_prefix + ".bmp" xml_filename = filename_prefix + ".xml" expected_filename = filename_prefix + "_expected.bmp" mod = om.OpenModeller() mod.setOccurrences(presences, absences) mod.setEnvironment([], nat_env_list, nat_env_mask) mod.setAlgorithm(alg_id, alg_params) mod.run() cfg = mod.getModelConfiguration() om.Configuration.writeXml(cfg, xml_filename) mf = om.MapFormat() mf.setFormat(om.MapFormat.GreyBMP) mod.projectNativeRange(bmp_filename, mf) result = omtest.get_map_results_obj(mod, None, presences, absences, "algs/" + bmp_filename, "algs/" + expected_filename, "algs/" + xml_filename) return ('success', result)
def matrix_input(args, options): nat_env_file = args[0] nat_env_name = args[1] alg_id = args[2] occ_file = args[3] spp_name = args[4] if not omtest.checkArguments(options, "algorithm", alg_id): return ('skip', None) coordSys = "GEOGCS[\"WGS84\", DATUM[\"WGS84\", SPHEROID[\"WGS84\", 6378137.0, 298.257223563]], PRIMEM[\"Greenwich\", 0.0], UNIT[\"degree\", 0.017453292519943295], AXIS[\"Longitude\",EAST], AXIS[\"Latitude\",NORTH]]" (nat_env_list, nat_env_mask) = omtest.get_env_list(nat_env_file, nat_env_name, "../data") (presences, absences) = omtest.get_occurrences(occ_file, spp_name, coordSys, 0, 1, 2, 3) # sample environment at presence and points natEnv = om.makeEnvironment([], nat_env_list, nat_env_mask) presences.setEnvironment(natEnv) absences.setEnvironment(natEnv) alg_params = omtest.get_alg_default_params(alg_id) filename_prefix = "matrix_input_%s_%s" % (alg_id, spp_name.replace( " ", "_")) bmp_filename = filename_prefix + ".bmp" xml_filename = filename_prefix + ".xml" expected_filename = filename_prefix + "_expected.bmp" mod = om.OpenModeller() mod.setOccurrences(presences, absences) mod.setAlgorithm(alg_id, alg_params) mod.run() cfg = mod.getModelConfiguration() om.Configuration.writeXml(cfg, xml_filename) mf = om.MapFormat() mf.setFormat(om.MapFormat.GreyBMP) mod.createMap(natEnv, bmp_filename, mf) result = omtest.get_map_results_obj(mod, natEnv, presences, absences, "algs/" + bmp_filename, "algs/" + expected_filename, "algs/" + xml_filename) return ('success', result)