pypsa.Network.copy#
- Network.copy(snapshots: Sequence | None = None, investment_periods: Sequence | None = None, ignore_standard_types: bool = False, with_time: bool | None = None) Network#
Return a deep copy of Network object.
If only default arguments are passed, the copy will be created via
copy.deepcopy()and will contain all components and time-varying data. For most networks this is the fastest way. However, if the network is very large, it might be better to filter snapshots and investment periods to reduce the size of the copy. In this casecopy.deepcopy()is not used and only the selected snapshots and investment periods are copied to a new object.- Parameters:
snapshots (list or tuple or pd.Index , default self.snapshots) – A list of snapshots to copy, must be a subset of n.snapshots. Pass an empty list ignore all snapshots.
investment_periods (list or tuple or pd.Index, default self.investment_period_weightings.index) – A list of investment periods to copy, must be a subset of n.investment_periods. Pass
ignore_standard_types (boolean, default False) – Ignore the PyPSA standard types.
with_time (boolean, default True) –
Copy snapshots and time-varying n.component_names_t data too.
Deprecated since version 0.29.0: The ‘with_time’ argument is deprecated in 0.29 and will be removed in a future version. Pass an empty list to ‘snapshots’ instead.
- Returns:
n – The copied network object.
- Return type:
Examples
With a simple reference the network is not copied: >>> n = pypsa.examples.ac_dc_meshed() >>> network_copy = n >>> id(network_copy) == id(n) True
Use the copy method to create a new network object: >>> network_copy = n.copy() >>> id(network_copy) == id(n) False
You can also filter on a subset of snapshots (or investment periods): >>> n.snapshots DatetimeIndex([‘2015-01-01 00:00:00’, ‘2015-01-01 01:00:00’,
‘2015-01-01 02:00:00’, ‘2015-01-01 03:00:00’, ‘2015-01-01 04:00:00’, ‘2015-01-01 05:00:00’, ‘2015-01-01 06:00:00’, ‘2015-01-01 07:00:00’, ‘2015-01-01 08:00:00’, ‘2015-01-01 09:00:00’],
dtype=’datetime64[ns]’, name=’snapshot’, freq=None)
>>> network_copy = n.copy(snapshots=n.snapshots[0]) >>> network_copy.snapshots DatetimeIndex(['2015-01-01'], dtype='datetime64[ns]', name='snapshot', freq=None)