Skip to content

Commit

Permalink
Merge pull request #186 from dstansby/black
Browse files Browse the repository at this point in the history
Apply black to codebase
  • Loading branch information
dstansby committed May 22, 2023
2 parents 25994ff + 72bea5b commit 14f8dbf
Show file tree
Hide file tree
Showing 17 changed files with 2,860 additions and 2,991 deletions.
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ repos:
- id: mixed-line-ending
exclude: ".*(.fits|.fts|.fit|.txt|tca.*|.svg)$"

- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black

# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: 'v1.3.0'
# hooks:
Expand Down
5 changes: 3 additions & 2 deletions benchmarks/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ class TimeSuite:
An example benchmark that times the performance of various kinds
of iterating over dictionaries in Python.
"""
params = ([True, False], )
param_names = ['to_np']

params = ([True, False],)
param_names = ["to_np"]

def setup(self, to_np):
self.epochs = np.ones(1000) * 62567898765432.0
Expand Down
4 changes: 2 additions & 2 deletions cdflib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from .cdf_to_xarray import cdf_to_xarray
from .xarray_to_cdf import xarray_to_cdf

__all__ = ['CDF', 'xarray_to_cdf', 'cdf_to_xarray']
__all__ = ["CDF", "xarray_to_cdf", "cdf_to_xarray"]
try:
from ._version import version as __version__
except Exception:
__version__ = 'unknown'
__version__ = "unknown"
387 changes: 221 additions & 166 deletions cdflib/cdf_to_xarray.py

Large diffs are not rendered by default.

1,496 changes: 728 additions & 768 deletions cdflib/cdfread.py

Large diffs are not rendered by default.

1,298 changes: 620 additions & 678 deletions cdflib/cdfwrite.py

Large diffs are not rendered by default.

756 changes: 364 additions & 392 deletions cdflib/epochs.py

Large diffs are not rendered by default.

52 changes: 26 additions & 26 deletions cdflib/epochs_astropy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,34 @@
from astropy.time import Time
from astropy.time.formats import TimeFromEpoch, erfa

__all__ = ['CDFAstropy']
__all__ = ["CDFAstropy"]


class CDFEpoch(TimeFromEpoch):
name = 'cdf_epoch'
name = "cdf_epoch"
unit = 1.0 / (erfa.DAYSEC * 1000) # Milliseconds
epoch_val = '0000-01-01 00:00:00'
epoch_val = "0000-01-01 00:00:00"
epoch_val2 = None
epoch_scale = 'utc'
epoch_format = 'iso'
epoch_scale = "utc"
epoch_format = "iso"


class CDFEpoch16(TimeFromEpoch):
name = 'cdf_epoch16'
name = "cdf_epoch16"
unit = 1.0 / (erfa.DAYSEC) # Seconds
epoch_val = '0000-01-01 00:00:00'
epoch_val = "0000-01-01 00:00:00"
epoch_val2 = None
epoch_scale = 'utc'
epoch_format = 'iso'
epoch_scale = "utc"
epoch_format = "iso"


class CDFTT2000(TimeFromEpoch):
name = 'cdf_tt2000'
name = "cdf_tt2000"
unit = 1.0 / (erfa.DAYSEC * 1e9) # Nanoseconds
epoch_val = '2000-01-01 12:00:00'
epoch_val = "2000-01-01 12:00:00"
epoch_val2 = None
epoch_scale = 'tt'
epoch_format = 'iso'
epoch_scale = "tt"
epoch_format = "iso"


class CDFAstropy:
Expand Down Expand Up @@ -76,33 +76,33 @@ def convert_to_astropy(epochs, format=None):

# Determine best format for the input type
if t in (int, np.int64):
return Time(epochs, format='cdf_tt2000', precision=9)
return Time(epochs, format="cdf_tt2000", precision=9)
elif t in (complex, np.complex128):
return Time(epochs.real, epochs.imag / 1000000000000.0, format='cdf_epoch16', precision=9)
return Time(epochs.real, epochs.imag / 1000000000000.0, format="cdf_epoch16", precision=9)
elif t in (float, np.float64):
return Time(epochs, format='cdf_epoch', precision=9)
return Time(epochs, format="cdf_epoch", precision=9)
else:
raise TypeError('Not sure how to handle type {}'.format(type(epochs)))
raise TypeError("Not sure how to handle type {}".format(type(epochs)))

@staticmethod
def encode(epochs, iso_8601: bool = True): # @NoSelf
epochs = CDFAstropy.convert_to_astropy(epochs)
if iso_8601:
return epochs.iso
else:
return epochs.strftime('%d-%b-%Y %H:%M:%S.%f')
return epochs.strftime("%d-%b-%Y %H:%M:%S.%f")

@staticmethod
def breakdown(epochs, to_np: bool = False):
# Returns either a single array, or a array of arrays depending on the input
epochs = CDFAstropy.convert_to_astropy(epochs)
if epochs.format == 'cdf_tt2000':
if epochs.format == "cdf_tt2000":
return CDFAstropy.breakdown_tt2000(epochs, to_np)
elif epochs.format == 'cdf_epoch':
elif epochs.format == "cdf_epoch":
return CDFAstropy.breakdown_epoch(epochs, to_np)
elif epochs.format == 'cdf_epoch16':
elif epochs.format == "cdf_epoch16":
return CDFAstropy.breakdown_epoch16(epochs, to_np)
raise TypeError('Not sure how to handle type {}'.format(type(epochs)))
raise TypeError("Not sure how to handle type {}".format(type(epochs)))

@staticmethod
def to_datetime(cdf_time) -> List[datetime.datetime]:
Expand Down Expand Up @@ -131,16 +131,16 @@ def compute(datetimes, to_np: bool = False): # @NoSelf
for d in datetimes:
unix_seconds = datetime.datetime(d[0], d[1], d[2], d[3], d[4], d[5]).replace(tzinfo=timezone.utc).timestamp()
if len(d) == 7:
remainder_seconds = (d[6] / 1000.0)
astrotime = Time(unix_seconds, remainder_seconds, format='unix', precision=9)
remainder_seconds = d[6] / 1000.0
astrotime = Time(unix_seconds, remainder_seconds, format="unix", precision=9)
cdf_time.append(astrotime.cdf_epoch)
if len(d) == 9:
remainder_seconds = (d[6] / 1000.0) + (d[7] / 1000000.0) + (d[8] / 1000000000.0)
astrotime = Time(unix_seconds, remainder_seconds, format='unix', precision=9)
astrotime = Time(unix_seconds, remainder_seconds, format="unix", precision=9)
cdf_time.append(astrotime.cdf_tt2000)
if len(d) == 10:
remainder_seconds = (d[6] / 1000.0) + (d[7] / 1000000.0) + (d[8] / 1000000000.0) + (d[9] / 1000000000000.0)
astrotime = Time(unix_seconds, remainder_seconds, format='unix', precision=9)
astrotime = Time(unix_seconds, remainder_seconds, format="unix", precision=9)
cdf_time.append(astrotime.cdf_epoch16)
if to_np:
return np.array(cdf_time)
Expand Down

0 comments on commit 14f8dbf

Please sign in to comment.