コード例 #1
0
ファイル: test_helpmanager.py プロジェクト: cgq-qgc/pyhelp
def helpm(output_dir):
    manager = HelpManager(workdir=output_dir,
                          path_to_grid=INPUT_FILES['grid'],
                          path_to_precip=INPUT_FILES['precip'],
                          path_to_airtemp=INPUT_FILES['airtemp'],
                          path_to_solrad=INPUT_FILES['solrad'])
    return manager
コード例 #2
0
def test_read_weather_incomplete(testvar, workdir):
    """
    Test that the HelpManager throws an error if the weather are not complete
    for one or more years in the dataset.
    """
    kwargs = {
        'workdir': workdir,
        'path_to_grid': osp.join(DATAFOLDER, 'input_grid.csv')
    }
    for var in ['precip', 'airtemp', 'solrad']:
        if var == testvar:
            filename = f'{var}_input_data_incomplete.csv'
        else:
            filename = f'{var}_input_data_2001-2002.csv'
        kwargs[f'path_to_{var}'] = osp.join(DATAFOLDER, filename)

    with pytest.raises(ValueError):
        HelpManager(**kwargs)
コード例 #3
0
def test_read_weather_dates_nomatch(testvar, workdir):
    """
    Test that the HelpManager throws an error if the len of the weather
    data do not match.
    """
    kwargs = {
        'workdir': workdir,
        'path_to_grid': osp.join(DATAFOLDER, 'input_grid.csv')
    }
    for var in VARNAMES:
        if var == testvar:
            kwargs[f'path_to_{var}'] = osp.join(
                DATAFOLDER, f'{var}_input_data_2002-2003.csv')
        else:
            kwargs[f'path_to_{var}'] = osp.join(
                DATAFOLDER, f'{var}_input_data_2001-2002.csv')

    with pytest.raises(ValueError):
        HelpManager(**kwargs)
コード例 #4
0
def test_read_input(workdir):
    """
    Test that the input files are read as expected by the HelpManager.
    """
    helpm = HelpManager(
        workdir,
        path_to_grid=osp.join(DATAFOLDER, 'input_grid.csv'),
        path_to_precip=osp.join(DATAFOLDER, 'precip_input_data_2001-2002.csv'),
        path_to_airtemp=osp.join(DATAFOLDER,
                                 'airtemp_input_data_2001-2002.csv'),
        path_to_solrad=osp.join(DATAFOLDER, 'solrad_input_data_2001-2002.csv'))

    assert len(helpm.airtemp_data) == 365 * 2
    assert list(helpm.airtemp_data.index.year.unique()) == [2001, 2002]
    assert list(helpm.airtemp_data.columns.get_level_values('lat_dd')) == [
        46.1, 45.9, 45.8, 45.9, 46, 46.1
    ]
    assert list(helpm.airtemp_data.columns.get_level_values('lon_dd')) == [
        -74, -74.4, -74.1, -74, -74.1, -74.1
    ]

    assert len(helpm.precip_data) == 365 * 2
    assert list(helpm.precip_data.index.year.unique()) == [2001, 2002]
    assert list(helpm.precip_data.columns.get_level_values('lat_dd')) == [
        46.1, 45.9, 45.8
    ]
    assert list(helpm.precip_data.columns.get_level_values('lon_dd')) == [
        -74, -74.4, -74.1
    ]

    assert len(helpm.solrad_data) == 365 * 2
    assert list(helpm.solrad_data.index.year.unique()) == [2001, 2002]
    assert list(
        helpm.solrad_data.columns.get_level_values('lat_dd')) == [45.47]
    assert list(
        helpm.solrad_data.columns.get_level_values('lon_dd')) == [-73.74]
コード例 #5
0
    helpm.build_help_input_files()
    output = helpm.calc_help_cells(help_output_hdf5, cellnames, tfsoil=-3)
    return output


