This repository has been archived by the owner on Oct 8, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added rain processing namespace, for work for dan.
- Loading branch information
Showing
13 changed files
with
164 additions
and
175 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,6 @@ docs | |
autodoc | ||
.#* | ||
*#* | ||
.classpath | ||
.settings/ | ||
.project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>forma</name> | ||
<comment> | ||
<name>forma</name> | ||
<comment> | ||
</comment> | ||
<projects/> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>ccw.builder</name> | ||
<arguments/> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments/> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>ccw.nature</nature> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>ccw.builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
<nature>ccw.nature</nature> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
(ns forma.hadoop.jobs.process-rain | ||
(:use cascalog.api | ||
[forma.source.tilesets :only (tile-set)] | ||
[forma.utils :only (weighted-mean)]) | ||
(:require [cascalog.ops :as c] | ||
[forma.date-time :as date] | ||
[forma.hadoop.io :as io] | ||
[forma.hadoop.predicate :as p] | ||
[forma.source.modis :as m] | ||
[forma.source.static :as static]) | ||
(:gen-class)) | ||
|
||
(def gadm-tap (hfs-seqfile "s3n://redddata/gadm/1000-00/*/*/")) | ||
(def precl-tap (hfs-seqfile "s3n://redddata/precl/1000-32/*/*/")) | ||
|
||
(defn rain-tap | ||
"TODO: Very similar to extract-tseries. Consolidate." | ||
[rain-src] | ||
(<- [?mod-h ?mod-v ?sample ?line ?date ?val] | ||
(rain-src _ ?s-res _ ?tilestring ?date ?chunkid ?chunk) | ||
(io/count-vals ?chunk :> ?chunk-size) | ||
(p/struct-index 0 ?chunk :> ?pix-idx ?val) | ||
(m/tilestring->hv ?tilestring :> ?mod-h ?mod-v) | ||
(m/tile-position ?s-res ?chunk-size ?chunkid ?pix-idx :> ?sample ?line))) | ||
|
||
(defbufferop weighted-avg [tuples] | ||
[(apply weighted-mean (flatten tuples))]) | ||
|
||
(defn run-rain | ||
[gadm-src rain-src] | ||
(let [gadm-src (static/static-tap gadm-src) | ||
rain-src (rain-tap rain-src) | ||
join (<- [?gadm ?mod-h ?mod-v ?sample ?line ?date ?count ?avg-rain] | ||
(gadm-src _ ?mod-h ?mod-v ?sample ?line ?gadm) | ||
(rain-src ?mod-h ?mod-v ?sample ?line ?date ?rain) | ||
(c/count ?count) | ||
(c/avg ?rain :> ?avg-rain))] | ||
(<- [?gadm ?date ?weighted-avg] | ||
(join ?gadm ?mod-h ?mod-v ?sample ?line ?date ?count ?avg-rain) | ||
(weighted-avg ?avg-rain ?count :> ?weighted-avg)))) | ||
|
||
(defn -main [path] | ||
(?- (io/myhfs-textline path) | ||
(run-rain gadm-tap precl-tap))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,126 +1,20 @@ | ||
package forma.tap; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import forma.schema.DataChunk; | ||
import org.apache.thrift.TBase; | ||
import org.apache.thrift.TFieldIdEnum; | ||
import org.apache.thrift.TUnion; | ||
import org.apache.thrift.meta_data.FieldMetaData; | ||
import org.apache.thrift.meta_data.FieldValueMetaData; | ||
import org.apache.thrift.meta_data.StructMetaData; | ||
|
||
import forma.schema.DataValue; | ||
import forma.schema.LocationProperty; | ||
import forma.schema.LocationPropertyValue; | ||
import forma.schema.ModisChunkLocation; | ||
|
||
public class SplitDataChunkPailStructure extends DataChunkPailStructure { | ||
// protected static interface FieldStructure { | ||
// public boolean isValidTarget(String[] dirs); | ||
// public void fillTarget(List<String> ret, Object val); | ||
// } | ||
|
||
// public static HashMap<Short, FieldStructure> validFieldMap = new HashMap<Short, FieldStructure>(); | ||
|
||
// private static Map<TFieldIdEnum, FieldMetaData> getMetadataMap(Class c) { | ||
// try { | ||
// Object o = c.newInstance(); | ||
// return (Map) c.getField("metaDataMap").get(o); | ||
// } catch (Exception e) { | ||
// throw new RuntimeException(e); | ||
// } | ||
// } | ||
|
||
// protected static class EdgeStructure implements FieldStructure { | ||
// public boolean isValidTarget(String[] dirs) { | ||
// return true; | ||
// } | ||
// public void fillTarget(List<String> ret, Object val) { | ||
|
||
// } | ||
// } | ||
|
||
// protected static class PropertyStructure implements FieldStructure { | ||
// private short valueId; | ||
// private HashSet<Short> validIds; | ||
|
||
// private static short getIdForClass(Map<TFieldIdEnum, FieldMetaData> meta, Class toFind) { | ||
// for(TFieldIdEnum k: meta.keySet()) { | ||
// FieldValueMetaData md = meta.get(k).valueMetaData; | ||
// if(md instanceof StructMetaData) { | ||
// if(toFind.equals(((StructMetaData) md).structClass)) { | ||
// return k.getThriftFieldId(); | ||
// } | ||
// } | ||
// } | ||
// throw new RuntimeException("Could not find " + toFind.toString() + " in " + meta.toString()); | ||
// } | ||
|
||
// public PropertyStructure(Class prop) { | ||
// try { | ||
// Map<TFieldIdEnum, FieldMetaData> propMeta = getMetadataMap(prop); | ||
// Class valClass = Class.forName(prop.getName() + "Value"); | ||
// valueId = getIdForClass(propMeta, valClass); | ||
|
||
// validIds = new HashSet<Short>(); | ||
// Map<TFieldIdEnum, FieldMetaData> valMeta = getMetadataMap(valClass); | ||
// for(TFieldIdEnum valId: valMeta.keySet()) { | ||
// validIds.add(valId.getThriftFieldId()); | ||
// } | ||
// } catch(Exception e) { | ||
// throw new RuntimeException(e); | ||
// } | ||
// } | ||
|
||
// public boolean isValidTarget(String[] dirs) { | ||
// if(dirs.length<2) return false; | ||
// try { | ||
// short s = Short.parseShort(dirs[1]); | ||
// return validIds.contains(s); | ||
// } catch(NumberFormatException e) { | ||
// return false; | ||
// } | ||
// } | ||
|
||
// public void fillTarget(List<String> ret, Object val) { | ||
// ret.add("" + ((TUnion) ((TBase)val).getFieldValue(valueId)).getSetField().getThriftFieldId()); | ||
// } | ||
// } | ||
|
||
// static { | ||
// for(DataUnit._Fields k: DataUnit.metaDataMap.keySet()) { | ||
// FieldValueMetaData md = DataUnit.metaDataMap.get(k).valueMetaData; | ||
// FieldStructure fieldStruct; | ||
// if(md instanceof StructMetaData && ((StructMetaData) md).structClass.getName().endsWith("Property")) { | ||
// fieldStruct = new PropertyStructure(((StructMetaData) md).structClass); | ||
// } else { | ||
// fieldStruct = new EdgeStructure(); | ||
// } | ||
// validFieldMap.put(k.getThriftFieldId(), fieldStruct); | ||
// } | ||
// } | ||
|
||
// @Override | ||
// public boolean isValidTarget(String[] dirs) { | ||
// if(dirs.length==0) return false; | ||
// try { | ||
// short id = Short.parseShort(dirs[0]); | ||
// FieldStructure s = validFieldMap.get(id); | ||
// if(s==null) return false; | ||
// else return s.isValidTarget(dirs); | ||
// } catch(NumberFormatException e) { | ||
// return false; | ||
// } | ||
// } | ||
|
||
// @Override | ||
// public List<String> getTarget(Data object) { | ||
// List<String> ret = new ArrayList<String>(); | ||
// DataUnit du = object.get_dataunit(); | ||
// short id = du.getSetField().getThriftFieldId(); | ||
// ret.add("" + id); | ||
// validFieldMap.get(id).fillTarget(ret, du.getFieldValue()); | ||
// return ret; | ||
// } | ||
|
||
@Override | ||
public List<String> getTarget(DataChunk t) { | ||
List<String> ret = new ArrayList<String>(); | ||
|
||
ret.add(t.getDataset()); | ||
return ret; | ||
} | ||
} | ||
|
Oops, something went wrong.