Git Product home page Git Product logo

Comments (11)

awesomebytes avatar awesomebytes commented on August 25, 2024

As you can read in the README:

Check notes_on_using_libermate.txt if you use it and it doesn't work properly (it's normal!) I give many hints there on how to correct problems I had while translating
You may want to try the new: https://github.com/victorlei/smop It's a work in progress, which means, someone is working on it! This one is just as it is.

Also, I personally doubt very much you'll get the plotting working out of the box with any translator.

from libermate.

sameerCoder avatar sameerCoder commented on August 25, 2024

from libermate.

awesomebytes avatar awesomebytes commented on August 25, 2024

Once again, try the other project, but I doubt it will work either. If it doesn't, you need to rewrite that logic with matplotlib yourself.

from libermate.

sameerCoder avatar sameerCoder commented on August 25, 2024

from libermate.

awesomebytes avatar awesomebytes commented on August 25, 2024

@sameerCoder you'll need to learn how to use matplotlib: https://matplotlib.org/

They have nice documentation and examples. The code looks very very similar to the MATLAB version of it, they even say in their website:

For simple plotting the pyplot module provides a MATLAB-like interface, particularly when combined with IPython. For the power user, you have full control of line styles, font properties, axes properties, etc, via an object oriented interface or via a set of functions familiar to MATLAB users.

In short: you will need to do it yourself by hand. You may use this library for a first guess and try to work out from there.

from libermate.

awesomebytes avatar awesomebytes commented on August 25, 2024

Are you even trying?

I ran libermate on your code and I got a translation after fixing some obvious errors, its a matter of trial and error man...

import numpy as np
import scipy
import matcompat
import scipy.io as sio
from datetime import date

# if available import pylab (from matlibplot)
try:
    import matplotlib.pylab as plt
except ImportError:
    pass

#%%% Plotting output obtained from East Coast UNSWAN operational model.
#%% Plotting magnitude of Hs with peak wave direction

