Utility classes and functions#
This subpackage contains general utility classes and functions
- class dysh.util.gaincorrection.BaseGainCorrection[source]#
Bases:
ABCThis class is the base class for gain corrections. It is intended to be subclassed for specific antennas. Subclasses will be used to calculate various gain corrections to go from antenna temperature to other scales like brightness temperature of flux density. Subclasses can implement the following attributes:
ap_eff_0long wavelength aperture efficiency (number between 0 and 1), i.e., in the absence of surface errors, $lambda >> epsilon_0$.
epsilon_0default rms surface accuracy with units of length (
Quantity)
physical_apertureantenna physical aperture with units of length**2 (
Quantity)
Methods
airmass(angle, zd, **kwargs)Computes the airmass at given elevation(s) or zenith distance(s).
aperture_efficiency(specval, **kwargs)Calculate the antenna aperture efficiency.
- abstract airmass(angle: Angle | Quantity, zd: bool, **kwargs) float | ndarray[source]#
Computes the airmass at given elevation(s) or zenith distance(s). Subclasses should implement an airmass function specific to their application.
- Parameters:
- angle
AngleorQuantity The elevation(s) or zenith distance(s) at which to compute the airmass
- zd: bool
True if the input value is zenith distance, False if it is elevation.
- **kwargsAny
Other possible parameters that affect the airmass, e.g. weather data.
- angle
- Returns:
- airmass - float or
ndarray - The value(s) of the airmass at the given elevation(s)/zenith distance(s)
- airmass - float or
- abstract aperture_efficiency(specval: Quantity, **kwargs) float | ndarray[source]#
Calculate the antenna aperture efficiency.
- Parameters:
- specval
Quantity The spectral value – frequency or wavelength – at which to compute the efficiency
- **kwargsAny
Other possible parameters that affect the aperture efficiency, e.g., elevation angle.
- specval
- Returns:
- aperture_efficiency - float or
ndarray - The value(s) of the aperture efficiency at the given frequency.
- The return value(s) are float(s) between zero and one.
- aperture_efficiency - float or
- class dysh.util.gaincorrection.GBTGainCorrection(gain_correction_table: Path | None = None)[source]#
Bases:
BaseGainCorrectionGain correction class and functions specific to the Green Bank Telescope
- Attributes:
gain_correction_tableThe table containing the parameterized gain correction as a fucntion of zenith distance and time
Methods
airmass(angle[, zd])Computes the airmass at given elevation(s) or zenith distance(s).
aperture_efficiency(specval, angle, date[, ...])Compute the aperture efficiency, as a float between zero and 1.
gain_correction(angle, date[, zd])Compute the gain correction scale factor, to be used in the aperture efficiency calculation.
surface_error(date)Lookup the applicable surface error in the gain correction table for the observation date.
- airmass(angle: Angle | Quantity, zd: bool = False, **kwargs) float | ndarray[source]#
Computes the airmass at given elevation(s) or zenith distance(s). The formula used is
\(A = -0.0234 + 1.014/sin(El+5.18/(El+3.35))\)
for elevation in degrees. This function is specific for the GBT location derived from vertical weather data. Source: (Maddalena 2007)
- Parameters:
- angle
AngleorQuantity The elevation(s) or zenith distance(s) at which to compute the airmass
- zd: bool
True if the input value is zenith distance, False if it is elevation. Default: False
- angle
- Returns:
- airmass - float or
ndarray - The value(s) of the airmass at the given elevation(s)/zenith distance(s)
- airmass - float or
- aperture_efficiency(specval: Quantity, angle: Angle | Quantity, date: Time, zd=False, eps0=None, **kwargs) float | ndarray[source]#
Compute the aperture efficiency, as a float between zero and 1. The aperture efficiency \(\eta_a\), is determined by:
\(\eta_a = \eta_0 G(ZD) \exp(-(4\pi\epsilon_0/\lambda)^2)\)
where \(\eta_0\) is the long wavelength aperture efficiency, \(G(ZD)\) is the gain correction factor at a zenith distance \(ZD, \epsilon_0\) is the surface error, and \(\lambda\) is the wavelength.
- Parameters:
- specval
Quantity The spectral value – frequency or wavelength – at which to compute the efficiency
- angle
AngleorQuantity The elevation(s) or zenith distance(s) at which to compute the efficiency
- date
Time The date at which to cmopute the efficieyncy
- zd: bool
True if the input value is zenith distance, False if it is elevation. Default: False
- eps0
Quantityor None The value of \(\epsilon_0\) to use. If given, must have units of length (typically microns). If None, the measured value from observatory testing will be used (See
surface_error()).
- specval
- Returns:
- float or
ndarray - The aperture efficiency at the given inputs
- float or
- gain_correction(angle: Angle | Quantity, date: Time, zd: bool = True) float | ndarray[source]#
Compute the gain correction scale factor, to be used in the aperture efficiency calculation. The factor is a float between zero and 1. (See GBT Memo 301). The factor is determined by:
\(G = A0 + A1*ZD + A2*ZD^2\)
where An are the time-dependent coefficients and ZD is the zenith distance angle in degrees.
- Parameters:
- Returns:
- gain_correction - float or
ndarray - The gain correction scale factor(s) at the given elevation(s)/zenith distance(s)
- gain_correction - float or
- property gain_correction_table#
The table containing the parameterized gain correction as a fucntion of zenith distance and time
- class dysh.util.selection.Flag(initobj, aliases={'dec': 'crval3', 'elevation': 'elevatio', 'freq': 'crval1', 'gallat': 'crval3', 'gallon': 'crval2', 'glat': 'crval3', 'glon': 'crval2', 'pol': 'plnum', 'ra': 'crval2', 'source': 'object', 'subref': 'subref_state'}, **kwargs)[source]#
Bases:
SelectionBaseThis class contains the methods for creating rules to flag data from an SDFITS object. Data (rows) can be selected for flagging using any column name in the input SDFITS object. Exact selection, range selection, upper/lower limit selection, and any-of selection are all supported.
Users create flag rules by specifying keyword (SDFITS columns) and value(s) to be flagged. Briefly, the flag methods are:
flag()- Flag exact valuesflag_range()- Flag ranges of valuesflag_within()- Flag a value +/- epsilonflag_channel()- Flag channels or ranges of channelsThe Flag object maintains a DataFrame for each flag rule created by the user. The
final()flag is the logical OR of these rules. Users can examine the current flags withshow()which will show the current rules and how many rows each rule selects for flagging from the unfiltered data.The actual flags, which are per channel, are stored in the GBTFITSLoad object, not in the Flag object. The Flag object just contains the flagging rules.
Aliases of keywords are supported. The user may add an alias for an existing SDFITS column with
alias(). Some defaultaliases()have been defined.GBTIDL Flags can be read in with
read().- Attributes:
TThe transpose of the DataFrame.
aliasesThe aliases that may be used to refer to SDFITS columns.
atAccess a single value for a row/column label pair.
attrsDictionary of global attributes of this dataset.
axesReturn a list representing the axes of the DataFrame.
- columns
The column labels of the DataFrame.
>>> df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]}) >>> df A B 0 1 3 1 2 4 >>> df.columns Index(['A', 'B'], dtype='object')
dtypesReturn the dtypes in the DataFrame.
emptyIndicator whether Series/DataFrame is empty.
finalCreate the final selection.
flagsGet the properties associated with this pandas object.
iatAccess a single value for a row/column pair by integer position.
ilocPurely integer-location based indexing for selection by position.
- index
The index (row labels) of the DataFrame.
The index of a DataFrame is a series of labels that identify each row. The labels can be integers, strings, or any other hashable type. The index is used for label-based access and alignment, and can be accessed or modified using this attribute.
- pandas.Index
The index labels of the DataFrame.
DataFrame.columns : The column labels of the DataFrame. DataFrame.to_numpy : Convert the DataFrame to a NumPy array.
>>> df = pd.DataFrame({'Name': ['Alice', 'Bob', 'Aritra'], ... 'Age': [25, 30, 35], ... 'Location': ['Seattle', 'New York', 'Kona']}, ... index=([10, 20, 30])) >>> df.index Index([10, 20, 30], dtype='int64')
In this example, we create a DataFrame with 3 rows and 3 columns, including Name, Age, and Location information. We set the index labels to be the integers 10, 20, and 30. We then access the
indexattribute of the DataFrame, which returns anIndexobject containing the index labels.>>> df.index = [100, 200, 300] >>> df Name Age Location 100 Alice 25 Seattle 200 Bob 30 New York 300 Aritra 35 Kona
In this example, we modify the index labels of the DataFrame by assigning a new list of labels to the
indexattribute. The DataFrame is then updated with the new labels, and the output shows the modified DataFrame.locAccess a group of rows and columns by label(s) or a boolean array.
ndimReturn an int representing the number of axes / array dimensions.
shapeReturn a tuple representing the dimensionality of the DataFrame.
sizeReturn an int representing the number of elements in this object.
styleReturns a Styler object.
valuesReturn a Numpy representation of the DataFrame.
Methods
abs()Return a Series/DataFrame with absolute numeric value of each element.
add(other[, axis, level, fill_value])Get Addition of dataframe and other, element-wise (binary operator
add).add_prefix(prefix[, axis])Prefix labels with string
prefix.add_suffix(suffix[, axis])Suffix labels with string
suffix.agg([func, axis])Aggregate using one or more operations over the specified axis.
aggregate([func, axis])Aggregate using one or more operations over the specified axis.
alias(aliases)Alias a set of keywords to existing columns.
align(other[, join, axis, level, copy, ...])Align two objects on their axes with the specified join method.
all([axis, bool_only, skipna])Return whether all elements are True, potentially over an axis.
any(*[, axis, bool_only, skipna])Return whether any element is True, potentially over an axis.
apply(func[, axis, raw, result_type, args, ...])Apply a function along an axis of the DataFrame.
applymap(func[, na_action])Apply a function to a Dataframe elementwise.
asfreq(freq[, method, how, normalize, ...])Convert time series to specified frequency.
asof(where[, subset])Return the last row(s) without any NaNs before
where.assign(**kwargs)Assign new columns to a DataFrame.
astype(dtype[, copy, errors])Cast a pandas object to a specified dtype
dtype.at_time(time[, asof, axis])Select values at particular time of day (e.g., 9:30AM).
backfill(*[, axis, inplace, limit, downcast])Fill NA/NaN values by using the next valid observation to fill the gap.
between_time(start_time, end_time[, ...])Select values between particular times of the day (e.g., 9:00-9:30 AM).
bfill(*[, axis, inplace, limit, downcast])Fill NA/NaN values by using the next valid observation to fill the gap.
bool()Return the bool of a single element Series or DataFrame.
boxplot([column, by, ax, fontsize, rot, ...])Make a box plot from DataFrame columns.
clear()Remove all selection rules
clip([lower, upper, axis, inplace])Trim values at input threshold(s).
columns_selected()The names of any columns which were used in a selection rule
combine(other, func[, fill_value, overwrite])Perform column-wise combine with another DataFrame.
combine_first(other)Update null elements with value in the same location in
other.compare(other[, align_axis, keep_shape, ...])Compare to another DataFrame and show the differences.
convert_dtypes([infer_objects, ...])Convert columns to the best possible dtypes using dtypes supporting
pd.NA.copy([deep])Make a copy of this object's indices and data.
corr([method, min_periods, numeric_only])Compute pairwise correlation of columns, excluding NA/null values.
corrwith(other[, axis, drop, method, ...])Compute pairwise correlation.
count([axis, numeric_only])Count non-NA cells for each column or row.
cov([min_periods, ddof, numeric_only])Compute pairwise covariance of columns, excluding NA/null values.
cummax([axis, skipna])Return cumulative maximum over a DataFrame or Series axis.
cummin([axis, skipna])Return cumulative minimum over a DataFrame or Series axis.
cumprod([axis, skipna])Return cumulative product over a DataFrame or Series axis.
cumsum([axis, skipna])Return cumulative sum over a DataFrame or Series axis.
describe([percentiles, include, exclude])Generate descriptive statistics.
diff([periods, axis])First discrete difference of element.
div(other[, axis, level, fill_value])Get Floating division of dataframe and other, element-wise (binary operator
truediv).divide(other[, axis, level, fill_value])Get Floating division of dataframe and other, element-wise (binary operator
truediv).dot(other)Compute the matrix multiplication between the DataFrame and other.
drop([labels, axis, index, columns, level, ...])Drop specified labels from rows or columns.
drop_duplicates([subset, keep, inplace, ...])Return DataFrame with duplicate rows removed.
droplevel(level[, axis])Return Series/DataFrame with requested index / column level(s) removed.
dropna(*[, axis, how, thresh, subset, ...])Remove missing values.
duplicated([subset, keep])Return boolean Series denoting duplicate rows.
eq(other[, axis, level])Get Equal to of dataframe and other, element-wise (binary operator
eq).equals(other)Test whether two objects contain the same elements.
eval(expr, *[, inplace])Evaluate a string describing operations on DataFrame columns.
ewm([com, span, halflife, alpha, ...])Provide exponentially weighted (EW) calculations.
expanding([min_periods, axis, method])Provide expanding window calculations.
explode(column[, ignore_index])Transform each element of a list-like to a row, replicating index values.
ffill(*[, axis, inplace, limit, downcast])Fill NA/NaN values by propagating the last valid observation to next valid.
fillna([value, method, axis, inplace, ...])Fill NA/NaN values using the specified method.
filter([items, like, regex, axis])Subset the dataframe rows or columns according to the specified index labels.
first(offset)Select initial periods of time series data based on a date offset.
first_valid_index()Return index for first non-NA value or None, if no non-NA value is found.
flag([tag])Add one or more exact flag rules, e.g.,
key1 = value1, key2 = value2, ...Ifvalueis array-like then a match to any of the array members will be flagged.flag_channel(channel[, tag])Flag channels and/or channel ranges for all data.
flag_range([tag])Flag a range of inclusive values for a given key(s).
flag_within([tag])Flag a value within a plus or minus for a given key(s).
floordiv(other[, axis, level, fill_value])Get Integer division of dataframe and other, element-wise (binary operator
floordiv).from_dict(data[, orient, dtype, columns])Construct DataFrame from dict of array-like or dicts.
from_records(data[, index, exclude, ...])Convert structured or record ndarray to DataFrame.
ge(other[, axis, level])Get Greater than or equal to of dataframe and other, element-wise (binary operator
ge).get(key)Get the selection/flag rule by its ID
groupby([by, axis, level, as_index, sort, ...])Group DataFrame using a mapper or by a Series of columns.
gt(other[, axis, level])Get Greater than of dataframe and other, element-wise (binary operator
gt).head([n])Return the first
nrows.hist([column, by, grid, xlabelsize, xrot, ...])Make a histogram of the DataFrame's columns.
idxmax([axis, skipna, numeric_only])Return index of first occurrence of maximum over requested axis.
idxmin([axis, skipna, numeric_only])Return index of first occurrence of minimum over requested axis.
infer_objects([copy])Attempt to infer better dtypes for object columns.
info([verbose, buf, max_cols, memory_usage, ...])Print a concise summary of a DataFrame.
insert(loc, column, value[, allow_duplicates])Insert column into DataFrame at specified location.
interpolate([method, axis, limit, inplace, ...])Fill NaN values using an interpolation method.
isetitem(loc, value)Set the given value in the column with position
loc.isin(values)Whether each element in the DataFrame is contained in values.
isna()Detect missing values.
isnull()DataFrame.isnull is an alias for DataFrame.isna.
items()Iterate over (column name, Series) pairs.
iterrows()Iterate over DataFrame rows as (index, Series) pairs.
itertuples([index, name])Iterate over DataFrame rows as namedtuples.
join(other[, on, how, lsuffix, rsuffix, ...])Join columns of another DataFrame.
keys()Get the 'info axis' (see Indexing for more).
kurt([axis, skipna, numeric_only])Return unbiased kurtosis over requested axis.
kurtosis([axis, skipna, numeric_only])Return unbiased kurtosis over requested axis.
last(offset)Select final periods of time series data based on a date offset.
last_valid_index()Return index for last non-NA value or None, if no non-NA value is found.
le(other[, axis, level])Get Less than or equal to of dataframe and other, element-wise (binary operator
le).lt(other[, axis, level])Get Less than of dataframe and other, element-wise (binary operator
lt).map(func[, na_action])Apply a function to a Dataframe elementwise.
mask(cond[, other, inplace, axis, level])Replace values where the condition is True.
max([axis, skipna, numeric_only])Return the maximum of the values over the requested axis.
mean([axis, skipna, numeric_only])Return the mean of the values over the requested axis.
median([axis, skipna, numeric_only])Return the median of the values over the requested axis.
melt([id_vars, value_vars, var_name, ...])Unpivot a DataFrame from wide to long format, optionally leaving identifiers set.
memory_usage([index, deep])Return the memory usage of each column in bytes.
merge(how[, on])Merge selection rules using a specific type of join.
min([axis, skipna, numeric_only])Return the minimum of the values over the requested axis.
mod(other[, axis, level, fill_value])Get Modulo of dataframe and other, element-wise (binary operator
mod).mode([axis, numeric_only, dropna])Get the mode(s) of each element along the selected axis.
mul(other[, axis, level, fill_value])Get Multiplication of dataframe and other, element-wise (binary operator
mul).multiply(other[, axis, level, fill_value])Get Multiplication of dataframe and other, element-wise (binary operator
mul).ne(other[, axis, level])Get Not equal to of dataframe and other, element-wise (binary operator
ne).nlargest(n, columns[, keep])Return the first
nrows ordered bycolumnsin descending order.notna()Detect existing (non-missing) values.
notnull()DataFrame.notnull is an alias for DataFrame.notna.
nsmallest(n, columns[, keep])Return the first
nrows ordered bycolumnsin ascending order.nunique([axis, dropna])Count number of distinct elements in specified axis.
pad(*[, axis, inplace, limit, downcast])Fill NA/NaN values by propagating the last valid observation to next valid.
pct_change([periods, fill_method, limit, freq])Fractional change between the current and a prior element.
pipe(func, *args, **kwargs)Apply chainable functions that expect Series or DataFrames.
pivot(*, columns[, index, values])Return reshaped DataFrame organized by given index / column values.
pivot_table([values, index, columns, ...])Create a spreadsheet-style pivot table as a DataFrame.
plotalias of
PlotAccessorpop(item)Return item and drop from frame.
pow(other[, axis, level, fill_value])Get Exponential power of dataframe and other, element-wise (binary operator
pow).prod([axis, skipna, numeric_only, min_count])Return the product of the values over the requested axis.
product([axis, skipna, numeric_only, min_count])Return the product of the values over the requested axis.
quantile([q, axis, numeric_only, ...])Return values at the given quantile over requested axis.
query(expr, *[, inplace])Query the columns of a DataFrame with a boolean expression.
radd(other[, axis, level, fill_value])Get Addition of dataframe and other, element-wise (binary operator
radd).rank([axis, method, numeric_only, ...])Compute numerical data ranks (1 through n) along axis.
rdiv(other[, axis, level, fill_value])Get Floating division of dataframe and other, element-wise (binary operator
rtruediv).read(fileobj, **kwargs)Read a GBTIDL flag file and instantiate Flag object.
reindex([labels, index, columns, axis, ...])Conform DataFrame to new index with optional filling logic.
reindex_like(other[, method, copy, limit, ...])Return an object with matching indices as other object.
remove([id, tag])Remove (delete) a selection rule(s).
rename([mapper, index, columns, axis, copy, ...])Rename columns or index labels.
rename_axis([mapper, index, columns, axis, ...])Set the name of the axis for the index or columns.
reorder_levels(order[, axis])Rearrange index levels using input order.
replace([to_replace, value, inplace, limit, ...])Replace values given in
to_replacewithvalue.resample(rule[, axis, closed, label, ...])Resample time-series data.
reset_index([level, drop, inplace, ...])Reset the index, or a level of it.
rfloordiv(other[, axis, level, fill_value])Get Integer division of dataframe and other, element-wise (binary operator
rfloordiv).rmod(other[, axis, level, fill_value])Get Modulo of dataframe and other, element-wise (binary operator
rmod).rmul(other[, axis, level, fill_value])Get Multiplication of dataframe and other, element-wise (binary operator
rmul).rolling(window[, min_periods, center, ...])Provide rolling window calculations.
round([decimals])Round a DataFrame to a variable number of decimal places.
rpow(other[, axis, level, fill_value])Get Exponential power of dataframe and other, element-wise (binary operator
rpow).rsub(other[, axis, level, fill_value])Get Subtraction of dataframe and other, element-wise (binary operator
rsub).rtruediv(other[, axis, level, fill_value])Get Floating division of dataframe and other, element-wise (binary operator
rtruediv).sample([n, frac, replace, weights, ...])Return a random sample of items from an axis of object.
select_dtypes([include, exclude])Return a subset of the DataFrame's columns based on the column dtypes.
sem([axis, skipna, ddof, numeric_only])Return unbiased standard error of the mean over requested axis.
set_axis(labels, *[, axis, copy])Assign desired index to given axis.
set_flags(*[, copy, allows_duplicate_labels])Return a new object with updated flags.
set_index(keys, *[, drop, append, inplace, ...])Set the DataFrame index using existing columns.
shift([periods, freq, axis, fill_value, suffix])Shift index by desired number of periods with an optional time
freq.show()Print the current selection rules.
skew([axis, skipna, numeric_only])Return unbiased skew over requested axis.
sort_index(*[, axis, level, ascending, ...])Sort object by labels (along an axis).
sort_values(by, *[, axis, ascending, ...])Sort by the values along either axis.
sparsealias of
SparseFrameAccessorsqueeze([axis])Squeeze 1 dimensional axis objects into scalars.
stack([level, dropna, sort, future_stack])Stack the prescribed level(s) from columns to index.
std([axis, skipna, ddof, numeric_only])Return sample standard deviation over requested axis.
sub(other[, axis, level, fill_value])Get Subtraction of dataframe and other, element-wise (binary operator
sub).subtract(other[, axis, level, fill_value])Get Subtraction of dataframe and other, element-wise (binary operator
sub).sum([axis, skipna, numeric_only, min_count])Return the sum of the values over the requested axis.
swapaxes(axis1, axis2[, copy])Interchange axes and swap values axes appropriately.
swaplevel([i, j, axis])Swap levels i and j in a
MultiIndex.tail([n])Return the last
nrows.take(indices[, axis])Return the elements in the given positional indices along an axis.
to_clipboard([excel, sep])Copy object to the system clipboard.
to_csv([path_or_buf, sep, na_rep, ...])Write object to a comma-separated values (csv) file.
to_dict([orient, into, index])Convert the DataFrame to a dictionary.
to_excel(excel_writer[, sheet_name, na_rep, ...])Write object to an Excel sheet.
to_feather(path, **kwargs)Write a DataFrame to the binary Feather format.
to_gbq(destination_table[, project_id, ...])Write a DataFrame to a Google BigQuery table.
to_hdf(path_or_buf, key[, mode, complevel, ...])Write the contained data to an HDF5 file using HDFStore.
to_html([buf, columns, col_space, header, ...])Render a DataFrame as an HTML table.
to_json([path_or_buf, orient, date_format, ...])Convert the object to a JSON string.
to_latex([buf, columns, header, index, ...])Render object to a LaTeX tabular, longtable, or nested table.
to_markdown([buf, mode, index, storage_options])Print DataFrame in Markdown-friendly format.
to_numpy([dtype, copy, na_value])Convert the DataFrame to a NumPy array.
to_orc([path, engine, index, engine_kwargs])Write a DataFrame to the ORC format.
to_parquet([path, engine, compression, ...])Write a DataFrame to the binary parquet format.
to_period([freq, axis, copy])Convert DataFrame from DatetimeIndex to PeriodIndex.
to_pickle(path[, compression, protocol, ...])Pickle (serialize) object to file.
to_records([index, column_dtypes, index_dtypes])Convert DataFrame to a NumPy record array.
to_sql(name, con, *[, schema, if_exists, ...])Write records stored in a DataFrame to a SQL database.
to_stata(path, *[, convert_dates, ...])Export DataFrame object to Stata dta format.
to_string([buf, columns, col_space, header, ...])Render a DataFrame to a console-friendly tabular output.
to_timestamp([freq, how, axis, copy])Cast to DatetimeIndex of timestamps, at beginning of period.
to_xarray()Return an xarray object from the pandas object.
to_xml([path_or_buffer, index, root_name, ...])Render a DataFrame to an XML document.
transform(func[, axis])Call
funcon self producing a DataFrame with the same axis shape as self.transpose(*args[, copy])Transpose index and columns.
truediv(other[, axis, level, fill_value])Get Floating division of dataframe and other, element-wise (binary operator
truediv).truncate([before, after, axis, copy])Truncate a Series or DataFrame before and after some index value.
tz_convert(tz[, axis, level, copy])Convert tz-aware axis to target time zone.
tz_localize(tz[, axis, level, copy, ...])Localize tz-naive index of a Series or DataFrame to target time zone.
unstack([level, fill_value, sort])Pivot a level of the (necessarily hierarchical) index labels.
update(other[, join, overwrite, ...])Modify in place using non-NA values from another DataFrame.
value_counts([subset, normalize, sort, ...])Return a Series containing the frequency of each distinct row in the Dataframe.
var([axis, skipna, ddof, numeric_only])Return unbiased variance over requested axis.
where(cond[, other, inplace, axis, level])Replace values where the condition is False.
xs(key[, axis, level, drop_level])Return cross-section from the Series/DataFrame.
- flag(tag=None, **kwargs)[source]#
Add one or more exact flag rules, e.g.,
key1 = value1, key2 = value2, ...Ifvalueis array-like then a match to any of the array members will be flagged. For instanceflag(object=['3C273', 'NGC1234'])will select data for either of those objects andflag(ifnum=[0,2])will flag IF number 0 or IF number 2. Channels for selected data can be flagged using keywordchannel, e.g.,flag(object='MBM12',channel=[0,23])will flag channels 0 through 23 inclusive for object MBM12.- Parameters:
- tagstr
An identifying tag by which the rule may be referred to later. If None, a randomly generated tag will be created.
- keystr
The key (SDFITS column name or other supported key)
- valueany
The value to select
- flag_channel(channel, tag=None, **kwargs)[source]#
Flag channels and/or channel ranges for all data. These are NOT used in
final()but rather will be used to create a mask for flagging. Single arrays/tuples will be treated as channel lists; nested arrays will be treated as *inclusive ranges. For instance:`` # flag channel 24 flag_channel(24) # flag channels 1 and 10 flag_channel([1,10]) # flags channels 1 thru 10 inclusive flag_channel([[1,10]]) # flag channel ranges 1 thru 10 and 47 thru 56 inclusive, and channel 75 flag_channel([[1,10], [47,56], 75)]) # tuples also work, though can be harder for a human to read flag_channel(((1,10), [47,56], 75)) ``
Note : channel numbers start at zero
- Parameters:
- channelnumber, or array-like
The channels to flag
- Returns:
- None.
- flag_range(tag=None, **kwargs)[source]#
Flag a range of inclusive values for a given key(s). e.g.,
key1 = (v1,v2), key2 = (v3,v4), ...will flag datav1 <= data1 <= v2, v3 <= data2 <= v4, ... ` Upper and lower limits may be given by setting one of the tuple values to None. e.g., `key1 = (None,v1)for an upper limitdata1 <= v1andkey1 = (v1,None)for a lower limitdata >=v1. Lower limits may also be specified by a one-element tuplekey1 = (v1,).- Parameters:
- tagstr, optional
An identifying tag by which the rule may be referred to later. If None, a randomly generated tag will be created.
- keystr
The key (SDFITS column name or other supported key)
- valuearray-like
Tuple or list giving the lower and upper limits of the range.
- Returns:
- None.
- flag_within(tag=None, **kwargs)[source]#
Flag a value within a plus or minus for a given key(s). e.g.
key1 = [value1,epsilon1], key2 = [value2,epsilon2], ...Will select datavalue1-epsilon1 <= data1 <= value1+epsilon1,value2-epsilon2 <= data2 <= value2+epsilon2,...- Parameters:
- tagstr, optional
An identifying tag by which the rule may be referred to later. If None, a randomly generated tag will be created.
- keystr
The key (SDFITS column name or other supported key)
- valuearray-like
Tuple or list giving the value and epsilon
- Returns:
- None.
- read(fileobj, **kwargs)[source]#
Read a GBTIDL flag file and instantiate Flag object.
- Parameters:
- fileobjstr, file-like or
pathlib.Path File to read. If a file object, must be opened in a readable mode.
- **kwargsdict
Extra keyword arguments to apply to the flag rule. (This is mainly for internal use.)
- fileobjstr, file-like or
- Returns:
- None.
- class dysh.util.selection.Selection(initobj, aliases={'dec': 'crval3', 'elevation': 'elevatio', 'freq': 'crval1', 'gallat': 'crval3', 'gallon': 'crval2', 'glat': 'crval3', 'glon': 'crval2', 'pol': 'plnum', 'ra': 'crval2', 'source': 'object', 'subref': 'subref_state'}, **kwargs)[source]#
Bases:
SelectionBaseThis class contains the methods for creating rules to select data from an SDFITS object. Data (rows) can be selected using any column name in the input SDFITS object. Exact selection, range selection, upper/lower limit selection, and any-of selection are all supported.
Users create selection rules by specifying keyword (SDFITS columns) and value(s) to be selected. Briefly, the selection methods are:
select()- Select exact valuesselect_range()- Select ranges of valuesselect_within()- Select a value +/- epsilonselect_channel()- Select channels or ranges of channelsThe Selection object maintains a DataFrame for each selection rule created by the user. The
final()selection is the logical OR of these rules. Users can examine the current selections withshow()which will show the current rules and how many rows each rule selects from the unfiltered data.Aliases of keywords are supported. The user may add an alias for an existing SDFITS column with
alias(). Some defaultaliases()have been defined.- Attributes:
TThe transpose of the DataFrame.
aliasesThe aliases that may be used to refer to SDFITS columns.
atAccess a single value for a row/column label pair.
attrsDictionary of global attributes of this dataset.
axesReturn a list representing the axes of the DataFrame.
- columns
The column labels of the DataFrame.
>>> df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]}) >>> df A B 0 1 3 1 2 4 >>> df.columns Index(['A', 'B'], dtype='object')
dtypesReturn the dtypes in the DataFrame.
emptyIndicator whether Series/DataFrame is empty.
finalCreate the final selection.
flagsGet the properties associated with this pandas object.
iatAccess a single value for a row/column pair by integer position.
ilocPurely integer-location based indexing for selection by position.
- index
The index (row labels) of the DataFrame.
The index of a DataFrame is a series of labels that identify each row. The labels can be integers, strings, or any other hashable type. The index is used for label-based access and alignment, and can be accessed or modified using this attribute.
- pandas.Index
The index labels of the DataFrame.
DataFrame.columns : The column labels of the DataFrame. DataFrame.to_numpy : Convert the DataFrame to a NumPy array.
>>> df = pd.DataFrame({'Name': ['Alice', 'Bob', 'Aritra'], ... 'Age': [25, 30, 35], ... 'Location': ['Seattle', 'New York', 'Kona']}, ... index=([10, 20, 30])) >>> df.index Index([10, 20, 30], dtype='int64')
In this example, we create a DataFrame with 3 rows and 3 columns, including Name, Age, and Location information. We set the index labels to be the integers 10, 20, and 30. We then access the
indexattribute of the DataFrame, which returns anIndexobject containing the index labels.>>> df.index = [100, 200, 300] >>> df Name Age Location 100 Alice 25 Seattle 200 Bob 30 New York 300 Aritra 35 Kona
In this example, we modify the index labels of the DataFrame by assigning a new list of labels to the
indexattribute. The DataFrame is then updated with the new labels, and the output shows the modified DataFrame.locAccess a group of rows and columns by label(s) or a boolean array.
ndimReturn an int representing the number of axes / array dimensions.
shapeReturn a tuple representing the dimensionality of the DataFrame.
sizeReturn an int representing the number of elements in this object.
styleReturns a Styler object.
valuesReturn a Numpy representation of the DataFrame.
Methods
abs()Return a Series/DataFrame with absolute numeric value of each element.
add(other[, axis, level, fill_value])Get Addition of dataframe and other, element-wise (binary operator
add).add_prefix(prefix[, axis])Prefix labels with string
prefix.add_suffix(suffix[, axis])Suffix labels with string
suffix.agg([func, axis])Aggregate using one or more operations over the specified axis.
aggregate([func, axis])Aggregate using one or more operations over the specified axis.
alias(aliases)Alias a set of keywords to existing columns.
align(other[, join, axis, level, copy, ...])Align two objects on their axes with the specified join method.
all([axis, bool_only, skipna])Return whether all elements are True, potentially over an axis.
any(*[, axis, bool_only, skipna])Return whether any element is True, potentially over an axis.
apply(func[, axis, raw, result_type, args, ...])Apply a function along an axis of the DataFrame.
applymap(func[, na_action])Apply a function to a Dataframe elementwise.
asfreq(freq[, method, how, normalize, ...])Convert time series to specified frequency.
asof(where[, subset])Return the last row(s) without any NaNs before
where.assign(**kwargs)Assign new columns to a DataFrame.
astype(dtype[, copy, errors])Cast a pandas object to a specified dtype
dtype.at_time(time[, asof, axis])Select values at particular time of day (e.g., 9:30AM).
backfill(*[, axis, inplace, limit, downcast])Fill NA/NaN values by using the next valid observation to fill the gap.
between_time(start_time, end_time[, ...])Select values between particular times of the day (e.g., 9:00-9:30 AM).
bfill(*[, axis, inplace, limit, downcast])Fill NA/NaN values by using the next valid observation to fill the gap.
bool()Return the bool of a single element Series or DataFrame.
boxplot([column, by, ax, fontsize, rot, ...])Make a box plot from DataFrame columns.
clear()Remove all selection rules
clip([lower, upper, axis, inplace])Trim values at input threshold(s).
columns_selected()The names of any columns which were used in a selection rule
combine(other, func[, fill_value, overwrite])Perform column-wise combine with another DataFrame.
combine_first(other)Update null elements with value in the same location in
other.compare(other[, align_axis, keep_shape, ...])Compare to another DataFrame and show the differences.
convert_dtypes([infer_objects, ...])Convert columns to the best possible dtypes using dtypes supporting
pd.NA.copy([deep])Make a copy of this object's indices and data.
corr([method, min_periods, numeric_only])Compute pairwise correlation of columns, excluding NA/null values.
corrwith(other[, axis, drop, method, ...])Compute pairwise correlation.
count([axis, numeric_only])Count non-NA cells for each column or row.
cov([min_periods, ddof, numeric_only])Compute pairwise covariance of columns, excluding NA/null values.
cummax([axis, skipna])Return cumulative maximum over a DataFrame or Series axis.
cummin([axis, skipna])Return cumulative minimum over a DataFrame or Series axis.
cumprod([axis, skipna])Return cumulative product over a DataFrame or Series axis.
cumsum([axis, skipna])Return cumulative sum over a DataFrame or Series axis.
describe([percentiles, include, exclude])Generate descriptive statistics.
diff([periods, axis])First discrete difference of element.
div(other[, axis, level, fill_value])Get Floating division of dataframe and other, element-wise (binary operator
truediv).divide(other[, axis, level, fill_value])Get Floating division of dataframe and other, element-wise (binary operator
truediv).dot(other)Compute the matrix multiplication between the DataFrame and other.
drop([labels, axis, index, columns, level, ...])Drop specified labels from rows or columns.
drop_duplicates([subset, keep, inplace, ...])Return DataFrame with duplicate rows removed.
droplevel(level[, axis])Return Series/DataFrame with requested index / column level(s) removed.
dropna(*[, axis, how, thresh, subset, ...])Remove missing values.
duplicated([subset, keep])Return boolean Series denoting duplicate rows.
eq(other[, axis, level])Get Equal to of dataframe and other, element-wise (binary operator
eq).equals(other)Test whether two objects contain the same elements.
eval(expr, *[, inplace])Evaluate a string describing operations on DataFrame columns.
ewm([com, span, halflife, alpha, ...])Provide exponentially weighted (EW) calculations.
expanding([min_periods, axis, method])Provide expanding window calculations.
explode(column[, ignore_index])Transform each element of a list-like to a row, replicating index values.
ffill(*[, axis, inplace, limit, downcast])Fill NA/NaN values by propagating the last valid observation to next valid.
fillna([value, method, axis, inplace, ...])Fill NA/NaN values using the specified method.
filter([items, like, regex, axis])Subset the dataframe rows or columns according to the specified index labels.
first(offset)Select initial periods of time series data based on a date offset.
first_valid_index()Return index for first non-NA value or None, if no non-NA value is found.
floordiv(other[, axis, level, fill_value])Get Integer division of dataframe and other, element-wise (binary operator
floordiv).from_dict(data[, orient, dtype, columns])Construct DataFrame from dict of array-like or dicts.
from_records(data[, index, exclude, ...])Convert structured or record ndarray to DataFrame.
ge(other[, axis, level])Get Greater than or equal to of dataframe and other, element-wise (binary operator
ge).get(key)Get the selection/flag rule by its ID
groupby([by, axis, level, as_index, sort, ...])Group DataFrame using a mapper or by a Series of columns.
gt(other[, axis, level])Get Greater than of dataframe and other, element-wise (binary operator
gt).head([n])Return the first
nrows.hist([column, by, grid, xlabelsize, xrot, ...])Make a histogram of the DataFrame's columns.
idxmax([axis, skipna, numeric_only])Return index of first occurrence of maximum over requested axis.
idxmin([axis, skipna, numeric_only])Return index of first occurrence of minimum over requested axis.
infer_objects([copy])Attempt to infer better dtypes for object columns.
info([verbose, buf, max_cols, memory_usage, ...])Print a concise summary of a DataFrame.
insert(loc, column, value[, allow_duplicates])Insert column into DataFrame at specified location.
interpolate([method, axis, limit, inplace, ...])Fill NaN values using an interpolation method.
isetitem(loc, value)Set the given value in the column with position
loc.isin(values)Whether each element in the DataFrame is contained in values.
isna()Detect missing values.
isnull()DataFrame.isnull is an alias for DataFrame.isna.
items()Iterate over (column name, Series) pairs.
iterrows()Iterate over DataFrame rows as (index, Series) pairs.
itertuples([index, name])Iterate over DataFrame rows as namedtuples.
join(other[, on, how, lsuffix, rsuffix, ...])Join columns of another DataFrame.
keys()Get the 'info axis' (see Indexing for more).
kurt([axis, skipna, numeric_only])Return unbiased kurtosis over requested axis.
kurtosis([axis, skipna, numeric_only])Return unbiased kurtosis over requested axis.
last(offset)Select final periods of time series data based on a date offset.
last_valid_index()Return index for last non-NA value or None, if no non-NA value is found.
le(other[, axis, level])Get Less than or equal to of dataframe and other, element-wise (binary operator
le).lt(other[, axis, level])Get Less than of dataframe and other, element-wise (binary operator
lt).map(func[, na_action])Apply a function to a Dataframe elementwise.
mask(cond[, other, inplace, axis, level])Replace values where the condition is True.
max([axis, skipna, numeric_only])Return the maximum of the values over the requested axis.
mean([axis, skipna, numeric_only])Return the mean of the values over the requested axis.
median([axis, skipna, numeric_only])Return the median of the values over the requested axis.
melt([id_vars, value_vars, var_name, ...])Unpivot a DataFrame from wide to long format, optionally leaving identifiers set.
memory_usage([index, deep])Return the memory usage of each column in bytes.
merge(how[, on])Merge selection rules using a specific type of join.
min([axis, skipna, numeric_only])Return the minimum of the values over the requested axis.
mod(other[, axis, level, fill_value])Get Modulo of dataframe and other, element-wise (binary operator
mod).mode([axis, numeric_only, dropna])Get the mode(s) of each element along the selected axis.
mul(other[, axis, level, fill_value])Get Multiplication of dataframe and other, element-wise (binary operator
mul).multiply(other[, axis, level, fill_value])Get Multiplication of dataframe and other, element-wise (binary operator
mul).ne(other[, axis, level])Get Not equal to of dataframe and other, element-wise (binary operator
ne).nlargest(n, columns[, keep])Return the first
nrows ordered bycolumnsin descending order.notna()Detect existing (non-missing) values.
notnull()DataFrame.notnull is an alias for DataFrame.notna.
nsmallest(n, columns[, keep])Return the first
nrows ordered bycolumnsin ascending order.nunique([axis, dropna])Count number of distinct elements in specified axis.
pad(*[, axis, inplace, limit, downcast])Fill NA/NaN values by propagating the last valid observation to next valid.
pct_change([periods, fill_method, limit, freq])Fractional change between the current and a prior element.
pipe(func, *args, **kwargs)Apply chainable functions that expect Series or DataFrames.
pivot(*, columns[, index, values])Return reshaped DataFrame organized by given index / column values.
pivot_table([values, index, columns, ...])Create a spreadsheet-style pivot table as a DataFrame.
plotalias of
PlotAccessorpop(item)Return item and drop from frame.
pow(other[, axis, level, fill_value])Get Exponential power of dataframe and other, element-wise (binary operator
pow).prod([axis, skipna, numeric_only, min_count])Return the product of the values over the requested axis.
product([axis, skipna, numeric_only, min_count])Return the product of the values over the requested axis.
quantile([q, axis, numeric_only, ...])Return values at the given quantile over requested axis.
query(expr, *[, inplace])Query the columns of a DataFrame with a boolean expression.
radd(other[, axis, level, fill_value])Get Addition of dataframe and other, element-wise (binary operator
radd).rank([axis, method, numeric_only, ...])Compute numerical data ranks (1 through n) along axis.
rdiv(other[, axis, level, fill_value])Get Floating division of dataframe and other, element-wise (binary operator
rtruediv).reindex([labels, index, columns, axis, ...])Conform DataFrame to new index with optional filling logic.
reindex_like(other[, method, copy, limit, ...])Return an object with matching indices as other object.
remove([id, tag])Remove (delete) a selection rule(s).
rename([mapper, index, columns, axis, copy, ...])Rename columns or index labels.
rename_axis([mapper, index, columns, axis, ...])Set the name of the axis for the index or columns.
reorder_levels(order[, axis])Rearrange index levels using input order.
replace([to_replace, value, inplace, limit, ...])Replace values given in
to_replacewithvalue.resample(rule[, axis, closed, label, ...])Resample time-series data.
reset_index([level, drop, inplace, ...])Reset the index, or a level of it.
rfloordiv(other[, axis, level, fill_value])Get Integer division of dataframe and other, element-wise (binary operator
rfloordiv).rmod(other[, axis, level, fill_value])Get Modulo of dataframe and other, element-wise (binary operator
rmod).rmul(other[, axis, level, fill_value])Get Multiplication of dataframe and other, element-wise (binary operator
rmul).rolling(window[, min_periods, center, ...])Provide rolling window calculations.
round([decimals])Round a DataFrame to a variable number of decimal places.
rpow(other[, axis, level, fill_value])Get Exponential power of dataframe and other, element-wise (binary operator
rpow).rsub(other[, axis, level, fill_value])Get Subtraction of dataframe and other, element-wise (binary operator
rsub).rtruediv(other[, axis, level, fill_value])Get Floating division of dataframe and other, element-wise (binary operator
rtruediv).sample([n, frac, replace, weights, ...])Return a random sample of items from an axis of object.
select([tag])Add one or more exact selection rules, e.g.,
key1 = value1, key2 = value2, ...Ifvalueis array-like then a match to any of the array members will be selected.select_channel(chan[, tag])Select channels and/or channel ranges.
select_dtypes([include, exclude])Return a subset of the DataFrame's columns based on the column dtypes.
select_range([tag])Select a range of inclusive values for a given key(s).
select_within([tag])Select a value within a plus or minus for a given key(s).
sem([axis, skipna, ddof, numeric_only])Return unbiased standard error of the mean over requested axis.
set_axis(labels, *[, axis, copy])Assign desired index to given axis.
set_flags(*[, copy, allows_duplicate_labels])Return a new object with updated flags.
set_index(keys, *[, drop, append, inplace, ...])Set the DataFrame index using existing columns.
shift([periods, freq, axis, fill_value, suffix])Shift index by desired number of periods with an optional time
freq.show()Print the current selection rules.
skew([axis, skipna, numeric_only])Return unbiased skew over requested axis.
sort_index(*[, axis, level, ascending, ...])Sort object by labels (along an axis).
sort_values(by, *[, axis, ascending, ...])Sort by the values along either axis.
sparsealias of
SparseFrameAccessorsqueeze([axis])Squeeze 1 dimensional axis objects into scalars.
stack([level, dropna, sort, future_stack])Stack the prescribed level(s) from columns to index.
std([axis, skipna, ddof, numeric_only])Return sample standard deviation over requested axis.
sub(other[, axis, level, fill_value])Get Subtraction of dataframe and other, element-wise (binary operator
sub).subtract(other[, axis, level, fill_value])Get Subtraction of dataframe and other, element-wise (binary operator
sub).sum([axis, skipna, numeric_only, min_count])Return the sum of the values over the requested axis.
swapaxes(axis1, axis2[, copy])Interchange axes and swap values axes appropriately.
swaplevel([i, j, axis])Swap levels i and j in a
MultiIndex.tail([n])Return the last
nrows.take(indices[, axis])Return the elements in the given positional indices along an axis.
to_clipboard([excel, sep])Copy object to the system clipboard.
to_csv([path_or_buf, sep, na_rep, ...])Write object to a comma-separated values (csv) file.
to_dict([orient, into, index])Convert the DataFrame to a dictionary.
to_excel(excel_writer[, sheet_name, na_rep, ...])Write object to an Excel sheet.
to_feather(path, **kwargs)Write a DataFrame to the binary Feather format.
to_gbq(destination_table[, project_id, ...])Write a DataFrame to a Google BigQuery table.
to_hdf(path_or_buf, key[, mode, complevel, ...])Write the contained data to an HDF5 file using HDFStore.
to_html([buf, columns, col_space, header, ...])Render a DataFrame as an HTML table.
to_json([path_or_buf, orient, date_format, ...])Convert the object to a JSON string.
to_latex([buf, columns, header, index, ...])Render object to a LaTeX tabular, longtable, or nested table.
to_markdown([buf, mode, index, storage_options])Print DataFrame in Markdown-friendly format.
to_numpy([dtype, copy, na_value])Convert the DataFrame to a NumPy array.
to_orc([path, engine, index, engine_kwargs])Write a DataFrame to the ORC format.
to_parquet([path, engine, compression, ...])Write a DataFrame to the binary parquet format.
to_period([freq, axis, copy])Convert DataFrame from DatetimeIndex to PeriodIndex.
to_pickle(path[, compression, protocol, ...])Pickle (serialize) object to file.
to_records([index, column_dtypes, index_dtypes])Convert DataFrame to a NumPy record array.
to_sql(name, con, *[, schema, if_exists, ...])Write records stored in a DataFrame to a SQL database.
to_stata(path, *[, convert_dates, ...])Export DataFrame object to Stata dta format.
to_string([buf, columns, col_space, header, ...])Render a DataFrame to a console-friendly tabular output.
to_timestamp([freq, how, axis, copy])Cast to DatetimeIndex of timestamps, at beginning of period.
to_xarray()Return an xarray object from the pandas object.
to_xml([path_or_buffer, index, root_name, ...])Render a DataFrame to an XML document.
transform(func[, axis])Call
funcon self producing a DataFrame with the same axis shape as self.transpose(*args[, copy])Transpose index and columns.
truediv(other[, axis, level, fill_value])Get Floating division of dataframe and other, element-wise (binary operator
truediv).truncate([before, after, axis, copy])Truncate a Series or DataFrame before and after some index value.
tz_convert(tz[, axis, level, copy])Convert tz-aware axis to target time zone.
tz_localize(tz[, axis, level, copy, ...])Localize tz-naive index of a Series or DataFrame to target time zone.
unstack([level, fill_value, sort])Pivot a level of the (necessarily hierarchical) index labels.
update(other[, join, overwrite, ...])Modify in place using non-NA values from another DataFrame.
value_counts([subset, normalize, sort, ...])Return a Series containing the frequency of each distinct row in the Dataframe.
var([axis, skipna, ddof, numeric_only])Return unbiased variance over requested axis.
where(cond[, other, inplace, axis, level])Replace values where the condition is False.
xs(key[, axis, level, drop_level])Return cross-section from the Series/DataFrame.
- select(tag=None, **kwargs)[source]#
Add one or more exact selection rules, e.g.,
key1 = value1, key2 = value2, ...Ifvalueis array-like then a match to any of the array members will be selected. For instanceselect(object=['3C273', 'NGC1234'])will select data for either of those objects andselect(ifnum=[0,2])will select IF number 0 or IF number 2.- Parameters:
- tagstr
An identifying tag by which the rule may be referred to later. If None, a randomly generated tag will be created.
- keystr
The key (SDFITS column name or other supported key)
- valueany
The value to select
- select_channel(chan, tag=None)[source]#
Select channels and/or channel ranges. These are NOT used in
final()but rather will be used to create a mask for calibration or flagging. Single arrays/tuples will be treated as channel lists; nested arrays will be treated as inclusive ranges. For instance:`` # select channel 24 select_channel(24) # selects channels 1 and 10 select_channel([1,10]) # selects channels 1 thru 10 inclusive select_channel([[1,10]]) # select channel ranges 1 thru 10 and 47 thru 56 inclusive, and channel 75 select_channel([[1,10], [47,56], 75)]) # tuples also work, though can be harder for a human to read select_channel(((1,10), [47,56], 75)) ``
Note : channel numbers start at zero.
- Parameters:
- channumber, or array-like
The channels to select
- Returns:
- None.
- select_range(tag=None, **kwargs)[source]#
Select a range of inclusive values for a given key(s). e.g.,
key1 = (v1,v2), key2 = (v3,v4), ...will select datav1 <= data1 <= v2, v3 <= data2 <= v4, ... ` Upper and lower limits may be given by setting one of the tuple values to None. e.g., `key1 = (None,v1)for an upper limitdata1 <= v1andkey1 = (v1,None)for a lower limitdata >=v1. Lower limits may also be specified by a one-element tuplekey1 = (v1,).- Parameters:
- tagstr, optional
An identifying tag by which the rule may be referred to later. If None, a randomly generated tag will be created.
- keystr
The key (SDFITS column name or other supported key)
- valuearray-like
Tuple or list giving the lower and upper limits of the range.
- Returns:
- None.
- select_within(tag=None, **kwargs)[source]#
Select a value within a plus or minus for a given key(s). e.g.
key1 = [value1,epsilon1], key2 = [value2,epsilon2], ...Will select datavalue1-epsilon1 <= data1 <= value1+epsilon1,value2-epsilon2 <= data2 <= value2+epsilon2,...- Parameters:
- tagstr, optional
An identifying tag by which the rule may be referred to later. If None, a randomly generated tag will be created.
- keystr
The key (SDFITS column name or other supported key)
- valuearray-like
Tuple or list giving the value and epsilon
- Returns:
- None.
- class dysh.util.selection.SelectionBase(initobj, aliases={'dec': 'crval3', 'elevation': 'elevatio', 'freq': 'crval1', 'gallat': 'crval3', 'gallon': 'crval2', 'glat': 'crval3', 'glon': 'crval2', 'pol': 'plnum', 'ra': 'crval2', 'source': 'object', 'subref': 'subref_state'}, **kwargs)[source]#
Bases:
DataFrameThis class is the base class for selection and flagging. Selection and flagging are both kinds of data selection, so
SelectionBasecan encapsulate most necessary functionality. Derived classes implement specific named methods e.g. select_channel, flag_channel that will simply call the base class methods.- Attributes:
TThe transpose of the DataFrame.
aliasesThe aliases that may be used to refer to SDFITS columns.
atAccess a single value for a row/column label pair.
attrsDictionary of global attributes of this dataset.
axesReturn a list representing the axes of the DataFrame.
- columns
The column labels of the DataFrame.
>>> df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]}) >>> df A B 0 1 3 1 2 4 >>> df.columns Index(['A', 'B'], dtype='object')
dtypesReturn the dtypes in the DataFrame.
emptyIndicator whether Series/DataFrame is empty.
finalCreate the final selection.
flagsGet the properties associated with this pandas object.
iatAccess a single value for a row/column pair by integer position.
ilocPurely integer-location based indexing for selection by position.
- index
The index (row labels) of the DataFrame.
The index of a DataFrame is a series of labels that identify each row. The labels can be integers, strings, or any other hashable type. The index is used for label-based access and alignment, and can be accessed or modified using this attribute.
- pandas.Index
The index labels of the DataFrame.
DataFrame.columns : The column labels of the DataFrame. DataFrame.to_numpy : Convert the DataFrame to a NumPy array.
>>> df = pd.DataFrame({'Name': ['Alice', 'Bob', 'Aritra'], ... 'Age': [25, 30, 35], ... 'Location': ['Seattle', 'New York', 'Kona']}, ... index=([10, 20, 30])) >>> df.index Index([10, 20, 30], dtype='int64')
In this example, we create a DataFrame with 3 rows and 3 columns, including Name, Age, and Location information. We set the index labels to be the integers 10, 20, and 30. We then access the
indexattribute of the DataFrame, which returns anIndexobject containing the index labels.>>> df.index = [100, 200, 300] >>> df Name Age Location 100 Alice 25 Seattle 200 Bob 30 New York 300 Aritra 35 Kona
In this example, we modify the index labels of the DataFrame by assigning a new list of labels to the
indexattribute. The DataFrame is then updated with the new labels, and the output shows the modified DataFrame.locAccess a group of rows and columns by label(s) or a boolean array.
ndimReturn an int representing the number of axes / array dimensions.
shapeReturn a tuple representing the dimensionality of the DataFrame.
sizeReturn an int representing the number of elements in this object.
styleReturns a Styler object.
valuesReturn a Numpy representation of the DataFrame.
Methods
abs()Return a Series/DataFrame with absolute numeric value of each element.
add(other[, axis, level, fill_value])Get Addition of dataframe and other, element-wise (binary operator
add).add_prefix(prefix[, axis])Prefix labels with string
prefix.add_suffix(suffix[, axis])Suffix labels with string
suffix.agg([func, axis])Aggregate using one or more operations over the specified axis.
aggregate([func, axis])Aggregate using one or more operations over the specified axis.
alias(aliases)Alias a set of keywords to existing columns.
align(other[, join, axis, level, copy, ...])Align two objects on their axes with the specified join method.
all([axis, bool_only, skipna])Return whether all elements are True, potentially over an axis.
any(*[, axis, bool_only, skipna])Return whether any element is True, potentially over an axis.
apply(func[, axis, raw, result_type, args, ...])Apply a function along an axis of the DataFrame.
applymap(func[, na_action])Apply a function to a Dataframe elementwise.
asfreq(freq[, method, how, normalize, ...])Convert time series to specified frequency.
asof(where[, subset])Return the last row(s) without any NaNs before
where.assign(**kwargs)Assign new columns to a DataFrame.
astype(dtype[, copy, errors])Cast a pandas object to a specified dtype
dtype.at_time(time[, asof, axis])Select values at particular time of day (e.g., 9:30AM).
backfill(*[, axis, inplace, limit, downcast])Fill NA/NaN values by using the next valid observation to fill the gap.
between_time(start_time, end_time[, ...])Select values between particular times of the day (e.g., 9:00-9:30 AM).
bfill(*[, axis, inplace, limit, downcast])Fill NA/NaN values by using the next valid observation to fill the gap.
bool()Return the bool of a single element Series or DataFrame.
boxplot([column, by, ax, fontsize, rot, ...])Make a box plot from DataFrame columns.
clear()Remove all selection rules
clip([lower, upper, axis, inplace])Trim values at input threshold(s).
The names of any columns which were used in a selection rule
combine(other, func[, fill_value, overwrite])Perform column-wise combine with another DataFrame.
combine_first(other)Update null elements with value in the same location in
other.compare(other[, align_axis, keep_shape, ...])Compare to another DataFrame and show the differences.
convert_dtypes([infer_objects, ...])Convert columns to the best possible dtypes using dtypes supporting
pd.NA.copy([deep])Make a copy of this object's indices and data.
corr([method, min_periods, numeric_only])Compute pairwise correlation of columns, excluding NA/null values.
corrwith(other[, axis, drop, method, ...])Compute pairwise correlation.
count([axis, numeric_only])Count non-NA cells for each column or row.
cov([min_periods, ddof, numeric_only])Compute pairwise covariance of columns, excluding NA/null values.
cummax([axis, skipna])Return cumulative maximum over a DataFrame or Series axis.
cummin([axis, skipna])Return cumulative minimum over a DataFrame or Series axis.
cumprod([axis, skipna])Return cumulative product over a DataFrame or Series axis.
cumsum([axis, skipna])Return cumulative sum over a DataFrame or Series axis.
describe([percentiles, include, exclude])Generate descriptive statistics.
diff([periods, axis])First discrete difference of element.
div(other[, axis, level, fill_value])Get Floating division of dataframe and other, element-wise (binary operator
truediv).divide(other[, axis, level, fill_value])Get Floating division of dataframe and other, element-wise (binary operator
truediv).dot(other)Compute the matrix multiplication between the DataFrame and other.
drop([labels, axis, index, columns, level, ...])Drop specified labels from rows or columns.
drop_duplicates([subset, keep, inplace, ...])Return DataFrame with duplicate rows removed.
droplevel(level[, axis])Return Series/DataFrame with requested index / column level(s) removed.
dropna(*[, axis, how, thresh, subset, ...])Remove missing values.
duplicated([subset, keep])Return boolean Series denoting duplicate rows.
eq(other[, axis, level])Get Equal to of dataframe and other, element-wise (binary operator
eq).equals(other)Test whether two objects contain the same elements.
eval(expr, *[, inplace])Evaluate a string describing operations on DataFrame columns.
ewm([com, span, halflife, alpha, ...])Provide exponentially weighted (EW) calculations.
expanding([min_periods, axis, method])Provide expanding window calculations.
explode(column[, ignore_index])Transform each element of a list-like to a row, replicating index values.
ffill(*[, axis, inplace, limit, downcast])Fill NA/NaN values by propagating the last valid observation to next valid.
fillna([value, method, axis, inplace, ...])Fill NA/NaN values using the specified method.
filter([items, like, regex, axis])Subset the dataframe rows or columns according to the specified index labels.
first(offset)Select initial periods of time series data based on a date offset.
first_valid_index()Return index for first non-NA value or None, if no non-NA value is found.
floordiv(other[, axis, level, fill_value])Get Integer division of dataframe and other, element-wise (binary operator
floordiv).from_dict(data[, orient, dtype, columns])Construct DataFrame from dict of array-like or dicts.
from_records(data[, index, exclude, ...])Convert structured or record ndarray to DataFrame.
ge(other[, axis, level])Get Greater than or equal to of dataframe and other, element-wise (binary operator
ge).get(key)Get the selection/flag rule by its ID
groupby([by, axis, level, as_index, sort, ...])Group DataFrame using a mapper or by a Series of columns.
gt(other[, axis, level])Get Greater than of dataframe and other, element-wise (binary operator
gt).head([n])Return the first
nrows.hist([column, by, grid, xlabelsize, xrot, ...])Make a histogram of the DataFrame's columns.
idxmax([axis, skipna, numeric_only])Return index of first occurrence of maximum over requested axis.
idxmin([axis, skipna, numeric_only])Return index of first occurrence of minimum over requested axis.
infer_objects([copy])Attempt to infer better dtypes for object columns.
info([verbose, buf, max_cols, memory_usage, ...])Print a concise summary of a DataFrame.
insert(loc, column, value[, allow_duplicates])Insert column into DataFrame at specified location.
interpolate([method, axis, limit, inplace, ...])Fill NaN values using an interpolation method.
isetitem(loc, value)Set the given value in the column with position
loc.isin(values)Whether each element in the DataFrame is contained in values.
isna()Detect missing values.
isnull()DataFrame.isnull is an alias for DataFrame.isna.
items()Iterate over (column name, Series) pairs.
iterrows()Iterate over DataFrame rows as (index, Series) pairs.
itertuples([index, name])Iterate over DataFrame rows as namedtuples.
join(other[, on, how, lsuffix, rsuffix, ...])Join columns of another DataFrame.
keys()Get the 'info axis' (see Indexing for more).
kurt([axis, skipna, numeric_only])Return unbiased kurtosis over requested axis.
kurtosis([axis, skipna, numeric_only])Return unbiased kurtosis over requested axis.
last(offset)Select final periods of time series data based on a date offset.
last_valid_index()Return index for last non-NA value or None, if no non-NA value is found.
le(other[, axis, level])Get Less than or equal to of dataframe and other, element-wise (binary operator
le).lt(other[, axis, level])Get Less than of dataframe and other, element-wise (binary operator
lt).map(func[, na_action])Apply a function to a Dataframe elementwise.
mask(cond[, other, inplace, axis, level])Replace values where the condition is True.
max([axis, skipna, numeric_only])Return the maximum of the values over the requested axis.
mean([axis, skipna, numeric_only])Return the mean of the values over the requested axis.
median([axis, skipna, numeric_only])Return the median of the values over the requested axis.
melt([id_vars, value_vars, var_name, ...])Unpivot a DataFrame from wide to long format, optionally leaving identifiers set.
memory_usage([index, deep])Return the memory usage of each column in bytes.
merge(how[, on])Merge selection rules using a specific type of join.
min([axis, skipna, numeric_only])Return the minimum of the values over the requested axis.
mod(other[, axis, level, fill_value])Get Modulo of dataframe and other, element-wise (binary operator
mod).mode([axis, numeric_only, dropna])Get the mode(s) of each element along the selected axis.
mul(other[, axis, level, fill_value])Get Multiplication of dataframe and other, element-wise (binary operator
mul).multiply(other[, axis, level, fill_value])Get Multiplication of dataframe and other, element-wise (binary operator
mul).ne(other[, axis, level])Get Not equal to of dataframe and other, element-wise (binary operator
ne).nlargest(n, columns[, keep])Return the first
nrows ordered bycolumnsin descending order.notna()Detect existing (non-missing) values.
notnull()DataFrame.notnull is an alias for DataFrame.notna.
nsmallest(n, columns[, keep])Return the first
nrows ordered bycolumnsin ascending order.nunique([axis, dropna])Count number of distinct elements in specified axis.
pad(*[, axis, inplace, limit, downcast])Fill NA/NaN values by propagating the last valid observation to next valid.
pct_change([periods, fill_method, limit, freq])Fractional change between the current and a prior element.
pipe(func, *args, **kwargs)Apply chainable functions that expect Series or DataFrames.
pivot(*, columns[, index, values])Return reshaped DataFrame organized by given index / column values.
pivot_table([values, index, columns, ...])Create a spreadsheet-style pivot table as a DataFrame.
plotalias of
PlotAccessorpop(item)Return item and drop from frame.
pow(other[, axis, level, fill_value])Get Exponential power of dataframe and other, element-wise (binary operator
pow).prod([axis, skipna, numeric_only, min_count])Return the product of the values over the requested axis.
product([axis, skipna, numeric_only, min_count])Return the product of the values over the requested axis.
quantile([q, axis, numeric_only, ...])Return values at the given quantile over requested axis.
query(expr, *[, inplace])Query the columns of a DataFrame with a boolean expression.
radd(other[, axis, level, fill_value])Get Addition of dataframe and other, element-wise (binary operator
radd).rank([axis, method, numeric_only, ...])Compute numerical data ranks (1 through n) along axis.
rdiv(other[, axis, level, fill_value])Get Floating division of dataframe and other, element-wise (binary operator
rtruediv).reindex([labels, index, columns, axis, ...])Conform DataFrame to new index with optional filling logic.
reindex_like(other[, method, copy, limit, ...])Return an object with matching indices as other object.
remove([id, tag])Remove (delete) a selection rule(s).
rename([mapper, index, columns, axis, copy, ...])Rename columns or index labels.
rename_axis([mapper, index, columns, axis, ...])Set the name of the axis for the index or columns.
reorder_levels(order[, axis])Rearrange index levels using input order.
replace([to_replace, value, inplace, limit, ...])Replace values given in
to_replacewithvalue.resample(rule[, axis, closed, label, ...])Resample time-series data.
reset_index([level, drop, inplace, ...])Reset the index, or a level of it.
rfloordiv(other[, axis, level, fill_value])Get Integer division of dataframe and other, element-wise (binary operator
rfloordiv).rmod(other[, axis, level, fill_value])Get Modulo of dataframe and other, element-wise (binary operator
rmod).rmul(other[, axis, level, fill_value])Get Multiplication of dataframe and other, element-wise (binary operator
rmul).rolling(window[, min_periods, center, ...])Provide rolling window calculations.
round([decimals])Round a DataFrame to a variable number of decimal places.
rpow(other[, axis, level, fill_value])Get Exponential power of dataframe and other, element-wise (binary operator
rpow).rsub(other[, axis, level, fill_value])Get Subtraction of dataframe and other, element-wise (binary operator
rsub).rtruediv(other[, axis, level, fill_value])Get Floating division of dataframe and other, element-wise (binary operator
rtruediv).sample([n, frac, replace, weights, ...])Return a random sample of items from an axis of object.
select_dtypes([include, exclude])Return a subset of the DataFrame's columns based on the column dtypes.
sem([axis, skipna, ddof, numeric_only])Return unbiased standard error of the mean over requested axis.
set_axis(labels, *[, axis, copy])Assign desired index to given axis.
set_flags(*[, copy, allows_duplicate_labels])Return a new object with updated flags.
set_index(keys, *[, drop, append, inplace, ...])Set the DataFrame index using existing columns.
shift([periods, freq, axis, fill_value, suffix])Shift index by desired number of periods with an optional time
freq.show()Print the current selection rules.
skew([axis, skipna, numeric_only])Return unbiased skew over requested axis.
sort_index(*[, axis, level, ascending, ...])Sort object by labels (along an axis).
sort_values(by, *[, axis, ascending, ...])Sort by the values along either axis.
sparsealias of
SparseFrameAccessorsqueeze([axis])Squeeze 1 dimensional axis objects into scalars.
stack([level, dropna, sort, future_stack])Stack the prescribed level(s) from columns to index.
std([axis, skipna, ddof, numeric_only])Return sample standard deviation over requested axis.
sub(other[, axis, level, fill_value])Get Subtraction of dataframe and other, element-wise (binary operator
sub).subtract(other[, axis, level, fill_value])Get Subtraction of dataframe and other, element-wise (binary operator
sub).sum([axis, skipna, numeric_only, min_count])Return the sum of the values over the requested axis.
swapaxes(axis1, axis2[, copy])Interchange axes and swap values axes appropriately.
swaplevel([i, j, axis])Swap levels i and j in a
MultiIndex.tail([n])Return the last
nrows.take(indices[, axis])Return the elements in the given positional indices along an axis.
to_clipboard([excel, sep])Copy object to the system clipboard.
to_csv([path_or_buf, sep, na_rep, ...])Write object to a comma-separated values (csv) file.
to_dict([orient, into, index])Convert the DataFrame to a dictionary.
to_excel(excel_writer[, sheet_name, na_rep, ...])Write object to an Excel sheet.
to_feather(path, **kwargs)Write a DataFrame to the binary Feather format.
to_gbq(destination_table[, project_id, ...])Write a DataFrame to a Google BigQuery table.
to_hdf(path_or_buf, key[, mode, complevel, ...])Write the contained data to an HDF5 file using HDFStore.
to_html([buf, columns, col_space, header, ...])Render a DataFrame as an HTML table.
to_json([path_or_buf, orient, date_format, ...])Convert the object to a JSON string.
to_latex([buf, columns, header, index, ...])Render object to a LaTeX tabular, longtable, or nested table.
to_markdown([buf, mode, index, storage_options])Print DataFrame in Markdown-friendly format.
to_numpy([dtype, copy, na_value])Convert the DataFrame to a NumPy array.
to_orc([path, engine, index, engine_kwargs])Write a DataFrame to the ORC format.
to_parquet([path, engine, compression, ...])Write a DataFrame to the binary parquet format.
to_period([freq, axis, copy])Convert DataFrame from DatetimeIndex to PeriodIndex.
to_pickle(path[, compression, protocol, ...])Pickle (serialize) object to file.
to_records([index, column_dtypes, index_dtypes])Convert DataFrame to a NumPy record array.
to_sql(name, con, *[, schema, if_exists, ...])Write records stored in a DataFrame to a SQL database.
to_stata(path, *[, convert_dates, ...])Export DataFrame object to Stata dta format.
to_string([buf, columns, col_space, header, ...])Render a DataFrame to a console-friendly tabular output.
to_timestamp([freq, how, axis, copy])Cast to DatetimeIndex of timestamps, at beginning of period.
to_xarray()Return an xarray object from the pandas object.
to_xml([path_or_buffer, index, root_name, ...])Render a DataFrame to an XML document.
transform(func[, axis])Call
funcon self producing a DataFrame with the same axis shape as self.transpose(*args[, copy])Transpose index and columns.
truediv(other[, axis, level, fill_value])Get Floating division of dataframe and other, element-wise (binary operator
truediv).truncate([before, after, axis, copy])Truncate a Series or DataFrame before and after some index value.
tz_convert(tz[, axis, level, copy])Convert tz-aware axis to target time zone.
tz_localize(tz[, axis, level, copy, ...])Localize tz-naive index of a Series or DataFrame to target time zone.
unstack([level, fill_value, sort])Pivot a level of the (necessarily hierarchical) index labels.
update(other[, join, overwrite, ...])Modify in place using non-NA values from another DataFrame.
value_counts([subset, normalize, sort, ...])Return a Series containing the frequency of each distinct row in the Dataframe.
var([axis, skipna, ddof, numeric_only])Return unbiased variance over requested axis.
where(cond[, other, inplace, axis, level])Replace values where the condition is False.
xs(key[, axis, level, drop_level])Return cross-section from the Series/DataFrame.
- alias(aliases)[source]#
Alias a set of keywords to existing columns. Multiple aliases for a single column are allowed, e.g., { ‘glon’:’crval2’, ‘lon’:’crval2’}
- Parameters:
- aliases{}
The dictionary of keywords and column names where the new alias is the key and the column name is the value and , i.e., {alias:column}
- Returns:
- None.
- Raises:
- ValueError if the column name is not recognized.
- property aliases#
The aliases that may be used to refer to SDFITS columns.
- Returns:
- dict
The dictionary of aliases and SDFITS column names
- columns_selected()[source]#
The names of any columns which were used in a selection rule
- Returns:
- colnames - set
A set of str column names. An empty set is returned if no selection rule has yet been made.
- property final#
Create the final selection. This is done by a logical AND of each of the selection rules (specifically
pandas.merge(how='inner')).- Returns:
- finalDataFrame
The resultant selection from all the rules.
- get(key)[source]#
Get the selection/flag rule by its ID
- Parameters:
- keyint
The ID value. See
show().
- Returns:
- ~pandas.DataFrame
The selection/flag rule
- merge(how, on=None)[source]#
Merge selection rules using a specific type of join.
- Parameters:
- how{‘left’, ‘right’, ‘outer’, ‘inner’, ‘cross’}, no default.
The type of join to be performed. See
pandas.merge().- on: label or list
Column or index level names to join on. These must be found in both DataFrames. If on is None and not merging on indexes then this defaults to the intersection of the columns in both DataFrames.
- Returns:
- finalDataFrame
The resultant selection from all the rules.
- remove(id=None, tag=None)[source]#
Remove (delete) a selection rule(s). You must specify either id or tag but not both. If there are multiple rules with the same tag, they will all be deleted.
- Parameters:
- idint
The ID number of the rule as displayed in
show()- tagstr
An identifying tag by which the rule may be referred to later.
- show()[source]#
Print the current selection rules. Only columns with a rule are shown. The first two columns are ID number a TAG string. Either of these may be used to
remove()a row. The final column# SELECTEDgives the number of rows that a given rule selects from the original. Thefinal()selection may be fewer rows because each selection rule is logically OR’ed to create the final selection.- Returns:
- None.
Core utility definitions, classes, and functions
- dysh.util.core.abbreviate_to(length, value, squeeze=True)[source]#
Abbreviate a value for display in limited space. The abbreviated value will have initial characters, ellipsis, and final characters, e.g. ‘[(a,b),(c,d)…(w,x),(y,z)]’.
- Parameters:
- lengthint
Maximum string length.
- valueany
The value to be abbreviated.
- squeezebool, optional
Squeeze blanks. If True, replace “, ” (comma space) with “,” (comma). The default is True.
- Returns:
- strvstr
Abbreviated string representation of the input value
- dysh.util.core.consecutive(data, stepsize=1)[source]#
Returns the indices of elements in
dataseparated by less than stepsize separated into groups.- Parameters:
- dataarray
Array with values to split.
- stepsizeint
Maximum separation between elements of
datato be considered a single group.
- Returns:
- groups
ndarray Array with values of
dataseparated into groups.
- groups
- dysh.util.core.convert_array_to_mask(a, length, value=True)[source]#
This method interprets a simple or compound array and returns a numpy mask of length
length. Single arrays/tuples will be treated as element index lists; nested arrays will be treated as inclusive ranges, for instance:`` # mask elements 1 and 10 convert_array_to_mask([1,10]) # mask elements 1 thru 10 inclusive convert_array_to_mask([[1,10]]) # mask ranges 1 thru 10 and 47 thru 56 inclusive, and element 75 convert_array_to_mask([[1,10], [47,56], 75)]) # tuples also work, though can be harder for a human to read convert_array_to_mask(((1,10), [47,56], 75)) ``
- Parameters:
- anumber or array-like
The
- lengthint
The length of the mask to return, e.g. the number of channels in a spectrum.
- valuebool
The value to fill the mask with. True to mask data, False to unmask.
- Returns:
- mask~np.ndarray
A numpy array where the mask is True according to the rules above.
- dysh.util.core.eliminate_flagged_rows(df, flag)[source]#
Remove rows from an index (selection) where all channels have been flagged.
- dysh.util.core.ensure_ascii(text: str | list[str], check: bool = False) str | list[str][source]#
Remove non-printable ASCII characters from a string or list of strings. This is to ensure that FITS cards conform to the standard
- Parameters:
- textstr
The text to clean
- check: bool
Check if the clean value is truly clean according to astropy FITS, raise ValueError if not
- Returns
- ——-
- str or list[str]
The cleaned text
- dysh.util.core.gbt_timestamp_to_time(timestamp)[source]#
Convert the GBT sdfits timestamp string format to an
Timeobject. GBT SDFITS timestamps have the form YYYY_MM_DD_HH:MM:SS in UTC.- Parameters:
- timestampstr or list-like
The GBT format timestamp as described above. If str, a Time object containing a single time is returned. If list-like, a Time object containing multiple UTC times is returned.
- Returns:
- time
Time The time object
- time
- dysh.util.core.generate_tag(values, hashlen, add_time=True)[source]#
Generate a unique tag based on input values. A hash object is created from the input values using SHA256, and a hex representation is created. The first
hashlencharacters of the hex string are returned.- Parameters:
- valuesarray-like
The values to use in creating the hash object
- hashlenint, optional
The length of the returned hash string.
- add_time: bool
Add the time of the call to the values for hash generation.
- Returns:
- tagstr
The hash string
- dysh.util.core.get_project_configuration() Path[source]#
Returns the directory where dysh configuration files are kept.
- Returns:
- Path
The project configuration directory.
- dysh.util.core.get_size(obj, seen=None)[source]#
Recursively finds size of objects. See https://goshippo.com/blog/measure-real-size-any-python-object/
- dysh.util.core.indices_where_value_changes(colname, df)[source]#
Find the
DataFrameindices where the value of the input column name changes.- Parameters:
- colnamestr
The column name to query.
- df
DataFrame The DataFrame to search
- Returns:
- indices~numpy.ndarray
The indices of the Dataframe where
colnamechanges value.
- dysh.util.core.keycase(d, case='upper')[source]#
Change the case of dictionary keys
- Parameters:
- ddict
The input dictionary
- casestr, one of ‘upper’, ‘lower’
Case to change keys to The default is “upper”.
- Returns:
- newDictdict
A copy of the dictionary with keys changed according to
case
- dysh.util.core.minimum_string_match(s, valid_strings)[source]#
return the valid string from a list, given a minimum string input
Example: minimum_string_match(‘a’,[‘alpha’,’beta’,’gamma’]) returns: ‘alpha’
- Parameters:
- sstring
string to use for minimum match
- valid_stringslist of strings
list of full strings to min match on
- Returns:
- string
matched string, if one is found. Otherwise “None” is returned.
- dysh.util.core.powerof2(number)[source]#
Computes the closest power of 2 for a given
number.- Parameters:
- numberfloat
number to determine the closest power of 2.
- Returns:
- pow2int
the closest power of 2.
- dysh.util.core.sq_weighted_avg(a, axis=0, weights=None)[source]#
Compute the mean square weighted average of an array (2nd moment).
\(v = \sqrt{\frac{\sum_i{w_i~a_i^{2}}}{\sum_i{w_i}}}\)
- Parameters:
- Returns:
- average
ndarray The average along the input axis
- average
- dysh.util.core.uniq(seq)[source]#
Remove duplicates from a list while preserving order. from http://stackoverflow.com/questions/480214/how-do-you-remove-duplicates-from-a-list-in-python-whilst-preserving-order