Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Library (julian), lack of usage information
#11
(Mar-03-2019, 04:32 PM)samsonite Wrote: No, because of the unnecessary import pendulum.
I did post a solution with datetime and strptime before in Thread.
>>> import datetime
>>> import julian
>>> 
>>> dt_str = '2018-09-09 12:12:12.005876'
>>> dt = datetime.datetime.strptime(dt_str, "%Y-%m-%d %H:%M:%S.%f")
>>> julian.to_jd(dt, fmt='jd')
2458371.0084722904
Pendulum works just like daytime,just with a lot of improvements like eg i use parse of dates strings.
Quote:Drop-in replacement for the standard datetime class.
It behaves exactly like it but with many improvements.

If libraries over time show that they are much better than what's is standard library,
i will recommenced that,like eg Requests over urllib and many more.
Quote
#12
Oh yes, snippsat! It's what I was looking for, fantastic! Get a glance to the comments below. Thanks again and cheers
# ------- jul_final.py ----------
import datetime
import julian
 
dt_str = '2018-09-09 12:12:12.005876'
dt = datetime.datetime.strptime(dt_str, "%Y-%m-%d %H:%M:%S.%f")
mjd= julian.to_jd(dt, fmt='jd') - 2400000.5
print(mjd)
# ------- OUTPUT ---------
# C:\Training>python jul_final.py
# 58370.508472290356
# ------- EXPECTED --------
# Given date and time as follows
# 2018-09-09  12:12:12.005876   (time accurate to 6 decimal places)
# find
# MJD    58370.50847229023 
# --------------------------
# My comments: the (julian) algorithm is highly performant
# Delta= (.50847229036-.50847229023) = 13e-11 days
# --------------------------------------------------------
Quote
#13
Slight amendment of one of my previous posts. Cheers
# ------- jul1bis.py --------
import julian
import datetime
mjd = 58370.5084722222
dt = julian.from_jd(mjd, fmt='mjd')
print(dt)
#
mjd2 = julian.to_jd(dt + datetime.timedelta(hours=0), fmt='jd') - 2400000.5
print(mjd2)

# ------- OUTPUTS -----------
# C:\Training>python jul1bis.py
# 2018-09-09 12:12:12.000012
# 58370.50847222237
# My comments: line 8 been amended with (hours=0, scaletime of MJD),
# so the back calculated (mjd2) fully matches (mjd) of line 4
# -------------------------------------------------------------------
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Create application that will take information from database and insert into PDF sorrelsj 1 168 Aug-19-2019, 10:08 PM
Last Post: Gribouillis
  Pygal: Displaying information for each data point KirkmanJ 0 77 Jul-29-2019, 01:10 PM
Last Post: KirkmanJ
  AWS_Utils Library macnisin 1 193 Jul-21-2019, 11:19 PM
Last Post: Larz60+
  How to gather information from remote host using ansible module in python amritjsr 0 90 Jul-20-2019, 01:17 AM
Last Post: amritjsr
  Calling Extended Embedding Python as shared library jibarra 0 118 Jul-19-2019, 05:22 PM
Last Post: jibarra
  Excel Library for Python 3 synthia 11 725 Jul-18-2019, 07:06 AM
Last Post: synthia
  return statement usage SB_J 3 165 Jul-16-2019, 07:24 PM
Last Post: snippsat
  Trying to Tabulate Information from an Aircraft Website Link(s) eddywinch82 35 2,067 Jun-25-2019, 09:40 PM
Last Post: snippsat
  Pymssql library failing when upgrading to Python 3.7 - win32 issue stixmagiggins 5 315 Jun-24-2019, 06:46 AM
Last Post: snippsat
  Help Importing Protocol Library Into Scapy joedirgy 0 191 May-02-2019, 07:31 PM
Last Post: joedirgy

Forum Jump:


Users browsing this thread: 1 Guest(s)