xyzfile = 'PUNSWANIObathy.xyz'
dx = 0.7
#% Distance between two consecutive wave direction arrows
xmin = 76.
#% Boundary coordinates of basemap
xmax = 90.
ymin = 4.
ymax = 24.
cmax = 7.
#%% Writing .mat output on basemap
sio.loadmat('EC_20180321.mat')
#% Creating date string from start and end dates
stdate = '21-03-2018 00:00:00'
enddate = '24-03-2018 00:00:00'
stdate_num = datenum(stdate, 'dd-mm-yyyy HH:MM:SS')
enddate_num = datenum(enddate, 'dd-mm-yyyy HH:MM:SS')
basename = 'fort'
#% basename of element file
param = 'Hsig'
#% parameter name should be same as that in the .mat file
hr_step = datenum(0., 0., 0., 3., 0., 0.)
#% Time interval(in hours)
date_array = np.arange(stdate_num, (enddate_num)+(hr_step), hr_step)
x = datestr(date_array, 'dd-mm-yyyy HH:MM:SS')
#% display in date format
siz_x = matcompat.size(x)
siz_x = siz_x[0,0]
#%% Importing element information
elefile = np.array(np.hstack((basename)))
fid = fopen(elefile)
#% load TRIANGLE element based connectivity file
[nelem] = fscanf(fid, '%i', np.array(np.hstack((1., 3.))))
#% get number of triangles
ncol = 4.+nelem[2]
#% specify number of columns in elefile
tri = fscanf(fid, '%i', np.array(np.hstack((ncol, nelem[0])))).conj().T
#% get connectivity table
fclose(fid)
for i in np.arange(1., (siz_x)+1):
    date = x[int(i)-1,:]
    day = date[0:2.]
    month = date[3:5.]
    year = date[6:10.]
    hr = date[11:13.]
    min = date[14:16.]
    sec = date[17:19.]
    varname = strcat(param, '_', year, month, day, '_', hr, min, sec)
    z = eval(np.array(np.hstack((varname))))
    openfig('basemapstates_25.fig')
    #% Converting time from GMT to IST
    t = datenum(date, 'dd-mm-yyyy HH:MM:SS')
    t = addtodate(t, 330., 'minute')
    date_IST = datestr(t, 'dd-mmm-yyyy HH:MM:SS')
    date_IST1 = date_IST[0:11.]
    time_IST = date_IST[12:17.]
    ax1_a = plt.gca
    xtik = np.arange(xmin, (xmax)+(1.), 1.)
    ytik = np.arange(ymin, (ymax)+(1.), 1.)
    set(ax1_a, 'Position', np.array(np.hstack((0.2, 0.15, 0.72, 0.72))), 'Xtick', xtik, 'Ytick', ytik, 'TickDir', 'out', 'FontName', 'Calibri', 'FontWeight', 'bold', 'Fontsize', 8., 'YAxisLocation', 'left', 'XAxisLocation', 'bottom')
    ax1_b = copyobj(plt.gca, plt.gcf)
    set(ax1_b, 'YAxisLocation', 'right', 'XAxisLocation', 'top')
    linkaxes(np.array(np.hstack((ax1_a, ax1_b))))
    ax1 = plt.gca
    plt.xlim(np.array(np.hstack((76., 90.))))
    plt.ylim(np.array(np.hstack((4., 24.))))
    ax2 = plt.axes
    #%% Setting axes properties
    set(ax2, 'ActivePositionProperty', 'outerposition', 'BusyAction', 'queue', 'Clipping', 'on', 'Color', 'none', 'DataAspectRatio', np.array(np.hstack((1., 1., 1.))), 'DataAspectRatioMode', 'manual', 'FontAngle', 'normal', 'FontName', 'Helvetica', 'FontSize', 10., 'FontUnits', 'points', 'FontWeight', 'normal', 'HandleVisibility', 'on', 'HitTest', 'on', 'Interruptible', 'on', 'Layer', 'bottom', 'LineStyleOrder', '-', 'LineWidth', 0.5000, 'NextPlot', 'add', 'OuterPosition', np.array(np.hstack((0., 0., 1., 1.))), 'PlotBoxAspectRatio', np.array(np.hstack((1., 1.3437, 1.2500))), 'PlotBoxAspectRatioMode', 'auto', 'Position', np.array(np.hstack((0.1300, 0.1100, 0.7750, 0.8150))), 'Projection', 'orthographic', 'PlotBoxAspectRatio', np.array(np.hstack((1., 1.3437, 1.2500))), 'PlotBoxAspectRatioMode', 'auto', 'Position', np.array(np.hstack((0.1300, 0.1100, 0.7750, 0.8150))), 'Projection', 'orthographic', 'Selected', 'off', 'SelectionHighlight', 'on', 'SortMethod', 'depth', 'Tag', '', 'TickDir', 'in', 'TickDirMode', 'auto', 'TickLength', np.array(np.hstack((0.0100, 0.0250))), 'UIContextMenu', np.array([]), 'Units', 'normalized', 'UserData', np.array([]), 'View', np.array(np.hstack((0., 90.))), 'Visible', 'off', 'XAxisLocation', 'bottom', 'XColor', np.array(np.hstack((0.1500, 0.1500, 0.1500))), 'XDir', 'normal', 'XGrid', 'on', 'XLimMode', 'manual', 'XMinorGrid', 'off', 'XScale', 'linear', 'XTick', np.array([]), 'YAxisLocation', 'left', 'YColor', np.array(np.hstack((0.1500, 0.1500, 0.1500))), 'YDir', 'normal', 'YGrid', 'on', 'YMinorGrid', 'off', 'YMinorTick', 'off', 'YScale', 'linear', 'YTick', np.array([]), 'YTickLabelMode', 'auto', 'ZColor', np.array(np.hstack((0.1500, 0.1500, 0.1500))), 'ZDir', 'normal', 'ZDir', 'normal', 'ZGrid', 'on', 'ZMinorGrid', 'off', 'ZMinorTick', 'off', 'ZScale', 'linear')
    trisurf(tri[:,1:4.], Xp, Yp, z, 'EdgeColor', 'none')
    caxis(np.array(np.hstack((0., cmax))))
    shading(interp)
    cmap1 = plt.jet
    cmap = np.array(np.vstack((np.hstack((cmap1[9,:])), np.hstack((cmap1[14,:])), np.hstack((cmap1[26,:])), np.hstack((cmap1[30,:])), np.hstack((cmap1[34,:])), np.hstack((cmap1[38,:])), np.hstack((cmap1[42,:])), np.hstack((cmap1[46,:])), np.hstack((cmap1[50,:])), np.hstack((cmap1[54,:])), np.hstack((cmap1[56,:])), np.hstack((cmap1[58,:])), np.hstack((cmap1[61,:])), np.hstack((cmap1[63,:])))))
    #%cmap = cmap(7:20,:)
    view(0., 90.)
    daspect(np.array(np.hstack((1., 1., 1.))))
    colormap(cmap)
    linkaxes(np.array(np.hstack((ax1, ax2))))
    #% Setting colorbar properties
    hcb = plt.colorbar
    ctick_vect = np.arange(0., (cmax)+(0.5), 0.5)
    set(hcb, 'location', 'southoutside', 'Xtick', ctick_vect, 'FontName', 'Calibri', 'FontWeight', 'bold', 'Fontsize', 8.)
    cpos = plt.get(hcb, 'Position')
    cpos[3] = np.dot(0.3, cpos[3])
    cpos[1] = np.dot(0.75, cpos[1])
    cpos[2] = 1.*cpos[2]
    cpos[0] = np.dot(1.13, cpos[0])
    set(hcb, 'Position', cpos)
    set(plt.gcf, 'units', 'centimeters', 'outerposition', np.array(np.hstack((0., 0., 30., 30.))))
    plt.hold(on)
    #%% Plotting directions
    var_dirname = strcat('PkDir', '_', year, month, day, '_', hr, min, sec)
    d = eval(np.array(np.hstack((var_dirname))))
    d1 = degunitcircle2degN(d)
    u = arrayfun(cosd, d1)
    v = arrayfun(sind, d1)
    w = np.zeros(matcompat.size(u))
    #% Making structured from unstructured dataset to get the uniform density
    #% of arrows everywhere
    [X, Y, Z, U, V, W] = unstrc2strcbathy(Xp, Yp, z, u, v, dx, xyzfile)
    idx = np.logical_and(not np.isnan(U), not np.isnan(V))
    Z = np.dot(cmax, np.ones(matcompat.size(U)))
    arr = quiver3(X[int(idx)-1], Y[int(idx)-1], Z[int(idx)-1], U[int(idx)-1], V[int(idx)-1], W[int(idx)-1], 'color', 'k', 'MaxHeadSize', 0.8, 'AutoScale', 'on', 'AutoScaleFactor', 0.45, 'LineWidth', 1.3)
    ax3 = plt.gca
    set(ax3, 'Position', np.array(np.hstack((0.2, 0.15, 0.72, 0.72))))
    title2 = np.array(np.hstack(('Experimental Forecast for', ' ', time_IST, ' ', 'IST', ' ', date_IST1)))
    annotation(plt.gcf, 'textbox', np.array(np.hstack((0.41, 0.895, 0.3, 0.0565552686204641))), 'String', 'Significant Wave Height (m)', 'HorizontalAlignment', 'center', 'FontWeight', 'bold', 'FontName', 'Calibri', 'FontSize', 11., 'LineStyle', 'none')
    annotation(plt.gcf, 'textbox', np.array(np.hstack((0.26, 0.87, 0.6, 0.0565552686204641))), 'String', title2, 'HorizontalAlignment', 'center', 'FontWeight', 'bold', 'FontName', 'Calibri', 'FontSize', 10., 'LineStyle', 'none', 'color', np.array(np.hstack((0., 0.5, 0.))))
    #% Create textbox
    annotation(plt.gcf, 'textbox', np.array(np.hstack((0.31, 0.029, 0.5, 0.0565552686204641))), 'String', 'Colour scale indicates magnitude of Hs', 'HorizontalAlignment', 'center', 'FontWeight', 'bold', 'FontName', 'Calibri', 'FontSize', 9., 'LineStyle', 'none')
    annotation(plt.gcf, 'textbox', np.array(np.hstack((0.31, 0.013, 0.5, 0.0565552686204641))), 'String', 'Direction of arrows represent peak wave direction', 'HorizontalAlignment', 'center', 'FontWeight', 'bold', 'FontName', 'Calibri', 'FontSize', 9., 'LineStyle', 'none')
    num = num2str(i)
    image_name = strcat(param, '-', day, '-', month, '-', year, '--', hr, min)
    drawnow
    export_fig(image_name, '-jpg', '-r200')
    plt.hold(off)
    plt.close(all)

That's what I got. I have no more time to dedicate to this.

from libermate.

sameerCoder avatar sameerCoder commented on August 25, 2024

from libermate.

awesomebytes avatar awesomebytes commented on August 25, 2024

I just read the error, went to the line of code of the error and fixed it with the most logical way of fixing it...

from libermate.

awesomebytes avatar awesomebytes commented on August 25, 2024

I have no more time to dedicate to this. I'm sorry. Good luck. Closing the issue.

from libermate.

sameerCoder avatar sameerCoder commented on August 25, 2024

from libermate.

awesomebytes avatar awesomebytes commented on August 25, 2024

I literally solved the errors by reading them, analyzing them, and trying to fix them. I didn't search anything. I just applied logic. Error on line X. Check what's in line X. Something looks weird? Fix it.

For example you have a line like:

for i = 1%:siz_x

And it stops there. Well. That code is clearly wrong in your MATLAB code. Anything after % is a comment. So it must be for i = 1:siz_x. Then from the already translated code MATLAB uses a function called datenum. There is no translation in Python. So you need to find how to do the same in Python. There is nowhere to look, really, you need to think what's going on and keep trying.

from libermate.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.