[PYTHON] Creating a list when the nomenclature is a fixed time

Hello.

This time, previous article :: "Introduction of drawing code for figures with" degree of perfection "of meteorological data" I would like to introduce you.

Introduction

The meteorological data obtained from the Meteorological Business Support Center follows the format specified by the International Meteorological Organization (GRIB2 format).

These data are named at different times for each time resolution.

List creation code

This time we will share a useful list creation when the data is named at regular time intervals.

time_list.py



def preparating_data(self, yyyy, mm, dd, hh):
  time_list = []
  num_time_list = len(time_list)
	
  month_thirtyone = [ 1, 3, 5, 7, 8, 10, 12 ]
  month_thirty    = [ 4, 6, 9, 11 ]
  month_twntynine = [ 2 ]

  while num_time_list < 13:
     time_list.append(str(yyyy) + str('%02d' % mm) + str('%02d' % dd) + str('%02d' % hh) + '00')
     #Action to add 0 to 1 digit number
     hh = hh - 6

     if hh < 0 and dd == 1:
        mm, hh = mm - 1, 18
        if mm in month_thirty:
           dd = 30
     elif mm in month_thirtyone:
        dd = 31
     elif mm in month_twntynine:
     #Leap year consideration

        if yyyy % 4 == 0:
           dd = 28
        else:
           dd =29

     elif hh < 0:
        dd, hh = dd - 1, 18

     num_time_list += 1

return time_list

that's all.

Thank you for watching until the end.

reference

・ Read GRIB2 (weather binary data) by yourself without using a library in PHP https://qiita.com/miyawa-tarou/items/e4eff81dfcac527572e5

・ Meteorology x Python ~ National Synthetic Radar ~ https://qiita.com/OSAKO/items/ef042f80ec63dd288225

Recommended Posts

Creating a list when the nomenclature is a fixed time
When creating a matrix in a list
Embedding in datetime when only the time is known
Python list is not a list
The image is a slug
Precautions when creating a two-dimensional array with all the same values
A note when gcloud is broken
Precautions when using a list or dictionary as the default argument
On Linux, the time stamp of a file is a little past.
[Python] Execution time when a function is entered in a dictionary value
[Profile] Identify where the program is taking a long time (google-perftool)
Precautions when creating a Python generator
It is surprisingly troublesome to get a list of the last login date and time of Workspaces
A memo when creating an environment that can be debugged with Lambda @ Edge for the time being
[Introduction to Python] What is the difference between a list and a tuple?
[Python memo] Be careful when creating a two-dimensional array (list of lists)
A useful note when using Python for the first time in a while
What to do when a warning message is displayed in pip list
Change the list in a for statement
When the target is Ubuntu 16.04 in Ansible
[python] [meta] Is the type of python a type?
python: Creating a ramen timer (pyttsx3, time)
If branch depending on whether there is a specific element in the list
Differences in the behavior of each LL language when the list index is skipped
[Python] Solution to the problem that elements are linked when copying a list
Precautions when creating a view that narrows down records by date and time
A note on customizing the dict list class
DJango Memo: From the beginning (creating a view)
Make a histogram for the time being (matplotlib)
Get only the subclass elements in a list
A memo when creating a python environment with miniconda
Use the e-paper module as a to-do list
It's a Mac. What is the Linux command Linux?
A python amateur tries to summarize the list ②
Directions when operating Miniconda after a long time
virtualenv For the time being, this is all!
It is a piggybacking story about the service that returns "Nyan" when you ping
When a file is placed in the shared folder of Raspberry Pi, the process is executed.
Import audit.log into Splunk and check the behavior when Splunk is started for the first time
Send a push message to the LINE Bot when the LTE-M Button is pressed [SORACOM]
How to check in Python if one of the elements of a list is in another list
There is a pattern that the program did not stop when using Python threading
A command to check when something goes wrong when the server is not doing anything
[Caution] When creating a binary image (1bit / pixel), be aware of the file format!
When a local variable with the same name as a global variable is defined in the function