15.5.2. crate_anon.preprocess.postcodes¶
Copyright (C) 2015-2018 Rudolf Cardinal (rudolf@pobox.com).
This file is part of CRATE.
CRATE is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
CRATE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with CRATE. If not, see <http://www.gnu.org/licenses/>.
Code-Point Open, CSV, GB - https://www.ordnancesurvey.co.uk/business-and-government/products/opendata-products.html - https://www.ordnancesurvey.co.uk/business-and-government/products/code-point-open.html - https://www.ordnancesurvey.co.uk/opendatadownload/products.html - http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/
Office for National Statistics Postcode Database (ONSPD): - https://geoportal.statistics.gov.uk/geoportal/catalog/content/filelist.page - e.g. ONSPD_MAY_2016_csv.zip - http://www.ons.gov.uk/methodology/geography/licences
Background: - OA = Output Area
… smallest: >=40 households, >=100 people … 181,408 OAs in England & Wales
- LSOA = Lower Layer Super Output Area
- … 34,753 LSOAs in England & Wales
- MSOA = Middle Layer Super Output Area
- … 7,201 MSOAs in England & Wales
- https://www.ons.gov.uk/methodology/geography/ukgeographies/censusgeography#output-area-oa
-
class
crate_anon.preprocess.postcodes.
Postcode
(**kwargs)[source]¶ Maps individual postcodes to… lots of things. Large table.
-
bua11
¶ Built-up Area (BUA) [FK to bua_built_up_area_england_wales_2013.bua_code]
-
buasd11
¶ Built-up Area Sub-division (BUASD) [FK to buasd_built_up_area_subdivision_england_wales_2013.buas_code]
-
casward
¶ Census Area Statistics (CAS) ward [PROBABLY FK to cas_ward_2003.cas_ward_code]
-
ccg
¶ Clinical Commissioning Group (CCG) / Local Health Board (LHB) / Community Health Partnership (CHP) / Local Commissioning Group (LCG) / Primary Healthcare Directorate (PHD) [FK to one of – ccg_clinical_commissioning_group_england_2015.ccg_ons_code, lhb_local_health_board_wales_2014.lhb_code]
-
cened
¶ 1991 Census Enumeration District (ED) (as Census code) [POSSIBLY FK to district_england_wales_1991.district_code_census]
-
ctry
¶ Country of the UK [England, Scotland, Wales, Northern Ireland] [FK to country_2012.country_code]
-
dointr
¶ Date of introduction (original format YYYYMM)
-
doterm
¶ Date of termination (original format YYYYMM) or NULL
-
edind
¶ ED positional quality indicator (PQI)
-
eer
¶ European Electoral Region (EER) [FK to eer_european_electoral_region_2010.eer_code]
-
gor
¶ Region (former GOR) [GOR = Government Office Regions] [FK to gor_govt_office_region_england_2010.gor_code]
-
hro
¶ Pan SHA [FK to psha_pan_strategic_health_authority_aka_hro_england_2010.psha_code]
-
imd
¶ Index of Multiple Deprivation (IMD) [rank of LSOA/DZ, where 1 is the most deprived, within each country] [FK to one of – imd_index_multiple_deprivation_england_2015.imd_rank; imd_index_multiple_deprivation_n_ireland_2010.imd_rank; imd_index_multiple_deprivation_scotland_2012.imd_rank; imd_index_multiple_deprivation_wales_2014.imd_rank]
-
lat
¶ Latitude (degrees, 6dp)
-
lea
¶ Previous Local Education Authority (LEA) / Education and Library Board (ELB) [PROBABLY FK to lea_local_education_authority_2009.lea_code]
-
lep1
¶ Local Enterprise Partnership (LEP) - first instance [FK to lep_local_enterprise_partnership_england_2013.lep1_code]
-
lep2
¶ Local Enterprise Partnership (LEP) - second instance [FK to lep_local_enterprise_partnership_england_2013.lep1_code]
-
long
¶ Longitude (degrees, 6dp)
-
lsoa01
¶ 2001 Census Lower Layer Super Output Area (LSOA) [England & Wales, ~1,500 population] / Data Zone (DZ) [Scotland] / Super Output Area (SOA) [FK to one of – lsoa_lower_layer_super_output_area_england_wales_2004.lsoa_code; lsoa_lower_layer_super_output_area_n_ireland_2005.lsoa_code]
-
lsoa11
¶ 2011 Census Lower Layer Super Output Area (LSOA) [England & Wales, ~1,500 population] / Data Zone (DZ) [Scotland] / Super Output Area (SOA) [FK to one of – lsoa_lower_layer_super_output_area_england_wales_2011.lsoa_code; dz_datazone_scotland_2011.dz_code]
-
msoa01
¶ 2001 Census Middle Layer Super Output Area (MSOA) [England & Wales, ~7,200 population] / Intermediate Zone (IZ) [Scotland] [FK to one of – msoa_middle_layer_super_output_area_england_wales_2004.msoa_code; iz_intermediate_zone_scotland_2005.iz_code]
-
msoa11
¶ 2011 Census Middle Layer Super Output Area (MSOA) [England & Wales, ~7,200 population] / Intermediate Zone (IZ) [Scotland] [FK to one of – msoa_middle_layer_super_output_area_england_wales_2011.msoa_code; iz_intermediate_zone_scotland_2011.iz_code]
-
nuts
¶ LAU2 areas [European Union spatial regions; Local Adminstrative Unit, level 2] / Nomenclature of Units for Territorial Statistics (NUTS) [FK to lau_eu_local_administrative_unit_2015.lau2_code]
-
oa01
¶ 2001 Census Output Area (OA). (There are about 222,000, so ~300 population?)
-
oa11
¶ 2011 Census Output Area (OA) [England, Wales, Scotland; ~100-625 population] / Small Area (SA) [N. Ireland]
-
oac01
¶ 2001 Census Output Area classification (OAC)[POSSIBLY FK to output_area_classification_2011.subgroup_code]
-
oac11
¶ 2011 Census Output Area classification (OAC) [FK to output_area_classification_2011.subgroup_code]
-
oldha
¶ Old-style health authority (prior to 2002 England, 2003 Wales [FK to ha_health_authority_2001.ha_code]
-
oldpct
¶ Old (pre-Oct 2006) Primary Care Trust (PCT) / Local Health Board (LHB) / Care Trust (CT) [FK to one of – pct_primary_care_trust_organization_england_2005.pct_code]
-
oscty
¶ County code [FK to county_england_2010.county_code]
-
oseast1m
¶ National grid reference Easting, 1m resolution
-
osgrdind
¶ Grid reference positional quality indicator
-
oshaprev
¶ Previous Strategic Health Authority (SHA) / Health Board (HB) / Health Authority (HA) / Health and Social Services Board (HSSB) [FK to one of – sha_strategic_health_authority_england_2010.sha_code or sha_strategic_health_authority_england_2004.sha_code]
-
oshlthau
¶ Former (up to 2013) Strategic Health Authority (SHA), Local Health Board (LHB), Health Board (HB), Health Authority (HA), or Health & Social Care Board (HSCB) [FK to one of – sha_strategic_health_authority_england_2010.sha_code or sha_strategic_health_authority_england_2004.sha_code; hb_health_board_n_ireland_2003.hb_code; hb_health_board_scotland_2014.hb_code; hscb_health_social_care_board_n_ireland_2010.hscb_code; lhb_local_health_board_wales_2014.lhb_code or lhb_local_health_board_wales_2006.lhb_code]
-
oslaua
¶ Local authority district (LUA), unitary authority (UA), metropolitan district (MD), London borough (LB), council area (CA), or district council area (DCA) [FK to lad_local_authority_district_2016.lad_code]
-
osnrth1m
¶ National grid reference Northing, 1m resolution
-
osward
¶ Electoral ward/division [FK e.g. to electoral_ward_2016.ward_code]
-
parish
¶ Parish/community [FK to parish_lad_england_wales_2014.parish_code; ncp_non_civil_parish_2014.ncp_code]
-
park
¶ National park [FK to park_national_park_2010.park_code]
-
pcd
¶ Unit postcode (7 characters) – 2-4 char outward code, left-aligned; 3-char inward code, right-aligned
-
pcd2
¶ Unit postcode (8 characters) – 2-4 char outward code, left-aligned; space; 3-char inward code, right-aligned
-
pcd_nospace
¶ Postcode (no spaces)
-
pcds
¶ Unit postcode (variable length) – 2-4 char outward code; space; 3-char inward code
-
pcon
¶ Westminster parliamentary constituency [FK to pcon_westminster_parliamentary_constituency_2014.pcon_code]
-
pct
¶ Primary Care Trust (PCT) / Care Trust / Care Trust Plus (CT) / Local Health Board (LHB) / Community Health Partnership (CHP) / Local Commissioning Group (LCG) / Primary Healthcare Directorate (PHD) [FK to one of – pct_primary_care_trust_organization_england_2011.pct_code; chp_community_health_partnership_scotland_2012.chp_code; lcg_local_commissioning_group_n_ireland_2010.lcg_code; lhb_local_health_board_wales_2014.lhb_code]
-
pfa
¶ Police Force Area (PFA) [FK to pfa_police_force_area_2015.pfa_code]
-
psed
¶ 1991 Census Enumeration District (ED) (as OGSS code) [POSSIBLY FK to district_england_wales_1991.district_code_ogss]
-
ru11ind
¶ 2011 Census rural-urban classification
-
statsward
¶ 2005 ‘statistical’ ward [?FK to electoral_ward_2005.ward_code]
-
streg
¶ Standard (Statistical) Region (SSR) [FK to ssr_standard_statistical_region_england_1995.ssr_code]
-
teclec
¶ Local Learning and Skills Council (LLSC) / Dept. of Children, Education, Lifelong Learning and Skills (DCELLS) / Enterprise Region (ER) [PROBABLY FK to one of – dcells_dept_children_wales_2010.dcells_code; er_enterprise_region_scotland_2010.er_code; llsc_local_learning_skills_council_england_2010.llsc_code]
-
ttwa
¶ Travel to Work Area (TTWA) [FK to ttwa_travel_to_work_area_2011.ttwa_code]
-
ur01ind
¶ 2001 Census urban/rural indicator [numeric in England/Wales/Scotland; letters in N. Ireland]
-
usertype
¶ Small (0) or large (1) postcode user
-
ward98
¶ 1998 administrative and electoral area [FK to electoral_ward_1998.ward_code]
-
wardc91
¶ 1991 administrative and electoral area (as Census code) [FK to electoral_ward_1991.ward_code_census]
-
wardo91
¶ 1991 administrative and electoral area (as OGSS code) [FK to electoral_ward_1991.ward_code_ogss]
-
wz11
¶ 2011 Census Workplace Zone (WZ)
-
-
crate_anon.preprocess.postcodes.
populate_generic_lookup_table
(sa_class: Any, datadir: str, session: sqlalchemy.orm.session.Session, args: Any, commit: bool = True) → None[source]¶ The .TXT files look at first glance like tab-separated values files, but in some cases have inconsistent numbers of tabs (e.g. “2011 Census Output Area Classification Names and Codes UK.txt”). So we’ll use the .XLSX files.
If the headings parameter is passed, those headings are used. Otherwise, the first row is used for headings.