[MITgcm-support] Barotropic ocean gyre tutorial
Jeremy Miller
jeremysharonmiller at gmail.com
Sun Apr 4 10:48:14 EDT 2021
Great, thanks very much.
On Sun, 4 Apr 2021 at 17:46, Oliver Jahn <jahn at mit.edu> wrote:
> dtype='>f4'
>
> On 2021-04-04 10:21, Jeremy Miller wrote:
> > Dear Oliver,
> >
> > Thanks. That appears to have worked. The plots I got look similar to the
> > ones in the tutorial.
> > I ran Jeff Scott's code in the exact same form (but
> > with h.astype('>f4').tofile('bathy.bin')
> > and tau.astype('>f4').tofile('windx_cosy.bin') commented).
> > I still get a mismatch between the outputs from snippet tauMax*sin(Y*pi)
> > and np.fromfile('windx_siny.bin',dtype='f4').
> > Why is that?
> >
> > Best
> >
> > Jeremy
> >
> > On Sun, 4 Apr 2021 at 16:41, Oliver Jahn <jahn at mit.edu
> > <mailto:jahn at mit.edu>> wrote:
> >
> > This
> >
> > [X,Y]=np.meshgrid(x,y,indexing='ij')
> >
> > should be
> >
> > [Y,X]=np.meshgrid(y,x,indexing='ij')
> >
> > (with indexing 'ij' it is y,x, with indexing 'xy' it is x,y)
> >
> > I am attaching the script from Jeff's pull request where this is all
> > done correctly.
> >
> > Oliver
> >
> >
> > On 2021-04-04 09:00, Jeremy Miller wrote:
> > > Dear Oliver,
> > >
> > > Thanks for coming back to me. I did just that. I now get a plot for
> > > "eta" that appears to be two sets of constant values, on the left
> and
> > > right of the line x=0.6*1e6 m (see the attached plot in
> > > fig_bar_gyre_windx_siny.png). I also notice that the output bin
> file
> > > (tau_2_1) still shows different values to the original numpy array
> > > (tau_2). I have attached the latest version of the python script
> > used to
> > > generate the data (gendata_tut4.1.py <http://gendata_tut4.1.py>
> > <http://gendata_tut4.1.py>) and the
> > > script used to generate the plots (tut_4.1_plots.py
> > <http://tut_4.1_plots.py>
> > > <http://tut_4.1_plots.py>).
> > >
> > > Best
> > > Jeremy
> > >
> > > On Sun, 4 Apr 2021 at 13:48, Oliver Jahn <jahn at mit.edu
> > <mailto:jahn at mit.edu>
> > > <mailto:jahn at mit.edu <mailto:jahn at mit.edu>>> wrote:
> > >
> > > Hi Jeremy,
> > >
> > > this will not work:
> > >
> > > > if sys.byteorder == 'little': tau_2.byteswap(True)
> > > > fid = open('windx_siny.bin', 'wb')
> > > > tau_2.astype('float32').tofile(fid)
> > >
> > > Can you instead try Jeff's suggestion:
> > >
> > > tau_2.astype('>f4').tofile('windx_siny.bin')
> > >
> > > and NOT use the byteswap command? Mixing byteswap and astype
> > is a bad
> > > idea as byteswap will create a mismatch between the data in
> > memory and
> > > numpy's assumption of the data type.
> > >
> > > Best,
> > > Oliver
> > >
> > >
> > > > as you suggested, the plot still came out blank.
> > > > Regarding Jeffrey Scott's comment that the reason I
> > could not read
> > > back
> > > > the bin file was due to a mismatch between float32 and
> > float64, I
> > > > followed his advice and read in the
> > > > bin file using the snippet
> > > >
> > > > tau_2_1 = np.fromfile('windx_siny.bin',dtype='float32')
> > > >
> > > > and I got back an array with every entry being 'inf'
> except the
> > > > penultimate column, being all '0'.
> > > >
> > > > Is it possible that the snippet
> > > >
> > > > # X=X.astype('float128')
> > > > # Y=Y.astype('float128')
> > > >
> > > > (which is commented) needs to be included but with
> > 'float128' replaced
> > > > with 'float32'?
> > > >
> > > > Best
> > > > Jeremy
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > On Thu, 1 Apr 2021 at 16:47, Jan Klaus Rieck
> > > <jan.rieck at mail.mcgill.ca <mailto:jan.rieck at mail.mcgill.ca>
> > <mailto:jan.rieck at mail.mcgill.ca <mailto:jan.rieck at mail.mcgill.ca>>
> > > > <mailto:jan.rieck at mail.mcgill.ca
> > <mailto:jan.rieck at mail.mcgill.ca>
> > > <mailto:jan.rieck at mail.mcgill.ca
> > <mailto:jan.rieck at mail.mcgill.ca>>>> wrote:
> > > >
> > > > Hello Jeremy Miller,
> > > >
> > > > I also use python to to generate input data for the
> > MITgcm. I
> > > found
> > > > that, to generate files that can be read by the MITgcm
> > > consistently,
> > > > I needed to specify the type explicitly.
> > > > My way of saving the files would look like this in your
> > case:
> > > >
> > > > if sys.byteorder == 'little': tau_2.byteswap(True)
> > > > fid = open(''windx_siny.bin', 'wb')
> > > > tau_2.astype('float32').tofile(fid)
> > > >
> > > > Of course, 'float32' could be replaced by 'float64' if
> > you require
> > > > double precision.
> > > >
> > > > I hope this helps,
> > > > Jan Rieck
> > > >
> > > > On Thu, 2021-04-01 at 10:22 +0300, Jeremy Miller wrote:
> > > >> Dear MITGCM forum,
> > > >>
> > > >> I am Jeremy Miller, I am new to MITgcm and I've been
> going
> > > through
> > > >> the tutorials. I have a question about the "Barotropic
> > Ocean
> > > Gyre"
> > > >> tutorial (section 4.1).
> > > >>
> > > >> I managed to compile and run the code, and re-produce
> > the first
> > > >> two plots shown in section 4.1.5 for wind stress of τ
> > = τ0 cos(
> > > >> πy/Ly), for both the advection and non-advection cases
> > (with the
> > > >> provided input binary files).
> > > >> I ran into problems when trying to produce the third
> plot,
> > > for the
> > > >> case where τ = τ0 sin( πy/Ly). I am a python user, so I
> > > translated
> > > >> gendata.m into python to write the input binary
> > > >> files 'windx_cosy.bin' 'windx_siny.bin' (see the file
> > > >> gendata_tut4.1py attached). As explained in section
> > 3.9 I've
> > > >> included the snippet
> > > >>
> > > >> if sys.byteorder == 'little': tau_2.byteswap(True)
> > > >>
> > > >> where "tau2" is the array to be output. There was no
> > issue in the
> > > >> cosine wind stress, and I managed to reproduce the
> > results that I
> > > >> got with the original 'windx_cosy.bin' provided in the
> > tutorial.
> > > >> However, with the sine wind stress case, the output in
> > > >> 'Eta.0000077760.001.001' is all zeros.
> > > >>
> > > >> When I attempt to read 'windx_siny.bin' with python
> > into a new
> > > >> array called tau2_1. I get absurdly big numbers back,
> which
> > > do not
> > > >> match the original array tau2 that I created. If I
> > Remove the
> > > >> snippet " if sys.byteorder == 'little':
> > tau_2.byteswap(True)
> > > ", in
> > > >> the python gendata code, tau2_1 and tau2 match. But,
> > then when I
> > > >> run the code again, the file output.txt contains a long
> > list
> > > of NaNs.
> > > >>
> > > >> I have also included the python code used to generate
> the
> > > plots in
> > > >> the file tut_4.1_plots.py <http://tut_4.1_plots.py>
> > <http://tut_4.1_plots.py>
> > > <http://tut_4.1_plots.py/>
> > > >>
> > > >> Look forward to hearing from you.
> > > >> Yours sincerely
> > > >> Jeremy Miller
> > > >> _______________________________________________
> > > >> MITgcm-support mailing list
> > > >> MITgcm-support at mitgcm.org
> > <mailto:MITgcm-support at mitgcm.org> <mailto:MITgcm-support at mitgcm.org
> > <mailto:MITgcm-support at mitgcm.org>>
> > > >> <mailto:MITgcm-support at mitgcm.org
> > <mailto:MITgcm-support at mitgcm.org>
> > > <mailto:MITgcm-support at mitgcm.org
> > <mailto:MITgcm-support at mitgcm.org>>>
> > > >>
> > > >>
> http://mailman.mitgcm.org/mailman/listinfo/mitgcm-support
> > > >>
> > > > _______________________________________________
> > > > MITgcm-support mailing list
> > > > MITgcm-support at mitgcm.org
> > <mailto:MITgcm-support at mitgcm.org> <mailto:MITgcm-support at mitgcm.org
> > <mailto:MITgcm-support at mitgcm.org>>
> > > <mailto:MITgcm-support at mitgcm.org
> > <mailto:MITgcm-support at mitgcm.org> <mailto:MITgcm-support at mitgcm.org
> > <mailto:MITgcm-support at mitgcm.org>>>
> > > >
> http://mailman.mitgcm.org/mailman/listinfo/mitgcm-support
> > > >
> > > >
> > > > _______________________________________________
> > > > MITgcm-support mailing list
> > > > MITgcm-support at mitgcm.org <mailto:MITgcm-support at mitgcm.org>
> > <mailto:MITgcm-support at mitgcm.org <mailto:MITgcm-support at mitgcm.org
> >>
> > > > http://mailman.mitgcm.org/mailman/listinfo/mitgcm-support
> > > >
> > > _______________________________________________
> > > MITgcm-support mailing list
> > > MITgcm-support at mitgcm.org <mailto:MITgcm-support at mitgcm.org>
> > <mailto:MITgcm-support at mitgcm.org <mailto:MITgcm-support at mitgcm.org
> >>
> > > http://mailman.mitgcm.org/mailman/listinfo/mitgcm-support
> > >
> > >
> > > _______________________________________________
> > > MITgcm-support mailing list
> > > MITgcm-support at mitgcm.org <mailto:MITgcm-support at mitgcm.org>
> > > http://mailman.mitgcm.org/mailman/listinfo/mitgcm-support
> > >
> > _______________________________________________
> > MITgcm-support mailing list
> > MITgcm-support at mitgcm.org <mailto:MITgcm-support at mitgcm.org>
> > http://mailman.mitgcm.org/mailman/listinfo/mitgcm-support
> >
> >
> > _______________________________________________
> > MITgcm-support mailing list
> > MITgcm-support at mitgcm.org
> > http://mailman.mitgcm.org/mailman/listinfo/mitgcm-support
> >
> _______________________________________________
> MITgcm-support mailing list
> MITgcm-support at mitgcm.org
> http://mailman.mitgcm.org/mailman/listinfo/mitgcm-support
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.mitgcm.org/pipermail/mitgcm-support/attachments/20210404/8d6d3fd1/attachment-0001.html>
More information about the MITgcm-support
mailing list