<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_field_groups(layer_purpose, layer_subcategory=None):
 """Obtain list of field groups from layer purpose and subcategory. :param layer_purpose: The layer purpose. :type layer_purpose: str :param layer_subcategory: Exposure or hazard value. :type layer_subcategory: str :returns: List of layer groups. :rtype: list """

    layer_purpose_dict = definition(layer_purpose)
    if not layer_purpose_dict:
        return []
    field_groups = deepcopy(layer_purpose_dict.get('field_groups', []))
    if layer_purpose in [
            layer_purpose_exposure['key'], layer_purpose_hazard['key']]:
        if layer_subcategory:
            subcategory = definition(layer_subcategory)
            if 'field_groups' in subcategory:
                field_groups += deepcopy(subcategory['field_groups'])
    return field_groups