Exemplo n.º 1
0
def get_structure_demand(pods, structures):
    """Get a single table with structure demand estimates.

    The structures file is expected to have the following fields:
    - PARCEL_ID : The parcel ID on which the structure lies.
    - STRUCTURE_ID : A unique identifier for each structure.
    - SummerAF: The water demand in the summer (AF)
    - WinterAF: The water demand in the winter (AF)

    The POD file is expected to have the following fields:
    PARCEL_ID : The parcel ID on which the POD lies.
    FEATUREID : The NHD+V2 catchment ID in which the POD lies.
    APPL_ID : The water right application ID.
    """
    pod_data = util.read_dbf(pods)
    structure_data = util.read_dbf(structures)
    join = pd.merge(structure_data, pod_data,
                    left_on='PARCEL_ID', right_on='PARCEL_ID',
                    how='inner', suffixes=('_pod', '_structure'))
    join['APPL_ID'] = join['APPL_ID'].map(lambda x: x[:-1] if x.endswith('R') else x)
    columns = [
        'APPL_ID',
        'STRUCT_ID',
        'SummerAF',
        'WinterAF',
        ]
    return join[columns].groupby('STRUCT_ID').agg({
        'APPL_ID': lambda x: x.iloc[0],
        'SummerAF': lambda x: x.iloc[0],
        'WinterAF': lambda x: x.iloc[0]
        }).groupby('APPL_ID').agg({
            'SummerAF': np.sum,
            'WinterAF': np.sum
            })
Exemplo n.º 2
0
def get_ag_demand(use_file, pod_file):
    """Get a single table with agricultural demand estimates.

    The use file is expected to contain the following columns:
    - POD_ID : A unique identifier for the point of diversion.
    - APPL_ID : The water right application ID
    - Vine_Water : The water used for the vineyard acreage
    - Orch_Water : The water used for the orchard acreage

    The POD file is expected to contain the following columns:
    - POD_ID : A unique identifier for the point of diversion
    - FEATUREID : The catchment feature ID (from the NHD+V2 dataset) in which the POD lies.

    Parameters
    ----------
    use_file : string
        The name of the file with all of the use information.
    pod_file : string
        The name of the file with the POD locations joined to their catchment.
    """
    use_data = pd.read_csv(use_file)

    pod_data = util.read_dbf(pod_file)

    pod_use = pd.merge(pod_data, use_data, left_on='POD_ID', right_on='POD_ID',
                       suffixes=('_pod', '_use'), how='left')
    pod_use['APPL_ID_pod'] = pod_use['APPL_ID_pod'].map(lambda x: x[:-1] if x.endswith('R') else x)
    columns = [
        'APPL_ID_pod',
        'FEATUREID',
        'Vine_Water',
        'Orch_Water',
        ]
    first = lambda x: x.iloc[0]
    return pod_use[columns].groupby('APPL_ID_pod').agg(first)
Exemplo n.º 3
0
def get_structure_demand_prepared(database):
    """Read already prepared POD-Structure demand table."""
    data = util.read_dbf(database)
    
    columns = [
        'APPL_ID',
        'STRUCT_ID',
        'SummerAF',
        'WinterAF',
        'FEATUREID',
    ]
    
    return data[columns].groupby('APPL_ID').agg({
        'SummerAF': np.sum,
        'WinterAF': np.sum,
        'FEATUREID': lambda x: x.iloc[0],
    })
Exemplo n.º 4
0
def create_use_reports(pod_file, ewrims_file):
    """Create use report stubs for hand entry.

    This function does not apply any automatic demand estimates.
    """
    ewrims_data = get_rights_data(ewrims_file)
    pod_data = util.read_dbf(pod_file)

    pod_right = pd.merge(pod_data, ewrims_data, left_on='APPL_ID',
                         right_on='Application Number', how='left')

    columns = [
        "APPL_ID",
        "FEATUREID",
        "Status Date",
        "Riparian",
        "Pre 1914",
        "FACEAMT",
        ]

    first = lambda x: x.iloc[0]
    agg = {
        "FEATUREID": first,
        "Status Date": first,
        "Riparian": first,
        "Pre 1914": first,
        "FACEAMT": np.sum
        }

    result = convert_ewrims_columns(pod_right[columns]).groupby("APPL_ID").agg(agg).sort("Status Date")

    result['Demand Year'] = pd.Series()
    for i in range(1, 13):
        result[calendar.month_abbr[i]] = pd.Series()

    return split_appropriative_riparian(result)