PCMDI / amipbcs

Code to generate boundary condition data for the AMIP experiment suite
2 stars 0 forks source link

Update fortran code calls to remove deprecated IO #14

Closed durack1 closed 5 years ago

durack1 commented 5 years ago

There is a need to modernize the process to generate these datasets, removing the dependence on the EzGet, lats and libdrs libraries. @pochedls has managed to achieve this using f2py and has a working example that requires validation

@taylor13 ping

doutriaux1 commented 5 years ago

@durack1 I agree, ezget is now cdms2/regrid2, lats can be replaced by cdms or cmor. The "pure" fortran can be indeed converted with numpy, but could very well be rewritten in pure python, maybe even improved via dask if speed is an issue.

durack1 commented 5 years ago

@pochedls code added to issue14_durack1_UpdateFortranCodeCalls

@doutriaux1 @pochedls has pulled out the guts of the mkhurrell1.f code and dropped it into a function that is being called by f2py. I have this issue as a placeholder to evaluate the output from this python version vs the original fortran.

pochedls commented 5 years ago

@doutriaux1 + @durack1 + @taylor13

The mkhurrell1.f code would take some time to rewrite in Python, because it is fairly complicated. While most of the mkhurrell.f functionality can be encapsulated in a few lines as a linear algebra solver, most of the lines of code deal with special / weird cases in which the simple solution does non-physical things.

@durack1 - the compile script + f2py compiles and creates an interface to the fortran code, which is then called in the simple wrapper example I sent you.

pochedls commented 5 years ago

@doutriaux1 + @durack1 + @taylor13

One other issue in case there is desire to fix this. This code is in fortran77, which required hardcoding the time series length. This could be problematic if someone wanted to "diddle" a really long time series. It might be possible to make the time series length allocatable, by updating the code to fortran 90 or re-writing it.

taylor13 commented 5 years ago

Another thing to consider: the fortran code performs a number of useful diagnostics on the data, which, for example, estimate the underestimation of variability that occurs if you simply interpolate the monthly mean values (rather than mid-point values). Do we want a new code with that capability?

durack1 commented 5 years ago

To get things working today, I had to follow the notes in https://github.com/CDAT/cd77/issues/4#issuecomment-511505613

taylor13 commented 5 years ago

@pochedls, @durack1, and I have now successfully extracted guts (the relevant fortran coding) and packaged them with a python driver that is responsible for the I/O. In addition to the newly written python code, notable changes to the fortran were:

  1. making the local arrays (length = length of monthly time series) allocatable, rather than hard-wired.
  2. improving the diagnostics if the solver is unable to converge
  3. Removing some unneeded code (see https://github.com/PCMDI/amipbcs/issues/16 )

Left to do: annotate the code with better documentation.