Other methods¶
copy¶
create¶
- classmethod RSK.create(timestamps: Collection[np.datetime64], values: Collection[Collection[float]], channels: Collection[str], units: Collection[str], filename: str = 'sample.rsk', model: str = 'unknown', serialID: int = 0) RSK¶
Create an
RSKinstance from given time series data.- Parameters:
timestamps¶ (Collection[np.datetime64]) – a 1D array/list of timestamps (np.datetime64 format) of size n
values¶ (Collection[Collection[float]]) – a 2D array/list of data of size [n,m]
channels¶ (Collection[str]) – a 1D array/list of channel names of size m
units¶ (Collection[str]) – a 1D array/list of channel units of size m
filename¶ (str, optional) – filename to give a general description of the data. Defaults to “sample.rsk”.
model¶ (str, optional) – instrument model from which data was collected. Defaults to “unknown”.
serialID¶ (int, optional) – serial ID of the instrument from which data was collected. Defaults to 0.
- Returns:
RSK – created
RSKclass instance with given time series data.
Creates an instance of this class containing data and channels specified by the user. For example, the data could originate from a CTD on a profiling float or a glider. The data could even come from CTDs from manufacturers. The purpose of this function is to allow users to easily apply pyRSKtools post-processing and visualisation functions to any dataset. It is particularly convenient when one needs to compare data measured with an RBR CTD to other sources (e.g., other CTDs or bottle samples).
Example:
>>> timestamps = [np.datetime64(1651550400000, "ms"), ... np.datetime64(1651550402000, "ms"), ... np.datetime64(1651550404000, "ms")] ... values = [[39.9973, 16.2695, 10.1034], ... [39.9873, 16.2648, 10.1266], ... [39.9887, 16.2553, 10.1247]] ... channels = ["conductivity","temperature","pressure"] ... units = ["mS/cm","°C","dbar"] ... rsk = RSK.create(timestamps=timestamps, values=values, channels=channels, units=units)
addchannel¶
- RSK.addchannel(data: Collection[float], channel: str = 'unknown', units: str = 'unknown', isMeasured: int = 0, isDerived: int = 0, schedule: str | int = 'default', shortName: str | None = None) None¶
Add a new channel with a defined channel name and unit. If the new channel already exists in the current RSK instance, it will overwrite the old one.
The channel is added to the specified schedule and padded with NaN in all other schedules to maintain structural consistency across dataArrays.
For multi-schedule RSK files, the schedule must be specified explicitly.
- Parameters:
data¶ (Collection[float]) – Array containing the data to be added.
channel¶ (str, optional) – name of the added channel. Defaults to “unknown”.
units¶ (str, optional) – unit of the added channel. Defaults to “unknown”.
isMeasured¶ (int, optional) – whether the added channel is directly measured. Defaults to 0.
isDerived¶ (int, optional) – whether the added channel is derived from other channels. Defaults to 0.
schedule¶ (Union[str, int], optional) – which schedule to add data to. For multi-schedule files, an explicit schedule label must be provided (e.g.,
"s.CTD"); a 1-based integer schedule id is also accepted. Defaults to “default”, which auto-resolves to the single available schedule.shortName¶ (str, optional) – channel-type short name for the new channel. Defaults to None; a known channel keeps its registered type, and an unknown one gets a generic count type (
"cnt_00") unless a short name is given (e.g. to inherit a source channel’s type).
Example:
>>> data = gsw.SA_from_SP(rsk.data["salinity"], rsk.data["sea_pressure"], -150, 49) ... rsk.addchannel(data, "absolute_salinity", units="g/kg", isMeasured=0, isDerived=1) ... # For multi-schedule files, specify the schedule: ... rsk.addchannel(data, "absolute_salinity", units="g/kg", schedule="s.CTD")
removecasts¶
- RSK.removecasts(direction: str = 'up') None¶
Remove the data elements with either an increasing or decreasing pressure.
Removes casts across all schedules using the stored profile direction metadata. Profile elements are kept aligned across schedules.
- Parameters:
direction¶ (str, optional) – cast direction of either “up” or “down”. Defaults to “up”.
NOTE: When there are only downcasts in the current
RSKinstance, the request to remove downcasts will not take effect. The same for upcasts.Example:
>>> rsk.removecasts(direction="up")
appendlog¶
- RSK.appendlog(logentry: str) None¶
Append the entry and current time to the log field.
- Parameters:
logentry¶ (str) – comment that will be added to the log.
Appends the entry and current time to the log field. It is frequently called by other RSK methods for record use so that the users will not lose track of what happened to the file or the data. This method can also be called by the user to record any customised behaviour.
Example:
>>> rsk.appendlog(logentry="New channel practical salinity is added.")
printchannels¶
- RSK.printchannels() None¶
Display instrument information, channel names, and units in the current RSK instance.
Example:
>>> rsk.printchannels()
Example output:
Model: RBRconcerto³ Serial ID: 60662 Sampling period: 0.125 second index name unit _____ ____________________________ _______ 0 'conductivity' 'mS/cm' 1 'temperature' '°C' 2 'pressure' 'dbar' 3 'temperature1' '°C' 4 'temperature2' '°C' 5 'sea_pressure' 'dbar' 6 'salinity' 'PSU'
getregionsbytypes¶
- RSK.getregionsbytypes(types: Type[Region] | Collection[Type[Region]]) List[Region]¶
Retrieve all the regions from
RSK.regionsthat match the list of Region types passed in as an argument.NOTE: a Region type is any class that inherits from
Region.- Parameters:
types¶ (Union[Type[Region], Collection[Type[Region]]]) – a single or list of Region type(s)
- Returns:
List[Region] – the filtered list of Region instances obtained from
RSK.regions.
Barometric correction¶
- RSK.importbarometer(source: Any, source_schedule: str | None = None, label: str = 'sch_patm', source_tz_offset_hours: float | None = None, csv_hints: dict | None = None) None¶
Import a barometer source and attach to this RSK.
The barometer pressure is interpolated onto each marine sample so that
deriveseapressure()(called withoutpatm) subtracts it to give a barometer-corrected sea pressure. Marine samples outside the barometer’s time range are filled with the nearest barometer reading, held constant. The correction is attached in memory; persist it later withRSK2RSKFULL()(orRSK2RSK()for a v2 file).Only one barometer can be attached at a time — call
removebarometer()before importing a different one. The correction is applied to a single schedule: the first one with pressure samples (a warning names it when the file has other pressure-bearing schedules).Eligible files are schema 3.2.0+, or 2.18.2/2.19.0 with dbType full/live/EPdesktop.
- Parameters:
source¶ –
One of:
A
(timestamps_utc_ns, pressures_dbar)tuple — two 1-D, equal-length, non-empty arrays.A path to a
.csvfile (format auto-detected, overridable viacsv_hints).A path to a
.rskfile, or an openRSKinstance; its first measured pressure channel is used as the barometer.The name (
shortNameorlongName) of a measured pressure channel of this RSK, or aChannelinstance.
source_schedule¶ (str, optional) – Schedule label to read from a multi-schedule source. Required when a source RSK has more than one schedule, or when a same-RSK source channel carries finite samples in more than one schedule; ignored for tuple and CSV sources.
label¶ (str) – Schedule label for the barometer output schedule.
source_tz_offset_hours¶ (float, optional) – Source UTC offset (OFFSET_FROM_UTC convention — hours east of UTC, negative west). For an RSK source,
Noneauto-detects the source’s stored OFFSET_FROM_UTC. For a CSV source it sets the timezone of naive timestamps (those with no offset in the string);Nonetreats them as UTC. Timestamps that carry an explicit offset are unaffected.csv_hints¶ (dict, optional) – CSV parsing overrides. Keys:
has_header(bool),time_format(strptime string),pressure_units(bar/dbar/psi/kPa). Each override replaces the corresponding auto-detected value.
- Raises:
RuntimeError – If a barometer is already attached.
ValueError – If the marine RSK or the source RSK is ineligible, the source type is unsupported, the CSV cannot be parsed, the tuple source fails validation, or the barometer does not overlap the marine data at all.
KeyError – If
source_scheduledoes not name a schedule of the source.
- RSK.removebarometer() None¶
Remove the attached barometer and revert to a constant atmosphere.
Detaches the barometer (and the
pres002atmospheric-pressure channel and schedule it added), then re-derives sea pressure using the default constant atmospheric pressure (10.1325 dbar). Depth is re-derived too, but only if a depth channel already exists, usingderivedepth()defaults (latitude 45.0, TEOS-10) — if you derived depth with non-default parameters, re-runderivedepth()afterwards.Acts in memory only; persist the result with
RSK2RSKFULL()orRSK2RSK(). If no barometer is attached, this is a no-op. To apply a different barometer, call this first, thenimportbarometer()again.