Maps.py - Map Background Configuration

September 25, 2012

Organization

Maps.py Format
   Site Information
   Map Definitions
   Putting it all togetherwith the maps list
   Importing localMaps

Overview

The Maps.py file defines how edit areas are generated for each map. When activated, the server processes the list of maps defined in the Maps.py file and generates edit areas.

The edit area generation software uses the maps database tables as input. These tables are populated by importing shape files provided by the National Weather Service. These tables are filtered by domain (based on the site) and attributes. There are different attributes available for each table. Refer to the AWIPS Map Background Database provided by the National Weather Service for details on the available shapefiles and the attributes contained within each shapefile. This information will be needed in order to tailor edit area generation for your site.

The user can select which polygons will be converted into edit areas and to which edit area groups they will be assigned.

This information is provided for you to help you understand the format of Maps.py. You should NEVER change the original Maps.py since your changes will be overwritten with the next upgrade. See the server configuration overview for information on how to make changes that are supported to the map backgrounds.

To override definitions in Maps.py, use the localMaps.py technique.

To update the maps database, refer to the MapFiles documentation, specifically the section on Updating Shapefiles.

Software releases after Jan 1, 2006 separate the map shapefile from the CORE GFE.   In some applications, such as AWIPS, the map shapefile configuration becomes the responsibility of the site since the map shapefiles will no longer be shipped with the GFE software. A separate install is available for non-AWIPS purposes and is posted with the software releases. If the associated Map Shapefile is not installed at your site, then sites will be responsible for:


Maps.py Format

Site Information

Maps.py imports the siteConfig file which provides the site identifier and the site's specific grid domain.
CWA = siteConfig.GFESUITE_SITEID

Map Definitions

The map definition section defines each map for which edit area generation is desired. Only a small portion of the Maps.py is shown here. Numerous examples with differing capabilities are shown.

Basic Map with Automatically Generated Edit Areas

This definition is for a basic map, with no filtering of attributes and automatic creation of edit areas. The edit areas will be included in the 'Misc' edit area group by default since no edit area group is specified. The ShapeTable object is created in the first line. The name of the maps database table is passed as a parameter to the ShapeTable constructor.
CWAzones = ShapeTable('zone')
CWAzones.name = CWA + '_zones'
CWAzones.editAreaName = ['state','zone']
The ifpServer can automatically generate edit areas based on the information in the shapefiles. The user specifies the "editAreaName" in the Maps.py or localMaps.py files, and the ifpServer uses that information to determine the name of each edit area.   There are three forms to the editAreaName line as shown:

mapVariable.editAreaName = "string"
Single String Format
mapVariable.editAreaName = ["string1", "string2", "string3"]
List of Strings Format
mapVariable.editAreaName = functionName
Function Format

Single String Format
In the example below, the name of each generated edit area is obtained from the attribute zone specified in the field editAreaName. The program looks up the value for the attribute zone in the database record for each polygon and creates an edit area with that name. The example below uses the simple format for the editAreaName, in which only one attribute is specified.
CWAzones = ShapeTable('zone')
CWAzones.name = CWA + '_zones'
CWAzones.editAreaName = 'zone'

Examples of the names of the edit areas generated from the above snippet is shown in the following table:
 
zone value from shapefile state (not used in this example) Name of Edit Area
034 CO zone034
041 CO zone041
041 NE zone041

Note that if a site's domain covers more than one state, this simple form of generating edit area names will not work. The "NE" example above illustrates that the same edit area name was generated even though the zones were from different states. Also note that the naming of the edit area includes the name "zone" only because the value of the zone value begins with a number.

NOTE: Changing the default set of edit area names as supplied in the baseline may render your text formatters and VTEC inoperable. The text formatters and VTEC assume standard UGC-named edit areas, such as COZ023 and UTC013.

List of Strings Format

A second, more complex form of the editAreaName involves using a Python list. The naming of an edit area is determined by using more than one attribute. This example uses the more complex form for the editAreaName, in which two attributes are specified.

CWAzones = ShapeTable('zone')
CWAzones.name = CWA + '_zones'
CWAzones.editAreaName = ['state','zone']

Examples of the names of the edit areas generated from the above snippet is shown in the following table:
 
zone value from shapefile state (not used in this example) Name of Edit Area
034 CO CO_034
041 CO CO_041
041 NE NE_041

The edit area name is determined from the value of the state attribute, followed by an underscore character, and then the value of the zone attribute.

Here is the software algorithm for naming of edit areas:

The ordering of the list of attributes can change the naming as shown in the following table, which assumes zone=034, state=CO, wfo=BOU, name=Summit County/Mosquito Range/Indian Peaks:
 
editAreaName string Name of Edit Area
'zone' zone034
['zone','state'] zone034_CO
['state','zone'] CO_034
['wfo','name'] BOU_SummitCountyMosquitoRangeIndianPeaks
['zone','name','state'] zone034_SummitCountyMosquitoRangeIndianPeaks_CO

