У меня есть пользовательская функция UT2LSTmine в matlab. Я хочу преобразовать ту же функцию в Python, которая работает точно так же, как и в Matlab. Я новичок в программировании на Python. Я много пробовал. Я также использовал онлайн-приложения для конвертации Matlab в Python (OMPC). Это не работает в соответствии с моим требованием.
Функция должна принимать универсальное время запуска (UT) и преобразовываться в местное звездное время (LST) с учетом увеличения даты и времени.
Функция преобразования часов UT, мин, сек в часы LST, мин, сек в GBD
Эта функция получает информацию от наблюдателя, такого как yr, mn, dd, uth, htm, uts. Возвращает преобразованные lsth, lstm, lsts. Эта функция также проверяет 24-часовой ввод и автоматически увеличивает день.
function [t] = UT2LSTmine(varargin)
yr = varargin{1};
mn = varargin{2};
dd = varargin{3};
uth = varargin{4};
utm = varargin{5};
uts = varargin{6};
t=[yr,mn,dd,uth,utm,uts];
format long g ;
gbdlong = 5.06138;
%%% Compute Julian Date for the given date
x=[t(1,1), t(1,2), t(1,3), 0,0,0.5];
[~,indx]=ismember(x,t,'rows');%for 24 hours check
if(indx > 0)
t(indx:end,3)=t(indx:end,3)+1;%Incrementing the day manually commented for RTLSDR on 30th MA
x=[t(indx,1), t(indx,2), t(indx,3), 23,59,59];
end
%%% Compute Local time & UT for the given IST
utd = t(:,4) + (t(:,5)./60) + (t(:,6)/3600);
for i=1:1:length(t)
julday(i) = juliandate(t(i,1),t(i,2),t(i,3)) + 0.5000000;
jd(i) = julday(i) - 0.5; %%% JD @ 0h UT
T(i) = (jd(i) - 2451545.0)/36525; %%% Time interval since 2000 jan 1
12h UT
%%% Compute Gmst @ 0h UT
gmst0(i) = 24110.54841 + (8640184.812866 * T(i)) + (0.093104 * T(i) *
T(i)) - (0.000006200 * T(i) * T(i) * T(i));
%%% Convert Gmst to Hours
gmst0(i) = gmst0(i) / (86400.0); %%% gmst0 in days
gmst0(i) = gmst0(i) - floor(gmst0(i)); %%% Get the fraction of the day
gmst0(i) = gmst0(i) * 24.0; %%% Convert into hours
if (gmst0(i) < -0.0000001);
gmst0(i) = gmst0(i) + 24;
end
%%% Compute equivalent of mean sidreal time interval from oh to UT of
%%% intrest
mst(i) = utd(i) * 1.0027379094;
if ( mst(i) - 24.0 > 0.000001);
mst(i) = mst(i) - 24.0;
end
%%% Greenwitch mean sidreal time @ required UT
gmst(i) = gmst0(i) + mst(i);
if ( gmst(i) - 24.0 > 0.000001);
gmst(i) =gmst(i) - 24.0;
end
%%% Local mean sidreal time
lst(i) = gmst(i) + gbdlong;
if ( lst(i) > 24.0);
lst(i) = lst(i) - 24.0;
else if ( lst(i) < 0);
lst(i) = lst(i) + 24.0;
else
lst(i) = lst(i);
end
lsth(i) = floor(lst(i));
lstm1(i) = (lst(i) - floor(lsth(i))) * 60.0;
lstm(i) = floor(lstm1(i));
lsts(i) = (lstm1(i) - floor(lstm(i))) * 60.0;
% IST corresponding to the given UT
istd(i) = utd(i) + 5.5;
if ( istd(i) > 24.0);
ist(i) = istd(i) - 24.0;
elseif ( istd(i) < 0);
ist(i) = istd(i) + 24.0;
else
ist(i) = istd(i);
end
isth(i) = floor(ist(i));
istm(i) = (ist(i) - floor(ist(i))) * 60;
ists(i) = (istm(i) - floor(istm(i))) * 60;
t(i,4)=lsth(i);t(i,5)=lstm(i);t(i,6)=lsts(i);
end
%%%%%%%%%%%%%%%%%%For checking 24hours condition for LST%%%%%
[~,index]=ismember(x,t,'rows');%for 24 hours check
if(indx > 0 & index == 0)
t(indx:end,3)=t(indx:end,3)-1;%If LST not completed 24 hours then do 1
day substraction do to the increment of UT
end
Я пробовал это -
import numpy as np
def UT2LSTmine(*args):
#Function to convert the UT hours, min, sec to LST hours, min, sec at GBD
# This fuction takes the input from the obsever such as
# yr,mn,dd,uth,htm,uts. Returs the converted lsth, lstm, lsts
#This fuction also checks for 24 hours input and automatically increments
#the day
yr = args[:,0]
mn = args[:,1]
dd = args[:,2]
uth = args[:,3]
utm = args[:,4]
uts = args[:,5]
t = [yr, mn, dd, uth, utm, uts]
format('long', 'g')
#gbdlong = 5.162351852;%for GBD
gbdlong = 5.06138#for IIT Indore
#########Compute Julian Date for the given date
x = [t(1, 1), t(1, 2), t(1, 3), 0, 0, 0.5]
ismember(x, t, 'rows') #for 24 hours check
for i in x:
index = np.where(t==i)[0]
if index.size == 0:
yield 0
else:
yield index
if (index > 0):
t[slice[index:stop], 3]= t(slice[index:end], 3) + 1 #Incrementing the day manually commented for
#RTLSDR on 30th MA
x = [t(index, 1), t(index, 2), t(index, 3), 23, 59, 59]
##### Compute Local time & UT for the given IST
utd = t(slice[:], 4) + (t(slice[:], 5) / 60) + (t(slice[:], 6) / 3600)
for i in slice[1:1:length(t)]:
julday[i] = juliandate(t(i, 1), t(i, 2), t(i, 3)) + 0.5000000
jd[i]= julday(i) - 0.5 #%% JD @ 0h UT
T[i] = (jd(i) - 2451545.0) / 36525 #%% Time interval since 2000 jan 1 12h UT
########Compute Gmst @ 0h UT
gmst0[i] = 24110.54841 + (8640184.812866 * T(i)) + (0.093104 * T(i) * T(i)) - (0.000006200 * T(i) * T(i) * T(i))
####Convert Gmst to Hours
gmst0[i] = gmst0(i) / (86400.0) #%% gmst0 in days
gmst0[i]= gmst0(i) - floor(gmst0(i)) #%% Get the fraction of the day
gmst0[i]= gmst0(i) * 24.0 #%% Convert into hours
if (gmst0(i) < -0.0000001):
gmst0[i]= gmst0(i) + 24
###Compute equivalent of mean sidreal time interval from oh to UT of intrest
mst[i] = utd(i) * 1.0027379094
if (mst(i) - 24.0 > 0.000001):
mst[i] = mst(i) - 24.0
end
###Greenwitch mean sidreal time @ required UT
gmst[i] = gmst0(i) + mst(i)
if (gmst(i) - 24.0 > 0.000001):
gmst[i] = gmst(i) - 24.0
# ####Local mean sidreal time
lst[i] = gmst(i) + gbdlong
if (lst(i) > 24.0):
lst[i]= lst(i) - 24.0
elif (lst(i) < 0):
lst[i]= lst(i) + 24.0
else:
lst[i]= lst(i)
lsth[i]= floor(lst(i))
lstm1[i]= (lst(i) - floor(lsth(i))) * 60.0
lstm[i]= floor(lstm1(i))
lsts[i]= (lstm1(i) - floor(lstm(i))) * 60.0
# IST corresponding to the given UT
istd[i]= utd(i) + 5.5
if (istd(i) > 24.0):
ist[i]= istd(i) - 24.0
elif (istd(i) < 0):
ist[i] = istd(i) + 24.0
else:
ist[i]= istd(i)
isth[i] = floor(ist(i))
istm[i]= (ist(i) - floor(ist(i))) * 60
ists[i]= (istm(i) - floor(istm(i))) * 60
t[i, 4]= lsth(i)
t[i, 5] = lstm(i)
t[i, 6] = lsts(i)
############For checking 24hours condition for LST ###################
ismember(x, t,'rows') #for 24 hours check
if (logical_and(indx > 0, index == 0)):
t[slice[indx:end], 3]= t(slice[indx:end], 3) - 1 #If LST not completed 24 hours then do 1 day substraction do to the increment of UT