Skip to content

Commit

Permalink
Add farm size.
Browse files Browse the repository at this point in the history
  • Loading branch information
makmanalp committed Jul 21, 2017
1 parent 5b47292 commit 2be9c25
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 2 deletions.
4 changes: 3 additions & 1 deletion product/Datlas/Rural/Tupfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ AGPRODUCTS = in/AgProducts_Hierarchy.tsv in/AgProducts_Names.tsv
AGPRODUCTS_CENSUS = in/AgProducts_Census_Hierarchy.tsv in/AgProducts_Census_Names.tsv
FARMTYPE = in/FarmType_Hierarchy.tsv in/FarmType_Names.tsv
LANDUSE = in/LandUse_Hierarchy.tsv in/LandUse_Names.tsv
FARMSIZE = in/FarmSize_Hierarchy.tsv in/FarmSize_Names.tsv

: |> $(PYTHON_PREFIX) download_sheets.py |> $(LIVESTOCK) $(AGPRODUCTS) $(AGPRODUCTS_CENSUS) $(FARMTYPE) $(LANDUSE)
: |> $(PYTHON_PREFIX) download_sheets.py |> $(LIVESTOCK) $(AGPRODUCTS) $(AGPRODUCTS_CENSUS) $(FARMTYPE) $(LANDUSE) $(FARMSIZE)
: $(LIVESTOCK) |> $(PYTHON_PREFIX) clean_livestock.py |> out/livestock.csv out/livestock.dta
: $(AGPRODUCTS_CENSUS) |> $(PYTHON_PREFIX) clean_agproducts_census.py |> out/agricultural_products_census.csv out/agricultural_products_census.dta
: $(AGPRODUCTS) |> $(PYTHON_PREFIX) clean_agproducts.py |> out/agricultural_products.csv out/agricultural_products.dta
: $(FARMTYPE) |> $(PYTHON_PREFIX) clean_farmtype.py |> out/farm_type.csv out/farm_type.dta
: $(LANDUSE) |> $(PYTHON_PREFIX) clean_landuse.py |> out/land_use.csv
: $(FARMSIZE) |> $(PYTHON_PREFIX) clean_farmsizetype.py |> out/farm_size.csv out/farm_size.dta
35 changes: 35 additions & 0 deletions product/Datlas/Rural/clean_farmsizetype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pandas as pd

from classification import (Hierarchy, repeated_table_to_parent_id_table,
parent_code_table_to_parent_id_table,
Classification)

if __name__ == "__main__":
names = pd.read_table("./in/FarmSize_Names.tsv", encoding="utf-8",
dtype={"code": str})

hierarchy = pd.read_table("./in/FarmSize_Hierarchy.tsv", encoding="utf-8")
hierarchy.columns = ["level1_code", "level0_code"]

fields = {
"level0": [],
"level1": [],
}

h = Hierarchy(["level0", "level1"])
parent_code_table = repeated_table_to_parent_id_table(hierarchy, h, fields)
parent_code_table.code = parent_code_table.code.astype(str)

parent_code_table = parent_code_table.merge(names, on=["code", "level"])

parent_id_table = parent_code_table_to_parent_id_table(parent_code_table, h)
parent_id_table["name"] = parent_id_table.name_en

parent_id_table = parent_id_table[["code", "name", "level", "name_en",
"name_es", "name_short_en",
"name_short_es", "parent_id"]]

c = Classification(parent_id_table, h)

c.to_csv("out/farm_size.csv")
c.to_stata("out/farm_size.dta")
5 changes: 5 additions & 0 deletions product/Datlas/Rural/download_sheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@
hierarchy, names = get_classification_from_gdrive("https://docs.google.com/spreadsheets/d/17EoKvwQKujYRCKzh2odu--bpR0d2grigrWDn4CjRaeg/edit#gid=1207195644")
hierarchy.to_csv("./in/LandUse_Hierarchy.tsv", sep="\t", index=False, encoding="utf-8")
names.to_csv("./in/LandUse_Names.tsv", sep="\t", index=False, encoding="utf-8")

# Farmsize Type
hierarchy, names = get_classification_from_gdrive("https://docs.google.com/spreadsheets/d/1ORWQDmc0wDPiOW4nBgi40JsKjL7tLm-YzaGBO6TP0Jk/edit#gid=1207195644")
hierarchy.to_csv("./in/FarmSize_Hierarchy.tsv", sep="\t", index=False, encoding="utf-8")
names.to_csv("./in/FarmSize_Names.tsv", sep="\t", index=False, encoding="utf-8")
3 changes: 3 additions & 0 deletions product/Datlas/Rural/in/FarmSize_Hierarchy.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
level1 level0
Agropecuario Agropecuario o no agropecuario
No agropecuario Agropecuario o no agropecuario
4 changes: 4 additions & 0 deletions product/Datlas/Rural/in/FarmSize_Names.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
code level name_en name_short_en name_es name_short_es
Agropecuario o no agropecuario level0 Total Total Agropecuario o no agropecuario Agropecuario o no agropecuario
Agropecuario level1 Agricultural Agricultural Agropecuario Agropecuario
No agropecuario level1 Nonagricultural Nonagricultural No agropecuario No agropecuario
4 changes: 4 additions & 0 deletions product/Datlas/Rural/out/farm_size.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"","code","name","level","name_en","name_es","name_short_en","name_short_es","parent_id"
0,"Agropecuario o no agropecuario","Total","level0","Total","Agropecuario o no agropecuario","Total","Agropecuario o no agropecuario",""
1,"Agropecuario","Agricultural","level1","Agricultural","Agropecuario","Agricultural","Agropecuario",0.0
2,"No agropecuario","Nonagricultural","level1","Nonagricultural","No agropecuario","Nonagricultural","No agropecuario",0.0
Binary file added product/Datlas/Rural/out/farm_size.dta
Binary file not shown.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="linnaeus",
version="v0.0.78",
version="v0.0.79",
author="Mali Akmanalp <Harvard CID>",
description=("Harvard CID's classification tools."),
url="http://github.com/cid-harvard/classifications/",
Expand All @@ -26,6 +26,7 @@
'product/Datlas/Rural/out/agricultural_products.csv',
'product/Datlas/Rural/out/agricultural_products_census.csv',
'product/Datlas/Rural/out/farm_type.csv',
'product/Datlas/Rural/out/farm_size.csv',
'product/HS/Atlas/out/hs92_atlas.csv',
'product/HS/Mexico_Prospedia/out/products_mexico_prospedia.csv',
'product/HS/Colombia_Prospedia/out/products_colombia_prospedia.csv',
Expand Down

0 comments on commit 2be9c25

Please sign in to comment.