Note that specification of an attribute that doesn't exist will simply use the name in the string. For example, if you are creating edit areas and you want them of the form ISC_xxx, where xxx is the value of the wfo attribute. The editAreaName string would be the following:

ISCareas.editAreaName = ['ISC', 'wfo'] 

NOTE: Changing the default set of edit area names as supplied in the baseline may render your text formatters and VTEC inoperable. The text formatters and VTEC assume standard UGC-named edit areas, such as COZ023 and UTC013.

Function Format

Occasionally there is a need to calculate a special edit area name and the single or list of strings methods are not sufficient. The function format requires the user to name a function and then define a function. The function has one argument, which receives a dictionary of attribute names and their values. The return value of the function is a string which becomes the edit area name.

For example, lets say that we want edit area names based on the county FIPS code. The desired format is stateCfips, such as COC013, for Colorado County #13. The county shapefile has a 'STATE' attribute, such as "CO", and it has a 'FIPS' attribute, such as 08013 for Colorado County #13.   Using the list of strings format, ['STATE', 'C', 'FIPS'], you would end up with CO_C_08013, when we really want COC013.

This is how the code would be implemented:
def cwaEAN(atts):
    fips = atts['fips'][-3:]        #take the last three characters from the FIPS code
    s = atts['state'] + "C" + fips  #assemble the name
    return s                        #return the complete edit area name
    
CWAcounties = ShapeTable('county')
CWAcounties.name = CWA + '_counties'
CWAcounties.editAreaName = cwaEAN
The "atts" dictionary looks simlilar to the following:
{'countyname': 'Delta', 
 'cwa': 'MQT'
 'fe_area': 'sr', 
 'fips': '26041', 
 'lat': 45.82085, 
 'lon': -86.909679999999994, 
 'state': 'MI', 
 'time_zone': 'E',
}
and the final string is: MIC041

Basic Map with Automatically Generated Edit Areas with group definition

An example of a basic map with automatically generated edit areas with group definition: This is identical to the Basic Map with Automatically Generated Edit Areas case except that the user has specified a group name. All of the generated edit areas will be placed in the edit area group called 'Zones'.
CWAzones = ShapeTable('zone')
CWAzones.name = CWA + '_zones'
CWAzones.editAreaName = 'zone'
CWAzones.groupName = 'Zones'

Filtered Map with Automatically Generated Edit Areas

This definition is for a filtered map with no automatic creation of edit areas. The filter line performs the filtering. The basic format of this line is as follows:
pythonMapName.filter(lambda x : x['ATTRIBUTENAME'] = AttributeValue)

where ATTRIBUTENAME is one of the attributes in the shapefile, and AttributeValue is the value that must match in the shapefile for this shape to be kept in the map. Attributes for the NWS shapefiles can be obtained from the AWIPS Map Catalog AWIPS Map Background Database.

CWAzones = ShapeTable('Zone')
CWAzones.name = CWA + '_zones'
CWAzones.filter(lambda x : x['cwa'] == CWA)
CWAzones.editAreaName = cwazones

The "lambda" function is a shortcut method of writing a function, the code snippet below performs the identical function:

def cwaZoneFilt(x):
    return x['cwa'] == CWA

CWAzones = ShapeTable('zone')
CWAzones.name = CWA + '_zones'
CWAzones.filter(cwaZoneFilt)
CWAzones.editAreaName = cwazones

Since this is all Python code, there is another technique you can use to write a filter function which is complex. Here is an example of writing a filter that selects certain counties (Summit, Sandusky, Huron, and Medina) from the county database table for a particular state (Ohio) and cwa (Cleveland):

def exampleFilt(x):
    myCounties = ['Summit', 'Sandusky', 'Huron', 'Medina']
    return x['countyname'] in myCounties and x['st'] == "OH" and x['cwa'] = 'CLE'

OHcounties = ShapeTable('county')
OHcounties.name = 'ExampleOHCounties'
OHcounties.filter(exampleFilt)
OHcounties.editAreaName = 'countyname'

Filtered Map with Automatically Generated Edit Areas with group definition

This is identical to the Filtered Map with Automatically Generated Edit Areas case except that the user has specified a group name. All of the generated edit areas will be placed in the edit area group called 'Zones'.
CWAzones = ShapeTable('zone')
CWAzones.name = CWA + '_zones'
CWAzones.filter(lambda x : x['cwa'] == CWA)
CWAzones.editAreaName = ['state','zone']
CWAzones.groupName = 'Zones'

Putting it all Together with the map list

In order for the system to recognize the list of defined maps, they must be put all together in a list. The list MUST be called maps. This example list, shows that there are three maps defined. The entries within the list are the Python variable names (name to the left of the equal sign on the ShapeTable line).
maps = [ CWAcounties, Counties, CWAzones ]

Importing localMaps

The final section of the Maps.py file is the software that checks for a localMaps configuration and uses it if it exists. Do not change this section of the file.
# import the local maps file
try:
    import localMaps
except:
    pass

 Back To Top
 Back To TOC