if __name__ == '__main__':
    # For an explanation of why (on Windows) the if __name__ == '__main__'
    # part is necessary, please see :
    #    https://docs.python.org/3.6/library/
    #    multiprocessing.html#programming-guidelines

    # Instantiate the HelpManager and calculate the monthrly water budget
    # for the 2000-2010 period.
    workdir = "C:/Users/User/pyhelp/example"
    helpm = HelpManager(workdir, year_range=(2000, 2010))
    output = run_help(helpm)

    # Export and save the data to an ESRI shapefile.
    help_output_shp = osp.join(workdir, 'help_example.shp')
    output.save_to_shp(help_output_shp)

    # Plot some results.
    output.plot_area_monthly_avg()
    output.plot_area_yearly_avg()
    output.plot_area_yearly_series()

    # Calculate the yearly water budget for surface water cells.
    evp_surf = 650
    surf_output_hdf5 = osp.join(workdir, 'surf_example.out')
    output_surf = helpm.calc_surf_water_cells(evp_surf, surf_output_hdf5)
コード例 #6
0
ファイル: help_example.py プロジェクト: cgq-qgc/pyhelp
import pyhelp.bilan as HelpBilan

if __name__ == '__main__':
    # For an explanation of why (on Windows) the if __name__ == '__main__'
    # part is necessary, please see :
    #    https://docs.python.org/3.6/library/
    #    multiprocessing.html#programming-guidelines

    # Define the working directory.
    workdir = "D:/Projets/pyhelp/example/"

    # Instantiate the HelpManager and provide the paths to the grid and
    # weather input data files so that they are loaded automatically.
    helpm = HelpManager(workdir,
                        path_to_grid=workdir + 'input_grid.csv',
                        path_to_precip=workdir + 'precip_input_data.csv',
                        path_to_airtemp=workdir + 'airtemp_input_data.csv',
                        path_to_solrad=workdir + 'solrad_input_data.csv')

    # Note that you can access the grid input data through
    # the 'grid' attribute of the HelpManager.

    # Note that you can access the weather input data through the
    # 'precip_data', 'airtemp_data', and 'solrad_data' attributes
    # of the HelpManager.

    # =========================================================================
    # Run HELP simulation for all the cells in cellnames.
    # =========================================================================

    # We want to run HELP only for the cells that are located within
コード例 #7
0
ファイル: produce_water_budget.py プロジェクト: USEPA/HELP
# rname = "LAUALL_inputHELP_0416t3_0.15edepth"
rname = "BTALL_inputHELP_0416base_0.35edepth"
figname_sufix = rname
riv = 2

rootdir = "C:\\Users\\User\\pyhelp\\RADEAU2\\calage_inputHELP_0416"
workdir = osp.join(rootdir, rname)
os.chdir(workdir)

path_help_output = osp.join(workdir, "help_%s.out" % rname)
path_surf_output = osp.join(workdir, "surface_%s.out" % rname)

# %% Load the HELP grid

path_togrid = osp.join(rootdir, 'inputHELP_0416t3.csv')
helpm = HelpManager(workdir, year_range=(1965, 2014))
grid = helpm.load_grid(path_togrid)

# %% Compute yearly values

# Compute monthly values for cells that were run in HELP.

help_output = h5py.File(path_help_output, mode='r+')
cellnames = list(help_output.keys())
years = help_output[cellnames[0]]['years'].value

# urbancells = grid['maille'][grid['Urbain'] == 1][grid['run'] == 1][grid['BT'] == 1].tolist()
# # ruralcells = grid['maille'][grid['Urbain'] == 0][grid['BT'] == 1]
# urbancells = grid['maille'][grid['Urbain'] == 1][grid['Contexte'] == 0][grid['BT'] == 1].tolist()

Np = len(cellnames)
コード例 #8
0
ファイル: test_helpmanager.py プロジェクト: USEPA/HELP
def helpm(example_folder):
    manager = HelpManager(example_folder, year_range=(2000, 2010))
    return manager