clmu module

class clmu.cesm_run(CASESCRIPT_local, CASEROOT_local, DOUT_S_ROOT, caseconfig: str | dict | DataFrame | Series)

Bases: object

This class is used to create CESM2/CTSM case. Run the CESM2/CTSM case should be done by running the generated shell script

using terminal or python subprocess or container (docker or singularity with CESM2/CTSM installed)

Parameters:
  • CASESCRIPT_local (str) – The path of the case script in the local machine.

  • CASEROOT_local (str) – The path of the case root in the local machine.

  • DOUT_S_ROOT (str) – The path of the output root in the local machine.

  • caseconfig (Union[str, dict, pd.DataFrame, pd.Series]) – The configuration of the case to be built.

CASESCRIPT

The path of the case script.

Type:

str

CASEROOT

The path of the case root.

Type:

str

DOUT_S_ROOT

The path of the output root.

Type:

str

case_lat

The latitude of the case.

Type:

float

case_lon

The longitude of the case.

Type:

float

case_name

The name of the case.

Type:

str

json_file_path

The path of the JSON file.

Type:

str

config

The configuration data.

Type:

dict

Methods

create_case(scriptpath)

Create the case scripts for single point modeling.

modify_case_config(scriptpaht)

Modify the case config file.

modify_forcing(var, action, forcing_location)

Modify the forcing file.

modify_surf(var, action[, numurbl])

Modify the surface data file.

nc_view([ds])

View the netcdf file.

read_json_config()

Read the JSON config file.

recover_forcing(forcing_location, ...)

Recover the forcing file.

reset_case([password])

Reset the case.

create_case(scriptpath) str

Create the case scripts for single point modeling.

Parameters:

filepath (str) – File path of the config file.

Returns:

The modified script file.

Return type:

script (str)

modify_case_config(scriptpaht) str

Modify the case config file.

Parameters:

scriptpath (str) – The path of the script file.

Returns:

The modified script file.

Return type:

script (str)

modify_forcing(var, action, forcing_location) None

Modify the forcing file.

Parameters:
  • var (str) – The variable to be modified.

  • action (float, np.ndarray, dict) – The action to be taken.

  • forcing_location (str) – The location of the forcing file. - if action is a dict, the key is the variable name, the value is the action. - if action is a float, the action will be added to the variable. - if action is a np.ndarray, the variable will be replaced by the action.

Returns:

None

modify_surf(var, action, numurbl=None) str

Modify the surface data file.

Parameters:
  • var (str) – The variable to be modified.

  • action (float, np.ndarray, dict) – The action to be taken. - if action is a dict, the key is the variable name, the value is the action. - if action is a float, the action will be added to the variable. - if action is a np.ndarray, the variable will be replaced by the action.

  • numurbl (int, optional) – The number of urban land units. Defaults to None. None means the action will be implemented to all the urban land units. numurbl 0 –> TBD urban, numurbl 1 –> HD urban, numurbl 2 –> MD urban

Returns:

The modified surface data file path.

Return type:

str

nc_view(ds: str = 'None') Dataset

View the netcdf file.

Parameters:
  • xarray.Dataset – The xarray dataset.

  • ds (str, optional) – The path of the netcdf file. Defaults to “None”.

Returns:

The xarray dataset.

Return type:

xarray.Dataset

read_json_config() dict

Read the JSON config file.

Returns:

The configuration data.

Return type:

config (dict)

recover_forcing(forcing_location, backup_location) None

Recover the forcing file.

Parameters:
  • forcing_location (str) – The location of the forcing file.

  • backup_location (str) – The location of the backup file.

Returns:

None

reset_case(password=None) CompletedProcess

Reset the case. (delete the case folders and files)

Parameters:

password (str, optional) – The password of the server. Defaults to None.

Returns:

The result of the command.

Return type:

subprocess.CompletedProcess

clmu.copy_file_if_not_exists(source_path, destination_path)
clmu.copy_file_if_not_exists2(source_path, destination_path, lon, lat, res='1.25*0.9') None

Copy the file if the destination file does not exist.

Parameters:
  • source_path (str) – The source file path.

  • destination_path (str) – The destination file path.

  • lon (str) – The longitude of the point.

  • lat (str) – The latitude of the point.

  • res (str) – The resolution of the file. Defaults to “1.25*0.9”.

clmu.get_forcing(start_year, end_year, start_month, end_month, lat, lon, zbot, source='cds')

get the forcing data from the era5 dataset

Parameters:
  • start_year (_type_) – the start year

  • end_year (_type_) – the end year

  • start_month (_type_) – the start month

  • end_month (_type_) – the end month

  • lat (_type_) – latitude of interest point

  • lon (_type_) – longitude of interest point

  • zbot (_type_) – the bottom level height

  • source (_type_) – the source of the data, cds or arco-era5

Returns:

the forcing dataset

Return type:

_type_

clmu.get_soil_params(ds: Dataset | DataArray | str, lat: float = 51.508965, lon: float = -0.118092) tuple

Get the soil parameters.

Parameters:
  • ds (_type_) – the soil dataset

  • lat (_type_) – latitude of interest point

  • lon (_type_) – longitude of interest point

Returns:

sand and clay content from the soil dataset

Return type:

tuple

clmu.get_urban_params(urban_ds: Dataset | str, soil_ds: Dataset | str, lat: float, lon: float, template: Dataset | str = '/home/runner/work/pyclmuapp/pyclmuapp/pyclmuapp/usp/surfdata.nc', PTC_URBAN: list = [0, 0, 100], outputname: str = 'surfdata.nc') Dataset

Get the urban parameters.

Parameters:
  • urban_ds (_type_) – the urban dataset

  • soil_ds (_type_) – the soil dataset

  • template (_type_) – the template dataset

  • lat (_type_) – latitude of interest point

  • lon (_type_) – longitude of interest point

  • PTC_URBAN (list, optional) – The percentage of urban. Defaults to [0,0,100]. 0. TBD urban, 1. HD urban, 2. MD urban

  • outputname (_type_, optional) – the output file name. Defaults to “surfdata.nc”.

Returns:

the modified template dataset

Return type:

_type_

clmu.getconfig(caseconfig: str | dict | DataFrame | Series = 'None') dict

Read the configuration of the case to be built.

Parameters:

caseconfig (Union[str, dict, pd.DataFrame, pd.Series]) – The configuration of the case to be built.

Returns:

The configuration data.

Return type:

dict

clmu.now_time()

Get the current time

clmu.run_command(command, password='None', logname='None', iflog=True) None

Run the command. There are two ways to run the command, with or without password. The loges will be saved in the log_ppo.txt file.

Parameters:
  • command (str) – The command to be run.

  • password (str, optional) – The password of the server.

  • logname (str, optional) – The name of the log file. Defaults to “cmdlog.txt”.

  • iflog (bool, optional) – If log is needed. Defaults to True.

Returns:

None