Profiles¶
- emiproc.profiles.operators.get_weights_of_gdf_profiles(
- gdf: GeoDataFrame,
- profiles_indexes: DataArray,
Read the emission values from the gdf to get the weights.
Weights for missing data will be 0. This makes sure that if later group different profiles, the data will the merged profile from the other categories.
- Parameters:
gdf – The gdf of an inventory, following the standard definition.
profiles_indexes – Indexes of the profiles to use.
- Return weights:
A xarray containing the weights of the given profiles_indexes.
- emiproc.profiles.operators.weighted_combination(
- profiles: VerticalProfiles | list[TemporalProfile],
- weights: ndarray,
Combine the different profiles according to the specified weights.
Each ratio of the new profile follow the formula:
\[r_{new} = \frac{\sum_{i}^n w_i r_i}{\sum_{i}^n w_i}\]where \(r_i\) is the ratio of the profile i and \(w_i\) is the weight of the profile i. and :math`n` is the number of profiles.
- Parameters:
profiles – The profiles to combine. If temporal, they must be all of the same type. If vertical, it must be a
VerticalProfilesobject.weights – The weights to use for the combination. See numpy.average() for more details on the weights.
- Returns:
The combined profile.
- emiproc.profiles.operators.combine_profiles(
- profiles: VerticalProfiles | list[list[TemporalProfile]] | CompositeTemporalProfiles,
- profiles_indexes: DataArray,
- dimension: str,
- weights: DataArray,
- chunk: bool = False,
- n_chunks: int = 20,
Combine profiles from multidimensional array by reducing over a specified dimension.
The indexes and the weights but be of the same dimensions.
- Parameters:
profiles – The profiles to use for merging.
profiles_indexes – The profiles indexes of the data.
dimension – The dimension along which the combination should be done.
weights – The weights of the data. In terms of emissions, it means the total emission of that data. Weights can be obtained through
get_weights_of_gdf_profiles()n_chunks – In case of MemoryError, the number of chunks to use for processing.
- Returns:
the new profiles and the indexes of the combined data in these new profiles. The indexes array has the dimension of combination removed.
- emiproc.profiles.operators.group_profiles_indexes(
- profiles: VerticalProfiles | list[list[TemporalProfile]],
- profiles_indexes: DataArray,
- indexes_weights: DataArray,
- categories_group: dict[str, list[str]],
- groupping_dimension: str = 'category',
- chunk: bool = False,
Groups profiles and their indexes according to the given mapping.
It is possible to group categories or substances or cells by setting the groupping_dimension to the corresponding dimension.
- Parameters:
profiles – The profiles to use for merging.
profiles_indexes – The profiles indexes of the data.
indexes_weights – The weights of the data. In terms of emissions, it means the total emission of that data. Weights can be obtained through
get_weights_of_gdf_profiles()categories_group – A dictionary containing the mapping of the categories. The keys are the new categories and the values are the list of categories that should be grouped together.
groupping_dimension – The dimension along which the combination should be done. Default is “category”.
- emiproc.profiles.operators.remap_profiles(
- profiles: VerticalProfiles | CompositeTemporalProfiles,
- profiles_indexes: DataArray,
- emissions_weights: DataArray,
- weights_mapping: dict[str, ndarray],
- dont_merge: bool = False,
Remap the profiles on a new grid.
- Parameters:
profiles – The profiles to remap.
profiles_indexes – The indexes of the profiles.
emissions_weights – The weights of the emissions. Can be calculated using
get_weights_of_gdf_profiles().weights_mapping – A dictionary containing the weights for the remapping. This is the result of
emiproc.utilities.get_weights_mapping().dont_merge – If True, will use one of the profiles intersecting instead of weighting by the remapping weights. This is useful to simplify the number of profiles.
- Returns:
The remapped profiles and the new indexes.
- emiproc.profiles.utils.ratios_to_factors(ratios: ndarray) ndarray¶
Convert ratios to factors.
- emiproc.profiles.utils.factors_to_ratios(factors: ndarray) ndarray¶
Convert factors to ratios.
- emiproc.profiles.utils.ratios_dataarray_to_profiles(
- da: DataArray,
- rounding_decimals: int | None = None,
Convert a dataarray of ratios to a profiles array and the indexes compatible for emiproc.
- Parameters:
da – DataArray with the ratios. Must contain a ‘ratio’ dimension. Other dimensions must be the ones allowed by the emiproc profiles.
rounding_decimals – The number of decimals to round the profiles to. This can be useful to reduce the number of unique profiles.
- Returns:
A tuple with the profiles array and the indexes DataArray. The profiles array is a 2D array which can be set at ratios in a Profile object. The indexes DataArray is an array that can be set to the indexes of an inventory.
Vertical Profiles¶
- class emiproc.profiles.vertical_profiles.VerticalProfile¶
Vertical profile.
A vertical profile defines how the emission is split vertically on the altitude. A vertical profile is defined simply by its ratios and the height levels.
You can check the conditions required on the profile in
check_valid_vertical_profile()- Parameters:
ratios – The proportion of emission that is in each layer.
height – The top height of the layers. The first layer starts at 0 meter and ends at height[0]. The second layer starts at height[0] and ends at height[1]. Over the last height value, there is no emission.
- __init__(ratios: ndarray, height: ndarray) None¶
- classmethod __new__(*args, **kwargs)¶
- class emiproc.profiles.vertical_profiles.VerticalProfiles¶
Vertical profiles.
This is very similar to
VerticalProfilebut it can store many ratios for the same height distributions- Parameters:
ratios – a (n_profiles, n_heights) array.
height – Same as
VerticalProfile.height.
- __init__(ratios: ndarray, height: ndarray) None¶
- classmethod __new__(*args, **kwargs)¶
Operators On Vertical Profiles¶
- emiproc.profiles.vertical_profiles.resample_vertical_profiles(
- *profiles: VerticalProfile | VerticalProfiles,
- specified_levels: ndarray | None = None,
Resample vertical profiles into one vertical profiles object.
Allows for profiles of different height levels to be groupped into one. Sample the profile on the heights level given.
Uses a conservative interpolation method, that ensure that even on higher resolution the profile will be exactly the same. Note that this sometimes has no physical sense and a linear interpolation when using profiles would be better at higher resolutions, but this has to be a choice from the user.
- Parameters:
specified_levels – If this is specified, you can select an arbitray scale on which to reproject. If not specified, all the levels found in the profiles will be used. The ordering of the profiles will match the order given as input.
- emiproc.profiles.vertical_profiles.check_valid_vertical_profile(
- vertical_profile: VerticalProfile | VerticalProfiles,
Check that the vertical profile meets requirements.
height must have positive values
height must have strictly increasing values
ratios must sum up to one
ratios must all be >= 0
ratios and height must have the same len
no nan values in any of the arrays
- Parameters:
veritcal_profile – The profile to check.
- Raises:
AssertionError – If the profile is invalid.
input/output¶
- emiproc.profiles.vertical_profiles.read_vertical_profiles(
- profiles_dir: PathLike,
- col_of_dim: dict[str, str] | None = None,
Read vertical profiles from csv files.
Vertical profiles only depend on the category.
The format expected from the files is: Line starting with # are ignored. A header line should contain a column for the category, substance, country …
The other columns should contain the value of the levels. The columns must be sorted from smallest to largest. They should be called one of the following: - using the ending height: ex. 12;23;76 - using the interval ex. 12-23;23-76
You can add a m (20m, 40m) to specify it is meters, but it is not required. The height is always assumed to be of meter units.
An example of a file is:
# This is a comment # Any number of comment lines are allowed # Below is the header line Category,Substance,20m,92m,184m,324m,522m,781m,1106m Public_Power,CO2,0,0,0.0025,0.51,0.453,0.0325,0.002 Public_Power,CH4,0,0,0.0025,0.51,0.453,0.0325,0.002 Industry,CO2,0.06,0.16,0.75,0.03,0,0,0 ...
- Parameters:
profiles_dir – The directory containing the profiles. The profiles file must contain the word “height” in their name. Alternatively you can provide a path to a specific file. For compatiblity with tno, you can also include the words “area” or “point” in the name of the file to specify if the profiles are for gridded emissions or for shapped emissions.
- Returns:
A tuple containing the vertical profiles and an xarray mapping which kind of emission correspond to which profile.
Temporal Profiles¶
- class emiproc.profiles.temporal.profiles.TemporalProfile¶
Temporal profile.
Temporal profile defines how the emission is distributed over time.
- __init__(ratios: ndarray | None = None, size: int = 1) None¶
- classmethod __new__(*args, **kwargs)¶
Cyclic Profiles¶
Profiles that can be repeated and applied at any time.
- class emiproc.profiles.temporal.profiles.DailyProfile¶
Daily profile.
Daily profile defines how the emission is distributed over the day. The profile starts at 00:00.
- __init__(ratios: ndarray | None = None) None¶
- classmethod __new__(*args, **kwargs)¶
- class emiproc.profiles.temporal.profiles.SpecificDayProfile¶
Same as DailyProfile but with a specific day of the week.
- __init__(
- ratios: ndarray | None = None,
- specific_day: SpecificDay | None = None,
- classmethod __new__(*args, **kwargs)¶
- class emiproc.profiles.temporal.profiles.WeeklyProfile¶
Weekly profile.
Weekly profile defines how the emission is distributed over the week. The profile starts on Monday.
- __init__(ratios: ndarray | None = None, size: int = 7) None¶
- classmethod __new__(*args, **kwargs)¶
- class emiproc.profiles.temporal.profiles.MounthsProfile¶
Yearly profile.
Yearly profile defines how the emission is distributed over the year using months.
- __init__(ratios: ndarray | None = None, size: int = 12) None¶
- classmethod __new__(*args, **kwargs)¶
- class emiproc.profiles.temporal.profiles.HourOfWeekProfile¶
Hour of week profile.
Hour of week profile defines how the emission is distributed over the week using hours. This is useful if you want to account for different daily patterns over the days of the week (usually for the weekend)
The profile starts on Monday at 00:00.
- __init__(
- ratios: ndarray | None = None,
- size: int = 168,
- classmethod __new__(*args, **kwargs)¶
Year Covering Profiles¶
Profiles that cannot be repeated, but apply specifically to a given time.
Composite Profiles¶
- class emiproc.profiles.temporal.composite.CompositeTemporalProfiles¶
A helper class to handle mixtures of temporal profiles.
Acts similar to a TemporalProfile
Stores a dict for each type of profile,
- __init__(
- profiles: list[list[DailyProfile | SpecificDayProfile | WeeklyProfile | MounthsProfile | HourOfYearProfile | HourOfLeapYearProfile | HourOfWeekProfile | Hour3OfDay | Hour3OfDayPerMonth | HourOfWeekPerMonthProfile | DayOfYearProfile | DayOfLeapYearProfile]] = [],
- static __new__(
- cls,
- profiles: list[list[DailyProfile | SpecificDayProfile | WeeklyProfile | MounthsProfile | HourOfYearProfile | HourOfLeapYearProfile | HourOfWeekProfile | Hour3OfDay | Hour3OfDayPerMonth | HourOfWeekPerMonthProfile | DayOfYearProfile | DayOfLeapYearProfile]] | CompositeTemporalProfiles,
- emiproc.profiles.temporal.composite.make_composite_profiles(
- profiles: AnyProfiles,
- indexes: DataArray,
Create a composite temporal profiles from a list of profiles and indexes.
- Parameters:
profiles – The profiles to use.
indexes – The indexes to use. The indexes must have a dim called “profile” with the name of the profile type.
Utilities¶
- emiproc.profiles.temporal.operators.interpolate_profiles_hour_of_year(
- profiles: CompositeTemporalProfiles,
- year: int,
- interpolation_method: str | dict[DailyProfile | SpecificDayProfile | WeeklyProfile | MounthsProfile | HourOfYearProfile | HourOfLeapYearProfile | HourOfWeekProfile | Hour3OfDay | Hour3OfDayPerMonth | HourOfWeekPerMonthProfile | DayOfYearProfile | DayOfLeapYearProfile, str] = 'linear',
- return_profiles: bool = False,
- output_type: TemporalProfilesInterpolated = TemporalProfilesInterpolated.HOUR_OF_YEAR,
Interpolate the profiles to create another specific profile.
- Parameters:
profiles – The profiles to use.
year – The year to use.
interpolation_method – The interpolation method to use. See xarray for more details. Using a dict, you can have different interpolation methods for different profiles.
return_profiles – If True, return the profiles instead of the ratios.
output_type – The type of the output profile.
- Returns:
The interpolated profiles or the ratios based on the return_profiles argument.
- emiproc.profiles.temporal.operators.create_scaling_factors_time_serie(
- start_time: datetime,
- end_time: datetime,
- profiles: list[DailyProfile | SpecificDayProfile | WeeklyProfile | MounthsProfile | HourOfYearProfile | HourOfLeapYearProfile | HourOfWeekProfile | Hour3OfDay | Hour3OfDayPerMonth | HourOfWeekPerMonthProfile | DayOfYearProfile | DayOfLeapYearProfile],
- apply_month_interpolation: bool = True,
- freq: str = 'h',
- inclusive: str = 'both',
- local_tz: str | None = None,
Create a time serie of ratios for the requested time range.
- Parameters:
start_time – The start time of the time serie.
end_time – The end time of the time serie.
profiles – The profiles to use to create .
apply_month_interpolation – If True, apply the month interpolation.
inclusive – {“both”, “neither”, “left”, “right”}, default “both” same as pd.date_range Include boundaries; Whether to set each bound as closed or open.
Specific days¶
Utilites to create profiles for specific days of the week.
- class emiproc.profiles.temporal.specific_days.SpecificDay¶
An enum to define specific day applied of a profile.
- emiproc.profiles.temporal.specific_days.days_of_specific_day(
- specific_day: SpecificDay,
- emiproc.profiles.temporal.specific_days.get_days_as_ints(
- specific_day: SpecificDay,
Return the days corresponding for a specific day.
This agrees with the pandas convention where Monday is 0 and Sunday is 6.
- emiproc.exports.icon.get_constant_time_profile(
- type: TemporalProfilesTypes = TemporalProfilesTypes.THREE_CYCLES,
- year: int | None = None,
Get a constant time profile compatible with ICON-OEM.
Emits the same at every time.
Contains three profiles: hour of day, day of week, month of year.
input/output¶
- emiproc.profiles.temporal.io.read_temporal_profiles(
- profiles_dir: PathLike,
- time_profiles_files_format: str = 'timeprofiles*.csv',
- profile_csv_kwargs: dict[str, Any] = {},
- rtol: float = 1e-05,
- col_of_dim: dict[str, str] | None = None,
Read the temporal profiles csv files to the emiproc inventory format.
The files for the time profiles are csv and must be all in the same directory named according to the argument time_profiles_files_format.
If no files are found, this returns a warning.
The format of the file will influence the name of the columns. Use the day of the weeks or the month names or the hour of the day to define the profile.
- Parameters:
profiles_dir – The directory where the time profiles are stored.
time_profiles_files_format – The format of the filenames to read.
profile_csv_kwargs – Extra arguments to pass to the function
emiproc.profiles.utils.read_profile_file()that reads the csv files.rtol – The relative tolerance to use when checking if the ratios sum to 1.
- Returns:
A tuple of the profiles and the indexes, following the emiproc inventory profiles format.
- emiproc.profiles.temporal.io.from_yaml(
- yaml_file: PathLike,
Read a yml file containing a temporal profile.
Only one temporal profile is currently accepted in the yaml definition.
- emiproc.profiles.temporal.io.to_yaml(
- profiles: list[DailyProfile | SpecificDayProfile | WeeklyProfile | MounthsProfile | HourOfYearProfile | HourOfLeapYearProfile | HourOfWeekProfile | Hour3OfDay | Hour3OfDayPerMonth | HourOfWeekPerMonthProfile | DayOfYearProfile | DayOfLeapYearProfile],
- yaml_file: PathLike,
Write a list of profiles to a yaml file.
Implemented Profiles¶
- emiproc.inventories.edgar.temporal.read_edgar_auxilary_profiles(
- auxiliary_filesdir: PathLike,
- inventory: Inventory,
Read the auxiliary profiles for the EDGAR inventory.
Outputs them in a format that they can directly be set as profiles to the inventory.
The auxiliary profiles are available at, as “auxiliary tables”: https://edgar.jrc.ec.europa.eu/dataset_temp_profile
some categories might missmatch.